From 13d93d8a14da34e43dad6447453699c5f4470517 Mon Sep 17 00:00:00 2001 From: Quality App System Date: Thu, 15 Jan 2026 18:57:48 +0200 Subject: [PATCH] updated fg_scan to enable print only is requested --- py_app/app/templates/fg_scan.html | 60 +++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/py_app/app/templates/fg_scan.html b/py_app/app/templates/fg_scan.html index a2e818a..c0f6457 100644 --- a/py_app/app/templates/fg_scan.html +++ b/py_app/app/templates/fg_scan.html @@ -155,6 +155,30 @@ document.addEventListener('DOMContentLoaded', function() { scanToBoxesEnabled = this.checked; localStorage.setItem('scan_to_boxes_enabled', this.checked); console.log('Toggle changed - Scan to boxes:', scanToBoxesEnabled); + + // Connect or disconnect QZ Tray based on toggle state + if (scanToBoxesEnabled) { + console.log('Scan-to-boxes enabled, connecting QZ Tray...'); + if (window.qz && !window.qz.websocket.isActive()) { + window.qz.websocket.connect().then(() => { + console.log('QZ Tray connected'); + showNotification('✅ QZ Tray connected for box label printing', 'success'); + }).catch(err => { + console.warn('QZ Tray connection failed:', err); + showNotification('⚠️ QZ Tray connection failed. Box labels cannot be printed.', 'warning'); + }); + } + } else { + console.log('Scan-to-boxes disabled, disconnecting QZ Tray...'); + if (window.qz && window.qz.websocket.isActive()) { + window.qz.websocket.disconnect().then(() => { + console.log('QZ Tray disconnected'); + showNotification('ℹ️ QZ Tray disconnected', 'info'); + }).catch(err => { + console.warn('QZ Tray disconnect failed:', err); + }); + } + } }); } @@ -773,13 +797,22 @@ document.addEventListener('DOMContentLoaded', function() { } }); - // Initialize QZ Tray for printing box labels - if (window.qz) { - window.qz.websocket.connect().then(() => { - console.log('QZ Tray connected for box label printing'); - }).catch(err => { - console.warn('QZ Tray not available:', err); - }); + // Initialize QZ Tray for printing box labels - only if scan-to-boxes is enabled + function initializeQzTray() { + if (window.qz && scanToBoxesEnabled) { + window.qz.websocket.connect().then(() => { + console.log('QZ Tray connected for box label printing'); + }).catch(err => { + console.warn('QZ Tray not available:', err); + }); + } else if (window.qz && !scanToBoxesEnabled) { + console.log('Scan-to-boxes disabled, skipping QZ Tray connection'); + } + } + + // Initialize on page load if enabled + if (scanToBoxesEnabled) { + initializeQzTray(); } }); @@ -789,6 +822,12 @@ document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() { // Quick box creation button document.getElementById('quick-box-create-btn').addEventListener('click', async function() { + // Check if scan-to-boxes is enabled + if (!scanToBoxesEnabled) { + showNotification('⚠️ Please enable "Scan to Boxes" feature first', 'warning'); + return; + } + try { this.disabled = true; this.textContent = 'Creating...'; @@ -908,6 +947,13 @@ document.addEventListener('DOMContentLoaded', function() { // Assign to scanned box button document.getElementById('assign-to-box-btn').addEventListener('click', async function() { + // Check if scan-to-boxes is enabled + if (!scanToBoxesEnabled) { + showNotification('⚠️ "Scan to Boxes" feature is disabled', 'warning'); + closeBoxModal(); + return; + } + const boxNumber = document.getElementById('scan-box-input').value.trim(); if (!boxNumber) { showNotification('⚠️ Please scan or enter a box number', 'warning');