Sync widget copy translations on save
This commit is contained in:
+39
-12
@@ -128,6 +128,8 @@ $("#onlineToggle").addEventListener("change", async () => {
|
||||
|
||||
$("#settingsForm").addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const submitButton = event.currentTarget.querySelector("button[type='submit']");
|
||||
setSettingsSaveStatus("saving", "Ukládám...");
|
||||
const form = new FormData(event.currentTarget);
|
||||
const settings = structuredClone(state.site.settings);
|
||||
const defaultLanguage = form.get("defaultLanguage") || "cs";
|
||||
@@ -148,10 +150,10 @@ $("#settingsForm").addEventListener("submit", async (event) => {
|
||||
onlineLabel: form.get("copyOnlineLabel") || "",
|
||||
offlineLabel: settings.widgetCopy[defaultLanguage]?.offlineLabel || "Offline",
|
||||
newReplyLabel: form.get("copyNewReplyLabel") || "",
|
||||
typingLabel: settings.widgetCopy[defaultLanguage]?.typingLabel || "Operator pise...",
|
||||
typingLabel: settings.widgetCopy[defaultLanguage]?.typingLabel || "Operátor píše...",
|
||||
infoTitle: settings.widgetCopy[defaultLanguage]?.infoTitle || "GDPR informace",
|
||||
infoText: form.get("copyInfoText") || "",
|
||||
closeLabel: settings.widgetCopy[defaultLanguage]?.closeLabel || "Zmensit chat",
|
||||
closeLabel: settings.widgetCopy[defaultLanguage]?.closeLabel || "Zmenšit chat",
|
||||
operatorReplyLabel: form.get("copyOperatorReplyLabel") || ""
|
||||
};
|
||||
syncLegacyWidgetCopy(settings);
|
||||
@@ -173,8 +175,25 @@ $("#settingsForm").addEventListener("submit", async (event) => {
|
||||
settings.notifications.badgeOnAdminReply = form.get("messageBadge") === "on";
|
||||
settings.notifications.labelOnAdminReply = form.get("messageLabel") === "on";
|
||||
settings.notifications.wiggleOnAdminReply = form.get("messageWiggle") === "on";
|
||||
await saveSite({ settings, isOnline: state.site.isOnline });
|
||||
$("#settingsPanel").classList.add("hidden");
|
||||
submitButton.disabled = true;
|
||||
try {
|
||||
setSettingsSaveStatus("translating", "Překládám...");
|
||||
const data = await saveSite({ settings, isOnline: state.site.isOnline });
|
||||
renderWidgetCopyFields(state.site.settings.widgetLanguage?.defaultLanguage || defaultLanguage);
|
||||
const sync = data.widgetCopySync;
|
||||
if (sync?.errors?.length) {
|
||||
const failedLanguages = [...new Set(sync.errors.map((item) => item.language?.toUpperCase()).filter(Boolean))];
|
||||
setSettingsSaveStatus("warning", `Uloženo, překlad selhal: ${failedLanguages.join(", ") || "AI"}`);
|
||||
return;
|
||||
}
|
||||
if (sync?.translated) setSettingsSaveStatus("saved", `✓ Uloženo a přeloženo`);
|
||||
else setSettingsSaveStatus("saved", "✓ Uloženo");
|
||||
setTimeout(() => $("#settingsPanel").classList.add("hidden"), 700);
|
||||
} catch (error) {
|
||||
setSettingsSaveStatus("error", "Akce se nepodařila.");
|
||||
} finally {
|
||||
submitButton.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
$("#replyForm").addEventListener("submit", async (event) => {
|
||||
@@ -493,16 +512,16 @@ function defaultWidgetCopy(language) {
|
||||
};
|
||||
}
|
||||
return {
|
||||
title: "Potrebujete poradit?",
|
||||
intro: "Napiste nam. Odpovime co nejdrive.",
|
||||
offlineIntro: "Ted nejsme online, ale zpravu nam muzete nechat.",
|
||||
placeholder: "Napiste zpravu...",
|
||||
title: "Potřebujete poradit?",
|
||||
intro: "Napište nám. Odpovíme co nejdříve.",
|
||||
offlineIntro: "Teď nejsme online, ale zprávu nám můžete nechat.",
|
||||
placeholder: "Napište zprávu...",
|
||||
sendLabel: "Odeslat",
|
||||
dropzoneLabel: "Pridat fotku nebo pretahnout",
|
||||
dropzoneLabel: "Přidat fotku nebo přetáhnout",
|
||||
onlineLabel: "Jsme online",
|
||||
newReplyLabel: "Nova odpoved",
|
||||
infoText: "Zpravu a technicke udaje relace zpracujeme jen pro odpoved na vas dotaz.",
|
||||
operatorReplyLabel: "odpovida"
|
||||
newReplyLabel: "Nová odpověď",
|
||||
infoText: "Zprávu a technické údaje relace zpracujeme jen pro odpověď na váš dotaz.",
|
||||
operatorReplyLabel: "odpovídá"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1230,6 +1249,14 @@ async function saveSite(patch) {
|
||||
state.site = data.site;
|
||||
state.snippet = data.snippet;
|
||||
renderSite();
|
||||
return data;
|
||||
}
|
||||
|
||||
function setSettingsSaveStatus(type, text) {
|
||||
const status = $("#settingsSaveStatus");
|
||||
if (!status) return;
|
||||
status.className = `settings-save-status ${type || ""}`.trim();
|
||||
status.textContent = text || "";
|
||||
}
|
||||
|
||||
function notify() {
|
||||
|
||||
Reference in New Issue
Block a user