/** * DeComPress CMS - Core Admin Logic */ const state = { currentView: 'Pages', themes: [ { id: 1, name: 'Minimalist', version: '1.2.0', active: true, color: 'bg-slate-300' }, { id: 2, name: 'Dark Mode Pro', version: '2.0.1', active: false, color: 'bg-gray-800' }, { id: 3, name: 'Ocean Breeze', version: '1.0.5', active: false, color: 'bg-blue-400' } ], customFields: [], // Dynamic state for the field builder navItems: [ { name: 'Pages', icon: '📄' }, { name: 'Themes', icon: '🎨' }, { name: 'Post Types', icon: '📌' }, { name: 'Custom Fields', icon: '🔧' }, { name: 'Users', icon: '👥' }, { name: 'Roles', icon: '🛡️' }, { name: 'Permissions', icon: '🔑' } ] } // --- Initialization --- document.addEventListener('DOMContentLoaded', () => { initApp() }) function initApp () { renderNav() navigateTo(state.currentView) // Mobile Toggle Logic document.getElementById('mobile-toggle').addEventListener('click', () => { const sidebar = document.getElementById('sidebar') sidebar.classList.toggle('hidden') sidebar.classList.toggle('absolute') sidebar.classList.toggle('z-50') sidebar.classList.toggle('h-full') }) } // --- Router --- function navigateTo (viewName) { state.currentView = viewName document.getElementById('view-title').innerText = viewName renderNav() // Refresh active state const container = document.getElementById('app-content') container.innerHTML = '' // Clear current switch (viewName) { case 'Pages': container.innerHTML = viewPages() break case 'Themes': container.innerHTML = viewThemes() break case 'Permissions': container.innerHTML = viewPermissions() break case 'Custom Fields': container.innerHTML = viewCustomFields() break case 'Users': container.innerHTML = viewUsers() break default: container.innerHTML = `
${viewName} module is currently under construction.
` } } // --- Views --- function viewPages () { return `
Page Title Status Actions
HomepagePublishedEdit
ContactDraftEdit
` } function viewThemes () { return `
${state.themes .map( t => `

${t.name}

Version ${ t.version }

` ) .join('')}
` } function viewPermissions () { const roles = ['Admin', 'Editor', 'Subscriber'] const caps = ['Update Core', 'Manage Themes', 'Delete Posts', 'Write Posts'] return `
${roles .map( r => `` ) .join('')} ${caps .map( c => ` ${roles .map( r => `` ) .join('')} ` ) .join('')}
Capability${r}
${c}
` } function viewCustomFields () { return `

Field Group: Blog Metadata

${ state.customFields.length === 0 ? '

No fields added yet. Click "+ Add Field" to begin.

' : '' }
` } function viewUsers () { return `

Invite New User

` } // --- Component Logic --- function renderNav () { const nav = document.getElementById('main-nav') nav.innerHTML = state.navItems .map( item => ` ` ) .join('') } function addField () { const id = Date.now() state.customFields.push({ id, label: '', type: 'text' }) refreshFields() } function removeField (id) { state.customFields = state.customFields.filter(f => f.id !== id) refreshFields() } function refreshFields () { const container = document.getElementById('fields-container') if (!container) return container.innerHTML = state.customFields .map( (field, index) => `
` ) .join('') } // --- General Handlers --- function handleUserInvite () { const email = document.getElementById('u-email').value if (!email.includes('@')) { alert('Please enter a valid email address.') return } alert(`Invitation sent to ${email}`) } function handleAction (msg) { console.log('CMS Action:', msg) alert(msg) }