diff --git a/public/assets/js/ui-editor.js b/public/assets/js/ui-editor.js index 269da7e..93c6f77 100644 --- a/public/assets/js/ui-editor.js +++ b/public/assets/js/ui-editor.js @@ -18,6 +18,7 @@ export function initEditor() { const sendForm = document.getElementById('sendTestForm'); const sendTo = document.getElementById('send_to'); const sendSubject = document.getElementById('send_subject'); + const sendInfo = document.getElementById('send_template_info'); const btnCancelSend= document.getElementById('btn-cancel-send'); const btnSendNow = document.getElementById('btn-send-now'); const prevFrame = document.getElementById('previewFrame'); @@ -36,6 +37,27 @@ export function initEditor() { return (b?.dataset?.tab) || (current?.resource) || 'templates'; } + function setSendContext(id, name = '') { + if (sendDlg) { + if (id) { + sendDlg.dataset.templateId = String(id); + } else { + delete sendDlg.dataset.templateId; + } + if (name) sendDlg.dataset.templateName = name; + } + if (sendInfo) { + if (!id) { + sendInfo.textContent = 'Kein Template ausgewählt.'; + sendInfo.classList.add('text-rose-600'); + } else { + const label = name ? `${name} – Template #${id}` : `Template #${id}`; + sendInfo.textContent = label; + sendInfo.classList.remove('text-rose-600'); + } + } + } + function writeHtmlToFrame(html) { iframe.srcdoc = `
@@ -246,6 +268,8 @@ export function initEditor() { // globaler Kontext window.__currentItemId = current.id; window.__currentEditorCtx = { id: current.id, mode: current.resource }; + setSendContext(current.id, current.name); + if (btnTest) btnTest.classList.toggle('hidden', current.resource !== 'templates'); // Neuen Token erzeugen & alten Listener entfernen reqToken++; @@ -388,24 +412,32 @@ export function initEditor() { prevDlg?.showModal?.(); } - async function openSend() { - sendSubject.value = 'Testversand'; - sendTo.value = ''; + async function openSend(ctx = null) { + const ctxId = ctx?.id ? Number(ctx.id) : (window.__currentItemId || current?.id || 0); + if (!ctxId) { + err('Kein Template geladen'); + return; + } + window.__currentItemId = ctxId; + const ctxName = ctx?.name ?? sendDlg?.dataset?.templateName ?? current?.name ?? ''; + setSendContext(ctxId, ctxName); + if (sendSubject) sendSubject.value = ctx?.subject || 'Testversand'; + if (sendTo) sendTo.value = ctx?.to || ''; sendDlg?.showModal?.(); } function closeSend(){ sendDlg?.close?.(); } async function doSend(ev){ ev?.preventDefault?.(); - const to = sendTo.value.trim(); - if(!to){ toast("Bitte Empfänger angeben", false); return; } + const to = (sendTo?.value || '').trim(); + if(!to){ err('Bitte Empfänger angeben'); return; } const win = iframe?.contentWindow; const ctx = (win && win.__currentEditorCtx) || {}; const id = (window.__currentItemId || ctx?.id || 0); if(!id){ toast("Kein Template geladen", false); return; } // Hier wird der gespeicherte HTML-Code verwendet, nicht der Live-HTML, da apiAction // keine Live-Daten erwartet. Es geht um template_id. - const r = await apiAction('templates.test_send', { method:'POST', data:{ template_id: id, to, subject: sendSubject.value || 'Testversand' } }); + const r = await apiAction('templates.test_send', { method:'POST', data:{ template_id: id, to, subject: (sendSubject?.value || 'Testversand') } }); if(r?.ok){ toast("Testversand ausgelöst"); closeSend(); } else { toast("Senden fehlgeschlagen", false); } } function closePreview(){ prevDlg?.close?.(); } @@ -440,6 +472,18 @@ export function initEditor() { btnCancelSend&& (btnCancelSend.onclick= closeSend); sendForm && (sendForm.onsubmit = doSend); + window.AdminTestSend = window.AdminTestSend || {}; + window.AdminTestSend.open = (opts = {}) => { + const targetId = Number(opts.id || window.__currentItemId || 0); + if (!targetId) { + err('Testversand: Keine ID vorhanden'); + return; + } + window.__currentItemId = targetId; + setSendContext(targetId, opts.name || ''); + openSend({ id: targetId, name: opts.name || '' }); + }; + // Public API window.EditorUI = { open, save, close, clear: clearEditor, preview: openPreview }; } diff --git a/public/assets/js/ui-list.js b/public/assets/js/ui-list.js index ecdeb18..03e0401 100644 --- a/public/assets/js/ui-list.js +++ b/public/assets/js/ui-list.js @@ -97,6 +97,9 @@ export async function loadList(resource){ const editBtn = (resource==='snippets') ? `` : ''; + const testBtn = resource==='templates' + ? `` : ''; + const prevBtn = ``; const delBtn = ``; @@ -104,7 +107,7 @@ export async function loadList(resource){