Update templates/menu.html
Browse files- templates/menu.html +82 -58
templates/menu.html
CHANGED
@@ -593,66 +593,90 @@ form-check-input addon-option{
|
|
593 |
<script>
|
594 |
// Show item details and fetch customization options
|
595 |
function showItemDetails(name, price, image, description, section, selectedCategory) {
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
.
|
613 |
-
.
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
const
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
646 |
});
|
647 |
-
|
648 |
-
|
|
|
|
|
649 |
});
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
function handleToggle(source) {
|
657 |
const form = document.getElementById("filter-form");
|
658 |
const veg = document.getElementById("veg-toggle");
|
|
|
593 |
<script>
|
594 |
// Show item details and fetch customization options
|
595 |
function showItemDetails(name, price, image, description, section, selectedCategory) {
|
596 |
+
// Fetch previous order details for the current user
|
597 |
+
fetch(`/fetch_previous_order?email=${encodeURIComponent(userEmail)}`)
|
598 |
+
.then(response => response.json())
|
599 |
+
.then(data => {
|
600 |
+
if (!data.success) {
|
601 |
+
console.error("Error fetching previous order");
|
602 |
+
return;
|
603 |
+
}
|
604 |
+
|
605 |
+
const previousOrder = data.previousOrder;
|
606 |
+
|
607 |
+
// Find the specific item in the previous order
|
608 |
+
const previousItem = previousOrder.find(item => item.name === name);
|
609 |
+
|
610 |
+
// Set the modal details as usual
|
611 |
+
document.getElementById('modal-name').innerText = name;
|
612 |
+
document.getElementById('modal-price').innerText = `$${price}`;
|
613 |
+
document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
|
614 |
+
document.getElementById('modal-description').innerText = description || 'No description available.';
|
615 |
+
document.getElementById('addons-list').innerHTML = 'Loading customization options...';
|
616 |
+
document.getElementById('modal-instructions').value = '';
|
617 |
+
const modalSectionEl = document.getElementById('modal-section');
|
618 |
+
modalSectionEl.setAttribute('data-section', section);
|
619 |
+
modalSectionEl.setAttribute('data-category', selectedCategory);
|
620 |
+
|
621 |
+
// Set the default quantity to 1 (or based on previous order)
|
622 |
+
document.getElementById('quantityInput').value = previousItem ? previousItem.quantity : 1;
|
623 |
+
|
624 |
+
// Fetch customization options based on the section
|
625 |
+
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
626 |
+
.then(response => response.json())
|
627 |
+
.then(data => {
|
628 |
+
const addonsList = document.getElementById('addons-list');
|
629 |
+
addonsList.innerHTML = ''; // Clear previous content
|
630 |
+
|
631 |
+
if (!data.success || !data.addons || data.addons.length === 0) {
|
632 |
+
addonsList.innerHTML = '<p>No customization options available.</p>';
|
633 |
+
return;
|
634 |
+
}
|
635 |
+
|
636 |
+
// Pre-select the add-ons based on previous selection
|
637 |
+
data.addons.forEach(addon => {
|
638 |
+
const sectionDiv = document.createElement('div');
|
639 |
+
sectionDiv.classList.add('addon-section'); // Add styling class
|
640 |
+
|
641 |
+
// Add section title
|
642 |
+
const title = document.createElement('h6');
|
643 |
+
title.innerText = addon.name;
|
644 |
+
sectionDiv.appendChild(title);
|
645 |
+
|
646 |
+
// Create options list
|
647 |
+
const optionsContainer = document.createElement('div');
|
648 |
+
addon.options.forEach((option, index) => {
|
649 |
+
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
650 |
+
const listItem = document.createElement('div');
|
651 |
+
listItem.classList.add('form-check');
|
652 |
+
|
653 |
+
// Check if this option was selected before
|
654 |
+
const checked = previousItem.addons.includes(option); // Pre-select based on previous addons
|
655 |
+
|
656 |
+
listItem.innerHTML = `
|
657 |
+
<input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}" ${checked ? 'checked' : ''}
|
658 |
+
data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
659 |
+
<label class="form-check-label" for="${optionId}">
|
660 |
+
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
661 |
+
</label>
|
662 |
+
`;
|
663 |
+
optionsContainer.appendChild(listItem);
|
664 |
+
});
|
665 |
+
|
666 |
+
sectionDiv.appendChild(optionsContainer);
|
667 |
+
addonsList.appendChild(sectionDiv);
|
668 |
});
|
669 |
+
})
|
670 |
+
.catch(err => {
|
671 |
+
console.error('Error fetching add-ons:', err);
|
672 |
+
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
673 |
});
|
674 |
+
})
|
675 |
+
.catch(err => {
|
676 |
+
console.error('Error fetching previous order:', err);
|
677 |
+
});
|
678 |
+
}
|
679 |
+
|
680 |
function handleToggle(source) {
|
681 |
const form = document.getElementById("filter-form");
|
682 |
const veg = document.getElementById("veg-toggle");
|