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

@@ -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);