Spaces:
Sleeping
Sleeping
Update templates/menu.html
Browse files- templates/menu.html +4 -353
templates/menu.html
CHANGED
@@ -41,70 +41,6 @@
|
|
41 |
margin-top:1px;
|
42 |
}
|
43 |
|
44 |
-
.modal-footer {
|
45 |
-
display: flex;
|
46 |
-
align-items: center;
|
47 |
-
justify-content: space-between; /* Space between quantity controls and Add to Cart button */
|
48 |
-
padding: 10px;
|
49 |
-
}
|
50 |
-
|
51 |
-
.modal-footer .d-flex {
|
52 |
-
display: flex;
|
53 |
-
align-items: center;
|
54 |
-
gap: 10px; /* Space between quantity buttons */
|
55 |
-
}
|
56 |
-
|
57 |
-
.modal-footer .btn {
|
58 |
-
height: 40px; /* Set consistent button height */
|
59 |
-
padding: 0 15px; /* Adjust padding to fit inside the buttons */
|
60 |
-
}
|
61 |
-
|
62 |
-
.modal-footer .form-control {
|
63 |
-
width: 50px; /* Fixed width for quantity input */
|
64 |
-
height: 40px; /* Match the height of buttons */
|
65 |
-
text-align: center; /* Center the value inside the input */
|
66 |
-
}
|
67 |
-
|
68 |
-
.modal-footer .btn-primary {
|
69 |
-
background-color: #0FAA39; /* Green background for Add to Cart button */
|
70 |
-
border-color: #0FAA39; /* Border color to match button background */
|
71 |
-
font-weight: bold; /* Bold text */
|
72 |
-
padding: 10px 20px; /* Adjust padding to make the button look better */
|
73 |
-
height: 40px; /* Match the height with quantity buttons */
|
74 |
-
display: flex;
|
75 |
-
justify-content: center;
|
76 |
-
align-items: center;
|
77 |
-
width: auto; /* Auto width to adjust to button text */
|
78 |
-
border-radius: 5px; /* Rounded corners for the button */
|
79 |
-
}
|
80 |
-
|
81 |
-
.modal-footer .btn-outline-secondary {
|
82 |
-
height: 40px; /* Ensure quantity buttons are the same size */
|
83 |
-
width: 40px; /* Make sure the buttons are square */
|
84 |
-
border-radius: 5px; /* Rounded corners for the buttons */
|
85 |
-
}
|
86 |
-
|
87 |
-
@media (max-width: 576px) {
|
88 |
-
/* Responsive adjustments for smaller screens */
|
89 |
-
.modal-dialog {
|
90 |
-
max-width: 98%; /* Adjust modal width for smaller screens */
|
91 |
-
}
|
92 |
-
|
93 |
-
.modal-footer .btn {
|
94 |
-
height: 35px; /* Smaller buttons for small screens */
|
95 |
-
padding: 0 12px; /* Adjust padding to make the button look proportional */
|
96 |
-
}
|
97 |
-
|
98 |
-
.modal-footer .form-control {
|
99 |
-
width: 40px; /* Adjust input size for smaller screens */
|
100 |
-
height: 35px;
|
101 |
-
}
|
102 |
-
|
103 |
-
.modal-footer .d-flex {
|
104 |
-
gap: 8px; /* Reduce space between quantity buttons on smaller screens */
|
105 |
-
}
|
106 |
-
}
|
107 |
-
|
108 |
|
109 |
|
110 |
|
@@ -488,7 +424,7 @@ form-check-input addon-option{
|
|
488 |
align-items: center;
|
489 |
gap: 10px;
|
490 |
}
|
491 |
-
|
492 |
display: flex;
|
493 |
align-items: center;
|
494 |
justify-content: space-between; /* Space between quantity and Add to Cart button */
|
@@ -535,7 +471,7 @@ form-check-input addon-option{
|
|
535 |
width: 40px; /* Adjust input size for smaller screens */
|
536 |
height: 35px;
|
537 |
}
|
538 |
-
}
|
539 |
</style>
|
540 |
</head>
|
541 |
<body>
|
@@ -684,7 +620,7 @@ form-check-input addon-option{
|
|
684 |
</div>
|
685 |
|
686 |
<!-- Modal for Item Details -->
|
687 |
-
|
688 |
<div class="modal-dialog modal-dialog-centered">
|
689 |
<div class="modal-content">
|
690 |
<div class="modal-header">
|
@@ -724,289 +660,4 @@ form-check-input addon-option{
|
|
724 |
</div>
|
725 |
</div>
|
726 |
</div>
|
727 |
-
</div>
|
728 |
-
<div class="modal fade" id="itemModal" tabindex="-1" aria-labelledby="itemModalLabel" aria-hidden="true">
|
729 |
-
<div class="modal-dialog modal-dialog-centered">
|
730 |
-
<div class="modal-content">
|
731 |
-
<div class="modal-header">
|
732 |
-
<h5 class="modal-title" id="itemModalLabel">Item Details</h5>
|
733 |
-
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
734 |
-
</div>
|
735 |
-
<div class="modal-body">
|
736 |
-
<!-- Item Image -->
|
737 |
-
<img id="modal-img" class="img-fluid rounded mb-3 d-block mx-auto" alt="Item Image" style="max-height: 200px; object-fit: cover;">
|
738 |
-
<!-- Item Name -->
|
739 |
-
<h5 id="modal-name" class="fw-bold text-center"></h5>
|
740 |
-
<!-- Item Price -->
|
741 |
-
<p id="modal-price" class="text-muted text-center"></p>
|
742 |
-
<!-- Item Description -->
|
743 |
-
<p id="modal-description" class="text-secondary"></p>
|
744 |
-
<!-- Add-ons -->
|
745 |
-
<div id="modal-addons" class="modal-addons mt-4">
|
746 |
-
<h6>Customization Options</h6>
|
747 |
-
<div id="addons-list" class="addons-container">Loading customization options...</div>
|
748 |
-
</div>
|
749 |
-
<div class="mt-4">
|
750 |
-
<h6>Custom Request</h6>
|
751 |
-
<textarea id="modal-instructions" class="form-control" placeholder="Enter any special instructions here..."></textarea>
|
752 |
-
</div>
|
753 |
-
<span id="modal-section" data-section="" data-category="" style="display: none;"></span>
|
754 |
-
</div>
|
755 |
-
<!-- Quantity Controls and Add to Cart Button -->
|
756 |
-
<div class="modal-footer d-flex align-items-center justify-content-between">
|
757 |
-
<!-- Quantity Controls -->
|
758 |
-
<div class="d-flex align-items-center gap-2">
|
759 |
-
<button type="button" class="btn btn-outline-secondary" id="decreaseQuantity">-</button>
|
760 |
-
<input type="text" class="form-control text-center" id="quantityInput" value="1" readonly style="width: 50px;
|
761 |
-
|
762 |
-
|
763 |
-
<!-- JavaScript -->
|
764 |
-
<script>
|
765 |
-
// Show item details and fetch customization options
|
766 |
-
function showItemDetails(name, price, image, description, section, selectedCategory) {
|
767 |
-
document.getElementById('modal-name').innerText = name;
|
768 |
-
document.getElementById('modal-price').innerText = `$${price}`;
|
769 |
-
document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
|
770 |
-
document.getElementById('modal-description').innerText = description || 'No description available.';
|
771 |
-
document.getElementById('addons-list').innerHTML = 'Loading customization options...';
|
772 |
-
document.getElementById('modal-instructions').value = '';
|
773 |
-
|
774 |
-
const modalSectionEl = document.getElementById('modal-section');
|
775 |
-
modalSectionEl.setAttribute('data-section', section);
|
776 |
-
modalSectionEl.setAttribute('data-category', selectedCategory);
|
777 |
-
|
778 |
-
// Set the default quantity to 1
|
779 |
-
document.getElementById('quantityInput').value = 1;
|
780 |
-
|
781 |
-
// Fetch customization options based on the section
|
782 |
-
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
783 |
-
.then(response => response.json())
|
784 |
-
.then(data => {
|
785 |
-
const addonsList = document.getElementById('addons-list');
|
786 |
-
addonsList.innerHTML = ''; // Clear previous content
|
787 |
-
|
788 |
-
if (!data.success || !data.addons || data.addons.length === 0) {
|
789 |
-
addonsList.innerHTML = '<p>No customization options available.</p>';
|
790 |
-
return;
|
791 |
-
}
|
792 |
-
|
793 |
-
// Display customization options inside styled divs
|
794 |
-
data.addons.forEach(addon => {
|
795 |
-
const sectionDiv = document.createElement('div');
|
796 |
-
sectionDiv.classList.add('addon-section'); // Add styling class
|
797 |
-
|
798 |
-
// Add section title
|
799 |
-
const title = document.createElement('h6');
|
800 |
-
title.innerText = addon.name;
|
801 |
-
sectionDiv.appendChild(title);
|
802 |
-
|
803 |
-
// Create options list
|
804 |
-
const optionsContainer = document.createElement('div');
|
805 |
-
addon.options.forEach((option, index) => {
|
806 |
-
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
807 |
-
const listItem = document.createElement('div');
|
808 |
-
listItem.classList.add('form-check');
|
809 |
-
listItem.innerHTML = `
|
810 |
-
<input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
|
811 |
-
data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
812 |
-
<label class="form-check-label" for="${optionId}">
|
813 |
-
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
814 |
-
</label>
|
815 |
-
`;
|
816 |
-
optionsContainer.appendChild(listItem);
|
817 |
-
});
|
818 |
-
sectionDiv.appendChild(optionsContainer);
|
819 |
-
addonsList.appendChild(sectionDiv);
|
820 |
-
});
|
821 |
-
})
|
822 |
-
.catch(err => {
|
823 |
-
console.error('Error fetching add-ons:', err);
|
824 |
-
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
825 |
-
});
|
826 |
-
}
|
827 |
-
|
828 |
-
// Handle single-select/deselect logic for checkbox groups in all modals
|
829 |
-
document.addEventListener('click', function(event) {
|
830 |
-
if (event.target.classList.contains('addon-option')) {
|
831 |
-
handleAddonClick(event.target);
|
832 |
-
}
|
833 |
-
});
|
834 |
-
|
835 |
-
// Handle checkbox selection logic
|
836 |
-
function handleAddonClick(checkbox) {
|
837 |
-
const groupName = checkbox.getAttribute('data-group');
|
838 |
-
const isMultiSelectGroup = ["Extra Toppings", "Choose Raita/Sides","Select Dip/Sauce","Extra Add-ons","Make it a Combo"].includes(groupName);
|
839 |
-
|
840 |
-
// If it's not multi-select, uncheck all other checkboxes in the same group
|
841 |
-
if (!isMultiSelectGroup) {
|
842 |
-
const checkboxes = document.querySelectorAll(`.addon-option[data-group="${groupName}"]`);
|
843 |
-
checkboxes.forEach(otherCheckbox => {
|
844 |
-
if (otherCheckbox !== checkbox) {
|
845 |
-
otherCheckbox.checked = false;
|
846 |
-
}
|
847 |
-
});
|
848 |
-
}
|
849 |
-
}
|
850 |
-
function filterMenu() {
|
851 |
-
let input = document.getElementById('searchBar').value.toLowerCase(); // Get the value from search bar
|
852 |
-
let sections = document.querySelectorAll('h3'); // Select section headers
|
853 |
-
let items = document.querySelectorAll('.menu-card'); // Select all items
|
854 |
-
let matchedSections = new Set(); // Store matched sections
|
855 |
-
|
856 |
-
// Hide all items initially
|
857 |
-
items.forEach(item => {
|
858 |
-
let itemName = item.querySelector('.card-title').innerText.toLowerCase(); // Get item name
|
859 |
-
let itemSection = item.closest('.row').previousElementSibling.innerText.toLowerCase(); // Get section name
|
860 |
-
|
861 |
-
// If the search matches item name or section, show the item
|
862 |
-
if (itemName.includes(input) || (itemSection && itemSection.includes(input))) {
|
863 |
-
item.style.display = 'block'; // Show item if it matches search
|
864 |
-
matchedSections.add(item.closest('.row')); // Add section to matched list
|
865 |
-
} else {
|
866 |
-
item.style.display = 'none'; // Hide item if not matched
|
867 |
-
}
|
868 |
-
});
|
869 |
-
|
870 |
-
// Show or hide sections based on matched items
|
871 |
-
sections.forEach(section => {
|
872 |
-
let sectionRow = section.nextElementSibling; // The row containing items
|
873 |
-
if (matchedSections.has(sectionRow)) {
|
874 |
-
section.style.display = 'block'; // Show section header
|
875 |
-
sectionRow.style.display = 'flex'; // Show section items
|
876 |
-
} else {
|
877 |
-
section.style.display = 'none'; // Hide section header
|
878 |
-
sectionRow.style.display = 'none'; // Hide section items
|
879 |
-
}
|
880 |
-
});
|
881 |
-
}
|
882 |
-
|
883 |
-
function addToCartFromModal() {
|
884 |
-
const itemName = document.getElementById('modal-name').innerText;
|
885 |
-
let itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
886 |
-
|
887 |
-
// Validate item price
|
888 |
-
if (isNaN(itemPrice)) {
|
889 |
-
alert('Invalid price for the item. Please check the item details.');
|
890 |
-
return;
|
891 |
-
}
|
892 |
-
|
893 |
-
const itemImage = document.getElementById('modal-img').src;
|
894 |
-
console.log(itemName, itemPrice, itemImage); // Log values for debugging
|
895 |
-
const modalSectionEl = document.getElementById('modal-section');
|
896 |
-
const section = modalSectionEl.getAttribute('data-section');
|
897 |
-
const selectedCategory = modalSectionEl.getAttribute('data-category');
|
898 |
-
if (!itemName || !itemPrice || !section || !itemImage) {
|
899 |
-
console.error('Missing data for cart item:', { itemName, itemPrice, section, itemImage});
|
900 |
-
return;
|
901 |
-
}
|
902 |
-
|
903 |
-
// Collect selected add-ons
|
904 |
-
let selectedAddOns = Array.from(
|
905 |
-
document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
|
906 |
-
).map(addon => ({
|
907 |
-
name: addon.getAttribute('data-name') || 'Default Name', // Fallback Name
|
908 |
-
price: parseFloat(addon.getAttribute('data-price') || 0)
|
909 |
-
}));
|
910 |
-
|
911 |
-
// Get the selected quantity
|
912 |
-
const quantity = parseInt(document.getElementById('quantityInput').value) || 1; // Default to 1 if invalid
|
913 |
-
|
914 |
-
const instructions = document.getElementById('modal-instructions').value;
|
915 |
-
|
916 |
-
// Prepare data for the cart
|
917 |
-
const cartPayload = {
|
918 |
-
itemName: itemName,
|
919 |
-
itemPrice: itemPrice,
|
920 |
-
itemImage: itemImage,
|
921 |
-
section: section,
|
922 |
-
category: selectedCategory,
|
923 |
-
addons: selectedAddOns,
|
924 |
-
instructions: instructions,
|
925 |
-
quantity: quantity // Include the quantity
|
926 |
-
};
|
927 |
-
|
928 |
-
// Send the cart data to the server
|
929 |
-
fetch('/cart/add', {
|
930 |
-
method: 'POST',
|
931 |
-
headers: {
|
932 |
-
'Content-Type': 'application/json',
|
933 |
-
},
|
934 |
-
body: JSON.stringify(cartPayload)
|
935 |
-
})
|
936 |
-
.then(response => response.json())
|
937 |
-
.then(data => {
|
938 |
-
if (data.success) {
|
939 |
-
alert('Item added to cart successfully!');
|
940 |
-
updateCartUI(data.cart); // Update cart UI after adding an item
|
941 |
-
const modal = document.getElementById('itemModal');
|
942 |
-
const modalInstance = bootstrap.Modal.getInstance(modal);
|
943 |
-
modalInstance.hide();
|
944 |
-
} else {
|
945 |
-
alert(data.error || 'Failed to add item to cart.');
|
946 |
-
}
|
947 |
-
})
|
948 |
-
.catch(err => {
|
949 |
-
console.error('Error adding item to cart:', err);
|
950 |
-
alert('An error occurred while adding the item to the cart.');
|
951 |
-
});
|
952 |
-
}
|
953 |
-
|
954 |
-
function updateCartUI(cart) {
|
955 |
-
if (!Array.isArray(cart)) {
|
956 |
-
console.error('Invalid cart data:', cart);
|
957 |
-
return;
|
958 |
-
}
|
959 |
-
const cartIcon = document.getElementById('cart-icon');
|
960 |
-
cartIcon.innerText = cart.length; // Assuming cart is an array of items
|
961 |
-
}
|
962 |
-
|
963 |
-
function updateCartDisplay(cart) {
|
964 |
-
if (!Array.isArray(cart)) {
|
965 |
-
console.error('Invalid cart data:', cart);
|
966 |
-
return;
|
967 |
-
}
|
968 |
-
// Optional: Update quantity on the cart page
|
969 |
-
const cartCountElement = document.getElementById('cart-count');
|
970 |
-
cartCountElement.innerText = cart.reduce((total, item)=> total+item.quantity,0); // Update cart item count //Sum of all quantities
|
971 |
-
|
972 |
-
// Optionally, show a small success notification that the item was added
|
973 |
-
const successNotification = document.createElement('div');
|
974 |
-
successNotification.classList.add('success-notification');
|
975 |
-
successNotification.innerText = 'Item added to cart!';
|
976 |
-
document.body.appendChild(successNotification);
|
977 |
-
setTimeout(() => {
|
978 |
-
successNotification.remove(); // Remove success notification after a few seconds
|
979 |
-
}, 2000);
|
980 |
-
}
|
981 |
-
|
982 |
-
document.addEventListener('DOMContentLoaded', function () {
|
983 |
-
// Get references to the quantity buttons and the input field
|
984 |
-
const decreaseBtn = document.getElementById('decreaseQuantity');
|
985 |
-
const increaseBtn = document.getElementById('increaseQuantity');
|
986 |
-
const quantityInput = document.getElementById('quantityInput');
|
987 |
-
|
988 |
-
// Add event listener to decrease button
|
989 |
-
decreaseBtn.addEventListener('click', function () {
|
990 |
-
let currentQuantity = parseInt(quantityInput.value);
|
991 |
-
if (currentQuantity > 1) {
|
992 |
-
currentQuantity--;
|
993 |
-
quantityInput.value = currentQuantity;
|
994 |
-
}
|
995 |
-
});
|
996 |
-
|
997 |
-
// Add event listener to increase button
|
998 |
-
increaseBtn.addEventListener('click', function () {
|
999 |
-
let currentQuantity = parseInt(quantityInput.value);
|
1000 |
-
currentQuantity++;
|
1001 |
-
quantityInput.value = currentQuantity;
|
1002 |
-
});
|
1003 |
-
});
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
</script>
|
1008 |
-
|
1009 |
-
<!-- Bootstrap JS -->
|
1010 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
1011 |
-
</body>
|
1012 |
-
</html>
|
|
|
41 |
margin-top:1px;
|
42 |
}
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
|
46 |
|
|
|
424 |
align-items: center;
|
425 |
gap: 10px;
|
426 |
}
|
427 |
+
.modal-footer {
|
428 |
display: flex;
|
429 |
align-items: center;
|
430 |
justify-content: space-between; /* Space between quantity and Add to Cart button */
|
|
|
471 |
width: 40px; /* Adjust input size for smaller screens */
|
472 |
height: 35px;
|
473 |
}
|
474 |
+
}
|
475 |
</style>
|
476 |
</head>
|
477 |
<body>
|
|
|
620 |
</div>
|
621 |
|
622 |
<!-- Modal for Item Details -->
|
623 |
+
<div class="modal fade" id="itemModal" tabindex="-1" aria-labelledby="itemModalLabel" aria-hidden="true">
|
624 |
<div class="modal-dialog modal-dialog-centered">
|
625 |
<div class="modal-content">
|
626 |
<div class="modal-header">
|
|
|
660 |
</div>
|
661 |
</div>
|
662 |
</div>
|
663 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|