Files
arrr-erp/app/ui/templates/components/staff_navigation_v2.html
T
2026-08-08 17:09:21 +05:30

396 lines
12 KiB
HTML

{% if navigation_render_location_v2|default('page') == 'global-host' or not global_role_navigation_host_v2|default(false) %}
{#
UI/UX V2 Phase 1B.2 — Unified Employee / Staff navigation.
Presentation only. Existing employee self-service permission helpers,
routes and route-level authorization remain authoritative.
#}
{% set _staff_path = request.url.path %}
{% set _staff_tab = request.query_params.get('tab', 'overview') %}
{% set navigation_aria_label_v2 = 'Staff workspace navigation' %}
{% set navigation_items_v2 = [
{
'label': 'Dashboard',
'visible': can_view_employee_portal(current_user, current_user_permissions, current_user_roles),
'active': _staff_path.startswith('/employee/dashboard'),
'children': [
{'label': 'Overview', 'url': '/employee/dashboard?tab=overview', 'active': _staff_path.startswith('/employee/dashboard') and _staff_tab == 'overview'},
{'label': 'Work', 'url': '/employee/dashboard?tab=work', 'active': _staff_path.startswith('/employee/dashboard') and _staff_tab == 'work'},
{'label': 'Attendance', 'url': '/employee/dashboard?tab=attendance', 'active': _staff_path.startswith('/employee/dashboard') and _staff_tab == 'attendance'},
{'label': 'HR & Profile', 'url': '/employee/dashboard?tab=hr', 'active': _staff_path.startswith('/employee/dashboard') and _staff_tab == 'hr'},
{'label': 'Reports', 'url': '/employee/dashboard?tab=reports', 'active': _staff_path.startswith('/employee/dashboard') and _staff_tab == 'reports'}
]
},
{
'label': 'Work',
'url': '/employee/work',
'visible': can_view_own_employee_work(current_user, current_user_permissions, current_user_roles),
'active': _staff_path.startswith('/employee/work')
},
{
'label': 'Attendance',
'url': '/employee/attendance',
'visible': can_view_own_employee_attendance(current_user, current_user_permissions, current_user_roles),
'active': _staff_path.startswith('/employee/attendance')
},
{
'label': 'Leave',
'url': '/employee/leave',
'visible': can_view_own_employee_leave(current_user, current_user_permissions, current_user_roles),
'active': _staff_path.startswith('/employee/leave')
},
{
'label': 'Documents',
'url': '/employee/documents',
'visible': can_view_own_employee_documents(current_user, current_user_permissions, current_user_roles),
'active': _staff_path.startswith('/employee/documents')
},
{
'label': 'Payslips',
'url': '/employee/payslips',
'visible': can_view_own_employee_payslips(current_user, current_user_permissions, current_user_roles),
'active': _staff_path.startswith('/employee/payslips')
},
{
'label': 'Offboarding',
'url': '/employee/offboarding',
'visible': can_request_own_employee_offboarding(current_user, current_user_permissions, current_user_roles),
'active': _staff_path.startswith('/employee/offboarding')
},
{
'label': 'Profile',
'url': '/employee/profile',
'visible': can_view_employee_portal(current_user, current_user_permissions, current_user_roles),
'active': _staff_path.startswith('/employee/profile')
},
{
'label': 'Bank Analyzer',
'url': '/tools/bank-statement-analyzer',
'visible': true,
'active': _staff_path.startswith('/tools/bank-statement-analyzer')
},
{
'label': 'Alerts',
'url': '/alerts',
'visible': true,
'active': _staff_path.startswith('/alerts'),
'badge': unread_alert_count if unread_alert_count is defined and unread_alert_count > 0 else none
}
] %}
<div class="border-b border-slate-200 bg-white shadow-sm" data-uiux-v2-pilot="staff">
{% include "ui/templates/components/navigation_v2.html" %}
{% include "ui/templates/components/mobile_navigation_v2.html" %}
</div>
<script>
(function () {
"use strict";
function initialiseStaffDropdowns() {
var root = document.querySelector('[data-uiux-v2-pilot="staff"]');
if (!root || root.dataset.dropdownAutoCloseInitialised === 'true') return;
var desktopNav = root.querySelector('nav[data-uiux-v2="desktop-navigation"]');
if (!desktopNav) return;
root.dataset.dropdownAutoCloseInitialised = 'true';
var dropdowns = Array.from(desktopNav.querySelectorAll('details'));
function closeAllExcept(exception) {
dropdowns.forEach(function (details) {
if (details !== exception) details.removeAttribute('open');
});
}
dropdowns.forEach(function (details) {
details.addEventListener('toggle', function () {
if (details.open) closeAllExcept(details);
});
details.querySelectorAll('a[href]').forEach(function (link) {
link.addEventListener('click', function () {
details.removeAttribute('open');
});
});
});
document.addEventListener('click', function (event) {
if (!root.contains(event.target)) closeAllExcept(null);
});
document.addEventListener('keydown', function (event) {
if (event.key === 'Escape') closeAllExcept(null);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initialiseStaffDropdowns, { once: true });
} else {
initialiseStaffDropdowns();
}
})();
</script>
{% endif %}
{# STAFF_NAV_GROUPING_ONEFILE_V1
One-file employee navigation grouping.
Existing routes, Jinja permission checks and feature visibility are preserved.
#}
<style>
.staff-nav-v2-grouped {
display: flex;
align-items: stretch;
gap: .35rem;
min-width: 0;
}
.staff-nav-v2-grouped > a,
.staff-nav-v2-grouped summary {
display: inline-flex;
min-height: 3.25rem;
align-items: center;
gap: .35rem;
padding: 0 .8rem;
border-bottom: 2px solid transparent;
color: rgb(30 41 59);
font-size: .95rem;
font-weight: 500;
text-decoration: none;
white-space: nowrap;
cursor: pointer;
list-style: none;
}
.staff-nav-v2-grouped summary::-webkit-details-marker {
display: none;
}
.staff-nav-v2-grouped > a:hover,
.staff-nav-v2-grouped summary:hover,
.staff-nav-v2-grouped > a[data-nav-active="1"],
.staff-nav-v2-grouped details[data-nav-active="1"] > summary {
color: rgb(15 23 42);
border-bottom-color: rgb(37 99 235);
}
.staff-nav-v2-group {
position: relative;
}
.staff-nav-v2-group-menu {
position: absolute;
z-index: 70;
top: calc(100% + .3rem);
left: 0;
min-width: 14rem;
padding: .5rem;
border: 1px solid rgb(226 232 240);
border-radius: 1rem;
background: white;
box-shadow: 0 14px 32px rgba(15, 23, 42, .14);
}
.staff-nav-v2-group-menu a {
display: flex;
width: 100%;
align-items: center;
padding: .65rem .75rem;
border-radius: .65rem;
color: rgb(51 65 85);
font-size: .9rem;
font-weight: 500;
text-decoration: none;
}
.staff-nav-v2-group-menu a:hover,
.staff-nav-v2-group-menu a[data-nav-active="1"] {
background: rgb(248 250 252);
color: rgb(15 23 42);
}
.staff-nav-v2-group-caret {
font-size: .65rem;
color: rgb(100 116 139);
}
[data-staff-nav-v2-original="1"] {
display: none !important;
}
@media (max-width: 1100px) {
.staff-nav-v2-grouped {
overflow-x: auto;
scrollbar-width: thin;
}
}
</style>
<script>
(function () {
"use strict";
function normalizeLabel(value) {
return (value || "").replace(/\s+/g, " ").trim().toLowerCase();
}
function activeFor(anchor) {
try {
const current = window.location.pathname.replace(/\/+$/, "") || "/";
const target = new URL(anchor.href, window.location.origin).pathname.replace(/\/+$/, "") || "/";
return current === target || (target !== "/" && current.startsWith(target + "/"));
} catch (_) {
return false;
}
}
function findNavigationRoot() {
const candidates = Array.from(document.querySelectorAll("nav, header, div"));
for (const node of candidates) {
const ownAnchors = Array.from(node.querySelectorAll("a[href]"));
if (!ownAnchors.length) continue;
const labels = new Set(ownAnchors.map(function (a) { return normalizeLabel(a.textContent); }));
if (
labels.has("work") &&
labels.has("attendance") &&
labels.has("leave") &&
labels.has("profile") &&
labels.has("bank analyzer")
) {
return node;
}
}
return null;
}
function findLink(anchors, names) {
const wanted = names.map(normalizeLabel);
return anchors.find(function (a) {
return wanted.includes(normalizeLabel(a.textContent));
}) || null;
}
function cleanClone(source, displayName) {
if (!source) return null;
const a = source.cloneNode(true);
a.className = "";
a.textContent = displayName || source.textContent.trim();
if (activeFor(source)) a.setAttribute("data-nav-active", "1");
return a;
}
function makeGroup(title, sources) {
const links = sources.filter(Boolean);
if (!links.length) return null;
const details = document.createElement("details");
details.className = "staff-nav-v2-group";
const summary = document.createElement("summary");
summary.appendChild(document.createTextNode(title));
const caret = document.createElement("span");
caret.className = "staff-nav-v2-group-caret";
caret.textContent = "▼";
summary.appendChild(caret);
details.appendChild(summary);
const menu = document.createElement("div");
menu.className = "staff-nav-v2-group-menu";
let active = false;
links.forEach(function (source) {
const item = cleanClone(source);
if (item && item.getAttribute("data-nav-active") === "1") active = true;
if (item) menu.appendChild(item);
});
if (active) details.setAttribute("data-nav-active", "1");
details.appendChild(menu);
return details;
}
function install() {
if (document.querySelector("[data-staff-nav-v2-grouped='1']")) return;
const root = findNavigationRoot();
if (!root) return;
const links = Array.from(root.querySelectorAll("a[href]"));
const dashboard = findLink(links, ["Dashboard", "Overview"]);
const work = findLink(links, ["Work", "My Work"]);
const attendance = findLink(links, ["Attendance"]);
const leave = findLink(links, ["Leave"]);
const documents = findLink(links, ["Documents"]);
const payslips = findLink(links, ["Payslips", "Payslip"]);
const offboarding = findLink(links, ["Offboarding"]);
const profile = findLink(links, ["Profile"]);
const bankAnalyzer = findLink(links, ["Bank Analyzer"]);
const reports = findLink(links, ["Reports", "My Reports"]);
const alerts = findLink(links, ["Alerts"]);
if (!work || !attendance || !leave || !profile) return;
const grouped = document.createElement("nav");
grouped.className = "staff-nav-v2-grouped";
grouped.setAttribute("data-staff-nav-v2-grouped", "1");
grouped.setAttribute("aria-label", "Employee portal navigation");
const dashboardLink = cleanClone(dashboard, "Dashboard");
if (dashboardLink) grouped.appendChild(dashboardLink);
const workLink = cleanClone(work, "Work");
if (workLink) grouped.appendChild(workLink);
const attendanceGroup = makeGroup("Attendance & Leave", [attendance, leave]);
if (attendanceGroup) grouped.appendChild(attendanceGroup);
const profileGroup = makeGroup(
"Profile & HR",
[profile, documents, payslips, offboarding]
);
if (profileGroup) grouped.appendChild(profileGroup);
const toolsGroup = makeGroup("Tools", [bankAnalyzer]);
if (toolsGroup) grouped.appendChild(toolsGroup);
const reportsLink = cleanClone(reports, "Reports");
if (reportsLink) grouped.appendChild(reportsLink);
const alertsLink = cleanClone(alerts, "Alerts");
if (alertsLink) grouped.appendChild(alertsLink);
Array.from(root.children).forEach(function (child) {
if (child === grouped) return;
if (child.tagName === "A" || (child.querySelector && child.querySelector("a[href]"))) {
child.setAttribute("data-staff-nav-v2-original", "1");
}
});
root.appendChild(grouped);
document.addEventListener("click", function (event) {
document.querySelectorAll(".staff-nav-v2-group[open]").forEach(function (group) {
if (!group.contains(event.target)) group.removeAttribute("open");
});
});
document.addEventListener("keydown", function (event) {
if (event.key !== "Escape") return;
document.querySelectorAll(".staff-nav-v2-group[open]").forEach(function (group) {
group.removeAttribute("open");
});
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", install);
} else {
install();
}
})();
</script>