Warnung deaktivierung Template

This commit is contained in:
2026-02-01 01:26:47 +01:00
parent b376a92007
commit 1709ae6551
4 changed files with 141 additions and 1 deletions

View File

@@ -1060,6 +1060,16 @@ export function initEditor() {
}
}
async function confirmTemplateReferences(actionLabel) {
if (!current?.section?.is_template || !current?.id) return true;
const res = await apiAction('templates.references', { method: 'GET', data: { template_id: current.id } }).catch(() => ({}));
const refs = Array.isArray(res?.references) ? res.references : [];
if (!refs.length) return true;
const preview = refs.slice(0, 6).map(r => `${r.name || 'Template'} #${r.id}`).join(', ');
const more = refs.length > 6 ? ` und ${refs.length - 6} weitere` : '';
return confirm(`Dieses Template wird in ${refs.length} anderen Template(s) verwendet (${preview}${more}). ${actionLabel} trotzdem?`);
}
// Buttons
btnSave && (btnSave.onclick = save);
btnClear && (btnClear.onclick = clearEditor);
@@ -1086,6 +1096,8 @@ export function initEditor() {
if (!current?.id) return;
if (!currentVersionMeta || Number(currentVersionMeta.is_active) !== 1) return;
try {
const okRefs = await confirmTemplateReferences('Deaktivieren');
if (!okRefs) return;
const res = await apiAction('content_versions.deactivate', { method: 'POST', data: { content_id: current.id } });
if (!res?.ok) throw new Error(res?.error || 'Deaktivieren fehlgeschlagen');
await loadVersionsForCurrent({ keepSelection: true, preferredId: currentVersionId });