asd
This commit is contained in:
@@ -34,47 +34,21 @@ function normalizeApiName(v=''){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function openSnippetEditor(id){
|
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 = {};
|
let resp = {};
|
||||||
try { resp = await apiGet('snippets', id) || {}; } catch(e){}
|
try { resp = await apiGet('snippets', id) || {}; } catch(e){}
|
||||||
const row = resp?.item || resp?.data || resp || {};
|
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 (window.EditorUI && typeof window.EditorUI.open === 'function') {
|
||||||
if (taContent) taContent.value = contentValue;
|
window.EditorUI.open({ id: Number(id), name }, 'snippets');
|
||||||
|
return;
|
||||||
function cleanup(){
|
|
||||||
form && form.removeEventListener('submit', onSubmit);
|
|
||||||
btnCancel && (btnCancel.onclick = null);
|
|
||||||
}
|
}
|
||||||
|
if (window.__openEditor) {
|
||||||
async function onSubmit(ev){
|
window.__openEditor({ resource: 'snippets', id: Number(id), name });
|
||||||
ev.preventDefault();
|
return;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
console.warn('Kein Editor-Entry-Point gefunden (EditorUI.open / __openEditor).');
|
||||||
if (form) form.addEventListener('submit', onSubmit, { once:false });
|
toast('Editor ist nicht initialisiert.', false);
|
||||||
if (btnCancel) btnCancel.onclick = () => { dlg && dlg.close(); cleanup(); };
|
|
||||||
|
|
||||||
dlg && dlg.showModal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openTemplateEditor(id){
|
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>` : '';
|
? `<button class='btn' data-open='${resource}:${item.id}'>Im E-Mail-Editor öffnen</button>` : '';
|
||||||
|
|
||||||
const editBtn = (resource==='snippets')
|
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')
|
const editTplBtn = (resource==='templates')
|
||||||
? `<button class='btn' data-edit='templates:${item.id}'>Bearbeiten</button>` : '';
|
? `<button class='btn' data-edit='templates:${item.id}'>Bearbeiten</button>` : '';
|
||||||
|
|||||||
Reference in New Issue
Block a user