upfdated to ptint plugin
This commit is contained in:
@@ -239,6 +239,11 @@ table tbody tr.selected td {
|
||||
<label for="print-label-btn" style="font-size: 14px; font-weight: 500; color: var(--app-card-text); margin-bottom: 0;">Print selected order</label>
|
||||
<button id="print-label-btn" class="btn btn-primary" style="font-size: 14px; padding: 6px 24px;">Print</button>
|
||||
</div>
|
||||
<div style="width: 100%; text-align: center; margin-top: 12px;">
|
||||
<a href="{{ url_for('main.download_extension') }}" target="_blank" style="font-size: 12px; color: #007bff; text-decoration: none;">
|
||||
🔗 Install Direct Print Extension
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Data Preview Card -->
|
||||
@@ -349,6 +354,9 @@ document.getElementById('check-db-btn').addEventListener('click', function() {
|
||||
if (data.length > 0) {
|
||||
updateLabelPreview(data[0]);
|
||||
|
||||
// Add fallback print functionality if extension is not available
|
||||
addFallbackPrintHandler();
|
||||
|
||||
// Auto-select first row
|
||||
setTimeout(() => {
|
||||
const firstRow = document.querySelector('.print-module-table tbody tr');
|
||||
@@ -428,5 +436,81 @@ function updateLabelPreview(order) {
|
||||
// Update barcode with the same prod order data
|
||||
document.getElementById('barcode-text').textContent = prodOrder;
|
||||
}
|
||||
|
||||
// Fallback print handler for when Chrome extension is not available
|
||||
function addFallbackPrintHandler() {
|
||||
// Check if Chrome extension modified the button
|
||||
setTimeout(() => {
|
||||
const printButton = document.getElementById('print-label-btn');
|
||||
|
||||
// If button text hasn't changed, extension is not active
|
||||
if (printButton && !printButton.innerHTML.includes('🖨️ Print Direct')) {
|
||||
console.log('Chrome extension not detected, adding fallback print handler');
|
||||
|
||||
// Add fallback event listener
|
||||
printButton.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const labelPreview = document.getElementById('label-preview');
|
||||
if (!labelPreview) {
|
||||
alert('Please select an order first.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new window for printing
|
||||
const printWindow = window.open('', '_blank');
|
||||
const printContent = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Quality Recticel Label</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
.print-container {
|
||||
width: 210mm;
|
||||
height: 297mm;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.label-wrapper {
|
||||
transform: scale(1.2);
|
||||
transform-origin: top left;
|
||||
}
|
||||
@media print {
|
||||
body { padding: 0; }
|
||||
.print-container { margin: 0; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="print-container">
|
||||
<div class="label-wrapper">
|
||||
${labelPreview.outerHTML}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
printWindow.document.write(printContent);
|
||||
printWindow.document.close();
|
||||
|
||||
// Wait for content to load, then print
|
||||
printWindow.onload = function() {
|
||||
printWindow.focus();
|
||||
printWindow.print();
|
||||
printWindow.close();
|
||||
};
|
||||
});
|
||||
|
||||
// Update button text to indicate fallback mode
|
||||
printButton.innerHTML = '🖨️ Print (Browser)';
|
||||
printButton.title = 'Print using browser dialog - Install Chrome Extension for direct printing';
|
||||
}
|
||||
}, 2000); // Wait 2 seconds for extension to load
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user