nagasurendra commited on
Commit
f5c85fe
·
verified ·
1 Parent(s): ee8a2f7

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +3 -34
templates/menu.html CHANGED
@@ -563,7 +563,7 @@ form-check-input addon-option{
563
  <p id="modal-price" class="text-muted text-center"></p>
564
  <!-- Item Description -->
565
  <p id="modal-description" class="text-secondary"></p>
566
- <div id="most-common-addons"></div>
567
  <!-- Add-ons -->
568
  <div id="modal-addons" class="modal-addons mt-4">
569
  <h6>Customization Options</h6>
@@ -597,6 +597,7 @@ form-check-input addon-option{
597
  window.most_common_addons = {{ most_common_addons | tojson }};
598
  console.log("Most common add-ons: ", window.most_common_addons);
599
  // Show item details and fetch customization options
 
600
  function showItemDetails(name, price, image, description, section, selectedCategory) {
601
  console.log(`Showing details for: ${name}`);
602
  document.getElementById('modal-name').innerText = name;
@@ -612,38 +613,15 @@ function showItemDetails(name, price, image, description, section, selectedCateg
612
  // Set the default quantity to 1
613
  document.getElementById('quantityInput').value = 1;
614
 
615
- // Display most common add-ons if available
616
- const mostCommonAddonsSection = document.getElementById('most-common-addons');
617
-
618
- // Ensure the element exists before setting its innerHTML
619
- if (mostCommonAddonsSection) {
620
- mostCommonAddonsSection.innerHTML = ''; // Clear previous content
621
- if (window.most_common_addons && window.most_common_addons.length > 0) {
622
- // Display the most common add-ons
623
- let commonAddonsText = "<h6>Most Common Add-Ons:</h6><ul>";
624
- window.most_common_addons.forEach(addon => {
625
- commonAddonsText += `<li>${addon}</li>`;
626
- });
627
- commonAddonsText += "</ul>";
628
- mostCommonAddonsSection.innerHTML = commonAddonsText;
629
- } else {
630
- mostCommonAddonsSection.innerHTML = '<p>No most common add-ons found.</p>';
631
- }
632
- } else {
633
- console.error("Element with id 'most-common-addons' not found.");
634
- }
635
-
636
  // Fetch customization options based on the section
637
  fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
638
  .then(response => response.json())
639
  .then(data => {
640
  const addonsList = document.getElementById('addons-list');
641
  addonsList.innerHTML = ''; // Clear previous content
642
- console.log("Fetching customization options:", data);
643
 
644
  if (!data.success || !data.addons || data.addons.length === 0) {
645
  addonsList.innerHTML = '<p>No customization options available.</p>';
646
- console.log("No customization options available.");
647
  return;
648
  }
649
 
@@ -678,28 +656,18 @@ function showItemDetails(name, price, image, description, section, selectedCateg
678
 
679
  // Pre-select the most common add-ons (if any)
680
  if (window.most_common_addons && window.most_common_addons.length > 0) {
681
- console.log("Pre-selecting most common add-ons:", window.most_common_addons);
682
-
683
  const checkboxes = document.querySelectorAll('.addon-option');
684
  checkboxes.forEach(checkbox => {
685
  const checkboxName = checkbox.getAttribute('data-name').trim(); // Trim spaces for checkbox value
686
- console.log(`Checking checkbox for: ${checkboxName}`);
687
 
688
  // Normalize the most common add-ons to avoid spaces, then check if it's in the list
689
  const normalizedAddons = window.most_common_addons.map(addon => addon.trim().toLowerCase()); // Normalize all to lowercase
690
 
691
- console.log("Normalized most common add-ons:", normalizedAddons);
692
-
693
  // If the checkbox option is one of the most common add-ons, select it
694
  if (normalizedAddons.includes(checkboxName.trim().toLowerCase())) {
695
- console.log(`Pre-selecting checkbox for: ${checkboxName}`);
696
  checkbox.checked = true;
697
- } else {
698
- console.log(`Not pre-selecting checkbox for: ${checkboxName}`);
699
  }
700
  });
701
- } else {
702
- console.log("No most common add-ons to pre-select.");
703
  }
704
  })
705
  .catch(err => {
@@ -709,6 +677,7 @@ function showItemDetails(name, price, image, description, section, selectedCateg
709
  }
710
 
711
 
 
712
  function handleToggle(source) {
713
  const form = document.getElementById("filter-form");
714
  const veg = document.getElementById("veg-toggle");
 
563
  <p id="modal-price" class="text-muted text-center"></p>
564
  <!-- Item Description -->
565
  <p id="modal-description" class="text-secondary"></p>
566
+
567
  <!-- Add-ons -->
568
  <div id="modal-addons" class="modal-addons mt-4">
569
  <h6>Customization Options</h6>
 
597
  window.most_common_addons = {{ most_common_addons | tojson }};
598
  console.log("Most common add-ons: ", window.most_common_addons);
599
  // Show item details and fetch customization options
600
+ // Show item details and fetch customization options
601
  function showItemDetails(name, price, image, description, section, selectedCategory) {
602
  console.log(`Showing details for: ${name}`);
603
  document.getElementById('modal-name').innerText = name;
 
613
  // Set the default quantity to 1
614
  document.getElementById('quantityInput').value = 1;
615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
  // Fetch customization options based on the section
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
 
 
656
 
657
  // Pre-select the most common add-ons (if any)
658
  if (window.most_common_addons && window.most_common_addons.length > 0) {
 
 
659
  const checkboxes = document.querySelectorAll('.addon-option');
660
  checkboxes.forEach(checkbox => {
661
  const checkboxName = checkbox.getAttribute('data-name').trim(); // Trim spaces for checkbox value
 
662
 
663
  // Normalize the most common add-ons to avoid spaces, then check if it's in the list
664
  const normalizedAddons = window.most_common_addons.map(addon => addon.trim().toLowerCase()); // Normalize all to lowercase
665
 
 
 
666
  // If the checkbox option is one of the most common add-ons, select it
667
  if (normalizedAddons.includes(checkboxName.trim().toLowerCase())) {
 
668
  checkbox.checked = true;
 
 
669
  }
670
  });
 
 
671
  }
672
  })
673
  .catch(err => {
 
677
  }
678
 
679
 
680
+
681
  function handleToggle(source) {
682
  const form = document.getElementById("filter-form");
683
  const veg = document.getElementById("veg-toggle");