/** * Общий навбар операторских страниц. *
*/ (function () { /* Один файл — одинаковый слот в светлой и тёмной теме (logo.png другой aspect ratio). */ const LOGO_LIGHT = "/static/logo2.png"; const LOGO_DARK = "/static/logo2.png"; function brandLogoHtml() { return ` `; } const PAGES = [ { id: "recipes", href: "/recipes", icon: "fa-utensils", label: "Рецепты" }, { id: "lab", href: "/lab", icon: "fa-flask", label: "Lab" }, { id: "feed_dispensers", href: "/feed_dispensers", icon: "fa-server", label: "Оборудование" }, { id: "components", href: "/components", icon: "fa-box", label: "Компоненты" }, { id: "reports", href: "/reports", icon: "fa-chart-bar", label: "Отчеты" }, { id: "feed_consumption", href: "/feed_consumption", icon: "fa-chart-line", label: "Учёт кормов" }, ]; function navItem(page, active, mobile) { const cls = mobile ? `mobile-menu-item${active ? " active" : ""}` : `menu-btn${active ? " active" : ""}`; const tag = mobile ? "a" : "a"; if (page.id === "settings") { return `<${tag} href="javascript:void(0)" data-action="open-settings" onclick="typeof openSettings==='function'&&openSettings(event)" class="${cls}"> Настройки`; } return `<${tag} href="${page.href}" class="${cls}"> ${page.label}`; } function pagesForNav(canLab) { if (canLab) return PAGES; return PAGES.filter((p) => p.id !== "lab"); } function renderNav(activeId, pages) { const desktop = pages.map((p) => navItem(p, p.id === activeId, false)).join(""); const mobile = pages.map((p) => navItem(p, p.id === activeId, true)).join(""); const settingsDesktop = navItem({ id: "settings" }, false, false); const settingsMobile = navItem({ id: "settings" }, false, true); return ``; } function wireMobileMenu() { const hamburgerMenu = document.getElementById("hamburgerMenu"); const mobileMenuOverlay = document.getElementById("mobileMenuOverlay"); const closeMenu = document.getElementById("closeMenu"); if (!hamburgerMenu || !mobileMenuOverlay) return; const open = () => { mobileMenuOverlay.classList.add("active"); hamburgerMenu.classList.add("active"); }; const close = () => { mobileMenuOverlay.classList.remove("active"); hamburgerMenu.classList.remove("active"); }; hamburgerMenu.addEventListener("click", open); closeMenu?.addEventListener("click", close); mobileMenuOverlay.addEventListener("click", (e) => { if (e.target === mobileMenuOverlay) close(); }); } async function fetchCanLab() { try { const response = await fetch("/api/auth/check"); const data = await response.json(); if (data.status === "success" && data.authenticated) { return Boolean(data.can_lab); } } catch (error) { console.error("Ошибка проверки доступа к Lab:", error); } return false; } async function mount() { const mountEl = document.getElementById("wespZootechNavMount"); if (!mountEl) return; const active = mountEl.getAttribute("data-active-page") || ""; const canLab = await fetchCanLab(); window.WESP_CAN_LAB = canLab; mountEl.outerHTML = renderNav(active, pagesForNav(canLab)); wireMobileMenu(); window.WespPageEnter?.init?.(); window.WespLabAccess?.apply?.(canLab); } window.WespZootechNav = { remount: mount }; if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", mount); } else { mount(); } })();