Upload new version

This commit is contained in:
2026-01-20 01:12:22 +01:00
parent abd74a9a50
commit 3d559924a9
15 changed files with 1632 additions and 517 deletions

View File

@@ -1,8 +1,7 @@
import { apiList, apiCreate, toast } from './api.js';
import { apiAction, toast } from './api.js';
export function initCreate(){
const btn=document.getElementById('btn-new'), dlg=document.getElementById('createDialog'), form=document.getElementById('createForm'), fields=document.getElementById('createFields'), hint=document.getElementById('createHint');
if(!btn||!dlg||!form||!fields) return;
const curTab=()=>{ const a=document.querySelector('nav [data-tab].bg-sky-50')||document.querySelector('nav [data-tab]'); return a?a.getAttribute('data-tab'):'templates'; };
const normalizeApiName=(v='')=>{
return String(v)
.trim()
@@ -14,7 +13,13 @@ export function initCreate(){
};
btn.onclick = async ()=>{
fields.innerHTML=''; const tab=curTab();
const section = window.__activeSection || null;
if (!section) {
toast('Bitte zuerst eine Section auswählen', false);
return;
}
const isTemplate = Number(section.is_template) === 1;
fields.innerHTML='';
const name=document.createElement('input'); name.type='text'; name.required=true; name.placeholder='Name*'; name.className='w-full border rounded-lg px-3 py-2'; name.id='f-name'; fields.appendChild(name);
let apiName = null;
let apiTouched = false;
@@ -31,7 +36,7 @@ export function initCreate(){
fields.appendChild(editorSelect);
};
if(tab==='templates'){
if(isTemplate){
apiName=document.createElement('input');
apiName.type='text';
apiName.required=true;
@@ -49,25 +54,27 @@ export function initCreate(){
if (!apiTouched) apiName.value = normalizeApiName(name.value);
});
}
async function addSel(id,label,res){ const sel=document.createElement('select'); sel.id=id; sel.className='w-full border rounded-lg px-3 py-2'; sel.innerHTML=`<option value="">(ohne ${label}-Zuordnung)</option>`; const data=await apiList(res); (data||[]).forEach(t=>{ const o=document.createElement('option'); o.value=t.id; o.textContent=`#${t.id} · ${t.name||''}`; sel.appendChild(o); }); fields.appendChild(sel); }
if(tab==='sections') await addSel('f-template','Template','templates');
if(tab==='blocks') await addSel('f-section','Section','sections');
if(tab==='snippets') await addSel('f-block','Block','blocks');
if (tab !== 'templates') addEditorSelect();
hint.textContent=`Neues ${tab} anlegen`; dlg.showModal();
if (!isTemplate) addEditorSelect();
hint.textContent=`Neues Element in ${section.name}`; dlg.showModal();
form.onsubmit=async(e)=>{ e.preventDefault();
const payload={ name:(document.getElementById('f-name')?.value||'').trim() }; if(!payload.name) return;
if(tab==='templates') {
if(isTemplate) {
payload.api_name=(document.getElementById('f-api-name')?.value||'').trim();
if(!payload.api_name) return;
}
payload.editor_type=(document.getElementById('f-editor-type')?.value||'grapesjs');
if(tab==='snippets') payload.content=''; else payload.html='';
if(tab==='sections') payload.template_id=document.getElementById('f-template')?.value||null;
if(tab==='blocks') payload.section_id =document.getElementById('f-section')?.value ||null;
if(tab==='snippets') payload.block_id =document.getElementById('f-block')?.value ||null;
const r=await apiCreate(tab,payload); if(r&&r.id){ dlg.close(); toast('Erstellt',true); window.loadList && window.loadList(tab); } else { toast('Erstellen fehlgeschlagen',false,{duration:3000}); console.error('Create failed',r); }
payload.html='';
payload.section_id = section.id;
const r=await apiAction('content.create', { method:'POST', data: payload });
if(r&&r.id){
dlg.close();
toast('Erstellt',true);
window.loadList && window.loadList(section);
} else {
toast('Erstellen fehlgeschlagen',false,{duration:3000});
console.error('Create failed',r);
}
};
};
const cancel=document.getElementById('createCancel'); cancel && (cancel.onclick=()=>dlg.close());