DSatishchandra commited on
Commit
1b3135e
·
verified ·
1 Parent(s): e4f03e2

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +27 -37
templates/menu.html CHANGED
@@ -522,26 +522,33 @@ form.text-center.mb-4 {
522
 
523
  <!-- JavaScript -->
524
  <script>
 
525
  function showItemDetails(name, price, image, description, section, selectedCategory) {
 
 
526
  document.getElementById('modal-name').innerText = name;
527
  document.getElementById('modal-price').innerText = `$${price}`;
528
  document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
529
  document.getElementById('modal-description').innerText = description || 'No description available.';
530
  document.getElementById('addons-list').innerHTML = 'Loading customization options...';
531
  document.getElementById('modal-instructions').value = '';
532
-
533
  // Set section and category for reference
534
  const modalSectionEl = document.getElementById('modal-section');
535
  modalSectionEl.setAttribute('data-section', section);
536
  modalSectionEl.setAttribute('data-category', selectedCategory);
 
 
537
 
538
  // Fetch customization options based on the section
539
  fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
540
  .then(response => response.json())
541
  .then(data => {
 
 
542
  const addonsList = document.getElementById('addons-list');
543
  addonsList.innerHTML = ''; // Clear previous content
544
-
545
  if (!data.success || !data.addons || data.addons.length === 0) {
546
  addonsList.innerHTML = '<p>No customization options available.</p>';
547
  return;
@@ -585,12 +592,14 @@ form.text-center.mb-4 {
585
  let sections = document.querySelectorAll('h3'); // Select section headers
586
  let items = document.querySelectorAll('.menu-card'); // Select all items
587
  let matchedSections = new Set(); // Store matched sections
588
-
 
 
589
  // Hide all items initially
590
  items.forEach(item => {
591
  let itemName = item.querySelector('.card-title').innerText.toLowerCase(); // Get item name
592
  let itemSection = item.closest('.row').previousElementSibling.innerText.toLowerCase(); // Get section name
593
-
594
  // If search matches item name or section, show the item
595
  if (itemName.includes(input) || (itemSection && itemSection.includes(input))) {
596
  item.style.display = 'block'; // Show item if it matches search
@@ -599,7 +608,7 @@ form.text-center.mb-4 {
599
  item.style.display = 'none'; // Hide item if not matched
600
  }
601
  });
602
-
603
  // Show or hide sections based on matched items
604
  sections.forEach(section => {
605
  let sectionRow = section.nextElementSibling; // The row containing items
@@ -616,18 +625,14 @@ form.text-center.mb-4 {
616
  function addToCartFromModal() {
617
  const itemName = document.getElementById('modal-name').innerText;
618
  let itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
619
-
620
- // Validate item price
621
- if (isNaN(itemPrice)) {
622
- alert('Invalid price for the item. Please check the item details.');
623
- return;
624
- }
625
-
626
  const itemImage = document.getElementById('modal-img').src;
627
  const modalSectionEl = document.getElementById('modal-section');
628
  const section = modalSectionEl.getAttribute('data-section');
629
  const selectedCategory = modalSectionEl.getAttribute('data-category');
630
-
 
 
 
631
  if (!itemName || !itemPrice || !section || !itemImage) {
632
  console.error('Missing data for cart item:', { itemName, itemPrice, section, itemImage });
633
  return;
@@ -641,10 +646,6 @@ form.text-center.mb-4 {
641
  price: parseFloat(addon.getAttribute('data-price') || 0)
642
  }));
643
 
644
- // Get the selected quantity
645
- const quantity = parseInt(document.getElementById('quantityInput').value) || 1; // Default to 1 if invalid
646
- const instructions = document.getElementById('modal-instructions').value;
647
-
648
  // Prepare data for the cart
649
  const cartPayload = {
650
  itemName: itemName,
@@ -653,10 +654,12 @@ form.text-center.mb-4 {
653
  section: section,
654
  category: selectedCategory,
655
  addons: selectedAddOns,
656
- instructions: instructions,
657
- quantity: quantity // Include the quantity
658
  };
659
 
 
 
660
  // Send the cart data to the server
661
  fetch('/cart/add', {
662
  method: 'POST',
@@ -667,6 +670,7 @@ form.text-center.mb-4 {
667
  })
668
  .then(response => response.json())
669
  .then(data => {
 
670
  if (data.success) {
671
  alert('Item added to cart successfully!');
672
  updateCartUI(data.cart); // Update cart UI after adding an item
@@ -684,6 +688,8 @@ form.text-center.mb-4 {
684
  }
685
 
686
  function updateCartUI(cart) {
 
 
687
  if (!Array.isArray(cart)) {
688
  console.error('Invalid cart data:', cart);
689
  return;
@@ -693,24 +699,6 @@ form.text-center.mb-4 {
693
  cartIcon.innerText = cart.length; // Assuming cart is an array of items
694
  }
695
 
696
- function updateCartDisplay(cart) {
697
- if (!Array.isArray(cart)) {
698
- console.error('Invalid cart data:', cart);
699
- return;
700
- }
701
-
702
- const cartCountElement = document.getElementById('cart-count');
703
- cartCountElement.innerText = cart.length; // Update cart item count
704
-
705
- const successNotification = document.createElement('div');
706
- successNotification.classList.add('success-notification');
707
- successNotification.innerText = 'Item added to cart!';
708
- document.body.appendChild(successNotification);
709
- setTimeout(() => {
710
- successNotification.remove(); // Remove success notification after a few seconds
711
- }, 2000);
712
- }
713
-
714
  document.addEventListener('DOMContentLoaded', function () {
715
  // Get references to the quantity buttons and the input field
716
  const decreaseBtn = document.getElementById('decreaseQuantity');
@@ -724,6 +712,7 @@ form.text-center.mb-4 {
724
  currentQuantity--;
725
  quantityInput.value = currentQuantity;
726
  }
 
727
  });
728
 
729
  // Add event listener to increase button
@@ -731,6 +720,7 @@ form.text-center.mb-4 {
731
  let currentQuantity = parseInt(quantityInput.value);
732
  currentQuantity++;
733
  quantityInput.value = currentQuantity;
 
734
  });
735
  });
736
 
 
522
 
523
  <!-- JavaScript -->
524
  <script>
525
+ <script>
526
  function showItemDetails(name, price, image, description, section, selectedCategory) {
527
+ console.log("showItemDetails called with:", {name, price, image, description, section, selectedCategory});
528
+
529
  document.getElementById('modal-name').innerText = name;
530
  document.getElementById('modal-price').innerText = `$${price}`;
531
  document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
532
  document.getElementById('modal-description').innerText = description || 'No description available.';
533
  document.getElementById('addons-list').innerHTML = 'Loading customization options...';
534
  document.getElementById('modal-instructions').value = '';
535
+
536
  // Set section and category for reference
537
  const modalSectionEl = document.getElementById('modal-section');
538
  modalSectionEl.setAttribute('data-section', section);
539
  modalSectionEl.setAttribute('data-category', selectedCategory);
540
+
541
+ console.log("Fetching customization options for item:", name);
542
 
543
  // Fetch customization options based on the section
544
  fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
545
  .then(response => response.json())
546
  .then(data => {
547
+ console.log("Customization options fetched:", data);
548
+
549
  const addonsList = document.getElementById('addons-list');
550
  addonsList.innerHTML = ''; // Clear previous content
551
+
552
  if (!data.success || !data.addons || data.addons.length === 0) {
553
  addonsList.innerHTML = '<p>No customization options available.</p>';
554
  return;
 
592
  let sections = document.querySelectorAll('h3'); // Select section headers
593
  let items = document.querySelectorAll('.menu-card'); // Select all items
594
  let matchedSections = new Set(); // Store matched sections
595
+
596
+ console.log("Filtering menu with input:", input);
597
+
598
  // Hide all items initially
599
  items.forEach(item => {
600
  let itemName = item.querySelector('.card-title').innerText.toLowerCase(); // Get item name
601
  let itemSection = item.closest('.row').previousElementSibling.innerText.toLowerCase(); // Get section name
602
+
603
  // If search matches item name or section, show the item
604
  if (itemName.includes(input) || (itemSection && itemSection.includes(input))) {
605
  item.style.display = 'block'; // Show item if it matches search
 
608
  item.style.display = 'none'; // Hide item if not matched
609
  }
610
  });
611
+
612
  // Show or hide sections based on matched items
613
  sections.forEach(section => {
614
  let sectionRow = section.nextElementSibling; // The row containing items
 
625
  function addToCartFromModal() {
626
  const itemName = document.getElementById('modal-name').innerText;
627
  let itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
 
 
 
 
 
 
 
628
  const itemImage = document.getElementById('modal-img').src;
629
  const modalSectionEl = document.getElementById('modal-section');
630
  const section = modalSectionEl.getAttribute('data-section');
631
  const selectedCategory = modalSectionEl.getAttribute('data-category');
632
+ const quantity = parseInt(document.getElementById('quantityInput').value) || 1; // Default to 1 if invalid
633
+
634
+ console.log("Adding to cart with data:", { itemName, itemPrice, itemImage, section, selectedCategory, quantity });
635
+
636
  if (!itemName || !itemPrice || !section || !itemImage) {
637
  console.error('Missing data for cart item:', { itemName, itemPrice, section, itemImage });
638
  return;
 
646
  price: parseFloat(addon.getAttribute('data-price') || 0)
647
  }));
648
 
 
 
 
 
649
  // Prepare data for the cart
650
  const cartPayload = {
651
  itemName: itemName,
 
654
  section: section,
655
  category: selectedCategory,
656
  addons: selectedAddOns,
657
+ quantity: quantity, // Include the quantity
658
+ instructions: document.getElementById('modal-instructions').value
659
  };
660
 
661
+ console.log("Cart Payload:", cartPayload);
662
+
663
  // Send the cart data to the server
664
  fetch('/cart/add', {
665
  method: 'POST',
 
670
  })
671
  .then(response => response.json())
672
  .then(data => {
673
+ console.log("Response from server:", data);
674
  if (data.success) {
675
  alert('Item added to cart successfully!');
676
  updateCartUI(data.cart); // Update cart UI after adding an item
 
688
  }
689
 
690
  function updateCartUI(cart) {
691
+ console.log("Updating cart UI with cart data:", cart);
692
+
693
  if (!Array.isArray(cart)) {
694
  console.error('Invalid cart data:', cart);
695
  return;
 
699
  cartIcon.innerText = cart.length; // Assuming cart is an array of items
700
  }
701
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
702
  document.addEventListener('DOMContentLoaded', function () {
703
  // Get references to the quantity buttons and the input field
704
  const decreaseBtn = document.getElementById('decreaseQuantity');
 
712
  currentQuantity--;
713
  quantityInput.value = currentQuantity;
714
  }
715
+ console.log("Decreased quantity:", quantityInput.value);
716
  });
717
 
718
  // Add event listener to increase button
 
720
  let currentQuantity = parseInt(quantityInput.value);
721
  currentQuantity++;
722
  quantityInput.value = currentQuantity;
723
+ console.log("Increased quantity:", quantityInput.value);
724
  });
725
  });
726