Spaces:
Sleeping
Sleeping
Update templates/menu.html
Browse files- templates/menu.html +96 -70
templates/menu.html
CHANGED
@@ -515,75 +515,8 @@ form.text-center.mb-4 {
|
|
515 |
|
516 |
<!-- JavaScript -->
|
517 |
<script>
|
518 |
-
// Show item details and fetch customization options
|
519 |
-
function showItemDetails(name, price, image, description, section, selectedCategory) {
|
520 |
-
document.getElementById('modal-name').innerText = name;
|
521 |
-
document.getElementById('modal-price').innerText = `$${price}`;
|
522 |
-
document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
|
523 |
-
document.getElementById('modal-description').innerText = description || 'No description available.';
|
524 |
-
document.getElementById('addons-list').innerHTML = 'Loading customization options...';
|
525 |
-
document.getElementById('modal-instructions').value = '';
|
526 |
-
|
527 |
-
const modalSectionEl = document.getElementById('modal-section');
|
528 |
-
modalSectionEl.setAttribute('data-section', section);
|
529 |
-
modalSectionEl.setAttribute('data-category', selectedCategory);
|
530 |
-
|
531 |
-
// Set the default quantity to 1
|
532 |
-
document.getElementById('quantityInput').value = 1;
|
533 |
-
|
534 |
-
// Fetch customization options based on the section
|
535 |
-
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
536 |
-
.then(response => response.json())
|
537 |
-
.then(data => {
|
538 |
-
const addonsList = document.getElementById('addons-list');
|
539 |
-
addonsList.innerHTML = ''; // Clear previous content
|
540 |
-
|
541 |
-
if (!data.success || !data.addons || data.addons.length === 0) {
|
542 |
-
addonsList.innerHTML = '<p>No customization options available.</p>';
|
543 |
-
return;
|
544 |
-
}
|
545 |
-
|
546 |
-
// Display customization options inside styled divs
|
547 |
-
data.addons.forEach(addon => {
|
548 |
-
const sectionDiv = document.createElement('div');
|
549 |
-
sectionDiv.classList.add('addon-section'); // Add styling class
|
550 |
-
|
551 |
-
// Add section title
|
552 |
-
const title = document.createElement('h6');
|
553 |
-
title.innerText = addon.name;
|
554 |
-
sectionDiv.appendChild(title);
|
555 |
-
|
556 |
-
// Create options list
|
557 |
-
const optionsContainer = document.createElement('div');
|
558 |
-
addon.options.forEach((option, index) => {
|
559 |
-
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
560 |
-
const listItem = document.createElement('div');
|
561 |
-
listItem.classList.add('form-check');
|
562 |
-
listItem.innerHTML = `
|
563 |
-
<input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
|
564 |
-
data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
565 |
-
<label class="form-check-label" for="${optionId}">
|
566 |
-
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
567 |
-
</label>
|
568 |
-
`;
|
569 |
-
optionsContainer.appendChild(listItem);
|
570 |
-
});
|
571 |
-
sectionDiv.appendChild(optionsContainer);
|
572 |
-
addonsList.appendChild(sectionDiv);
|
573 |
-
});
|
574 |
-
})
|
575 |
-
.catch(err => {
|
576 |
-
console.error('Error fetching add-ons:', err);
|
577 |
-
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
578 |
-
});
|
579 |
-
}
|
580 |
|
581 |
-
|
582 |
-
document.addEventListener('click', function(event) {
|
583 |
-
if (event.target.classList.contains('addon-option')) {
|
584 |
-
handleAddonClick(event.target);
|
585 |
-
}
|
586 |
-
});
|
587 |
|
588 |
// Handle checkbox selection logic
|
589 |
function handleAddonClick(checkbox) {
|
@@ -737,22 +670,115 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
737 |
const decreaseBtn = document.getElementById('decreaseQuantity');
|
738 |
const increaseBtn = document.getElementById('increaseQuantity');
|
739 |
const quantityInput = document.getElementById('quantityInput');
|
740 |
-
|
741 |
// Add event listener to decrease button
|
742 |
decreaseBtn.addEventListener('click', function () {
|
743 |
let currentQuantity = parseInt(quantityInput.value);
|
744 |
if (currentQuantity > 1) {
|
745 |
currentQuantity--;
|
746 |
quantityInput.value = currentQuantity;
|
|
|
747 |
}
|
748 |
});
|
749 |
-
|
750 |
// Add event listener to increase button
|
751 |
increaseBtn.addEventListener('click', function () {
|
752 |
let currentQuantity = parseInt(quantityInput.value);
|
753 |
currentQuantity++;
|
754 |
quantityInput.value = currentQuantity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
755 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
756 |
});
|
757 |
|
758 |
// Function to round reward points to a single digit
|
|
|
515 |
|
516 |
<!-- JavaScript -->
|
517 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
|
519 |
+
|
|
|
|
|
|
|
|
|
|
|
520 |
|
521 |
// Handle checkbox selection logic
|
522 |
function handleAddonClick(checkbox) {
|
|
|
670 |
const decreaseBtn = document.getElementById('decreaseQuantity');
|
671 |
const increaseBtn = document.getElementById('increaseQuantity');
|
672 |
const quantityInput = document.getElementById('quantityInput');
|
673 |
+
|
674 |
// Add event listener to decrease button
|
675 |
decreaseBtn.addEventListener('click', function () {
|
676 |
let currentQuantity = parseInt(quantityInput.value);
|
677 |
if (currentQuantity > 1) {
|
678 |
currentQuantity--;
|
679 |
quantityInput.value = currentQuantity;
|
680 |
+
updatePrice(); // Update price when quantity decreases
|
681 |
}
|
682 |
});
|
683 |
+
|
684 |
// Add event listener to increase button
|
685 |
increaseBtn.addEventListener('click', function () {
|
686 |
let currentQuantity = parseInt(quantityInput.value);
|
687 |
currentQuantity++;
|
688 |
quantityInput.value = currentQuantity;
|
689 |
+
updatePrice(); // Update price when quantity increases
|
690 |
+
});
|
691 |
+
});
|
692 |
+
|
693 |
+
// Function to update the total price dynamically
|
694 |
+
function updatePrice() {
|
695 |
+
const itemPrice = parseFloat(document.getElementById('modal-price').getAttribute('data-base-price'));
|
696 |
+
const quantity = parseInt(document.getElementById('quantityInput').value) || 1;
|
697 |
+
let addonsPrice = 0;
|
698 |
+
|
699 |
+
// Calculate price for selected add-ons
|
700 |
+
const selectedAddOns = Array.from(document.querySelectorAll('#addons-list input[type="checkbox"]:checked'));
|
701 |
+
selectedAddOns.forEach(addon => {
|
702 |
+
addonsPrice += parseFloat(addon.getAttribute('data-price') || 0);
|
703 |
});
|
704 |
+
|
705 |
+
// Update the total price in the modal
|
706 |
+
const totalPrice = (itemPrice * quantity) + addonsPrice;
|
707 |
+
document.getElementById('modal-price').innerText = `$${totalPrice.toFixed(2)}`;
|
708 |
+
}
|
709 |
+
|
710 |
+
// Function to show item details and customization options in the modal
|
711 |
+
function showItemDetails(name, price, image, description, section, selectedCategory) {
|
712 |
+
document.getElementById('modal-name').innerText = name;
|
713 |
+
document.getElementById('modal-price').innerText = `$${price}`; // Set the initial price
|
714 |
+
document.getElementById('modal-price').setAttribute('data-base-price', price); // Store the base price
|
715 |
+
document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
|
716 |
+
document.getElementById('modal-description').innerText = description || 'No description available.';
|
717 |
+
document.getElementById('addons-list').innerHTML = 'Loading customization options...';
|
718 |
+
document.getElementById('modal-instructions').value = '';
|
719 |
+
|
720 |
+
const modalSectionEl = document.getElementById('modal-section');
|
721 |
+
modalSectionEl.setAttribute('data-section', section);
|
722 |
+
modalSectionEl.setAttribute('data-category', selectedCategory);
|
723 |
+
|
724 |
+
// Set the default quantity to 1
|
725 |
+
document.getElementById('quantityInput').value = 1;
|
726 |
+
|
727 |
+
// Fetch customization options based on the section
|
728 |
+
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
729 |
+
.then(response => response.json())
|
730 |
+
.then(data => {
|
731 |
+
const addonsList = document.getElementById('addons-list');
|
732 |
+
addonsList.innerHTML = ''; // Clear previous content
|
733 |
+
if (!data.success || !data.addons || data.addons.length === 0) {
|
734 |
+
addonsList.innerHTML = '<p>No customization options available.</p>';
|
735 |
+
return;
|
736 |
+
}
|
737 |
+
|
738 |
+
// Display customization options inside styled divs
|
739 |
+
data.addons.forEach(addon => {
|
740 |
+
const sectionDiv = document.createElement('div');
|
741 |
+
sectionDiv.classList.add('addon-section'); // Add styling class
|
742 |
+
|
743 |
+
// Add section title
|
744 |
+
const title = document.createElement('h6');
|
745 |
+
title.innerText = addon.name;
|
746 |
+
sectionDiv.appendChild(title);
|
747 |
+
|
748 |
+
// Create options list
|
749 |
+
const optionsContainer = document.createElement('div');
|
750 |
+
addon.options.forEach((option, index) => {
|
751 |
+
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
752 |
+
const listItem = document.createElement('div');
|
753 |
+
listItem.classList.add('form-check');
|
754 |
+
listItem.innerHTML = `
|
755 |
+
<input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
|
756 |
+
data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
757 |
+
<label class="form-check-label" for="${optionId}">
|
758 |
+
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
759 |
+
</label>
|
760 |
+
`;
|
761 |
+
optionsContainer.appendChild(listItem);
|
762 |
+
});
|
763 |
+
sectionDiv.appendChild(optionsContainer);
|
764 |
+
addonsList.appendChild(sectionDiv);
|
765 |
+
});
|
766 |
+
})
|
767 |
+
.catch(err => {
|
768 |
+
console.error('Error fetching add-ons:', err);
|
769 |
+
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
770 |
+
});
|
771 |
+
|
772 |
+
// Update the price dynamically once the modal is populated
|
773 |
+
updatePrice();
|
774 |
+
}
|
775 |
+
|
776 |
+
// Handle single-select/deselect logic for checkbox groups in all modals
|
777 |
+
document.addEventListener('click', function(event) {
|
778 |
+
if (event.target.classList.contains('addon-option')) {
|
779 |
+
handleAddonClick(event.target);
|
780 |
+
updatePrice(); // Update price when add-on is selected or deselected
|
781 |
+
}
|
782 |
});
|
783 |
|
784 |
// Function to round reward points to a single digit
|