Update templates/menu.html
Browse files- templates/menu.html +79 -67
templates/menu.html
CHANGED
@@ -594,77 +594,89 @@ form-check-input addon-option{
|
|
594 |
|
595 |
// Show item details and fetch customization options
|
596 |
// Show item details and fetch customization options
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
document.getElementById('quantityInput').value = 1;
|
610 |
|
611 |
-
|
612 |
-
|
613 |
-
|
|
|
|
|
|
|
614 |
.then(data => {
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
const sectionDiv = document.createElement('div');
|
625 |
-
sectionDiv.classList.add('addon-section'); // Add styling class
|
626 |
-
|
627 |
-
// Add section title
|
628 |
-
const title = document.createElement('h6');
|
629 |
-
title.innerText = addon.name;
|
630 |
-
sectionDiv.appendChild(title);
|
631 |
-
|
632 |
-
// Create options list
|
633 |
-
const optionsContainer = document.createElement('div');
|
634 |
-
addon.options.forEach((option, index) => {
|
635 |
-
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
636 |
-
const listItem = document.createElement('div');
|
637 |
-
listItem.classList.add('form-check');
|
638 |
-
listItem.innerHTML = `
|
639 |
-
<input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
|
640 |
-
data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
641 |
-
<label class="form-check-label" for="${optionId}">
|
642 |
-
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
643 |
-
</label>
|
644 |
-
`;
|
645 |
-
optionsContainer.appendChild(listItem);
|
646 |
-
});
|
647 |
-
sectionDiv.appendChild(optionsContainer);
|
648 |
-
addonsList.appendChild(sectionDiv);
|
649 |
-
});
|
650 |
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
666 |
});
|
667 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
668 |
|
669 |
|
670 |
|
|
|
594 |
|
595 |
// Show item details and fetch customization options
|
596 |
// Show item details and fetch customization options
|
597 |
+
// Show item details and fetch customization options
|
598 |
+
function showItemDetails(name, price, image, description, section, selectedCategory) {
|
599 |
+
console.log(`Showing details for: ${name}`);
|
600 |
+
document.getElementById('modal-name').innerText = name;
|
601 |
+
document.getElementById('modal-price').innerText = `$${price}`;
|
602 |
+
document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
|
603 |
+
document.getElementById('modal-description').innerText = description || 'No description available.';
|
604 |
+
document.getElementById('addons-list').innerHTML = 'Loading customization options...';
|
605 |
+
document.getElementById('modal-instructions').value = '';
|
606 |
+
const modalSectionEl = document.getElementById('modal-section');
|
607 |
+
modalSectionEl.setAttribute('data-section', section);
|
608 |
+
modalSectionEl.setAttribute('data-category', selectedCategory);
|
|
|
609 |
|
610 |
+
// Set the default quantity to 1
|
611 |
+
document.getElementById('quantityInput').value = 1;
|
612 |
+
|
613 |
+
// Fetch customization options based on the section
|
614 |
+
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
615 |
+
.then(response => response.json())
|
616 |
.then(data => {
|
617 |
+
const addonsList = document.getElementById('addons-list');
|
618 |
+
addonsList.innerHTML = ''; // Clear previous content
|
619 |
+
console.log("Fetching customization options:", data);
|
620 |
+
|
621 |
+
if (!data.success || !data.addons || data.addons.length === 0) {
|
622 |
+
addonsList.innerHTML = '<p>No customization options available.</p>';
|
623 |
+
console.log("No customization options available.");
|
624 |
+
return;
|
625 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
626 |
|
627 |
+
// Display customization options inside styled divs
|
628 |
+
data.addons.forEach(addon => {
|
629 |
+
const sectionDiv = document.createElement('div');
|
630 |
+
sectionDiv.classList.add('addon-section'); // Add styling class
|
631 |
+
|
632 |
+
// Add section title
|
633 |
+
const title = document.createElement('h6');
|
634 |
+
title.innerText = addon.name;
|
635 |
+
sectionDiv.appendChild(title);
|
636 |
+
|
637 |
+
// Create options list
|
638 |
+
const optionsContainer = document.createElement('div');
|
639 |
+
addon.options.forEach((option, index) => {
|
640 |
+
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
641 |
+
const listItem = document.createElement('div');
|
642 |
+
listItem.classList.add('form-check');
|
643 |
+
listItem.innerHTML = `
|
644 |
+
<input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
|
645 |
+
data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
646 |
+
<label class="form-check-label" for="${optionId}">
|
647 |
+
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
648 |
+
</label>
|
649 |
+
`;
|
650 |
+
optionsContainer.appendChild(listItem);
|
651 |
+
});
|
652 |
+
sectionDiv.appendChild(optionsContainer);
|
653 |
+
addonsList.appendChild(sectionDiv);
|
654 |
});
|
655 |
+
|
656 |
+
// Pre-select the most common add-ons (if any)
|
657 |
+
if (window.most_common_addons && window.most_common_addons.length > 0) {
|
658 |
+
console.log("Pre-selecting most common add-ons:", window.most_common_addons);
|
659 |
+
|
660 |
+
const checkboxes = document.querySelectorAll('.addon-option');
|
661 |
+
checkboxes.forEach(checkbox => {
|
662 |
+
const checkboxName = checkbox.getAttribute('data-name');
|
663 |
+
// If the checkbox option is one of the most common add-ons, select it
|
664 |
+
if (window.most_common_addons.includes(checkboxName)) {
|
665 |
+
console.log(`Pre-selecting checkbox for: ${checkboxName}`);
|
666 |
+
checkbox.checked = true;
|
667 |
+
} else {
|
668 |
+
console.log(`Not pre-selecting checkbox for: ${checkboxName}`);
|
669 |
+
}
|
670 |
+
});
|
671 |
+
} else {
|
672 |
+
console.log("No most common add-ons to pre-select.");
|
673 |
+
}
|
674 |
+
})
|
675 |
+
.catch(err => {
|
676 |
+
console.error('Error fetching add-ons:', err);
|
677 |
+
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
678 |
+
});
|
679 |
+
}
|
680 |
|
681 |
|
682 |
|