lokeshloki143 commited on
Commit
951c254
·
verified ·
1 Parent(s): eb11612

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +139 -72
templates/menu.html CHANGED
@@ -1438,7 +1438,7 @@
1438
  <label class="form-label fw-bold">Filters:</label>
1439
  <div class="toggle-container">
1440
  <!-- Veg Only Toggle -->
1441
- <input type="checkbox" id="veg-toggle" name="veg"
1442
  {% if selected_category == "Veg" %}checked{% endif %}
1443
  class="custom-toggle" onchange="handleToggle('veg')"
1444
  aria-label="Toggle Vegetarian filter">
@@ -1687,6 +1687,23 @@
1687
  "Tomato Ketchup", "Tomatoes", "Turmeric Powder", "Vinegar", "Water", "Wheat Flour (for dough)",
1688
  "Whole Wheat Flour", "Yogurt (Curd)"
1689
  ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1690
  function addToCartLocalStorage(payload) {
1691
  let cart = JSON.parse(localStorage.getItem('cart')) || [];
1692
  const existingItem = cart.find(item =>
@@ -1829,78 +1846,120 @@
1829
  console.log("Most common add-ons: ", window.most_common_addons);
1830
  function showItemDetails(name, price, image, description, section, selectedCategory) {
1831
  document.getElementById('modal-name').innerText = name;
1832
- baseItemPrice = parseFloat(price) || 0;
1833
  document.getElementById('modal-price').innerText = `$${baseItemPrice.toFixed(2)}`;
1834
- const modalImg = document.getElementById('modal-img');
1835
- modalImg.src = image || '/static/placeholder.jpg';
1836
- document.getElementById('modal-description').innerText = description || 'No description available.';
1837
- document.getElementById('addons-list').innerHTML = '';
1838
- document.getElementById('addons-list').classList.add('addon-loading');
1839
  document.getElementById('modal-instructions').value = '';
1840
- const modalSectionEl = document.getElementById('modal-section');
1841
- modalSectionEl.setAttribute('data-section', section);
1842
- modalSectionEl.setAttribute('data-category', selectedCategory);
1843
- document.getElementById('quantityInput').value = 1;
 
1844
  fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
1845
  .then(response => response.json())
1846
  .then(data => {
1847
- const addonsList = document.getElementById('addons-list');
1848
  addonsList.classList.remove('addon-loading');
1849
- addonsList.innerHTML = '';
1850
- if (!data.success || !data.addons || data.addons.length === 0) {
1851
- const noAddonsMessage = document.createElement('p');
1852
- noAddonsMessage.textContent = 'No add-ons available for this item.';
1853
- noAddonsMessage.className = 'text-muted';
1854
- addonsList.appendChild(noAddonsMessage);
1855
  } else {
1856
- data.addons.forEach(addon => {
1857
- const addonSection = document.createElement('div');
1858
- addonSection.className = 'addon-section';
1859
- const addonHeader = document.createElement('h6');
1860
- addonHeader.textContent = addon.section;
1861
- addonHeader.setAttribute('data-bs-toggle', 'collapse');
1862
- addonHeader.setAttribute('data-bs-target', `#addon-collapse-${addon.section.replace(/\s+/g, '-')}`);
1863
- addonHeader.setAttribute('aria-expanded', 'true');
1864
- addonHeader.setAttribute('aria-controls', `addon-collapse-${addon.section.replace(/\s+/g, '-')}`);
1865
- addonSection.appendChild(addonHeader);
1866
- const addonCollapse = document.createElement('div');
1867
- addonCollapse.id = `addon-collapse-${addon.section.replace(/\s+/g, '-')}`;
1868
- addonCollapse.className = 'addon-options collapse show';
1869
- addon.items.forEach(item => {
1870
- const addonItem = document.createElement('div');
1871
- addonItem.className = 'form-check';
1872
- const input = document.createElement('input');
1873
- input.type = 'checkbox';
1874
- input.className = 'form-check-input';
1875
- input.id = `addon-${item.name.replace(/\s+/g, '-')}`;
1876
- input.setAttribute('data-price', item.price || 0);
1877
- input.setAttribute('data-name', item.name);
1878
- input.setAttribute('data-section', addon.section);
1879
- input.addEventListener('change', updateModalPrice);
1880
- const label = document.createElement('label');
1881
- label.className = 'form-check-label';
1882
- label.htmlFor = `addon-${item.name.replace(/\s+/g, '-')}`;
1883
- label.textContent = item.name;
1884
- if (item.price > 0) {
1885
- const priceSpan = document.createElement('span');
1886
- priceSpan.className = 'extra-charge';
1887
- priceSpan.textContent = `+$${parseFloat(item.price).toFixed(2)}`;
1888
- label.appendChild(priceSpan);
1889
- }
1890
- addonItem.appendChild(label);
1891
- addonItem.appendChild(input);
1892
- addonCollapse.appendChild(addonItem);
1893
- });
1894
- addonSection.appendChild(addonCollapse);
1895
- addonsList.appendChild(addonSection);
1896
- });
1897
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1898
  })
1899
  .catch(err => {
1900
  console.error('Error fetching addons:', err);
1901
- const addonsList = document.getElementById('addons-list');
1902
  addonsList.classList.remove('addon-loading');
1903
- addonsList.innerHTML = '<p class="text-muted">Failed to load add-ons.</p>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1904
  });
1905
  }
1906
  function addToCartFromModal() {
@@ -1987,17 +2046,25 @@
1987
  function handleToggle(toggleType) {
1988
  const vegToggle = document.getElementById('veg-toggle');
1989
  const customToggle = document.getElementById('category-CustomizedDish');
1990
- let url = '/menu?';
1991
- const params = [];
1992
- if (toggleType === 'veg' && vegToggle.checked) {
1993
- params.push('veg=Veg');
1994
- customToggle.checked = false;
1995
- } else if (toggleType === 'custom' && customToggle.checked) {
1996
- params.push('category=Customized+Dish');
1997
- vegToggle.checked = false;
1998
- }
1999
- url += params.join('&');
2000
- window.location.href = url;
 
 
 
 
 
 
 
 
2001
  }
2002
  document.addEventListener('DOMContentLoaded', function () {
2003
  const avatarIcon = document.querySelector('.avatar-icon');
 
1438
  <label class="form-label fw-bold">Filters:</label>
1439
  <div class="toggle-container">
1440
  <!-- Veg Only Toggle -->
1441
+ <input type="checkbox" id="veg-toggle" name="veg" value="Veg"
1442
  {% if selected_category == "Veg" %}checked{% endif %}
1443
  class="custom-toggle" onchange="handleToggle('veg')"
1444
  aria-label="Toggle Vegetarian filter">
 
1687
  "Tomato Ketchup", "Tomatoes", "Turmeric Powder", "Vinegar", "Water", "Wheat Flour (for dough)",
1688
  "Whole Wheat Flour", "Yogurt (Curd)"
1689
  ];
1690
+ const fallbackAddons = [
1691
+ {
1692
+ section: "Extras",
1693
+ items: [
1694
+ { name: "Extra Cheese", price: 1.50 },
1695
+ { name: "Extra Sauce", price: 0.75 },
1696
+ { name: "Spicy Seasoning", price: 0.50 }
1697
+ ]
1698
+ },
1699
+ {
1700
+ section: "Sides",
1701
+ items: [
1702
+ { name: "Naan Bread", price: 2.00 },
1703
+ { name: "Raita", price: 1.00 }
1704
+ ]
1705
+ }
1706
+ ];
1707
  function addToCartLocalStorage(payload) {
1708
  let cart = JSON.parse(localStorage.getItem('cart')) || [];
1709
  const existingItem = cart.find(item =>
 
1846
  console.log("Most common add-ons: ", window.most_common_addons);
1847
  function showItemDetails(name, price, image, description, section, selectedCategory) {
1848
  document.getElementById('modal-name').innerText = name;
1849
+ baseItemPrice = parseFloat(price) || 0;
1850
  document.getElementById('modal-price').innerText = `$${baseItemPrice.toFixed(2)}`;
1851
+ document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
1852
+ document.getElementById('modal-description').innerText = description || 'No description available';
1853
+ document.getElementById('quantityInput').value = '1';
 
 
1854
  document.getElementById('modal-instructions').value = '';
1855
+ document.getElementById('modal-section').setAttribute('data-section', section);
1856
+ document.getElementById('modal-section').setAttribute('data-category', selectedCategory);
1857
+ const addonsList = document.getElementById('addons-list');
1858
+ addonsList.innerHTML = '';
1859
+ addonsList.classList.add('addon-loading');
1860
  fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
1861
  .then(response => response.json())
1862
  .then(data => {
1863
+ console.log('Addons API response:', data);
1864
  addonsList.classList.remove('addon-loading');
1865
+ let addons = [];
1866
+ if (data.success && Array.isArray(data.addons) && data.addons.length > 0) {
1867
+ addons = data.addons;
1868
+ } else if (window.most_common_addons && Array.isArray(window.most_common_addons) && window.most_common_addons.length > 0) {
1869
+ console.log('Using most_common_addons as fallback');
1870
+ addons = window.most_common_addons;
1871
  } else {
1872
+ console.log('Using static fallback addons');
1873
+ addons = fallbackAddons;
1874
+ }
1875
+ if (addons.length === 0) {
1876
+ addonsList.innerHTML = '<p class="text-muted">No customization options available.</p>';
1877
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1878
  }
1879
+ addons.forEach(addon => {
1880
+ const addonSection = document.createElement('div');
1881
+ addonSection.className = 'addon-section';
1882
+ const addonHeader = document.createElement('h6');
1883
+ addonHeader.textContent = addon.section;
1884
+ addonHeader.setAttribute('data-bs-toggle', 'collapse');
1885
+ addonHeader.setAttribute('data-bs-target', `#collapse-${addon.section.replace(/\s+/g, '-')}`);
1886
+ addonSection.appendChild(addonHeader);
1887
+ const addonCollapse = document.createElement('div');
1888
+ addonCollapse.id = `collapse-${addon.section.replace(/\s+/g, '-')}`;
1889
+ addonCollapse.className = 'addon-options';
1890
+ addon.items.forEach(item => {
1891
+ const addonItem = document.createElement('div');
1892
+ addonItem.className = 'form-check';
1893
+ const input = document.createElement('input');
1894
+ input.type = 'checkbox';
1895
+ input.className = 'form-check-input';
1896
+ input.id = `addon-${item.name.replace(/\s+/g, '-')}`;
1897
+ input.setAttribute('data-price', item.price || 0);
1898
+ input.setAttribute('data-name', item.name);
1899
+ input.setAttribute('data-section', addon.section);
1900
+ input.addEventListener('change', updateModalPrice);
1901
+ const label = document.createElement('label');
1902
+ label.className = 'form-check-label';
1903
+ label.htmlFor = `addon-${item.name.replace(/\s+/g, '-')}`;
1904
+ label.textContent = item.name;
1905
+ if (item.price > 0) {
1906
+ const priceSpan = document.createElement('span');
1907
+ priceSpan.className = 'extra-charge';
1908
+ priceSpan.textContent = `+$${parseFloat(item.price).toFixed(2)}`;
1909
+ label.appendChild(priceSpan);
1910
+ }
1911
+ addonItem.appendChild(label);
1912
+ addonItem.appendChild(input);
1913
+ addonCollapse.appendChild(addonItem);
1914
+ });
1915
+ addonSection.appendChild(addonCollapse);
1916
+ addonsList.appendChild(addonSection);
1917
+ });
1918
  })
1919
  .catch(err => {
1920
  console.error('Error fetching addons:', err);
 
1921
  addonsList.classList.remove('addon-loading');
1922
+ console.log('Using static fallback addons due to error');
1923
+ addonsList.innerHTML = '';
1924
+ fallbackAddons.forEach(addon => {
1925
+ const addonSection = document.createElement('div');
1926
+ addonSection.className = 'addon-section';
1927
+ const addonHeader = document.createElement('h6');
1928
+ addonHeader.textContent = addon.section;
1929
+ addonHeader.setAttribute('data-bs-toggle', 'collapse');
1930
+ addonHeader.setAttribute('data-bs-target', `#collapse-${addon.section.replace(/\s+/g, '-')}`);
1931
+ addonSection.appendChild(addonHeader);
1932
+ const addonCollapse = document.createElement('div');
1933
+ addonCollapse.id = `collapse-${addon.section.replace(/\s+/g, '-')}`;
1934
+ addonCollapse.className = 'addon-options';
1935
+ addon.items.forEach(item => {
1936
+ const addonItem = document.createElement('div');
1937
+ addonItem.className = 'form-check';
1938
+ const input = document.createElement('input');
1939
+ input.type = 'checkbox';
1940
+ input.className = 'form-check-input';
1941
+ input.id = `addon-${item.name.replace(/\s+/g, '-')}`;
1942
+ input.setAttribute('data-price', item.price || 0);
1943
+ input.setAttribute('data-name', item.name);
1944
+ input.setAttribute('data-section', addon.section);
1945
+ input.addEventListener('change', updateModalPrice);
1946
+ const label = document.createElement('label');
1947
+ label.className = 'form-check-label';
1948
+ label.htmlFor = `addon-${item.name.replace(/\s+/g, '-')}`;
1949
+ label.textContent = item.name;
1950
+ if (item.price > 0) {
1951
+ const priceSpan = document.createElement('span');
1952
+ priceSpan.className = 'extra-charge';
1953
+ priceSpan.textContent = `+$${parseFloat(item.price).toFixed(2)}`;
1954
+ label.appendChild(priceSpan);
1955
+ }
1956
+ addonItem.appendChild(label);
1957
+ addonItem.appendChild(input);
1958
+ addonCollapse.appendChild(addonItem);
1959
+ });
1960
+ addonSection.appendChild(addonCollapse);
1961
+ addonsList.appendChild(addonSection);
1962
+ });
1963
  });
1964
  }
1965
  function addToCartFromModal() {
 
2046
  function handleToggle(toggleType) {
2047
  const vegToggle = document.getElementById('veg-toggle');
2048
  const customToggle = document.getElementById('category-CustomizedDish');
2049
+ const form = document.getElementById('filter-form');
2050
+ if (toggleType === 'veg') {
2051
+ if (vegToggle.checked) {
2052
+ customToggle.checked = false;
2053
+ vegToggle.value = 'Veg';
2054
+ } else {
2055
+ vegToggle.value = '';
2056
+ }
2057
+ } else if (toggleType === 'custom') {
2058
+ if (customToggle.checked) {
2059
+ vegToggle.checked = false;
2060
+ vegToggle.value = '';
2061
+ }
2062
+ }
2063
+ console.log('Filter state:', {
2064
+ veg: vegToggle.checked ? 'Veg' : '',
2065
+ category: customToggle.checked ? 'Customized Dish' : ''
2066
+ });
2067
+ form.submit();
2068
  }
2069
  document.addEventListener('DOMContentLoaded', function () {
2070
  const avatarIcon = document.querySelector('.avatar-icon');