// ================================================================ // AMS — Core Application Logic | app.js // ================================================================ /* ── HTML escaping (XSS-safe output) ───────────────────────────── */ function escapeHtml(value) { if (value === null || value === undefined) return ''; return String(value) .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } // Escape for use inside a single-quoted JS string in an inline handler. function escapeJs(value) { if (value === null || value === undefined) return ''; return String(value).replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/"/g, '"').replace(/ { const href = el.getAttribute('href') || ''; el.classList.toggle('active', !!href && href === active); }); } /* ── Modals ─────────────────────────────────────────────────────── */ function openModal(id) { const el = document.getElementById(id); if (el) { el.classList.add('open'); document.body.style.overflow = 'hidden'; } } function closeModal(id) { const el = document.getElementById(id); if (el) { el.classList.remove('open'); document.body.style.overflow = ''; } } /* ── Tabs ─────────────────────────────────────────────────────── */ function initTabs(container) { const root = container || document; root.querySelectorAll('.tab-btn').forEach(btn => { btn.addEventListener('click', () => { const tabsEl = btn.closest('.tabs'); const tabGroup = tabsEl ? tabsEl.dataset.group : null; const targetId = btn.dataset.tab; tabsEl.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active')); btn.classList.add('active'); const scope = btn.closest('.tab-container') || btn.closest('.card') || btn.closest('.content') || document; scope.querySelectorAll('.tab-content').forEach(tc => { if (tabGroup && tc.dataset.group && tc.dataset.group !== tabGroup) return; tc.classList.toggle('active', tc.id === targetId); }); }); }); } /* ── Toast ─────────────────────────────────────────────────────── */ function showToast(title, text='', type='success', dur=4200) { const icons = { success:'✅', error:'❌', warning:'⚠️', info:'ℹ️' }; const c = document.getElementById('toastContainer'); if (!c) return; const t = document.createElement('div'); t.className = `toast ${type}`; t.innerHTML = `
You do not have the required permissions to access this module. Current Role: ${AMS.currentUser.role}