// ===== Panel Management ===== // Mengelola Left Sidebar Toggle + Right Panel + Layer Control (function () { // ---- State ---- let activePanel = null; // ---- Elements ---- const sidebarToggleBtn = document.getElementById('sidebarToggleBtn'); const sidebarToggleIcon = document.getElementById('sidebarToggleIcon'); const leftSidebar = document.getElementById('leftSidebar'); const rightPanel = document.getElementById('rightPanel'); const rightPanelTitle = document.getElementById('rightPanelTitle'); const rightPanelActions = document.getElementById('rightPanelActions'); const rightPanelBody = document.getElementById('rightPanelBody'); const rightPanelClose = document.getElementById('rightPanelClose'); // ---- Sidebar Toggle ---- if (sidebarToggleBtn) { sidebarToggleBtn.addEventListener('click', function () { const isOpen = leftSidebar.style.display !== 'none'; if (isOpen) { leftSidebar.style.display = 'none'; sidebarToggleBtn.classList.remove('open'); sidebarToggleIcon.className = 'fas fa-chevron-right'; } else { leftSidebar.style.display = 'flex'; sidebarToggleBtn.classList.add('open'); sidebarToggleIcon.className = 'fas fa-chevron-left'; } }); } // ---- Sidebar Buttons ---- document.querySelectorAll('.sidebar-btn').forEach(btn => { btn.addEventListener('click', function () { const panel = this.dataset.panel; if (activePanel === panel) { closePanel(); } else { openPanel(panel); } }); }); if (rightPanelClose) { rightPanelClose.addEventListener('click', closePanel); } // ---- Open / Close Panel ---- function openPanel(panel) { if (typeof window.deactivateAddMode === 'function') window.deactivateAddMode(); activePanel = panel; rightPanel.classList.add('open'); document.body.classList.add('right-panel-open'); document.querySelectorAll('.sidebar-btn').forEach(b => b.classList.remove('active')); const activeBtn = document.querySelector(`.sidebar-btn[data-panel="${panel}"]`); if (activeBtn) activeBtn.classList.add('active'); renderPanel(panel); } function closePanel() { if (typeof window.deactivateAddMode === 'function') window.deactivateAddMode(); activePanel = null; rightPanel.classList.remove('open'); document.body.classList.remove('right-panel-open'); document.querySelectorAll('.sidebar-btn').forEach(b => b.classList.remove('active')); } window.refreshActivePanel = function () { if (activePanel && activePanel !== 'layer') renderPanel(activePanel); }; // ---- Render Panel by Type ---- function renderPanel(type) { rightPanelBody.innerHTML = '
Memuat data...
'; rightPanelActions.innerHTML = ''; switch (type) { case 'jalan': renderJalanPanel(); break; } } // ========================== // ===== Jalan Panel ======== // ========================== function renderJalanPanel() { rightPanelTitle.textContent = '🛣️ Daftar Jalan'; const isAdmin = !!(window.currentUser && window.currentUser.role === 'admin'); if (isAdmin) { rightPanelActions.innerHTML = ` `; document.getElementById('btnPanelAddJalan').addEventListener('click', () => { window.activateDraw('polyline'); }); } else { rightPanelActions.innerHTML = ''; } const items = []; jalanLayer.eachLayer(l => { if (l.jalanData) items.push(l.jalanData); }); if (!items.length) { rightPanelBody.innerHTML = '
Belum ada data Jalan
'; return; } rightPanelBody.innerHTML = ''; items.forEach(d => { const card = document.createElement('div'); card.className = 'data-card'; let actionButtons = ''; if (isAdmin) { actionButtons = `
`; } card.innerHTML = `
🛣️
${escHtml(d.nama)}
📏 ${d.panjang.toFixed(2)} m • 🏷️ ${escHtml(d.status)}
${actionButtons}
`; if (isAdmin) { card.querySelector('.btn-card-edit').addEventListener('click', (e) => { e.stopPropagation(); window.openEditJalanModal(d.id); }); card.querySelector('.btn-card-delete').addEventListener('click', (e) => { e.stopPropagation(); window.deleteJalan(d.id); }); } card.addEventListener('click', () => { jalanLayer.eachLayer(l => { if (l.jalanData && l.jalanData.id == d.id) { map.fitBounds(l.getBounds()); l.openPopup(); } }); }); rightPanelBody.appendChild(card); }); } // ---- Utility ---- function escHtml(str) { if (!str) return ''; return String(str).replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"'); } // ---- Expose ---- window.openRightPanel = openPanel; })();