Initial commit: Product Slip Manager
This commit is contained in:
433
slips/static/slips/css/style.css
Normal file
433
slips/static/slips/css/style.css
Normal file
@@ -0,0 +1,433 @@
|
||||
/* Base Variables */
|
||||
:root {
|
||||
--bg-primary: #0f172a;
|
||||
--bg-secondary: #1e293b;
|
||||
--bg-glass: rgba(30, 41, 59, 0.7);
|
||||
--accent: #3b82f6;
|
||||
--accent-glow: #60a5fa;
|
||||
--success: #10b981;
|
||||
--warning: #f59e0b;
|
||||
--danger: #ef4444;
|
||||
--text-primary: #f1f5f9;
|
||||
--text-secondary: #94a3b8;
|
||||
--border: rgba(148, 163, 184, 0.1);
|
||||
|
||||
--font-sans: 'Inter', sans-serif;
|
||||
--font-mono: 'JetBrains Mono', monospace;
|
||||
}
|
||||
|
||||
/* Reset & Base */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-sans);
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
line-height: 1.5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
/* Navigation */
|
||||
.navbar {
|
||||
background: var(--bg-glass);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
border-bottom: 1px solid var(--border);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.nav-container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 1rem 2rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav-logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
text-decoration: none;
|
||||
color: var(--text-primary);
|
||||
font-weight: 700;
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.nav-links {
|
||||
display: flex;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
transition: color 0.2s;
|
||||
padding: 0.5rem 0;
|
||||
}
|
||||
|
||||
.nav-link:hover, .nav-link.active {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.nav-link.active {
|
||||
border-bottom: 2px solid var(--accent);
|
||||
}
|
||||
|
||||
/* Layout */
|
||||
.main-content {
|
||||
max-width: 1200px;
|
||||
margin: 2rem auto;
|
||||
padding: 0 2rem;
|
||||
}
|
||||
|
||||
.page-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1.5fr;
|
||||
gap: 2rem;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
/* Print queue spans full width */
|
||||
.print-queue-layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
/* Cards & Glassmorphism */
|
||||
.card {
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--border);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.glass-card {
|
||||
background: var(--bg-glass);
|
||||
backdrop-filter: blur(16px);
|
||||
-webkit-backdrop-filter: blur(16px);
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
padding: 1.5rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Forms */
|
||||
form {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.form-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
input, select {
|
||||
background: rgba(15, 23, 42, 0.5);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text-primary);
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 6px;
|
||||
font-family: inherit;
|
||||
font-size: 1rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
input:focus, select:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
|
||||
}
|
||||
|
||||
.computed-value {
|
||||
padding: 0.75rem 1rem;
|
||||
background: rgba(59, 130, 246, 0.1);
|
||||
border-radius: 6px;
|
||||
color: var(--accent-glow);
|
||||
font-weight: 600;
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.sub-panel {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
margin-top: 0.5rem;
|
||||
border-left: 2px solid var(--accent);
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
border: none;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 1rem 2rem;
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
|
||||
.btn-accent {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-accent:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.btn-glow {
|
||||
box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
|
||||
}
|
||||
|
||||
.btn-glow:hover {
|
||||
box-shadow: 0 0 25px rgba(59, 130, 246, 0.6);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.btn-ghost:hover {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
color: var(--danger);
|
||||
border-color: rgba(239, 68, 68, 0.3);
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
.table-wrap {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.data-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.data-table th, .data-table td {
|
||||
padding: 1rem 1.5rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.data-table tbody tr {
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.data-table tbody tr:hover {
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
color: var(--text-secondary);
|
||||
padding: 3rem !important;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Badges */
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.badge-pending { background: rgba(245, 158, 11, 0.1); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
|
||||
.badge-done { background: rgba(16, 185, 129, 0.1); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.2); }
|
||||
.badge-cancelled { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }
|
||||
.badge-accent { background: rgba(59, 130, 246, 0.1); color: var(--accent-glow); border: 1px solid rgba(59, 130, 246, 0.2); }
|
||||
.badge-neutral { background: rgba(255, 255, 255, 0.05); color: var(--text-secondary); border: 1px solid var(--border); }
|
||||
|
||||
.card-badge {
|
||||
background: rgba(0,0,0,0.3);
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Print Queue Grid */
|
||||
.queue-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
||||
gap: 1.5rem;
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.queue-item {
|
||||
background: rgba(15, 23, 42, 0.4);
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.queue-item:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
|
||||
border-color: rgba(59, 130, 246, 0.3);
|
||||
}
|
||||
|
||||
.queue-item-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1rem 1.5rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.queue-item-body {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.product-title {
|
||||
font-size: 1.125rem;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.order-details-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.detail-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.detail-col .label {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.detail-col .value {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.print-meta {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
margin-top: 1rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.queue-item-actions {
|
||||
padding: 1rem 1.5rem;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-top: 1px solid var(--border);
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.queue-item-actions .btn {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* Toast */
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 2rem;
|
||||
right: 2rem;
|
||||
background: var(--bg-secondary);
|
||||
color: white;
|
||||
padding: 1rem 1.5rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
|
||||
border-left: 4px solid var(--accent);
|
||||
transform: translateY(150%);
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.toast.error {
|
||||
border-left-color: var(--danger);
|
||||
}
|
||||
|
||||
/* RTL Support for Persian */
|
||||
html[dir="rtl"] {
|
||||
/* Kept LTR as requested by user, but framework is ready if they change their mind */
|
||||
}
|
||||
151
slips/static/slips/js/entry.js
Normal file
151
slips/static/slips/js/entry.js
Normal file
@@ -0,0 +1,151 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const productSelect = document.getElementById('product');
|
||||
const totalWeightInput = document.getElementById('total-weight');
|
||||
const canisterWeightInput = document.getElementById('canister-weight');
|
||||
const canistersPerBoxInput = document.getElementById('canisters-per-box');
|
||||
const previewDisplay = document.getElementById('preview-display');
|
||||
const form = document.getElementById('order-form');
|
||||
|
||||
// Default dates
|
||||
const today = new Date();
|
||||
dateInput.valueAsDate = today;
|
||||
|
||||
// Auto calculate +6 months
|
||||
function updateNextControl() {
|
||||
const d = new Date(dateInput.value);
|
||||
if (isNaN(d)) return;
|
||||
d.setMonth(d.getMonth() + 6);
|
||||
nextControlInput.valueAsDate = d;
|
||||
}
|
||||
updateNextControl();
|
||||
dateInput.addEventListener('change', updateNextControl);
|
||||
|
||||
// Auto calculate previews
|
||||
function updatePreview() {
|
||||
const tw = parseFloat(totalWeightInput.value) || 0;
|
||||
const cw = parseFloat(canisterWeightInput.value) || 1;
|
||||
const cpb = parseInt(canistersPerBoxInput.value) || 1;
|
||||
|
||||
const cc = Math.ceil(tw / cw);
|
||||
const cp = Math.ceil(cc / 4);
|
||||
|
||||
const bc = Math.ceil(cc / cpb);
|
||||
const bp = Math.ceil(bc / 4);
|
||||
|
||||
previewDisplay.textContent = `Canisters: ${cc} (${cp} pages) | Boxes: ${bc} (${bp} pages)`;
|
||||
}
|
||||
|
||||
// Listeners for updates
|
||||
totalWeightInput.addEventListener('input', updatePreview);
|
||||
canisterWeightInput.addEventListener('input', updatePreview);
|
||||
canistersPerBoxInput.addEventListener('input', updatePreview);
|
||||
updatePreview();
|
||||
|
||||
// Auto weight from product selection
|
||||
productSelect.addEventListener('change', (e) => {
|
||||
const opt = e.target.options[e.target.selectedIndex];
|
||||
if (opt && opt.dataset.weight) {
|
||||
canisterWeightInput.value = opt.dataset.weight;
|
||||
updatePreview();
|
||||
}
|
||||
});
|
||||
|
||||
// Submit new order
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const payload = {
|
||||
product_id: parseInt(productSelect.value),
|
||||
batch_number: document.getElementById('batch').value,
|
||||
production_date: dateInput.value,
|
||||
next_control_date: nextControlInput.value,
|
||||
total_weight: parseFloat(totalWeightInput.value),
|
||||
canister_weight: parseFloat(canisterWeightInput.value),
|
||||
canisters_per_box: parseInt(canistersPerBoxInput.value)
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/orders', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
showToast(currentLang === 'fa' ? 'سفارش به صف چاپ اضافه شد' : 'Order added to print queue!');
|
||||
form.reset();
|
||||
dateInput.valueAsDate = today;
|
||||
updateNextControl();
|
||||
updatePreview();
|
||||
setTimeout(() => window.location.reload(), 1000);
|
||||
} else {
|
||||
const err = await res.json();
|
||||
console.error(err);
|
||||
showToast('Error creating order', true);
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('Network error', true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Inline Product addition
|
||||
function showAddProduct() {
|
||||
document.getElementById('add-product-panel').style.display = 'block';
|
||||
}
|
||||
|
||||
function hideAddProduct() {
|
||||
document.getElementById('add-product-panel').style.display = 'none';
|
||||
}
|
||||
|
||||
async function addProduct() {
|
||||
const code = document.getElementById('new-code').value;
|
||||
const desc = document.getElementById('new-desc').value;
|
||||
const weight = parseFloat(document.getElementById('new-weight').value);
|
||||
|
||||
if (!code || !desc) {
|
||||
showToast('Code and Description are required', true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/products', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, description: desc, default_net_weight: weight })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const p = await res.json();
|
||||
const select = document.getElementById('product');
|
||||
const opt = document.createElement('option');
|
||||
opt.value = p.id;
|
||||
opt.dataset.weight = p.default_net_weight;
|
||||
opt.textContent = `${p.code} — ${p.description}`;
|
||||
select.appendChild(opt);
|
||||
select.value = p.id;
|
||||
document.getElementById('canister-weight').value = p.default_net_weight;
|
||||
updatePreview();
|
||||
|
||||
hideAddProduct();
|
||||
showToast('Product added');
|
||||
} else {
|
||||
showToast('Error adding product', true);
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('Network error', true);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteOrder(id) {
|
||||
if (!confirm('Cancel this order?')) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/orders/${id}`, { method: 'DELETE' });
|
||||
if (res.ok) {
|
||||
window.location.reload();
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('Error', true);
|
||||
}
|
||||
}
|
||||
120
slips/static/slips/js/i18n.js
Normal file
120
slips/static/slips/js/i18n.js
Normal file
@@ -0,0 +1,120 @@
|
||||
const translations = {
|
||||
'en': {
|
||||
'app_title': 'Product Slip Manager',
|
||||
'data_entry': 'Data Entry',
|
||||
'print_queue': 'Print Queue',
|
||||
'calibrate': 'Calibrate',
|
||||
'new_order': 'New Order',
|
||||
'product': 'Product',
|
||||
'add_product': '+ Add New Product',
|
||||
'product_code': 'Product Code',
|
||||
'description': 'Description',
|
||||
'default_weight': 'Default Weight',
|
||||
'save': 'Save',
|
||||
'cancel': 'Cancel',
|
||||
'batch_number': 'Batch #',
|
||||
'date': 'Date',
|
||||
'next_control': 'Next Control Date',
|
||||
'net_weight': 'Net Weight (kg)',
|
||||
'total_weight': 'Total Weight (kg)',
|
||||
'canister_weight': 'Canister Weight (kg)',
|
||||
'canisters_per_box': 'Canisters per Box',
|
||||
'labels_preview': 'Labels Generated',
|
||||
'canisters': 'Canisters',
|
||||
'boxes': 'Boxes',
|
||||
'pages_needed': 'Pages Needed',
|
||||
'total_pages': 'Pages',
|
||||
'add_to_queue': 'Add to Print Queue',
|
||||
'recent_orders': 'Recent Orders',
|
||||
'status': 'Status',
|
||||
'no_orders': 'No orders yet',
|
||||
'no_pending_orders': 'No pending orders to print.',
|
||||
'print': 'Print',
|
||||
'mark_done': 'Mark Done',
|
||||
'print_history': 'Print History',
|
||||
'printed_at': 'Printed At',
|
||||
'no_history': 'No print history'
|
||||
},
|
||||
'fa': {
|
||||
'app_title': 'مدیریت برچسب محصول',
|
||||
'data_entry': 'ثبت اطلاعات',
|
||||
'print_queue': 'صف چاپ',
|
||||
'calibrate': 'کالیبراسیون',
|
||||
'new_order': 'سفارش جدید',
|
||||
'product': 'محصول',
|
||||
'add_product': '+ افزودن محصول جدید',
|
||||
'product_code': 'کد محصول',
|
||||
'description': 'شرح',
|
||||
'default_weight': 'وزن پیشفرض',
|
||||
'save': 'ذخیره',
|
||||
'cancel': 'لغو',
|
||||
'batch_number': 'شماره بچ',
|
||||
'date': 'تاریخ',
|
||||
'next_control': 'تاریخ کنترل بعدی',
|
||||
'net_weight': 'وزن خالص (کیلوگرم)',
|
||||
'total_weight': 'وزن کل (کیلوگرم)',
|
||||
'canister_weight': 'وزن قوطی (کیلوگرم)',
|
||||
'canisters_per_box': 'تعداد قوطی در هر کارتن',
|
||||
'labels_preview': 'برچسبهای تولیدی',
|
||||
'canisters': 'تعداد قوطی',
|
||||
'boxes': 'تعداد کارتن',
|
||||
'pages_needed': 'تعداد صفحات',
|
||||
'total_pages': 'صفحات',
|
||||
'add_to_queue': 'افزودن به صف چاپ',
|
||||
'recent_orders': 'سفارشات اخیر',
|
||||
'status': 'وضعیت',
|
||||
'no_orders': 'سفارشی ثبت نشده',
|
||||
'no_pending_orders': 'سفارشی در انتظار چاپ نیست.',
|
||||
'print': 'چاپ',
|
||||
'mark_done': 'تایید چاپ',
|
||||
'print_history': 'سابقه چاپ',
|
||||
'printed_at': 'زمان چاپ',
|
||||
'no_history': 'سابقهای وجود ندارد'
|
||||
}
|
||||
};
|
||||
|
||||
let currentLang = localStorage.getItem('slip_lang') || 'en';
|
||||
|
||||
function applyLanguage(lang) {
|
||||
document.querySelectorAll('[data-i18n]').forEach(el => {
|
||||
const key = el.getAttribute('data-i18n');
|
||||
if (translations[lang][key]) {
|
||||
el.textContent = translations[lang][key];
|
||||
}
|
||||
});
|
||||
|
||||
const toggleBtn = document.getElementById('lang-label');
|
||||
if (toggleBtn) {
|
||||
toggleBtn.textContent = lang === 'en' ? '🇮🇷 FA' : '🇬🇧 EN';
|
||||
}
|
||||
|
||||
// User requested Persian to be LTR, so we don't change the dir attribute
|
||||
// document.documentElement.dir = lang === 'fa' ? 'rtl' : 'ltr';
|
||||
}
|
||||
|
||||
function toggleLanguage() {
|
||||
currentLang = currentLang === 'en' ? 'fa' : 'en';
|
||||
localStorage.setItem('slip_lang', currentLang);
|
||||
applyLanguage(currentLang);
|
||||
}
|
||||
|
||||
// Common Toast notification
|
||||
function showToast(message, isError = false) {
|
||||
const toast = document.getElementById('toast');
|
||||
if (!toast) return;
|
||||
|
||||
toast.textContent = message;
|
||||
if (isError) {
|
||||
toast.classList.add('error');
|
||||
} else {
|
||||
toast.classList.remove('error');
|
||||
}
|
||||
|
||||
toast.classList.add('show');
|
||||
setTimeout(() => toast.classList.remove('show'), 3000);
|
||||
}
|
||||
|
||||
// Initialize on load
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
applyLanguage(currentLang);
|
||||
});
|
||||
52
slips/static/slips/js/print.js
Normal file
52
slips/static/slips/js/print.js
Normal file
@@ -0,0 +1,52 @@
|
||||
function printOrder(id) {
|
||||
// Open the print page in a new window/tab
|
||||
const win = window.open(`/print-page/${id}/`, '_blank');
|
||||
if (win) {
|
||||
win.focus();
|
||||
} else {
|
||||
showToast('Please allow popups to print', true);
|
||||
}
|
||||
}
|
||||
|
||||
async function markDone(id) {
|
||||
try {
|
||||
const res = await fetch(`/api/orders/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status: 'done' })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
showToast('Order marked as done');
|
||||
document.getElementById(`order-${id}`).style.display = 'none';
|
||||
// Reload after brief delay to update history table
|
||||
setTimeout(() => window.location.reload(), 1500);
|
||||
} else {
|
||||
showToast('Error updating status', true);
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('Network error', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-refresh pending queue every 10 seconds
|
||||
setInterval(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/orders?status=pending');
|
||||
if (res.ok) {
|
||||
const orders = await res.json();
|
||||
document.getElementById('pending-count').textContent = orders.length;
|
||||
|
||||
// Simple approach: if count changes, just reload to get clean state
|
||||
// In a larger app, we'd do smart DOM updates here
|
||||
const currentItems = document.querySelectorAll('.queue-item:not([style*="display: none"])').length;
|
||||
if (orders.length > currentItems) {
|
||||
// New order arrived!
|
||||
showToast(currentLang === 'fa' ? 'سفارش جدید دریافت شد!' : 'New order arrived!');
|
||||
setTimeout(() => window.location.reload(), 2000);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('Refresh failed silently');
|
||||
}
|
||||
}, 10000);
|
||||
Reference in New Issue
Block a user