nagasurendra commited on
Commit
4da8e75
·
verified ·
1 Parent(s): 819bead

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +40 -7
templates/menu.html CHANGED
@@ -1765,6 +1765,10 @@
1765
  cartItemCount.style.display = totalQuantity > 0 ? 'inline-flex' : 'none';
1766
  }
1767
  }
 
 
 
 
1768
  function showItemDetails(name, price, image, description, section, selectedCategory) {
1769
  document.getElementById('modal-name').innerText = name;
1770
  baseItemPrice = parseFloat(price) || 0;
@@ -1779,7 +1783,6 @@
1779
  modalSectionEl.setAttribute('data-section', section);
1780
  modalSectionEl.setAttribute('data-category', selectedCategory);
1781
  document.getElementById('quantityInput').value = 1;
1782
-
1783
  fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
1784
  .then(response => response.json())
1785
  .then(data => {
@@ -1790,7 +1793,6 @@
1790
  addonsList.innerHTML = '<p>No customization options available.</p>';
1791
  return;
1792
  }
1793
-
1794
  data.addons.forEach(addon => {
1795
  const sectionDiv = document.createElement('div');
1796
  sectionDiv.classList.add('addon-section');
@@ -1799,7 +1801,6 @@
1799
  sectionDiv.appendChild(title);
1800
  const optionsContainer = document.createElement('div');
1801
  optionsContainer.classList.add('addon-options');
1802
-
1803
  addon.options.forEach((option, index) => {
1804
  const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
1805
  const listItem = document.createElement('div');
@@ -1814,11 +1815,9 @@
1814
  `;
1815
  optionsContainer.appendChild(listItem);
1816
  });
1817
-
1818
  sectionDiv.appendChild(optionsContainer);
1819
  addonsList.appendChild(sectionDiv);
1820
  });
1821
-
1822
  const addonSections = addonsList.querySelectorAll('.addon-section');
1823
  addonSections.forEach(section => {
1824
  const title = section.querySelector('h6');
@@ -1828,11 +1827,9 @@
1828
  options.classList.toggle('collapsed');
1829
  });
1830
  });
1831
-
1832
  document.querySelectorAll('.addon-option').forEach(checkbox => {
1833
  checkbox.addEventListener('change', updateModalPrice);
1834
  });
1835
-
1836
  document.querySelectorAll('.addon-option').forEach(checkbox => {
1837
  checkbox.addEventListener('change', function () {
1838
  const groupName = this.getAttribute('data-group');
@@ -1846,6 +1843,42 @@
1846
  }
1847
  });
1848
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1849
  })
1850
  .catch(err => {
1851
  console.error('Error fetching add-ons:', err);
 
1765
  cartItemCount.style.display = totalQuantity > 0 ? 'inline-flex' : 'none';
1766
  }
1767
  }
1768
+
1769
+
1770
+ window.most_common_addons = {{ most_common_addons | tojson }};
1771
+ console.log("Most common add-ons: ", window.most_common_addons);
1772
  function showItemDetails(name, price, image, description, section, selectedCategory) {
1773
  document.getElementById('modal-name').innerText = name;
1774
  baseItemPrice = parseFloat(price) || 0;
 
1783
  modalSectionEl.setAttribute('data-section', section);
1784
  modalSectionEl.setAttribute('data-category', selectedCategory);
1785
  document.getElementById('quantityInput').value = 1;
 
1786
  fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
1787
  .then(response => response.json())
1788
  .then(data => {
 
1793
  addonsList.innerHTML = '<p>No customization options available.</p>';
1794
  return;
1795
  }
 
1796
  data.addons.forEach(addon => {
1797
  const sectionDiv = document.createElement('div');
1798
  sectionDiv.classList.add('addon-section');
 
1801
  sectionDiv.appendChild(title);
1802
  const optionsContainer = document.createElement('div');
1803
  optionsContainer.classList.add('addon-options');
 
1804
  addon.options.forEach((option, index) => {
1805
  const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
1806
  const listItem = document.createElement('div');
 
1815
  `;
1816
  optionsContainer.appendChild(listItem);
1817
  });
 
1818
  sectionDiv.appendChild(optionsContainer);
1819
  addonsList.appendChild(sectionDiv);
1820
  });
 
1821
  const addonSections = addonsList.querySelectorAll('.addon-section');
1822
  addonSections.forEach(section => {
1823
  const title = section.querySelector('h6');
 
1827
  options.classList.toggle('collapsed');
1828
  });
1829
  });
 
1830
  document.querySelectorAll('.addon-option').forEach(checkbox => {
1831
  checkbox.addEventListener('change', updateModalPrice);
1832
  });
 
1833
  document.querySelectorAll('.addon-option').forEach(checkbox => {
1834
  checkbox.addEventListener('change', function () {
1835
  const groupName = this.getAttribute('data-group');
 
1843
  }
1844
  });
1845
  });
1846
+ // Pre-select the highest-count spice level
1847
+ if (window.most_common_addons && window.most_common_addons.length > 0) {
1848
+ const checkboxes = document.querySelectorAll('.addon-option');
1849
+ const categorySelection = {
1850
+ "Select Spice Level": null,
1851
+ "Choose Spice Level": null,
1852
+ "Raita/Sides": [],
1853
+ };
1854
+ // First pass: Find and select the highest-count spice level
1855
+ for (let spice of window.most_common_addons) {
1856
+ const isSpiceLevel = ["Mild", "Medium", "Spicy", "Extra Spicy"].includes(spice); // Define valid spice levels
1857
+ if (isSpiceLevel) {
1858
+ checkboxes.forEach(checkbox => {
1859
+ const checkboxName = checkbox.getAttribute('data-name').trim();
1860
+ const checkboxGroup = checkbox.getAttribute('data-group');
1861
+ if ((checkboxGroup === "Select Spice Level" || checkboxGroup === "Choose Spice Level") &&
1862
+ checkboxName === spice && categorySelection[checkboxGroup] === null) {
1863
+ console.log(`Pre-selecting highest-count spice level: ${checkboxName}`);
1864
+ checkbox.checked = true;
1865
+ categorySelection[checkboxGroup] = checkboxName;
1866
+ }
1867
+ });
1868
+ if (categorySelection["Select Spice Level"] || categorySelection["Choose Spice Level"]) break; // Stop after selecting the first spice
1869
+ }
1870
+ }
1871
+ // Second pass: Select other non-spice add-ons (e.g., Raita/Sides)
1872
+ checkboxes.forEach(checkbox => {
1873
+ const checkboxName = checkbox.getAttribute('data-name').trim();
1874
+ const checkboxGroup = checkbox.getAttribute('data-group');
1875
+ if (checkboxGroup === "Raita/Sides" && window.most_common_addons.includes(checkboxName)) {
1876
+ console.log(`Pre-selecting add-on: ${checkboxName}`);
1877
+ checkbox.checked = true;
1878
+ categorySelection["Raita/Sides"].push(checkboxName);
1879
+ }
1880
+ });
1881
+ }
1882
  })
1883
  .catch(err => {
1884
  console.error('Error fetching add-ons:', err);