From d8a2b361fbf28b96830a8cbe1dcbb44068cf12da Mon Sep 17 00:00:00 2001 From: diaco Date: Mon, 5 Oct 2026 14:52:02 +0330 Subject: [PATCH] Add start-from-page control for mid-print resume Co-authored-by: Cursor --- slips/templates/slips/print_page.html | 100 ++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 5 deletions(-) diff --git a/slips/templates/slips/print_page.html b/slips/templates/slips/print_page.html index 9d16705..0bb0591 100644 --- a/slips/templates/slips/print_page.html +++ b/slips/templates/slips/print_page.html @@ -36,7 +36,7 @@ z-index: 100; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } - + .preview-controls button { background: #3b82f6; color: white; @@ -57,8 +57,28 @@ cursor: wait; } + .preview-controls .start-from { + display: inline-flex; + align-items: center; + gap: 8px; + margin-right: 12px; + font-family: sans-serif; + font-size: 14px; + vertical-align: middle; + } + + .preview-controls .start-from input { + width: 4.5em; + padding: 8px 6px; + font-size: 16px; + border: 1px solid #475569; + border-radius: 6px; + background: #0f172a; + color: #fff; + } + .page-wrapper { - margin-top: 80px; /* Space for controls */ + margin-top: 110px; /* Space for controls */ display: flex; flex-direction: column; align-items: center; @@ -78,6 +98,25 @@ page-break-after: always; } + .a4-page.skip-print { + opacity: 0.4; + } + + .page-badge { + position: absolute; + top: 8px; + right: 8px; + z-index: 2; + background: #1e293b; + color: #fff; + font-family: sans-serif; + font-size: 12px; + font-weight: bold; + padding: 4px 8px; + border-radius: 4px; + pointer-events: none; + } + /* CSS Grid for the 4 slips */ .slip-grid { display: grid; @@ -120,6 +159,15 @@ box-shadow: none; width: 100%; height: 100vh; /* Fill printed page */ + opacity: 1; + } + + .a4-page.skip-print { + display: none !important; + } + + .page-badge { + display: none; } } @@ -128,16 +176,22 @@

Order #{{ order.id }} — {{ order.product.code }}
- {{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) | + {{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) | {{ order.box_count }} Boxes ({{ order.box_pages }} Pages)

+
{% for page in pages %} -
+
+
Page {{ forloop.counter }} / {{ pages|length }}
{% for weight in page.slips %}
@@ -157,6 +211,9 @@ const FIELDS = ['batch', 'date', 'next', 'weight']; const varsEl = document.getElementById('calibration-vars'); const btn = document.getElementById('btn-print'); + const startInput = document.getElementById('start-from'); + const pages = document.querySelectorAll('.a4-page'); + const total = pages.length; function cssFromCal(cal) { const lines = [':root {']; @@ -177,11 +234,44 @@ return lines.join('\n'); } + function clampStart(n) { + if (!total) return 1; + n = parseInt(n, 10); + if (isNaN(n) || n < 1) return 1; + if (n > total) return total; + return n; + } + + function applySkip() { + const start = clampStart(startInput.value); + startInput.value = start; + pages.forEach(function (el) { + const pageNum = parseInt(el.getAttribute('data-page'), 10); + el.classList.toggle('skip-print', pageNum < start); + }); + } + + function seedFromQuery() { + const params = new URLSearchParams(window.location.search); + const from = params.get('from'); + if (from != null) { + startInput.value = clampStart(from); + } + applySkip(); + } + function enablePrint() { btn.disabled = false; - btn.onclick = function () { window.print(); }; + btn.onclick = function () { + applySkip(); + window.print(); + }; } + startInput.addEventListener('change', applySkip); + startInput.addEventListener('input', applySkip); + seedFromQuery(); + fetch('/api/calibration', { cache: 'no-store' }) .then(function (res) { if (!res.ok) throw new Error('HTTP ' + res.status);