This commit is contained in:
2026-01-19 00:45:41 +01:00
parent 6cae9eaab2
commit b25ca61f07
3 changed files with 19 additions and 10 deletions

View File

@@ -18,14 +18,7 @@ export function initCreate(){
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;
if(tab==='templates'){
apiName=document.createElement('input');
apiName.type='text';
apiName.required=true;
apiName.placeholder='API Name* (ohne Leerzeichen)';
apiName.className='w-full border rounded-lg px-3 py-2';
apiName.id='f-api-name';
fields.appendChild(apiName);
const addEditorSelect = () => {
const editorSelect = document.createElement('select');
editorSelect.id = 'f-editor-type';
editorSelect.className = 'w-full border rounded-lg px-3 py-2';
@@ -36,6 +29,17 @@ export function initCreate(){
const defaultEditor = (window.__editorDefault || 'grapesjs').toLowerCase();
editorSelect.value = defaultEditor === 'craftjs' ? 'craftjs' : 'grapesjs';
fields.appendChild(editorSelect);
};
if(tab==='templates'){
apiName=document.createElement('input');
apiName.type='text';
apiName.required=true;
apiName.placeholder='API Name* (ohne Leerzeichen)';
apiName.className='w-full border rounded-lg px-3 py-2';
apiName.id='f-api-name';
fields.appendChild(apiName);
addEditorSelect();
apiName.addEventListener('input', ()=>{
apiTouched = true;
const next = normalizeApiName(apiName.value);
@@ -49,6 +53,7 @@ export function initCreate(){
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();
form.onsubmit=async(e)=>{ e.preventDefault();
@@ -56,8 +61,8 @@ export function initCreate(){
if(tab==='templates') {
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');
}
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;