Spaces:
Running
Running
Download script.js from maojo/deepsite-project-41q2a: direct link, hf CLI and curl.
- Browser
- Download file 23.8 kB
-
https://huggingface.co/spaces/maojo/deepsite-project-41q2a/resolve/main/script.js
- Command line
-
hf download hf://spaces/maojo/deepsite-project-41q2a/script.js
-
curl -L -o script.js https://huggingface.co/spaces/maojo/deepsite-project-41q2a/resolve/main/script.js
23.8 kB
| // Supplier QC Tracker System - Main JavaScript | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize Lucide icons | |
| if (typeof lucide !== 'undefined') { | |
| lucide.createIcons(); | |
| } | |
| // Check if user is logged in before running main script | |
| const currentUser = localStorage.getItem('qc-user'); | |
| if (!currentUser) { | |
| // Not logged in, script won't run (auth.js will handle login) | |
| return; | |
| } | |
| // Sample orders data | |
| const orders = [ | |
| { | |
| id: 'ORD-001', | |
| name: 'Plastic Containers', | |
| description: 'Food-grade plastic containers with lids', | |
| type: 'ready-made', | |
| status: 'approved', | |
| supplier: 'ABC Manufacturing Co.', | |
| responsible: 'China Staff', | |
| orderDate: '2023-10-15', | |
| expectedShipDate: '2023-11-05', | |
| qcPhotos: 0, | |
| hasDiscrepancy: false, | |
| discrepancyNotes: '' | |
| }, | |
| { | |
| id: 'ORD-002', | |
| name: 'Custom Metal Brackets', | |
| description: 'Custom fabricated steel brackets', | |
| type: 'custom', | |
| status: 'qc-required', | |
| supplier: 'Precision Components Inc.', | |
| responsible: 'China Staff', | |
| orderDate: '2023-10-20', | |
| expectedShipDate: '2023-11-15', | |
| qcPhotos: 2, | |
| hasDiscrepancy: false, | |
| discrepancyNotes: '' | |
| }, | |
| { | |
| id: 'ORD-003', | |
| name: 'Electronic Components', | |
| description: 'Standard resistors and capacitors', | |
| type: 'ready-made', | |
| status: 'shipped', | |
| supplier: 'Global Parts Ltd.', | |
| responsible: 'China Staff', | |
| orderDate: '2023-10-10', | |
| expectedShipDate: '2023-10-30', | |
| qcPhotos: 1, | |
| hasDiscrepancy: false, | |
| discrepancyNotes: '' | |
| }, | |
| { | |
| id: 'ORD-004', | |
| name: 'Custom Packaging Boxes', | |
| description: 'Custom printed cardboard boxes', | |
| type: 'custom', | |
| status: 'discrepancy', | |
| supplier: 'XYZ Industrial Supplies', | |
| responsible: 'China Staff', | |
| orderDate: '2023-09-28', | |
| expectedShipDate: '2023-10-25', | |
| qcPhotos: 3, | |
| hasDiscrepancy: true, | |
| discrepancyNotes: 'Wrong dimensions received at warehouse' | |
| }, | |
| { | |
| id: 'ORD-005', | |
| name: 'Office Chairs', | |
| description: 'Ergonomic office chairs', | |
| type: 'ready-made', | |
| status: 'received', | |
| supplier: 'ABC Manufacturing Co.', | |
| responsible: 'China Staff', | |
| orderDate: '2023-09-15', | |
| expectedShipDate: '2023-10-10', | |
| qcPhotos: 0, | |
| hasDiscrepancy: false, | |
| discrepancyNotes: '' | |
| }, | |
| { | |
| id: 'ORD-006', | |
| name: 'Custom Display Stands', | |
| description: 'Acrylic display stands with branding', | |
| type: 'custom', | |
| status: 'in-progress', | |
| supplier: 'Precision Components Inc.', | |
| responsible: 'China Staff', | |
| orderDate: '2023-10-25', | |
| expectedShipDate: '2023-11-30', | |
| qcPhotos: 0, | |
| hasDiscrepancy: false, | |
| discrepancyNotes: '' | |
| } | |
| ]; | |
| // DOM Elements | |
| const ordersTable = document.getElementById('orders-table'); | |
| const newOrderBtn = document.getElementById('new-order-btn'); | |
| const newOrderModal = document.getElementById('new-order-modal'); | |
| const cancelOrderBtn = document.getElementById('cancel-order-btn'); | |
| const nextStepBtn = document.getElementById('next-step-btn'); | |
| const prevStepBtn = document.getElementById('prev-step-btn'); | |
| const qcUploadArea = document.getElementById('qc-upload-area'); | |
| const qcPhotosInput = document.getElementById('qc-photos'); | |
| const fileList = document.getElementById('file-list'); | |
| const uploadedFilesDiv = document.getElementById('uploaded-files'); | |
| // Get current language | |
| const currentLanguage = localStorage.getItem('qc-language') || 'en'; | |
| // New order form steps | |
| const steps = ['step-1', 'step-2', 'step-3', 'step-4', 'step-5']; | |
| let currentStep = 0; | |
| let uploadedFiles = []; | |
| // Language-specific status texts | |
| const statusTranslations = { | |
| 'en': { | |
| 'pending': 'Pending', | |
| 'in-progress': 'In Progress', | |
| 'qc-required': 'QC Required', | |
| 'approved': 'Approved', | |
| 'shipped': 'Shipped', | |
| 'received': 'Received', | |
| 'discrepancy': 'Discrepancy', | |
| 'Custom': 'Custom', | |
| 'Ready-made': 'Ready-made', | |
| 'Discrepancy': 'Discrepancy', | |
| 'View': 'View', | |
| 'Edit': 'Edit', | |
| 'Next Step': 'Next Step', | |
| 'Create Order': 'Create Order', | |
| 'Previous': 'Previous', | |
| 'Cancel': 'Cancel' | |
| }, | |
| 'zh': { | |
| 'pending': '待处理', | |
| 'in-progress': '进行中', | |
| 'qc-required': '需要QC审核', | |
| 'approved': '已批准', | |
| 'shipped': '已发货', | |
| 'received': '已收货', | |
| 'discrepancy': '差异', | |
| 'Custom': '定制', | |
| 'Ready-made': '现成产品', | |
| 'Discrepancy': '差异', | |
| 'View': '查看', | |
| 'Edit': '编辑', | |
| 'Next Step': '下一步', | |
| 'Create Order': '创建订单', | |
| 'Previous': '上一步', | |
| 'Cancel': '取消' | |
| } | |
| }; | |
| // Get localized text | |
| function getLocalizedText(key) { | |
| return statusTranslations[currentLanguage][key] || key; | |
| } | |
| // Render orders table | |
| function renderOrdersTable() { | |
| if (!ordersTable) return; | |
| ordersTable.innerHTML = ''; | |
| orders.forEach(order => { | |
| const statusClass = getStatusClass(order.status); | |
| const statusText = getLocalizedText(order.status); | |
| const typeText = getLocalizedText(order.type === 'custom' ? 'Custom' : 'Ready-made'); | |
| const typeBadgeClass = order.type === 'custom' ? | |
| 'bg-purple-100 text-purple-800' : 'bg-green-100 text-green-800'; | |
| const discrepancyText = getLocalizedText('Discrepancy'); | |
| const discrepancyBadge = order.hasDiscrepancy ? | |
| `<span class="ml-2 px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">${discrepancyText}</span>` : ''; | |
| const viewText = getLocalizedText('View'); | |
| const editText = getLocalizedText('Edit'); | |
| const row = document.createElement('tr'); | |
| row.innerHTML = ` | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"> | |
| ${order.id} | |
| ${discrepancyBadge} | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"> | |
| <div class="font-medium text-gray-900">${order.name}</div> | |
| <div class="text-gray-500 text-xs">${order.description}</div> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"> | |
| <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${typeBadgeClass}"> | |
| ${typeText} | |
| </span> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <span class="${statusClass} px-2 inline-flex text-xs leading-5 font-semibold rounded-full"> | |
| ${statusText} | |
| </span> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"> | |
| <div class="flex items-center"> | |
| <div class="h-6 w-6 rounded-full bg-blue-100 flex items-center justify-center text-blue-600 text-xs font-medium mr-2">CS</div> | |
| ${order.responsible} | |
| </div> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium"> | |
| <button class="text-blue-600 hover:text-blue-900 mr-3 view-order-btn" data-order-id="${order.id}"> | |
| <i data-lucide="eye" class="h-4 w-4 inline"></i> ${viewText} | |
| </button> | |
| <button class="text-indigo-600 hover:text-indigo-900 edit-order-btn" data-order-id="${order.id}"> | |
| <i data-lucide="edit" class="h-4 w-4 inline"></i> ${editText} | |
| </button> | |
| </td> | |
| `; | |
| ordersTable.appendChild(row); | |
| }); | |
| // Re-initialize icons | |
| if (typeof lucide !== 'undefined') { | |
| lucide.createIcons(); | |
| } | |
| // Add event listeners to view buttons | |
| document.querySelectorAll('.view-order-btn').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const orderId = this.getAttribute('data-order-id'); | |
| viewOrderDetails(orderId); | |
| }); | |
| }); | |
| // Add event listeners to edit buttons | |
| document.querySelectorAll('.edit-order-btn').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const orderId = this.getAttribute('data-order-id'); | |
| editOrder(orderId); | |
| }); | |
| }); | |
| } | |
| // Get status class for styling | |
| function getStatusClass(status) { | |
| switch(status) { | |
| case 'pending': return 'status-pending'; | |
| case 'in-progress': return 'status-in-progress'; | |
| case 'qc-required': return 'status-qc-required'; | |
| case 'approved': return 'status-approved'; | |
| case 'shipped': return 'status-shipped'; | |
| case 'received': return 'status-received'; | |
| case 'discrepancy': return 'status-discrepancy'; | |
| default: return 'status-pending'; | |
| } | |
| } | |
| // View order details | |
| function viewOrderDetails(orderId) { | |
| const order = orders.find(o => o.id === orderId); | |
| if (!order) return; | |
| const typeText = order.type === 'custom' ? | |
| (currentLanguage === 'zh' ? '定制产品' : 'Custom Fabrication') : | |
| (currentLanguage === 'zh' ? '现成产品' : 'Ready-made'); | |
| const message = currentLanguage === 'zh' ? | |
| `订单详情:\n\n` + | |
| `订单号: ${order.id}\n` + | |
| `名称: ${order.name}\n` + | |
| `描述: ${order.description}\n` + | |
| `类型: ${typeText}\n` + | |
| `状态: ${getLocalizedText(order.status)}\n` + | |
| `供应商: ${order.supplier}\n` + | |
| `负责人: ${order.responsible}\n` + | |
| `订单日期: ${order.orderDate}\n` + | |
| `预计发货日期: ${order.expectedShipDate}\n` + | |
| `QC照片: ${order.qcPhotos}\n` + | |
| `差异: ${order.hasDiscrepancy ? '是 - ' + order.discrepancyNotes : '否'}` | |
| : | |
| `Order Details:\n\n` + | |
| `Order ID: ${order.id}\n` + | |
| `Name: ${order.name}\n` + | |
| `Description: ${order.description}\n` + | |
| `Type: ${typeText}\n` + | |
| `Status: ${getLocalizedText(order.status)}\n` + | |
| `Supplier: ${order.supplier}\n` + | |
| `Responsible: ${order.responsible}\n` + | |
| `Order Date: ${order.orderDate}\n` + | |
| `Expected Ship Date: ${order.expectedShipDate}\n` + | |
| `QC Photos: ${order.qcPhotos}\n` + | |
| `Discrepancy: ${order.hasDiscrepancy ? 'Yes - ' + order.discrepancyNotes : 'No'}`; | |
| alert(message); | |
| } | |
| // Edit order | |
| function editOrder(orderId) { | |
| const message = currentLanguage === 'zh' ? | |
| `编辑订单 ${orderId}。完整实现中,这将打开编辑表单。` : | |
| `Editing order ${orderId}. In a full implementation, this would open an edit form.`; | |
| alert(message); | |
| } | |
| // New order modal functions | |
| function showNewOrderModal() { | |
| newOrderModal.classList.remove('hidden'); | |
| resetNewOrderForm(); | |
| showStep(0); | |
| } | |
| function hideNewOrderModal() { | |
| newOrderModal.classList.add('hidden'); | |
| } | |
| function resetNewOrderForm() { | |
| currentStep = 0; | |
| uploadedFiles = []; | |
| // Reset form fields | |
| document.getElementById('order-name').value = ''; | |
| document.getElementById('order-description').value = ''; | |
| document.getElementById('order-specs').value = ''; | |
| document.getElementById('ready-made').checked = true; | |
| document.getElementById('supplier-select').value = ''; | |
| document.getElementById('supplier-link').value = ''; | |
| document.getElementById('final-approval').checked = false; | |
| // Reset file display | |
| fileList.innerHTML = ''; | |
| uploadedFilesDiv.classList.add('hidden'); | |
| // Update button text | |
| nextStepBtn.textContent = getLocalizedText('Next Step'); | |
| prevStepBtn.textContent = getLocalizedText('Previous'); | |
| cancelOrderBtn.textContent = getLocalizedText('Cancel'); | |
| } | |
| function showStep(stepIndex) { | |
| // Hide all steps | |
| steps.forEach(stepId => { | |
| const stepElement = document.getElementById(stepId); | |
| if (stepElement) { | |
| stepElement.classList.add('hidden'); | |
| } | |
| }); | |
| // Show current step | |
| const currentStepElement = document.getElementById(steps[stepIndex]); | |
| if (currentStepElement) { | |
| currentStepElement.classList.remove('hidden'); | |
| } | |
| // Update button visibility | |
| prevStepBtn.classList.toggle('hidden', stepIndex === 0); | |
| // Update next button text | |
| if (stepIndex === steps.length - 1) { | |
| nextStepBtn.textContent = getLocalizedText('Create Order'); | |
| } else { | |
| nextStepBtn.textContent = getLocalizedText('Next Step'); | |
| } | |
| // Update QC requirements based on item type | |
| if (stepIndex === 3) { | |
| updateQCRequirements(); | |
| } | |
| } | |
| function updateQCRequirements() { | |
| const isCustom = document.getElementById('custom-fabrication').checked; | |
| const qcInfoDiv = document.querySelector('#step-4 .bg-blue-50 p'); | |
| if (isCustom) { | |
| if (currentLanguage === 'zh') { | |
| qcInfoDiv.innerHTML = `根据您选择的<strong class="font-semibold">定制产品</strong>,QC照片在发货批准前是<strong class="font-semibold">必需的</strong>。请上传制造进度照片和最终产品照片。`; | |
| } else { | |
| qcInfoDiv.innerHTML = `Based on your selection of <strong class="font-semibold">Custom Fabrication</strong>, QC photos are <strong class="font-semibold">required</strong> before shipment approval. Please upload fabrication progress photos and final product photos.`; | |
| } | |
| } else { | |
| if (currentLanguage === 'zh') { | |
| qcInfoDiv.innerHTML = `根据您选择的<strong class="font-semibold">现成产品</strong>,QC照片是<strong class="font-semibold">可选但推荐</strong>的。对于定制产品,QC照片在发货批准前是必需的。`; | |
| } else { | |
| qcInfoDiv.innerHTML = `Based on your selection of <strong class="font-semibold">Ready-made</strong> items, QC photos are <strong class="font-semibold">optional but recommended</strong>. For custom fabrication, QC photos would be required before shipment approval.`; | |
| } | |
| } | |
| } | |
| function goToNextStep() { | |
| if (currentStep < steps.length - 1) { | |
| currentStep++; | |
| showStep(currentStep); | |
| } else { | |
| // Create the order | |
| createNewOrder(); | |
| } | |
| } | |
| function goToPrevStep() { | |
| if (currentStep > 0) { | |
| currentStep--; | |
| showStep(currentStep); | |
| } | |
| } | |
| function createNewOrder() { | |
| // Get form values | |
| const orderName = document.getElementById('order-name').value; | |
| const orderDescription = document.getElementById('order-description').value; | |
| const orderSpecs = document.getElementById('order-specs').value; | |
| const itemType = document.querySelector('input[name="item-type"]:checked').value; | |
| const supplier = document.getElementById('supplier-select').value; | |
| const supplierLink = document.getElementById('supplier-link').value; | |
| const finalApproval = document.getElementById('final-approval').checked; | |
| // Validation | |
| if (!orderName || !orderDescription || !supplier) { | |
| const errorMsg = currentLanguage === 'zh' | |
| ? '请填写所有必填字段。' | |
| : 'Please fill in all required fields.'; | |
| alert(errorMsg); | |
| return; | |
| } | |
| if (!finalApproval && currentStep === steps.length - 1) { | |
| const errorMsg = currentLanguage === 'zh' | |
| ? '请在创建订单前确认批准。' | |
| : 'Please confirm approval before creating the order.'; | |
| alert(errorMsg); | |
| return; | |
| } | |
| // Create new order object | |
| const newOrder = { | |
| id: `ORD-${String(orders.length + 1).padStart(3, '0')}`, | |
| name: orderName, | |
| description: orderDescription, | |
| type: itemType, | |
| status: itemType === 'custom' ? 'qc-required' : 'pending', | |
| supplier: document.getElementById('supplier-select').options[document.getElementById('supplier-select').selectedIndex].text, | |
| responsible: 'China Staff', | |
| orderDate: new Date().toISOString().split('T')[0], | |
| expectedShipDate: new Date(Date.now() + 20 * 24 * 60 * 60 * 1000).toISOString().split('T')[0], // 20 days from now | |
| qcPhotos: uploadedFiles.length, | |
| hasDiscrepancy: false, | |
| discrepancyNotes: '' | |
| }; | |
| // Add to orders array | |
| orders.unshift(newOrder); | |
| // Re-render table | |
| renderOrdersTable(); | |
| // Hide modal | |
| hideNewOrderModal(); | |
| // Show success message | |
| if (currentLanguage === 'zh') { | |
| alert(`订单 ${newOrder.id} 创建成功!\n\n已建立责任跟踪。${itemType === 'custom' ? '发货前需要QC照片。' : '对于此现成产品,QC照片是可选的。'}`); | |
| } else { | |
| alert(`Order ${newOrder.id} created successfully!\n\nAccountability trail established. ${itemType === 'custom' ? 'QC photos are required before shipment.' : 'QC photos are optional for this ready-made item.'}`); | |
| } | |
| } | |
| // File upload handling | |
| function handleFileUpload(files) { | |
| for (let i = 0; i < files.length; i++) { | |
| const file = files[i]; | |
| // Check if file is an image | |
| if (!file.type.startsWith('image/')) { | |
| const errorMsg = currentLanguage === 'zh' | |
| ? 'QC照片只允许上传图像文件。' | |
| : 'Only image files are allowed for QC photos.'; | |
| alert(errorMsg); | |
| continue; | |
| } | |
| // Add to uploaded files array | |
| uploadedFiles.push({ | |
| name: file.name, | |
| size: file.size, | |
| type: file.type, | |
| url: URL.createObjectURL(file) | |
| }); | |
| } | |
| // Update file list display | |
| updateFileListDisplay(); | |
| } | |
| function updateFileListDisplay() { | |
| if (uploadedFiles.length === 0) { | |
| uploadedFilesDiv.classList.add('hidden'); | |
| return; | |
| } | |
| fileList.innerHTML = ''; | |
| uploadedFiles.forEach((file, index) => { | |
| const fileSize = file.size > 1024 * 1024 ? | |
| `${(file.size / (1024 * 1024)).toFixed(1)} MB` : | |
| `${(file.size / 1024).toFixed(1)} KB`; | |
| const fileItem = document.createElement('div'); | |
| fileItem.className = 'flex items-center justify-between p-2 bg-gray-50 rounded'; | |
| fileItem.innerHTML = ` | |
| <div class="flex items-center"> | |
| <i data-lucide="image" class="h-5 w-5 text-gray-500 mr-3"></i> | |
| <div> | |
| <p class="text-sm font-medium text-gray-900 truncate max-w-xs">${file.name}</p> | |
| <p class="text-xs text-gray-500">${fileSize}</p> | |
| </div> | |
| </div> | |
| <button class="text-red-500 hover:text-red-700 remove-file-btn" data-index="${index}"> | |
| <i data-lucide="trash-2" class="h-4 w-4"></i> | |
| </button> | |
| `; | |
| fileList.appendChild(fileItem); | |
| }); | |
| uploadedFilesDiv.classList.remove('hidden'); | |
| // Re-initialize icons | |
| if (typeof lucide !== 'undefined') { | |
| lucide.createIcons(); | |
| } | |
| // Add event listeners to remove buttons | |
| document.querySelectorAll('.remove-file-btn').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const index = parseInt(this.getAttribute('data-index')); | |
| uploadedFiles.splice(index, 1); | |
| updateFileListDisplay(); | |
| }); | |
| }); | |
| } | |
| // Event Listeners | |
| newOrderBtn.addEventListener('click', showNewOrderModal); | |
| cancelOrderBtn.addEventListener('click', hideNewOrderModal); | |
| nextStepBtn.addEventListener('click', goToNextStep); | |
| prevStepBtn.addEventListener('click', goToPrevStep); | |
| // Close modal when clicking outside | |
| newOrderModal.addEventListener('click', function(e) { | |
| if (e.target === this) { | |
| hideNewOrderModal(); | |
| } | |
| }); | |
| // File upload event listeners | |
| qcUploadArea.addEventListener('click', () => { | |
| qcPhotosInput.click(); | |
| }); | |
| qcUploadArea.addEventListener('dragover', (e) => { | |
| e.preventDefault(); | |
| qcUploadArea.classList.add('dragover'); | |
| }); | |
| qcUploadArea.addEventListener('dragleave', () => { | |
| qcUploadArea.classList.remove('dragover'); | |
| }); | |
| qcUploadArea.addEventListener('drop', (e) => { | |
| e.preventDefault(); | |
| qcUploadArea.classList.remove('dragover'); | |
| const files = e.dataTransfer.files; | |
| handleFileUpload(files); | |
| }); | |
| qcPhotosInput.addEventListener('change', (e) => { | |
| handleFileUpload(e.target.files); | |
| e.target.value = ''; // Reset input | |
| }); | |
| // Item type change listener to update QC requirements | |
| document.querySelectorAll('input[name="item-type"]').forEach(radio => { | |
| radio.addEventListener('change', updateQCRequirements); | |
| }); | |
| // Initialize the page | |
| renderOrdersTable(); | |
| // Add keyboard shortcuts | |
| document.addEventListener('keydown', (e) => { | |
| // Escape key closes modal | |
| if (e.key === 'Escape' && !newOrderModal.classList.contains('hidden')) { | |
| hideNewOrderModal(); | |
| } | |
| // Ctrl/Cmd + N creates new order | |
| if ((e.ctrlKey || e.metaKey) && e.key === 'n') { | |
| e.preventDefault(); | |
| showNewOrderModal(); | |
| } | |
| }); | |
| }); |