Add page range control for print preview #20
@@ -57,8 +57,28 @@
|
|||||||
cursor: wait;
|
cursor: wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preview-controls .page-range {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
margin-right: 12px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-controls .page-range input {
|
||||||
|
width: 4.5em;
|
||||||
|
padding: 8px 6px;
|
||||||
|
font-size: 16px;
|
||||||
|
border: 1px solid #475569;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #0f172a;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
.page-wrapper {
|
.page-wrapper {
|
||||||
margin-top: 80px; /* Space for controls */
|
margin-top: 110px; /* Space for controls */
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -78,6 +98,25 @@
|
|||||||
page-break-after: always;
|
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 */
|
/* CSS Grid for the 4 slips */
|
||||||
.slip-grid {
|
.slip-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
@@ -120,6 +159,15 @@
|
|||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100vh; /* Fill printed page */
|
height: 100vh; /* Fill printed page */
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.a4-page.skip-print {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-badge {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -131,13 +179,21 @@
|
|||||||
{{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) |
|
{{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) |
|
||||||
{{ order.box_count }} Boxes ({{ order.box_pages }} Pages)
|
{{ order.box_count }} Boxes ({{ order.box_pages }} Pages)
|
||||||
</p>
|
</p>
|
||||||
|
<label class="page-range">
|
||||||
|
Pages
|
||||||
|
<input id="start-from" type="number" min="1" max="{{ pages|length }}" value="1" {% if not pages %}disabled{% endif %}>
|
||||||
|
–
|
||||||
|
<input id="end-at" type="number" min="1" max="{{ pages|length }}" value="{{ pages|length }}" {% if not pages %}disabled{% endif %}>
|
||||||
|
/ {{ pages|length }}
|
||||||
|
</label>
|
||||||
<button id="btn-print" type="button" disabled>🖨️ Print Now</button>
|
<button id="btn-print" type="button" disabled>🖨️ Print Now</button>
|
||||||
<button type="button" onclick="window.close()" style="background:#64748b; margin-left: 10px;">Close</button>
|
<button type="button" onclick="window.close()" style="background:#64748b; margin-left: 10px;">Close</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page-wrapper">
|
<div class="page-wrapper">
|
||||||
{% for page in pages %}
|
{% 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">
|
<div class="slip-grid">
|
||||||
{% for weight in page.slips %}
|
{% for weight in page.slips %}
|
||||||
<div class="slip-quadrant">
|
<div class="slip-quadrant">
|
||||||
@@ -157,6 +213,10 @@
|
|||||||
const FIELDS = ['batch', 'date', 'next', 'weight'];
|
const FIELDS = ['batch', 'date', 'next', 'weight'];
|
||||||
const varsEl = document.getElementById('calibration-vars');
|
const varsEl = document.getElementById('calibration-vars');
|
||||||
const btn = document.getElementById('btn-print');
|
const btn = document.getElementById('btn-print');
|
||||||
|
const startInput = document.getElementById('start-from');
|
||||||
|
const endInput = document.getElementById('end-at');
|
||||||
|
const pages = document.querySelectorAll('.a4-page');
|
||||||
|
const total = pages.length;
|
||||||
|
|
||||||
function cssFromCal(cal) {
|
function cssFromCal(cal) {
|
||||||
const lines = [':root {'];
|
const lines = [':root {'];
|
||||||
@@ -177,11 +237,49 @@
|
|||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clampPage(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() {
|
||||||
|
let start = clampPage(startInput.value);
|
||||||
|
let end = clampPage(endInput.value);
|
||||||
|
if (start > end) end = start;
|
||||||
|
startInput.value = start;
|
||||||
|
endInput.value = end;
|
||||||
|
pages.forEach(function (el) {
|
||||||
|
const pageNum = parseInt(el.getAttribute('data-page'), 10);
|
||||||
|
el.classList.toggle('skip-print', pageNum < start || pageNum > end);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function seedFromQuery() {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
const from = params.get('from');
|
||||||
|
const to = params.get('to');
|
||||||
|
if (from != null) startInput.value = clampPage(from);
|
||||||
|
if (to != null) endInput.value = clampPage(to);
|
||||||
|
applySkip();
|
||||||
|
}
|
||||||
|
|
||||||
function enablePrint() {
|
function enablePrint() {
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
btn.onclick = function () { window.print(); };
|
btn.onclick = function () {
|
||||||
|
applySkip();
|
||||||
|
window.print();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startInput.addEventListener('change', applySkip);
|
||||||
|
startInput.addEventListener('input', applySkip);
|
||||||
|
endInput.addEventListener('change', applySkip);
|
||||||
|
endInput.addEventListener('input', applySkip);
|
||||||
|
seedFromQuery();
|
||||||
|
|
||||||
fetch('/api/calibration', { cache: 'no-store' })
|
fetch('/api/calibration', { cache: 'no-store' })
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||||
|
|||||||
Reference in New Issue
Block a user