Add order count edit, remove, and undo-done

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-07 08:16:16 +03:30
parent ab4416251a
commit a5b863fa6c
10 changed files with 189 additions and 41 deletions

View File

@@ -598,6 +598,46 @@ html[dir="rtl"][data-theme="light"] .card-header::after {
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid var(--border);
flex-wrap: wrap;
align-items: center;
}
.count-stepper {
display: inline-flex;
align-items: center;
gap: 0.35rem;
padding: 0.2rem 0.5rem;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--bg-muted);
font-variant-numeric: tabular-nums;
}
.count-stepper .stepper-label {
font-size: 0.75rem;
color: var(--text-secondary);
margin-inline-start: 0.15rem;
}
.stepper-btn {
width: 1.5rem;
height: 1.5rem;
padding: 0;
border: 1px solid var(--border);
border-radius: 4px;
background: var(--bg-secondary);
color: var(--text-primary);
cursor: pointer;
font-size: 1rem;
line-height: 1;
display: inline-flex;
align-items: center;
justify-content: center;
}
.stepper-btn:hover {
background: var(--bg-hover);
border-color: var(--accent);
}
.queue-item-actions {

View File

@@ -165,16 +165,3 @@ async function addProduct() {
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);
}
}

View File

@@ -36,6 +36,8 @@ const translations = {
'no_pending_orders': 'No pending orders to print.',
'print': 'Print',
'mark_done': 'Mark Done',
'undo_done': 'Undo',
'remove': 'Remove',
'print_history': 'Print History',
'printed_at': 'Printed At',
'no_history': 'No print history'
@@ -77,6 +79,8 @@ const translations = {
'no_pending_orders': 'سفارشی در انتظار چاپ نیست.',
'print': 'چاپ',
'mark_done': 'چاپ شد',
'undo_done': 'بازگردانی',
'remove': 'حذف',
'print_history': 'سابقه چاپ',
'printed_at': 'زمان چاپ',
'no_history': 'سابقه‌ای وجود ندارد'
@@ -152,6 +156,56 @@ function showToast(message, isError = false) {
setTimeout(() => toast.classList.remove('show'), 3000);
}
async function adjustCount(id, field, delta) {
const spanId = field === 'canister_count' ? `cc-${id}` : `bc-${id}`;
const span = document.getElementById(spanId);
if (!span) return;
const next = parseInt(span.textContent, 10) + delta;
if (next < 1) return;
try {
const res = await fetch(`/api/orders/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ [field]: next })
});
if (!res.ok) {
showToast(currentLang === 'fa' ? 'خطا در ویرایش' : 'Error updating order', true);
return;
}
const order = await res.json();
const cc = document.getElementById(`cc-${id}`);
const bc = document.getElementById(`bc-${id}`);
if (cc) cc.textContent = order.canister_count;
if (bc) bc.textContent = order.box_count;
const tw = document.getElementById(`tw-${id}`);
if (tw) tw.textContent = `${order.total_weight} kg`;
const pages = document.getElementById(`pages-${id}`);
if (pages) {
const unit = (translations[currentLang] || translations.en).pages_unit;
pages.innerHTML = `${order.canister_pages + order.box_pages} <span data-i18n="pages_unit">${unit}</span>`;
}
} catch (err) {
showToast('Network error', true);
}
}
async function deleteOrder(id) {
const msg = currentLang === 'fa' ? 'این سفارش حذف شود؟' : 'Remove this order?';
if (!confirm(msg)) return;
try {
const res = await fetch(`/api/orders/${id}`, { method: 'DELETE' });
if (res.ok) {
window.location.reload();
} else {
showToast(currentLang === 'fa' ? 'خطا در حذف' : 'Error removing order', true);
}
} catch (err) {
showToast('Network error', true);
}
}
// Initialize on load
document.addEventListener('DOMContentLoaded', () => {
applyTheme(currentTheme);

View File

@@ -17,12 +17,30 @@ async function markDone(id) {
});
if (res.ok) {
showToast('Order marked as done');
showToast(currentLang === 'fa' ? 'سفارش به عنوان چاپ‌شده علامت خورد' : '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);
showToast(currentLang === 'fa' ? 'خطا در به‌روزرسانی وضعیت' : 'Error updating status', true);
}
} catch (err) {
showToast('Network error', true);
}
}
async function undoDone(id) {
try {
const res = await fetch(`/api/orders/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ status: 'pending' })
});
if (res.ok) {
showToast(currentLang === 'fa' ? 'سفارش به صف چاپ بازگشت' : 'Order returned to print queue');
setTimeout(() => window.location.reload(), 1000);
} else {
showToast(currentLang === 'fa' ? 'خطا در بازگردانی' : 'Error undoing status', true);
}
} catch (err) {
showToast('Network error', true);