data init idk other stuff
This commit is contained in:
@@ -228,6 +228,114 @@ async function generateAddressLabels() {
|
||||
}
|
||||
}
|
||||
|
||||
// Show return labels modal
|
||||
function showReturnLabelsModal() {
|
||||
const modal = document.getElementById('returnLabelsModal');
|
||||
modal.classList.remove('hidden');
|
||||
modal.classList.add('flex');
|
||||
}
|
||||
|
||||
// Close return labels modal
|
||||
function closeReturnLabelsModal() {
|
||||
const modal = document.getElementById('returnLabelsModal');
|
||||
modal.classList.remove('flex');
|
||||
modal.classList.add('hidden');
|
||||
}
|
||||
|
||||
// Submit return labels request
|
||||
async function submitReturnLabels() {
|
||||
try {
|
||||
const numberOfLabels = document.getElementById('numberOfLabels').value;
|
||||
if (!numberOfLabels || numberOfLabels < 1) {
|
||||
showToast('Please enter a valid number of labels', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
const response = await fetch(`${API_BASE_URL}/orders/generate-return-labels`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
number_of_labels: parseInt(numberOfLabels)
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.detail || 'Failed to generate return labels');
|
||||
}
|
||||
|
||||
showToast('Return labels generated successfully');
|
||||
closeReturnLabelsModal();
|
||||
} catch (error) {
|
||||
showToast('Error generating return labels: ' + error.message, 'error');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate return labels (opens modal)
|
||||
function generateReturnLabels() {
|
||||
showReturnLabelsModal();
|
||||
}
|
||||
|
||||
// Show Pirate Ship label modal
|
||||
function showPirateShipModal() {
|
||||
const modal = document.getElementById('pirateShipModal');
|
||||
modal.classList.remove('hidden');
|
||||
modal.classList.add('flex');
|
||||
}
|
||||
|
||||
// Close Pirate Ship label modal
|
||||
function closePirateShipModal() {
|
||||
const modal = document.getElementById('pirateShipModal');
|
||||
modal.classList.remove('flex');
|
||||
modal.classList.add('hidden');
|
||||
// Reset file input
|
||||
document.getElementById('pirateShipFile').value = '';
|
||||
}
|
||||
|
||||
// Submit Pirate Ship label
|
||||
async function submitPirateShipLabel() {
|
||||
try {
|
||||
const fileInput = document.getElementById('pirateShipFile');
|
||||
const file = fileInput.files[0];
|
||||
|
||||
if (!file) {
|
||||
showToast('Please select a PDF file', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.type !== 'application/pdf') {
|
||||
showToast('Please select a valid PDF file', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/orders/print-pirate-ship-label`, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.detail || 'Failed to print Pirate Ship label');
|
||||
}
|
||||
|
||||
showToast('Pirate Ship label printed successfully');
|
||||
closePirateShipModal();
|
||||
} catch (error) {
|
||||
showToast('Error printing Pirate Ship label: ' + error.message, 'error');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Load orders when page loads
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
fetchOrders();
|
||||
|
Reference in New Issue
Block a user