/* Global app navigation drawer for the Work Package Suite. The suite grew page by page and the only way between them was the browser's back button or the home page. This is the one place that lists everywhere you can go — a ☰ button in the app bar opening an off-canvas drawer. ROLE GATING: the drawer only offers what the signed-in account can actually reach. The Admin Console is admins-only, so it appears for admins only; the User Directory is readable by everyone (that's the point of a directory), so it always appears. Every destination re-checks server-side — this is navigation, not a permission. PROJECT CONTEXT: links that open a project-scoped page carry the active ?project= so the drawer doesn't silently drop the job you were looking at. Add it to a page with: after auth-guard.js. It mounts itself into whichever top bar the page has, and skips iframes (the embedded WP creator lives inside a page that already has one). */ (function () { 'use strict'; var inIframe = (function () { try { return window.top !== window.self; } catch (e) { return true; } })(); if (inIframe) return; // ── the map ──────────────────────────────────────────────────────────────── // `match` is what marks a link current; `project` means "carry ?project=". // `show` is an optional gate, evaluated once the user is known. var LINKS = [ { section: 'Work' }, { href: 'index.html', match: /(^|\/)(index\.html)?$/, icon: '⌂', label: 'Home', sub: 'Projects & what\'s next' }, { href: 'work-package-suite.html?tab=sop', match: /work-package-suite\.html/, icon: '⚙', label: 'SOP Configuration', sub: 'The project baseline', project: true, tab: 'sop' }, { href: 'work-package-suite.html?tab=wp', match: null, icon: '▤', label: 'Work Package Creator', sub: 'Build and edit IWPs', project: true, tab: 'wp' }, { href: 'work-package-suite.html?tab=dashboard', match: null, icon: '▦', label: 'Dashboard', sub: 'Status & release gates', project: true, tab: 'dashboard' }, { href: 'field.html', match: /(^|\/)field\.html$/, icon: '⚒', label: 'Field View', sub: 'Update packages on site', project: true }, { section: 'People' }, { href: 'users.html', match: /(^|\/)users\.html$/, icon: '☺', label: 'User Directory', sub: 'Who\'s on the project' }, { href: 'admin.html', match: /(^|\/)admin\.html$/, icon: '⚡', label: 'Admin Console', sub: 'Settings & diagnostics', show: function () { return typeof window.wpIsAdmin === 'function' && window.wpIsAdmin(); } }, ]; function esc(v) { return String(v == null ? '' : v) .replace(/&/g, '&').replace(//g, '>') .replace(/"/g, '"').replace(/'/g, '''); } function isDark(node) { try { var m = (getComputedStyle(node).backgroundColor || '').match(/(\d+),\s*(\d+),\s*(\d+)/); if (!m) return true; return (0.299 * +m[1] + 0.587 * +m[2] + 0.114 * +m[3]) < 140; } catch (e) { return true; } } function activeProjectId() { try { var q = new URLSearchParams(location.search).get('project'); if (q) return q; return (window.ProjectData && ProjectData.getActiveId && ProjectData.getActiveId()) || ''; } catch (e) { return ''; } } // The suite page reads ?tab= and ?project=; keeping the current project on the link // is the difference between "open the dashboard" and "open the dashboard, then pick // the job again". function hrefFor(item) { if (!item.project) return item.href; var pid = activeProjectId(); if (!pid) return item.href; var sep = item.href.indexOf('?') >= 0 ? '&' : '?'; return item.href + sep + 'project=' + encodeURIComponent(pid); } // Current-page marking. The three suite tabs share one file, so they're told apart // by ?tab= (defaulting to sop, which is what work-package-suite.html itself does). function isCurrent(item) { var path = location.pathname; if (item.tab) { if (!/work-package-suite\.html$/.test(path)) return false; var tab = ''; try { tab = new URLSearchParams(location.search).get('tab') || 'sop'; } catch (e) { tab = 'sop'; } return tab === item.tab; } return !!(item.match && item.match.test(path)); } // ── build ────────────────────────────────────────────────────────────────── var drawer, scrim, btn, lastFocus = null; function buildDrawer(user) { scrim = document.createElement('div'); scrim.className = 'wp-navscrim'; scrim.hidden = true; scrim.addEventListener('click', close); drawer = document.createElement('nav'); drawer.className = 'wp-sidenav'; drawer.id = 'wp-sidenav'; drawer.setAttribute('aria-label', 'Suite navigation'); drawer.setAttribute('aria-hidden', 'true'); var rows = ''; LINKS.forEach(function (item) { if (item.section) { rows += '
' +
'Work Package SuitePrime Controls' +
'' +
'