Cancelled
${statuses.Cancelled}
`;
}
dashboardTableBody.addEventListener('change', e => {
if (e.target.classList.contains('status-select')) {
const orderId = e.target.dataset.orderId;
const order = orders.find(o => o.id === orderId);
if (order) {
order.status = e.target.value;
updateDashboardSummary();
}
}
});
// --- Tab & Navigation Logic ---
function switchTab(targetTabId) {
if (targetTabId === 'dashboard' && !synchronizeData()) {
return;
}
currentTab = targetTabId;
tabs.forEach(tab => tab.classList.toggle('active', tab.dataset.tab === currentTab));
tabContents.forEach(content => content.classList.toggle('active', content.id === currentTab));
updateNavButtons();
}
tabs.forEach(tab => tab.addEventListener('click', () => switchTab(tab.dataset.tab)));
nextBtn.addEventListener('click', () => currentTab === 'dashboard' ? switchTab('config') : switchTab('dashboard'));
prevBtn.addEventListener('click', () => currentTab === 'config' ? switchTab('dashboard') : switchTab('dashboard'));
function updateNavButtons() {
if (currentTab === 'dashboard') {
nextBtn.textContent = 'Manage Data';
prevBtn.style.display = 'none';
pdfButtonContainer.style.display = 'block';
} else {
nextBtn.textContent = 'Update Dashboard';
prevBtn.style.display = 'inline-flex';
pdfButtonContainer.style.display = 'none';
}
}
// --- PDF Download ---
downloadPdfBtn.addEventListener('click', async () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'l', unit: 'mm', format: 'a4' });
// Temporarily replace selects with static badges for PDF
document.querySelectorAll('#dashboard-table .status-select').forEach(select => {
const status = select.value;
const badge = document.createElement('span');
badge.textContent = status;
badge.className = `status-badge status-${status.toLowerCase()}`;
badge.dataset.pdfRevert = 'true';
select.style.display = 'none';
select.parentNode.insertBefore(badge, select);
});
const content = document.getElementById('pdf-content');
await new Promise(r => setTimeout(r, 100)); // Allow DOM to update
const canvas = await html2canvas(content, { scale: 2 });
const imgData = canvas.toDataURL('image/jpeg', 1.0);
doc.setFont('helvetica', 'bold');
doc.setFontSize(18);
doc.text('Dropshipping Order Synchronization Report', 14, 22);
doc.setFontSize(11);
doc.setTextColor(100);
doc.text(`Generated on: ${new Date().toLocaleDateString()}`, 14, 28);
const imgProps = doc.getImageProperties(imgData);
const pdfWidth = doc.internal.pageSize.getWidth() - 28;
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
doc.addImage(imgData, 'JPEG', 14, 40, pdfWidth, pdfHeight);
doc.save(`Dropship-Order-Report-${new Date().toISOString().slice(0,10)}.pdf`);
// Revert UI changes
document.querySelectorAll('[data-pdf-revert="true"]').forEach(el => el.remove());
document.querySelectorAll('#dashboard-table .status-select').forEach(select => select.style.display = 'block');
});
// --- Initial Load ---
function populateSampleData() {
['USA Print Pro', 'Global Gadgets', 'Fashion Direct'].forEach(s => createSupplierRow(s));
[
{ id: 'DS-78101', customer: 'Alex Johnson', product: 'Custom T-Shirt', supplier: 'USA Print Pro'},
{ id: 'DS-78102', customer: 'Maria Garcia', product: 'Wireless Earbuds', supplier: 'Global Gadgets'},
{ id: 'DS-78103', customer: 'Chen Wei', product: 'Summer Dress', supplier: 'Fashion Direct'},
{ id: 'DS-78104', customer: 'Sam Miller', product: 'Phone Case', supplier: 'Global Gadgets'}
].forEach(o => createOrderRow(o));
updateAllSupplierDropdowns();
}
populateSampleData();
synchronizeData();
switchTab('dashboard');
});