Add start-from-page control for mid-print resume
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -128,16 +176,22 @@
|
||||
<div class="preview-controls">
|
||||
<p style="margin-bottom: 10px; font-family: sans-serif;">
|
||||
Order #{{ order.id }} — {{ order.product.code }} <br>
|
||||
{{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) |
|
||||
{{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) |
|
||||
{{ order.box_count }} Boxes ({{ order.box_pages }} Pages)
|
||||
</p>
|
||||
<label class="start-from" for="start-from">
|
||||
Start from page
|
||||
<input id="start-from" type="number" min="1" max="{{ pages|length }}" value="1" {% if not pages %}disabled{% endif %}>
|
||||
/ {{ pages|length }}
|
||||
</label>
|
||||
<button id="btn-print" type="button" disabled>🖨️ Print Now</button>
|
||||
<button type="button" onclick="window.close()" style="background:#64748b; margin-left: 10px;">Close</button>
|
||||
</div>
|
||||
|
||||
<div class="page-wrapper">
|
||||
{% for page in pages %}
|
||||
<div class="a4-page">
|
||||
<div class="a4-page" data-page="{{ forloop.counter }}">
|
||||
<div class="page-badge">Page {{ forloop.counter }} / {{ pages|length }}</div>
|
||||
<div class="slip-grid">
|
||||
{% for weight in page.slips %}
|
||||
<div class="slip-quadrant">
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user