diff --git a/public/assets/js/ui-list.js b/public/assets/js/ui-list.js index 45f2f54..e8c1681 100644 --- a/public/assets/js/ui-list.js +++ b/public/assets/js/ui-list.js @@ -68,7 +68,6 @@ async function openTemplateManager(item, section) { const badge = document.getElementById('manage_tpl_badge'); const versionsWrap = document.getElementById('manage_tpl_versions'); const btnClose = document.getElementById('manageTemplateClose'); - const btnSave = document.getElementById('manageTemplateSave'); const btnDelete = document.getElementById('manageTemplateDelete'); const deleteHint = document.getElementById('manage_tpl_delete_hint'); const delDlg = document.getElementById('deleteDialog'); @@ -140,15 +139,8 @@ async function openTemplateManager(item, section) { } }; - const cleanup = () => { - inpApiName && inpApiName.removeEventListener('input', onApiInput); - versionsWrap && versionsWrap.removeEventListener('click', onVersionsClick); - if (btnClose) btnClose.onclick = null; - if (btnSave) btnSave.onclick = null; - if (btnDelete) btnDelete.onclick = null; - }; - - const onSave = async () => { + let autoSaveTimer = null; + const autoSave = async () => { try { const payload = { name: inpName ? inpName.value : '', @@ -158,12 +150,29 @@ async function openTemplateManager(item, section) { payload.api_name = inpApiName ? inpApiName.value : ''; } const res = await apiUpdate('content', item.id, payload); - toast(res && res.ok ? 'Gespeichert' : 'Speichern fehlgeschlagen', !!(res && res.ok)); if (res?.ok && typeof window.loadList === 'function') window.loadList(section); + if (!res?.ok) toast(res?.error || 'Speichern fehlgeschlagen', false); } catch { toast('Speichern fehlgeschlagen', false); } }; + const scheduleAutoSave = () => { + if (autoSaveTimer) clearTimeout(autoSaveTimer); + autoSaveTimer = setTimeout(autoSave, 450); + }; + + const cleanup = () => { + inpApiName && inpApiName.removeEventListener('input', onApiInput); + inpName && inpName.removeEventListener('input', scheduleAutoSave); + inpApiName && inpApiName.removeEventListener('input', scheduleAutoSave); + versionsWrap && versionsWrap.removeEventListener('click', onVersionsClick); + if (btnClose) btnClose.onclick = null; + if (btnDelete) btnDelete.onclick = null; + if (autoSaveTimer) { + clearTimeout(autoSaveTimer); + autoSaveTimer = null; + } + }; const onDeleteItem = async () => { if (activeId) return; @@ -230,8 +239,9 @@ async function openTemplateManager(item, section) { }; inpApiName && inpApiName.addEventListener('input', onApiInput); + inpName && inpName.addEventListener('input', scheduleAutoSave); + inpApiName && inpApiName.addEventListener('input', scheduleAutoSave); btnClose && (btnClose.onclick = () => { dlg && dlg.close(); cleanup(); }); - btnSave && (btnSave.onclick = onSave); btnDelete && (btnDelete.onclick = onDeleteItem); versionsWrap && versionsWrap.addEventListener('click', onVersionsClick); diff --git a/public/index.php b/public/index.php index 3e8be81..8c146d0 100644 --- a/public/index.php +++ b/public/index.php @@ -169,7 +169,6 @@ require __DIR__ . '/../partials/structure/layout_start.php'; ID –