Update templates/menu.html
Browse files- templates/menu.html +33 -39
templates/menu.html
CHANGED
@@ -613,29 +613,25 @@ function showItemDetails(name, price, image, description, section, selectedCateg
|
|
613 |
// Set the default quantity to 1
|
614 |
document.getElementById('quantityInput').value = 1;
|
615 |
|
616 |
-
//
|
|
|
617 |
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
618 |
.then(response => response.json())
|
619 |
.then(data => {
|
620 |
const addonsList = document.getElementById('addons-list');
|
621 |
addonsList.innerHTML = ''; // Clear previous content
|
622 |
-
|
623 |
if (!data.success || !data.addons || data.addons.length === 0) {
|
624 |
addonsList.innerHTML = '<p>No customization options available.</p>';
|
625 |
return;
|
626 |
}
|
627 |
|
628 |
-
//
|
629 |
data.addons.forEach(addon => {
|
630 |
const sectionDiv = document.createElement('div');
|
631 |
-
sectionDiv.classList.add('addon-section');
|
632 |
-
|
633 |
-
// Add section title
|
634 |
const title = document.createElement('h6');
|
635 |
title.innerText = addon.name;
|
636 |
sectionDiv.appendChild(title);
|
637 |
-
|
638 |
-
// Create options list
|
639 |
const optionsContainer = document.createElement('div');
|
640 |
addon.options.forEach((option, index) => {
|
641 |
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
@@ -654,43 +650,41 @@ function showItemDetails(name, price, image, description, section, selectedCateg
|
|
654 |
addonsList.appendChild(sectionDiv);
|
655 |
});
|
656 |
|
657 |
-
// Pre-select the
|
658 |
if (window.most_common_addons && window.most_common_addons.length > 0) {
|
659 |
const checkboxes = document.querySelectorAll('.addon-option');
|
660 |
-
|
661 |
-
// Group add-ons by category
|
662 |
const categorySelection = {
|
663 |
-
"Select Spice Level": null,
|
664 |
-
"Choose Spice Level": null,
|
665 |
-
"Raita/Sides": [],
|
666 |
-
// Add other categories if needed
|
667 |
};
|
668 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
checkboxes.forEach(checkbox => {
|
670 |
-
const checkboxName = checkbox.getAttribute('data-name').trim();
|
671 |
-
const checkboxGroup = checkbox.getAttribute('data-group');
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
console.log(`Pre-selecting spice level: ${checkboxName} for ${checkboxGroup}`);
|
677 |
-
checkbox.checked = true;
|
678 |
-
categorySelection[checkboxGroup] = checkboxName; // Mark as selected for this category
|
679 |
-
}
|
680 |
-
|
681 |
-
} else if (checkboxGroup === "Raita/Sides") {
|
682 |
-
// For Raita/Sides, select any matching add-ons
|
683 |
-
if (window.most_common_addons.includes(checkboxName)) {
|
684 |
-
console.log(`Pre-selecting add-on: ${checkboxName}`);
|
685 |
-
checkbox.checked = true;
|
686 |
-
categorySelection["Raita/Sides"].push(checkboxName); // Mark as selected
|
687 |
-
}
|
688 |
-
} else {
|
689 |
-
// For other categories, select matching add-ons
|
690 |
-
if (window.most_common_addons.includes(checkboxName)) {
|
691 |
-
console.log(`Pre-selecting add-on: ${checkboxName}`);
|
692 |
-
checkbox.checked = true;
|
693 |
-
}
|
694 |
}
|
695 |
});
|
696 |
}
|
|
|
613 |
// Set the default quantity to 1
|
614 |
document.getElementById('quantityInput').value = 1;
|
615 |
|
616 |
+
// ... (existing code up to fetch)
|
617 |
+
|
618 |
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
619 |
.then(response => response.json())
|
620 |
.then(data => {
|
621 |
const addonsList = document.getElementById('addons-list');
|
622 |
addonsList.innerHTML = ''; // Clear previous content
|
|
|
623 |
if (!data.success || !data.addons || data.addons.length === 0) {
|
624 |
addonsList.innerHTML = '<p>No customization options available.</p>';
|
625 |
return;
|
626 |
}
|
627 |
|
628 |
+
// Render add-ons as before
|
629 |
data.addons.forEach(addon => {
|
630 |
const sectionDiv = document.createElement('div');
|
631 |
+
sectionDiv.classList.add('addon-section');
|
|
|
|
|
632 |
const title = document.createElement('h6');
|
633 |
title.innerText = addon.name;
|
634 |
sectionDiv.appendChild(title);
|
|
|
|
|
635 |
const optionsContainer = document.createElement('div');
|
636 |
addon.options.forEach((option, index) => {
|
637 |
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
|
|
650 |
addonsList.appendChild(sectionDiv);
|
651 |
});
|
652 |
|
653 |
+
// Pre-select the highest-count spice level
|
654 |
if (window.most_common_addons && window.most_common_addons.length > 0) {
|
655 |
const checkboxes = document.querySelectorAll('.addon-option');
|
|
|
|
|
656 |
const categorySelection = {
|
657 |
+
"Select Spice Level": null,
|
658 |
+
"Choose Spice Level": null,
|
659 |
+
"Raita/Sides": [],
|
|
|
660 |
};
|
661 |
|
662 |
+
// First pass: Find and select the highest-count spice level
|
663 |
+
for (let spice of window.most_common_addons) {
|
664 |
+
const isSpiceLevel = ["Mild", "Medium", "Extra Spicy", "Hot"].includes(spice); // Define valid spice levels
|
665 |
+
if (isSpiceLevel) {
|
666 |
+
checkboxes.forEach(checkbox => {
|
667 |
+
const checkboxName = checkbox.getAttribute('data-name').trim();
|
668 |
+
const checkboxGroup = checkbox.getAttribute('data-group');
|
669 |
+
if ((checkboxGroup === "Select Spice Level" || checkboxGroup === "Choose Spice Level") &&
|
670 |
+
checkboxName === spice && categorySelection[checkboxGroup] === null) {
|
671 |
+
console.log(`Pre-selecting highest-count spice level: ${checkboxName}`);
|
672 |
+
checkbox.checked = true;
|
673 |
+
categorySelection[checkboxGroup] = checkboxName;
|
674 |
+
}
|
675 |
+
});
|
676 |
+
if (categorySelection["Select Spice Level"] || categorySelection["Choose Spice Level"]) break; // Stop after selecting the first spice
|
677 |
+
}
|
678 |
+
}
|
679 |
+
|
680 |
+
// Second pass: Select other non-spice add-ons (e.g., Raita/Sides)
|
681 |
checkboxes.forEach(checkbox => {
|
682 |
+
const checkboxName = checkbox.getAttribute('data-name').trim();
|
683 |
+
const checkboxGroup = checkbox.getAttribute('data-group');
|
684 |
+
if (checkboxGroup === "Raita/Sides" && window.most_common_addons.includes(checkboxName)) {
|
685 |
+
console.log(`Pre-selecting add-on: ${checkboxName}`);
|
686 |
+
checkbox.checked = true;
|
687 |
+
categorySelection["Raita/Sides"].push(checkboxName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
688 |
}
|
689 |
});
|
690 |
}
|