Fetch fresh calibration on every print
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Print Order #{{ order.id }}</title>
|
||||
<link rel="stylesheet" href="{% static 'slips/css/label_print.css' %}">
|
||||
<style>
|
||||
<style id="calibration-vars">
|
||||
{{ calibration_css|safe }}
|
||||
</style>
|
||||
<style>
|
||||
@@ -48,10 +48,15 @@
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.preview-controls button:hover {
|
||||
.preview-controls button:hover:not(:disabled) {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.preview-controls button:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: wait;
|
||||
}
|
||||
|
||||
.page-wrapper {
|
||||
margin-top: 80px; /* Space for controls */
|
||||
display: flex;
|
||||
@@ -126,8 +131,8 @@
|
||||
{{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) |
|
||||
{{ order.box_count }} Boxes ({{ order.box_pages }} Pages)
|
||||
</p>
|
||||
<button onclick="window.print()">🖨️ Print Now</button>
|
||||
<button onclick="window.close()" style="background:#64748b; margin-left: 10px;">Close</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>
|
||||
</div>
|
||||
|
||||
<div class="page-wrapper">
|
||||
@@ -148,8 +153,48 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Optional: auto-trigger print dialog when opened
|
||||
// window.onload = function() { window.print(); }
|
||||
(function () {
|
||||
const FIELDS = ['batch', 'date', 'next', 'weight'];
|
||||
const varsEl = document.getElementById('calibration-vars');
|
||||
const btn = document.getElementById('btn-print');
|
||||
|
||||
function cssFromCal(cal) {
|
||||
const lines = [':root {'];
|
||||
for (const field of FIELDS) {
|
||||
const v = cal[field];
|
||||
lines.push(' --' + field + '-top: ' + v.top + 'mm;');
|
||||
lines.push(' --' + field + '-left: ' + v.left + 'mm;');
|
||||
lines.push(' --' + field + '-font: ' + v.font + 'pt;');
|
||||
lines.push(' --' + field + '-bottom-top: ' + v.bottom_top + 'mm;');
|
||||
if (v.bottom_left != null) {
|
||||
lines.push(' --' + field + '-bottom-left: ' + v.bottom_left + 'mm;');
|
||||
}
|
||||
if (v.right_left != null) {
|
||||
lines.push(' --' + field + '-right-left: ' + v.right_left + 'mm;');
|
||||
}
|
||||
}
|
||||
lines.push('}');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function enablePrint() {
|
||||
btn.disabled = false;
|
||||
btn.onclick = function () { window.print(); };
|
||||
}
|
||||
|
||||
fetch('/api/calibration', { cache: 'no-store' })
|
||||
.then(function (res) {
|
||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||
return res.json();
|
||||
})
|
||||
.then(function (cal) {
|
||||
varsEl.textContent = cssFromCal(cal);
|
||||
})
|
||||
.catch(function () {
|
||||
// Keep server-rendered vars; still allow print
|
||||
})
|
||||
.finally(enablePrint);
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user