Add widget settings save button

This commit is contained in:
rajchales-monito
2026-07-30 16:56:29 +02:00
parent 0f3c608d86
commit 1a6eaa69fe
2 changed files with 16 additions and 8 deletions
+5 -1
View File
@@ -145,7 +145,7 @@
<label>Info/GDPR <textarea name="copyInfoText" rows="2"></textarea></label> <label>Info/GDPR <textarea name="copyInfoText" rows="2"></textarea></label>
<div class="settings-actions"> <div class="settings-actions">
<button type="submit">Uložit a přeložit</button> <button type="submit">Uložit a přeložit</button>
<span id="settingsSaveStatus" class="settings-save-status" aria-live="polite"></span> <span id="settingsSaveStatus" class="settings-save-status" data-settings-save-status aria-live="polite"></span>
</div> </div>
</fieldset> </fieldset>
<label class="color-field">Barva <label class="color-field">Barva
@@ -181,6 +181,10 @@
<label><input name="messageLabel" type="checkbox"> kratky stitek</label> <label><input name="messageLabel" type="checkbox"> kratky stitek</label>
<label><input name="messageWiggle" type="checkbox"> zhoupnuti</label> <label><input name="messageWiggle" type="checkbox"> zhoupnuti</label>
</fieldset> </fieldset>
<div class="settings-actions">
<button type="submit">Ulozit widget</button>
<span class="settings-save-status" data-settings-save-status aria-live="polite"></span>
</div>
</form> </form>
<h3>GTM snippet</h3> <h3>GTM snippet</h3>
<pre id="snippet"></pre> <pre id="snippet"></pre>
+9 -5
View File
@@ -168,7 +168,7 @@ $("#onlineToggle").addEventListener("change", async () => {
$("#settingsForm").addEventListener("submit", async (event) => { $("#settingsForm").addEventListener("submit", async (event) => {
event.preventDefault(); event.preventDefault();
const submitButton = event.currentTarget.querySelector("button[type='submit']"); const submitButtons = [...event.currentTarget.querySelectorAll("button[type='submit']")];
setSettingsSaveStatus("saving", "Ukládám..."); setSettingsSaveStatus("saving", "Ukládám...");
const form = new FormData(event.currentTarget); const form = new FormData(event.currentTarget);
const settings = structuredClone(state.site.settings); const settings = structuredClone(state.site.settings);
@@ -215,7 +215,9 @@ $("#settingsForm").addEventListener("submit", async (event) => {
settings.notifications.badgeOnAdminReply = form.get("messageBadge") === "on"; settings.notifications.badgeOnAdminReply = form.get("messageBadge") === "on";
settings.notifications.labelOnAdminReply = form.get("messageLabel") === "on"; settings.notifications.labelOnAdminReply = form.get("messageLabel") === "on";
settings.notifications.wiggleOnAdminReply = form.get("messageWiggle") === "on"; settings.notifications.wiggleOnAdminReply = form.get("messageWiggle") === "on";
submitButton.disabled = true; submitButtons.forEach((button) => {
button.disabled = true;
});
try { try {
setSettingsSaveStatus("translating", "Překládám..."); setSettingsSaveStatus("translating", "Překládám...");
const data = await saveSite({ settings, isOnline: state.site.isOnline }); const data = await saveSite({ settings, isOnline: state.site.isOnline });
@@ -232,7 +234,9 @@ $("#settingsForm").addEventListener("submit", async (event) => {
} catch (error) { } catch (error) {
setSettingsSaveStatus("error", "Akce se nepodařila."); setSettingsSaveStatus("error", "Akce se nepodařila.");
} finally { } finally {
submitButton.disabled = false; submitButtons.forEach((button) => {
button.disabled = false;
});
} }
}); });
@@ -1615,10 +1619,10 @@ async function saveSite(patch) {
} }
function setSettingsSaveStatus(type, text) { function setSettingsSaveStatus(type, text) {
const status = $("#settingsSaveStatus"); for (const status of document.querySelectorAll("[data-settings-save-status]")) {
if (!status) return;
status.className = `settings-save-status ${type || ""}`.trim(); status.className = `settings-save-status ${type || ""}`.trim();
status.textContent = text || ""; status.textContent = text || "";
}
} }
function notify() { function notify() {