This commit is contained in:
2026-01-16 02:46:28 +01:00
parent 9d33f15e19
commit 8bc927bfcd

View File

@@ -34,47 +34,21 @@ function normalizeApiName(v=''){
}
async function openSnippetEditor(id){
const dlg = document.getElementById('editSnippetDialog');
const form = document.getElementById('editSnippetForm');
const inpName = document.getElementById('edit_snip_name');
const taContent = document.getElementById('edit_snip_content');
const btnCancel = document.getElementById('editSnippetCancel');
// Daten laden
let resp = {};
try { resp = await apiGet('snippets', id) || {}; } catch(e){}
const row = resp?.item || resp?.data || resp || {};
const contentValue = (row?.content ?? resp?.html ?? resp?.content ?? '');
const name = row?.name || '';
if (inpName) inpName.value = row.name || '';
if (taContent) taContent.value = contentValue;
function cleanup(){
form && form.removeEventListener('submit', onSubmit);
btnCancel && (btnCancel.onclick = null);
if (window.EditorUI && typeof window.EditorUI.open === 'function') {
window.EditorUI.open({ id: Number(id), name }, 'snippets');
return;
}
async function onSubmit(ev){
ev.preventDefault();
try{
const res = await apiUpdate('snippets', id, {
name: inpName ? inpName.value : '',
content: taContent ? taContent.value : ''
});
toast(res && res.ok ? 'Snippet gespeichert' : 'Speichern fehlgeschlagen', !!(res && res.ok));
dlg && dlg.close();
cleanup();
// Liste neu laden
loadList('snippets');
}catch(e){
toast('Speichern fehlgeschlagen', false);
}
if (window.__openEditor) {
window.__openEditor({ resource: 'snippets', id: Number(id), name });
return;
}
if (form) form.addEventListener('submit', onSubmit, { once:false });
if (btnCancel) btnCancel.onclick = () => { dlg && dlg.close(); cleanup(); };
dlg && dlg.showModal();
console.warn('Kein Editor-Entry-Point gefunden (EditorUI.open / __openEditor).');
toast('Editor ist nicht initialisiert.', false);
}
async function openTemplateEditor(id){
@@ -166,7 +140,7 @@ export async function loadList(resource){
? `<button class='btn' data-open='${resource}:${item.id}'>Im E-Mail-Editor öffnen</button>` : '';
const editBtn = (resource==='snippets')
? `<button class='btn' data-edit='snippets:${item.id}'>Bearbeiten</button>` : '';
? `<button class='btn' data-edit='snippets:${item.id}'>Im Editor</button>` : '';
const editTplBtn = (resource==='templates')
? `<button class='btn' data-edit='templates:${item.id}'>Bearbeiten</button>` : '';