diff --git a/admin/DashboardController.php b/admin/DashboardController.php index 039df60..c5fbac6 100644 --- a/admin/DashboardController.php +++ b/admin/DashboardController.php @@ -3337,11 +3337,28 @@ function addNew(type) { } else if (type === 'menu') { showModal(\`

➕ Nuevo Menú

-
-
-
-
-
+
+
+ +
+
+
+
+
+
Botones (máx 3):
+
+ +
+
@@ -3387,18 +3404,48 @@ function saveNewCommand() { saveConfig(); } +function newMenuTypeToggle() { + const isBtn = document.getElementById('newMenuType').value === 'button'; + document.getElementById('newMenuBtnArea').style.display = isBtn ? '' : 'none'; + document.getElementById('newMenuListArea').style.display = isBtn ? 'none' : ''; +} + +function addNewMenuBtnRow() { + const cont = document.getElementById('newMenuBtnRows'); + const bi = cont.querySelectorAll('.new-btn-row').length; + const div = document.createElement('div'); + div.className = 'new-btn-row'; + div.style.cssText = 'display:flex;gap:6px;margin-bottom:4px'; + div.innerHTML = \` + + \`; + cont.appendChild(div); +} + function saveNewMenu() { const key = document.getElementById('newMenuKey').value.trim(); if (!key) { alert('El ID del menú es requerido'); return; } if (CONFIG.menus[key]) { alert('El menú "' + key + '" ya existe'); return; } - CONFIG.menus[key] = { - type: 'list', - header: document.getElementById('newMenuHeader').value.trim(), - body: document.getElementById('newMenuBody').value.trim(), - footer: document.getElementById('newMenuFooter').value.trim(), - button: document.getElementById('newMenuButton').value.trim() || 'Menú', - sections: [] - }; + const menuType = document.getElementById('newMenuType').value; + const body = document.getElementById('newMenuBody').value.trim(); + if (menuType === 'button') { + const buttons = []; + document.getElementById('newMenuBtnRows').querySelectorAll('.new-btn-row').forEach((row, bi) => { + const id = (row.querySelector('.nbtn-id-' + bi) || row.querySelector('input:first-child'))?.value?.trim(); + const title = (row.querySelector('.nbtn-title-' + bi) || row.querySelector('input:nth-child(2)'))?.value?.trim(); + if (id && title) buttons.push({ id, title: title.substring(0, 20) }); + }); + CONFIG.menus[key] = { type: 'button', body, buttons }; + } else { + CONFIG.menus[key] = { + type: 'list', + header: document.getElementById('newMenuHeader')?.value?.trim() || '', + body, + footer: document.getElementById('newMenuFooter')?.value?.trim() || '', + button: document.getElementById('newMenuButton')?.value?.trim() || 'Ver opciones', + sections: [] + }; + } hideModal(); saveConfig(); } @@ -3442,20 +3489,28 @@ function saveConfig() { // Menus let mi = 0; Object.entries(fullConfig.menus || {}).forEach(([mk, menu]) => { + const mtype = menu.type || 'button'; fd.append('menu_key[]', mk); - fd.append('menu_type[]', menu.type || 'list'); - fd.append('menu_header[]', menu.header || ''); + fd.append('menu_type[]', mtype); fd.append('menu_body[]', menu.body || ''); - fd.append('menu_footer[]', menu.footer || ''); - fd.append('menu_button[]', menu.button || 'Menú'); - (menu.sections || []).forEach((section, si) => { - fd.append('menu_sections[' + mi + '][' + si + '][title]', section.title); - (section.rows || []).forEach((row, ri) => { - fd.append('menu_sections[' + mi + '][' + si + '][rows][' + ri + '][id]', row.id); - fd.append('menu_sections[' + mi + '][' + si + '][rows][' + ri + '][title]', row.title); - fd.append('menu_sections[' + mi + '][' + si + '][rows][' + ri + '][description]', row.description || ''); + if (mtype === 'button') { + (menu.buttons || []).forEach((btn, bi) => { + fd.append('menu_btn_id[' + mi + '][]', btn.id || ''); + fd.append('menu_btn_title[' + mi + '][]', btn.title || ''); }); - }); + } else { + fd.append('menu_header[]', menu.header || ''); + fd.append('menu_footer[]', menu.footer || ''); + fd.append('menu_button[]', menu.button || 'Ver opciones'); + (menu.sections || []).forEach((section, si) => { + fd.append('menu_sections[' + mi + '][' + si + '][title]', section.title); + (section.rows || []).forEach((row, ri) => { + fd.append('menu_sections[' + mi + '][' + si + '][rows][' + ri + '][id]', row.id); + fd.append('menu_sections[' + mi + '][' + si + '][rows][' + ri + '][title]', row.title); + fd.append('menu_sections[' + mi + '][' + si + '][rows][' + ri + '][description]', row.description || ''); + }); + }); + } mi++; }); @@ -3600,13 +3655,17 @@ HTML; echo '
'; } - // ── Render orphan flows (not linked by any menu row) ── + // ── Render orphan flows (not linked by any menu item) ── $linkedFlows = []; foreach ($menus as $mk => $menu) { - foreach ($menu['sections'] ?? [] as $section) { - foreach ($section['rows'] ?? [] as $row) { - if (isset($flows[$row['id']])) { - $linkedFlows[$row['id']] = true; + if (($menu['type'] ?? 'button') === 'button') { + foreach ($menu['buttons'] ?? [] as $btn) { + if (isset($flows[$btn['id']])) $linkedFlows[$btn['id']] = true; + } + } else { + foreach ($menu['sections'] ?? [] as $section) { + foreach ($section['rows'] ?? [] as $row) { + if (isset($flows[$row['id']])) $linkedFlows[$row['id']] = true; } } }