Selecting an option closes the list without blurring the input, so a later click never fires focus. Open the panel on mousedown as well. Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
759 lines
22 KiB
HTML
759 lines
22 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>New QC Sheet</title>
|
|
<script>
|
|
try {
|
|
if (localStorage.getItem("xlsx-clean-theme") === "light") {
|
|
document.documentElement.setAttribute("data-theme", "light");
|
|
}
|
|
} catch (error) {
|
|
/* localStorage may be unavailable in some WebView embeds */
|
|
}
|
|
</script>
|
|
<style>
|
|
@font-face {
|
|
font-family: "Inter";
|
|
src: url("../fonts/Inter-Regular.ttf") format("truetype");
|
|
font-weight: 400;
|
|
font-style: normal;
|
|
font-display: swap;
|
|
}
|
|
|
|
@font-face {
|
|
font-family: "Inter";
|
|
src: url("../fonts/Inter-Bold.ttf") format("truetype");
|
|
font-weight: 700;
|
|
font-style: normal;
|
|
font-display: swap;
|
|
}
|
|
|
|
:root {
|
|
--primary: #e54d5e;
|
|
--primary-hover: #c93d4e;
|
|
--accent: #6366f1;
|
|
--accent-2: #8b5cf6;
|
|
--accent-3: #a855f7;
|
|
--success: #22c55e;
|
|
--warning: #f59e0b;
|
|
--error: #ef4444;
|
|
--bg: #0b0e14;
|
|
--bg-alt: #111520;
|
|
--surface: #161b22;
|
|
--surface-2: #1c2230;
|
|
--border: rgba(255, 255, 255, 0.08);
|
|
--border-strong: rgba(255, 255, 255, 0.14);
|
|
--grid-line: rgba(255, 255, 255, 0.06);
|
|
--grid-size: 32px;
|
|
--text: #e6e6ef;
|
|
--text-muted: #8b8b9e;
|
|
--text-dim: #5a5a6e;
|
|
--grad-brand: linear-gradient(135deg, var(--primary), var(--accent-3));
|
|
--grad-soft: linear-gradient(135deg, rgba(229, 77, 94, 0.12), rgba(168, 85, 247, 0.12));
|
|
--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
|
|
--font-mono: ui-monospace, "JetBrains Mono", "Fira Code", "SF Mono", monospace;
|
|
--radius: 14px;
|
|
--radius-sm: 9px;
|
|
--ease: cubic-bezier(0.22, 1, 0.36, 1);
|
|
--status-ready: transparent;
|
|
--status-success: rgba(34, 197, 94, 0.12);
|
|
--status-skipped: rgba(245, 158, 11, 0.12);
|
|
--status-error: rgba(239, 68, 68, 0.12);
|
|
--label-bg: rgba(11, 14, 20, 0.5);
|
|
}
|
|
|
|
html[data-theme="light"] {
|
|
--bg: #f9f9fb;
|
|
--bg-alt: #f0f0f5;
|
|
--surface: #ffffff;
|
|
--surface-2: #f5f5fa;
|
|
--border: rgba(0, 0, 0, 0.08);
|
|
--border-strong: rgba(0, 0, 0, 0.14);
|
|
--grid-line: rgba(0, 0, 0, 0.07);
|
|
--text: #1a1a2e;
|
|
--text-muted: #71717a;
|
|
--text-dim: #9a9aa5;
|
|
--grad-soft: linear-gradient(135deg, rgba(229, 77, 94, 0.08), rgba(168, 85, 247, 0.08));
|
|
--status-success: rgba(34, 197, 94, 0.1);
|
|
--status-skipped: rgba(245, 158, 11, 0.12);
|
|
--status-error: rgba(239, 68, 68, 0.1);
|
|
--label-bg: rgba(249, 249, 251, 0.5);
|
|
}
|
|
|
|
* { box-sizing: border-box; }
|
|
|
|
body {
|
|
min-height: 100vh;
|
|
margin: 0;
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
font-family: var(--font-sans);
|
|
font-size: 15px;
|
|
line-height: 1.5;
|
|
-webkit-font-smoothing: antialiased;
|
|
}
|
|
|
|
body::before {
|
|
content: "";
|
|
position: fixed;
|
|
inset: 0;
|
|
z-index: -1;
|
|
pointer-events: none;
|
|
background-image:
|
|
linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
|
|
linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
|
|
background-size: var(--grid-size) var(--grid-size);
|
|
}
|
|
|
|
.page {
|
|
display: flex;
|
|
min-height: 100vh;
|
|
padding: 24px;
|
|
}
|
|
|
|
.panel {
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: min(100%, 36rem);
|
|
margin: auto;
|
|
background: transparent;
|
|
}
|
|
|
|
.heading-row {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
justify-content: space-between;
|
|
gap: 12px;
|
|
}
|
|
|
|
.theme-toggle {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex-shrink: 0;
|
|
min-width: 52px;
|
|
height: 28px;
|
|
margin-top: 2px;
|
|
padding: 0 8px;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-sm);
|
|
background: var(--surface-2);
|
|
color: var(--text);
|
|
cursor: pointer;
|
|
font: inherit;
|
|
font-size: 0.7rem;
|
|
font-weight: 700;
|
|
letter-spacing: 0.04em;
|
|
text-transform: uppercase;
|
|
line-height: 1;
|
|
}
|
|
|
|
.theme-toggle:hover {
|
|
background: var(--bg-alt);
|
|
border-color: var(--border-strong);
|
|
}
|
|
|
|
.theme-toggle:focus-visible {
|
|
outline: 2px solid var(--accent-3);
|
|
outline-offset: 2px;
|
|
}
|
|
|
|
.eyebrow {
|
|
margin: 0 0 8px;
|
|
color: var(--primary);
|
|
font-size: 0.75rem;
|
|
font-weight: 700;
|
|
letter-spacing: 0.08em;
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
h1 {
|
|
margin: 0;
|
|
color: var(--text);
|
|
font-size: 1.875rem;
|
|
font-weight: 700;
|
|
line-height: 1.15;
|
|
letter-spacing: -0.02em;
|
|
}
|
|
|
|
.subtitle {
|
|
margin: 8px 0 22px;
|
|
color: var(--text-muted);
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.fields { display: grid; gap: 18px; }
|
|
|
|
.field {
|
|
position: relative;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: flex-start;
|
|
gap: 6px;
|
|
}
|
|
|
|
.field-label {
|
|
z-index: 1;
|
|
margin-left: 4px;
|
|
padding: 0 4px;
|
|
background: var(--label-bg);
|
|
color: var(--primary);
|
|
font-size: 0.75rem;
|
|
line-height: 1.2;
|
|
pointer-events: none;
|
|
}
|
|
|
|
select, input {
|
|
width: 100%;
|
|
align-self: stretch;
|
|
min-height: 54px;
|
|
padding: 16px 12px;
|
|
border: 1px solid var(--border-strong);
|
|
border-radius: var(--radius-sm);
|
|
outline: none;
|
|
background: var(--surface-2);
|
|
color: var(--text);
|
|
font: inherit;
|
|
transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
|
|
}
|
|
|
|
.combobox-input {
|
|
padding-right: 36px;
|
|
cursor: text;
|
|
}
|
|
|
|
.combobox { position: relative; }
|
|
|
|
.combobox > select {
|
|
position: absolute;
|
|
width: 1px;
|
|
height: 1px;
|
|
padding: 0;
|
|
margin: -1px;
|
|
overflow: hidden;
|
|
clip: rect(0 0 0 0);
|
|
white-space: nowrap;
|
|
border: 0;
|
|
background: transparent;
|
|
}
|
|
|
|
.combobox-caret {
|
|
position: absolute;
|
|
right: 12px;
|
|
bottom: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
height: 54px;
|
|
color: var(--text-muted);
|
|
pointer-events: none;
|
|
font-size: 0.75rem;
|
|
}
|
|
|
|
.combobox-panel {
|
|
position: absolute;
|
|
top: calc(100% + 4px);
|
|
left: 0;
|
|
right: 0;
|
|
z-index: 5;
|
|
max-height: 220px;
|
|
overflow-y: auto;
|
|
padding: 4px 0;
|
|
background: var(--surface-2);
|
|
border: 1px solid var(--border-strong);
|
|
border-radius: var(--radius-sm);
|
|
box-shadow: 0 12px 32px rgb(0 0 0 / 35%);
|
|
}
|
|
|
|
.combobox-panel[hidden] { display: none; }
|
|
|
|
.combobox-option {
|
|
padding: 8px 12px;
|
|
cursor: pointer;
|
|
color: var(--text);
|
|
line-height: 1.25;
|
|
}
|
|
|
|
.combobox-option[aria-selected="true"],
|
|
.combobox-option:hover {
|
|
background: var(--grad-soft);
|
|
color: var(--text);
|
|
}
|
|
|
|
.combobox-option[hidden] { display: none; }
|
|
|
|
.combobox-empty {
|
|
padding: 8px 12px;
|
|
color: var(--text-muted);
|
|
font-style: italic;
|
|
}
|
|
|
|
select:focus, input:focus,
|
|
.combobox-input:focus {
|
|
border-color: var(--accent);
|
|
box-shadow: 0 0 0 3px rgb(99 102 241 / 28%);
|
|
}
|
|
|
|
select:disabled, input:disabled,
|
|
.combobox-input:disabled {
|
|
cursor: not-allowed;
|
|
background: var(--bg-alt);
|
|
color: var(--text-dim);
|
|
}
|
|
|
|
.divider {
|
|
height: 1px;
|
|
margin: 22px 0;
|
|
background: var(--border);
|
|
}
|
|
|
|
#create-button {
|
|
width: 100%;
|
|
min-height: 44px;
|
|
border: 0;
|
|
border-radius: var(--radius-sm);
|
|
background: var(--grad-brand);
|
|
color: #fff;
|
|
cursor: pointer;
|
|
font: inherit;
|
|
font-size: 0.875rem;
|
|
font-weight: 700;
|
|
letter-spacing: 0.04em;
|
|
text-transform: uppercase;
|
|
box-shadow: 0 8px 22px -10px var(--primary);
|
|
transition: transform 150ms var(--ease), box-shadow 150ms var(--ease), filter 150ms var(--ease);
|
|
}
|
|
|
|
#create-button:hover:not(:disabled) {
|
|
filter: brightness(1.06);
|
|
box-shadow: 0 10px 26px -8px var(--primary);
|
|
}
|
|
|
|
#create-button:focus-visible {
|
|
outline: 2px solid var(--accent-3);
|
|
outline-offset: 2px;
|
|
}
|
|
|
|
#create-button:disabled { cursor: not-allowed; opacity: 0.65; }
|
|
|
|
.status {
|
|
min-height: 48px;
|
|
margin-top: 16px;
|
|
padding: 12px;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-sm);
|
|
color: var(--text-muted);
|
|
font-family: var(--font-mono);
|
|
font-size: 0.8rem;
|
|
line-height: 1.45;
|
|
white-space: pre-wrap;
|
|
}
|
|
|
|
.status::before {
|
|
content: "$ ";
|
|
color: var(--primary);
|
|
font-weight: 700;
|
|
}
|
|
|
|
.status-ready { background: var(--status-ready); }
|
|
.status-success { background: var(--status-success); color: var(--success); }
|
|
.status-skipped { background: var(--status-skipped); color: var(--warning); }
|
|
.status-error { background: var(--status-error); color: var(--error); }
|
|
|
|
.version {
|
|
margin-top: 16px;
|
|
color: var(--text-dim);
|
|
font-family: var(--font-mono);
|
|
font-size: 0.75rem;
|
|
text-align: right;
|
|
}
|
|
|
|
@media (max-width: 480px) {
|
|
.page { padding: 14px; }
|
|
h1 { font-size: 1.5rem; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main class="page">
|
|
<section class="panel" aria-labelledby="heading">
|
|
<div class="heading-row">
|
|
<div>
|
|
<p class="eyebrow">QC datasheet</p>
|
|
<h1 id="heading">New QC Sheet</h1>
|
|
</div>
|
|
<button
|
|
id="theme-toggle"
|
|
class="theme-toggle"
|
|
type="button"
|
|
aria-label="Switch to light theme"
|
|
title="Switch theme">
|
|
Aa
|
|
</button>
|
|
</div>
|
|
<p class="subtitle">Create a new QC datasheet from the latest matching workbook.</p>
|
|
|
|
<div class="fields">
|
|
<label class="field combobox" for="set-dropdown-input">
|
|
<span id="set-label" class="field-label">Select Set</span>
|
|
<input
|
|
id="set-dropdown-input"
|
|
class="combobox-input"
|
|
type="text"
|
|
autocomplete="off"
|
|
spellcheck="false"
|
|
role="combobox"
|
|
aria-expanded="false"
|
|
aria-controls="set-dropdown-panel"
|
|
aria-autocomplete="list"
|
|
aria-labelledby="set-label"
|
|
placeholder=" ">
|
|
<select id="set-dropdown" aria-labelledby="set-label" tabindex="-1"></select>
|
|
<span class="combobox-caret" aria-hidden="true">▾</span>
|
|
<div id="set-dropdown-panel" class="combobox-panel" role="listbox" aria-labelledby="set-label" hidden></div>
|
|
</label>
|
|
<label class="field combobox" for="ink-dropdown-input">
|
|
<span id="ink-label" class="field-label">Select Ink Color</span>
|
|
<input
|
|
id="ink-dropdown-input"
|
|
class="combobox-input"
|
|
type="text"
|
|
autocomplete="off"
|
|
spellcheck="false"
|
|
role="combobox"
|
|
aria-expanded="false"
|
|
aria-controls="ink-dropdown-panel"
|
|
aria-autocomplete="list"
|
|
aria-labelledby="ink-label"
|
|
placeholder=" ">
|
|
<select id="ink-dropdown" aria-labelledby="ink-label" tabindex="-1"></select>
|
|
<span class="combobox-caret" aria-hidden="true">▾</span>
|
|
<div id="ink-dropdown-panel" class="combobox-panel" role="listbox" aria-labelledby="ink-label" hidden></div>
|
|
</label>
|
|
<label class="field" for="serial-input">
|
|
<span id="serial-label" class="field-label">Serial:</span>
|
|
<input id="serial-input" type="text" placeholder="e.g. 1234/A" aria-labelledby="serial-label">
|
|
</label>
|
|
</div>
|
|
|
|
<div class="divider"></div>
|
|
<button id="create-button" type="button">Create datasheet</button>
|
|
<div id="status" class="status status-ready" role="status">Loading configuration...</div>
|
|
<p id="version" class="version"></p>
|
|
</section>
|
|
</main>
|
|
|
|
<script>
|
|
const setDropdown = document.getElementById("set-dropdown");
|
|
const inkDropdown = document.getElementById("ink-dropdown");
|
|
const setInput = document.getElementById("set-dropdown-input");
|
|
const inkInput = document.getElementById("ink-dropdown-input");
|
|
const setPanel = document.getElementById("set-dropdown-panel");
|
|
const inkPanel = document.getElementById("ink-dropdown-panel");
|
|
const serialInput = document.getElementById("serial-input");
|
|
const createBtn = document.getElementById("create-button");
|
|
const status = document.getElementById("status");
|
|
const themeToggle = document.getElementById("theme-toggle");
|
|
|
|
function isLightTheme() {
|
|
return document.documentElement.getAttribute("data-theme") === "light";
|
|
}
|
|
|
|
function syncThemeToggle() {
|
|
const light = isLightTheme();
|
|
themeToggle.setAttribute(
|
|
"aria-label",
|
|
light ? "Switch to dark theme" : "Switch to light theme"
|
|
);
|
|
themeToggle.textContent = light ? "Dark" : "Light";
|
|
}
|
|
|
|
function applyTheme(theme) {
|
|
if (theme === "light") {
|
|
document.documentElement.setAttribute("data-theme", "light");
|
|
} else {
|
|
document.documentElement.removeAttribute("data-theme");
|
|
}
|
|
try {
|
|
localStorage.setItem("xlsx-clean-theme", theme);
|
|
} catch (error) {
|
|
/* ignore quota / privacy mode */
|
|
}
|
|
syncThemeToggle();
|
|
}
|
|
|
|
themeToggle.addEventListener("click", () => {
|
|
applyTheme(isLightTheme() ? "dark" : "light");
|
|
});
|
|
syncThemeToggle();
|
|
|
|
// Builds a searchable combobox. The underlying <select> stays as the
|
|
// semantic source of truth; the visible widget is a text <input> plus a
|
|
// listbox panel that filters options as the user types.
|
|
function createCombobox(selectEl, inputEl, panelEl) {
|
|
let openState = false;
|
|
let inputDirty = false;
|
|
|
|
const visibleOptions = () =>
|
|
Array.from(panelEl.querySelectorAll(".combobox-option")).filter(
|
|
(node) => !node.hidden
|
|
);
|
|
|
|
const open = () => {
|
|
if (openState || inputEl.disabled) return;
|
|
openState = true;
|
|
panelEl.hidden = false;
|
|
inputEl.setAttribute("aria-expanded", "true");
|
|
filter();
|
|
};
|
|
|
|
const close = () => {
|
|
if (!openState) return;
|
|
openState = false;
|
|
panelEl.hidden = true;
|
|
inputEl.setAttribute("aria-expanded", "false");
|
|
inputEl.removeAttribute("aria-activedescendant");
|
|
for (const node of panelEl.querySelectorAll(".combobox-option")) {
|
|
node.setAttribute("aria-selected", "false");
|
|
}
|
|
};
|
|
|
|
const setActive = (idx) => {
|
|
const options = visibleOptions();
|
|
for (const node of panelEl.querySelectorAll(".combobox-option")) {
|
|
node.setAttribute("aria-selected", "false");
|
|
}
|
|
if (idx < 0 || idx >= options.length) {
|
|
inputEl.removeAttribute("aria-activedescendant");
|
|
return;
|
|
}
|
|
const node = options[idx];
|
|
node.setAttribute("aria-selected", "true");
|
|
node.scrollIntoView({ block: "nearest" });
|
|
inputEl.setAttribute("aria-activedescendant", node.id);
|
|
};
|
|
|
|
const filter = () => {
|
|
const needle = inputDirty ? inputEl.value.trim().toLowerCase() : "";
|
|
let firstVisible = -1;
|
|
let count = 0;
|
|
for (const node of panelEl.querySelectorAll(".combobox-option")) {
|
|
const value = (node.dataset.value || "").toLowerCase();
|
|
const match = !needle || value.includes(needle);
|
|
node.hidden = !match;
|
|
if (match) {
|
|
if (firstVisible === -1) firstVisible = count;
|
|
count += 1;
|
|
}
|
|
}
|
|
const empty = panelEl.querySelector(".combobox-empty");
|
|
if (empty) empty.hidden = count > 0;
|
|
setActive(firstVisible === -1 ? -1 : 0);
|
|
};
|
|
|
|
const selectValue = (value) => {
|
|
if (selectEl.value !== value) {
|
|
selectEl.value = value;
|
|
selectEl.dispatchEvent(new Event("change", { bubbles: true }));
|
|
}
|
|
inputEl.value = value;
|
|
inputDirty = false;
|
|
close();
|
|
inputEl.focus();
|
|
};
|
|
|
|
const syncDisabled = () => {
|
|
inputEl.disabled = selectEl.disabled;
|
|
if (selectEl.disabled) close();
|
|
};
|
|
|
|
const rebuild = () => {
|
|
panelEl.replaceChildren();
|
|
const values = Array.from(selectEl.options).map((o) => o.value);
|
|
for (const value of values) {
|
|
const node = document.createElement("div");
|
|
node.className = "combobox-option";
|
|
node.id = `${selectEl.id}-opt-${CSS.escape(value)}`;
|
|
node.setAttribute("role", "option");
|
|
node.setAttribute("aria-selected", "false");
|
|
node.dataset.value = value;
|
|
node.textContent = value;
|
|
node.addEventListener("mousedown", (event) => {
|
|
// mousedown (not click) so we beat the input's blur handler.
|
|
event.preventDefault();
|
|
selectValue(value);
|
|
});
|
|
panelEl.append(node);
|
|
}
|
|
const empty = document.createElement("div");
|
|
empty.className = "combobox-empty";
|
|
empty.textContent = "No matches";
|
|
empty.hidden = true;
|
|
panelEl.append(empty);
|
|
inputEl.value = selectEl.value || "";
|
|
inputDirty = false;
|
|
syncDisabled();
|
|
};
|
|
|
|
inputEl.addEventListener("focus", open);
|
|
inputEl.addEventListener("mousedown", () => {
|
|
open();
|
|
});
|
|
inputEl.addEventListener("input", () => {
|
|
inputDirty = true;
|
|
if (!openState) open();
|
|
filter();
|
|
});
|
|
inputEl.addEventListener("blur", () => {
|
|
// Defer close so a mousedown on a panel option can fire first.
|
|
setTimeout(() => {
|
|
if (inputEl.value !== selectEl.value) {
|
|
inputEl.value = selectEl.value || "";
|
|
inputDirty = false;
|
|
}
|
|
close();
|
|
}, 0);
|
|
});
|
|
inputEl.addEventListener("keydown", (event) => {
|
|
const options = visibleOptions();
|
|
if (event.key === "ArrowDown") {
|
|
event.preventDefault();
|
|
if (!openState) open();
|
|
const idx = options.findIndex(
|
|
(n) => n.getAttribute("aria-selected") === "true"
|
|
);
|
|
setActive(Math.min(idx + 1, options.length - 1));
|
|
} else if (event.key === "ArrowUp") {
|
|
event.preventDefault();
|
|
if (!openState) open();
|
|
const idx = options.findIndex(
|
|
(n) => n.getAttribute("aria-selected") === "true"
|
|
);
|
|
setActive(Math.max(idx - 1, 0));
|
|
} else if (event.key === "Home") {
|
|
if (openState) {
|
|
event.preventDefault();
|
|
setActive(0);
|
|
}
|
|
} else if (event.key === "End") {
|
|
if (openState) {
|
|
event.preventDefault();
|
|
setActive(options.length - 1);
|
|
}
|
|
} else if (event.key === "Enter") {
|
|
if (openState) {
|
|
event.preventDefault();
|
|
const node = panelEl.querySelector(
|
|
'.combobox-option[aria-selected="true"]'
|
|
);
|
|
if (node) selectValue(node.dataset.value);
|
|
}
|
|
} else if (event.key === "Escape") {
|
|
if (openState) {
|
|
event.preventDefault();
|
|
close();
|
|
}
|
|
}
|
|
});
|
|
|
|
// Click outside closes the panel.
|
|
document.addEventListener("mousedown", (event) => {
|
|
if (!openState) return;
|
|
if (!inputEl.parentElement.contains(event.target)) close();
|
|
});
|
|
|
|
return { rebuild, syncDisabled };
|
|
}
|
|
|
|
const setCombobox = createCombobox(setDropdown, setInput, setPanel);
|
|
const inkCombobox = createCombobox(inkDropdown, inkInput, inkPanel);
|
|
|
|
function populateDropdown(dropdown, combobox, values) {
|
|
dropdown.replaceChildren();
|
|
for (const value of values) {
|
|
const option = document.createElement("option");
|
|
option.value = value;
|
|
option.textContent = value;
|
|
dropdown.append(option);
|
|
}
|
|
dropdown.disabled = values.length === 0;
|
|
combobox.rebuild();
|
|
}
|
|
|
|
function populateDropdowns(sets, inks) {
|
|
populateDropdown(setDropdown, setCombobox, sets);
|
|
populateDropdown(inkDropdown, inkCombobox, inks);
|
|
}
|
|
|
|
function populateInkDropdown(inks) {
|
|
populateDropdown(inkDropdown, inkCombobox, inks);
|
|
}
|
|
|
|
function setLabels(labels) {
|
|
document.getElementById("set-label").textContent = labels.set;
|
|
document.getElementById("ink-label").textContent = labels.ink;
|
|
document.getElementById("serial-label").textContent = labels.serial;
|
|
}
|
|
|
|
function setVersion(version) {
|
|
document.getElementById("version").textContent = `v${version}`;
|
|
}
|
|
|
|
function showStatus(result) {
|
|
const details = [result.message];
|
|
if (result.template) details.push(`Template: ${result.template}`);
|
|
if (result.destination) details.push(`Output: ${result.destination}`);
|
|
if (result.backend) details.push(`Backend: ${result.backend}`);
|
|
status.textContent = details.join("\n");
|
|
status.className = "status";
|
|
if (result.skipped) {
|
|
status.classList.add("status-skipped");
|
|
} else if (result.ok) {
|
|
status.classList.add("status-success");
|
|
} else {
|
|
status.classList.add("status-error");
|
|
}
|
|
}
|
|
|
|
async function initialize() {
|
|
try {
|
|
const data = await window.pywebview.api.get_initial_data();
|
|
populateDropdowns(data.sets, data.inks);
|
|
setLabels(data.labels);
|
|
setVersion(data.version);
|
|
showStatus({ message: "Ready.", ok: true, skipped: false });
|
|
} catch (error) {
|
|
showStatus({ message: `Failed to load configuration: ${error}`, ok: false, skipped: false });
|
|
createBtn.disabled = true;
|
|
}
|
|
}
|
|
|
|
setDropdown.addEventListener("change", async () => {
|
|
try {
|
|
const inks = await window.pywebview.api.get_inks(setDropdown.value);
|
|
populateInkDropdown(inks);
|
|
} catch (error) {
|
|
showStatus({ message: `Failed to load ink colors: ${error}`, ok: false, skipped: false });
|
|
}
|
|
});
|
|
|
|
createBtn.addEventListener("click", async () => {
|
|
createBtn.disabled = true;
|
|
try {
|
|
const result = await window.pywebview.api.create(
|
|
setDropdown.value, inkDropdown.value, serialInput.value
|
|
);
|
|
showStatus(result);
|
|
} catch (error) {
|
|
showStatus({ message: `Failed to create datasheet: ${error}`, ok: false, skipped: false });
|
|
} finally {
|
|
createBtn.disabled = false;
|
|
}
|
|
});
|
|
|
|
window.addEventListener("pywebviewready", initialize);
|
|
</script>
|
|
</body>
|
|
</html>
|