| (function () { |
| function setText(selector, value) { |
| if (!value) { |
| return; |
| } |
| document.querySelectorAll(selector).forEach(function (node) { |
| node.textContent = value; |
| }); |
| } |
|
|
| function setStatus(kind, text) { |
| var badge = document.querySelector("[data-load-badge]"); |
| if (!badge) { |
| return; |
| } |
| badge.classList.remove("loading", "loaded", "error"); |
| badge.classList.add(kind); |
| badge.textContent = text; |
| } |
|
|
| function initFullscreen(shell, button) { |
| if (!shell || !button) { |
| return; |
| } |
|
|
| function updateLabel() { |
| var active = document.fullscreenElement === shell; |
| button.textContent = active ? "Close expanded view" : "Expand view"; |
| } |
|
|
| button.addEventListener("click", async function () { |
| try { |
| if (document.fullscreenElement === shell) { |
| await document.exitFullscreen(); |
| } else { |
| await shell.requestFullscreen(); |
| } |
| } catch (error) { |
| setStatus("error", "Expanded view failed"); |
| } |
| }); |
|
|
| document.addEventListener("fullscreenchange", updateLabel); |
| updateLabel(); |
| } |
|
|
| function initToggleChips() { |
| document.querySelectorAll("[data-filter-group]").forEach(function (group) { |
| group.querySelectorAll("[data-toggle-chip]").forEach(function (button) { |
| button.addEventListener("click", function () { |
| group.querySelectorAll("[data-toggle-chip]").forEach(function (item) { |
| item.classList.remove("is-active"); |
| }); |
| button.classList.add("is-active"); |
| }); |
| }); |
| }); |
| } |
|
|
| function initTabs() { |
| document.querySelectorAll("[data-tab-scope]").forEach(function (scope) { |
| var buttons = scope.querySelectorAll("[data-tab-target]"); |
| var panels = scope.querySelectorAll("[data-tab-panel]"); |
| buttons.forEach(function (button) { |
| button.addEventListener("click", function () { |
| var target = button.getAttribute("data-tab-target"); |
| buttons.forEach(function (item) { |
| item.classList.toggle("is-active", item === button); |
| }); |
| panels.forEach(function (panel) { |
| panel.classList.toggle("is-active", panel.getAttribute("data-tab-panel") === target); |
| }); |
| }); |
| }); |
| }); |
| } |
|
|
| function initNavItems() { |
| document.querySelectorAll(".nav-list").forEach(function (list) { |
| var items = list.querySelectorAll("[data-nav-item]"); |
| function activate(target) { |
| items.forEach(function (item) { |
| item.classList.toggle("active", item === target); |
| }); |
| } |
| items.forEach(function (item) { |
| item.addEventListener("click", function () { |
| activate(item); |
| }); |
| item.addEventListener("keydown", function (event) { |
| if (event.key === "Enter" || event.key === " ") { |
| event.preventDefault(); |
| activate(item); |
| } |
| }); |
| }); |
| }); |
| } |
|
|
| function initRowActions() { |
| document.querySelectorAll("[data-row-action]").forEach(function (button) { |
| var primary = button.getAttribute("data-primary-label") || button.textContent.trim() || "Open"; |
| var secondary = button.getAttribute("data-secondary-label") || "Undo"; |
| button.textContent = primary; |
| button.addEventListener("click", function () { |
| var row = button.closest(".queue-row"); |
| if (!row) { |
| return; |
| } |
| var mode = button.getAttribute("data-row-action"); |
| if (mode === "complete") { |
| var complete = !row.classList.contains("is-complete"); |
| row.classList.toggle("is-complete", complete); |
| var status = row.querySelector("[data-status-label]"); |
| if (status) { |
| if (!status.dataset.originalStatus) { |
| status.dataset.originalStatus = status.textContent; |
| } |
| status.textContent = complete ? "Completed" : status.dataset.originalStatus; |
| } |
| button.textContent = complete ? secondary : primary; |
| return; |
| } |
| var acknowledged = !row.classList.contains("is-acknowledged"); |
| row.classList.toggle("is-acknowledged", acknowledged); |
| button.textContent = acknowledged ? secondary : primary; |
| }); |
| }); |
| } |
|
|
| function initUtilityPanels() { |
| var panels = document.querySelectorAll("[data-utility-panel]"); |
| document.querySelectorAll("[data-panel-toggle]").forEach(function (button) { |
| button.addEventListener("click", function () { |
| panels.forEach(function (panel) { |
| panel.hidden = !panel.hidden; |
| }); |
| }); |
| }); |
| document.querySelectorAll("[data-panel-close]").forEach(function (button) { |
| button.addEventListener("click", function () { |
| var panel = button.closest("[data-utility-panel]"); |
| if (panel) { |
| panel.hidden = true; |
| } |
| }); |
| }); |
| } |
|
|
| function initChart() { |
| var params = new URLSearchParams(window.location.search); |
| var body = document.body; |
| var chartSrc = params.get("chart_src") || (body ? body.dataset.defaultChartSrc : "") || ""; |
| var caseName = params.get("case_name") || ""; |
| var caseNote = params.get("case_note") || ""; |
| var iframe = document.querySelector("[data-chart-frame]"); |
| var placeholder = document.querySelector("[data-placeholder]"); |
| var shell = document.querySelector("[data-chart-shell]"); |
| var button = document.querySelector("[data-fullscreen-btn]"); |
|
|
| if (caseName) { |
| setText("[data-case-name]", caseName); |
| } |
| if (caseNote) { |
| setText("[data-case-note]", caseNote); |
| } |
| initFullscreen(shell, button); |
| initToggleChips(); |
| initTabs(); |
| initNavItems(); |
| initRowActions(); |
| initUtilityPanels(); |
|
|
| if (!iframe || !chartSrc || /^(https?:)?\/\//i.test(chartSrc)) { |
| setStatus("error", "View source unavailable"); |
| return; |
| } |
|
|
| iframe.addEventListener("load", function () { |
| setStatus("loaded", "View ready"); |
| if (placeholder) { |
| placeholder.hidden = true; |
| } |
| }); |
|
|
| iframe.addEventListener("error", function () { |
| setStatus("error", "View failed to load"); |
| }); |
|
|
| setStatus("loading", "Loading view"); |
| iframe.src = chartSrc; |
| } |
|
|
| if (document.readyState === "loading") { |
| document.addEventListener("DOMContentLoaded", initChart); |
| } else { |
| initChart(); |
| } |
| })(); |
|
|