nagasurendra commited on
Commit
387755a
·
verified ·
1 Parent(s): a30ed98

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +82 -58
templates/menu.html CHANGED
@@ -593,66 +593,90 @@ form-check-input addon-option{
593
  <script>
594
  // Show item details and fetch customization options
595
  function showItemDetails(name, price, image, description, section, selectedCategory) {
596
- document.getElementById('modal-name').innerText = name;
597
- document.getElementById('modal-price').innerText = `$${price}`;
598
- document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
599
- document.getElementById('modal-description').innerText = description || 'No description available.';
600
- document.getElementById('addons-list').innerHTML = 'Loading customization options...';
601
- document.getElementById('modal-instructions').value = '';
602
-
603
- const modalSectionEl = document.getElementById('modal-section');
604
- modalSectionEl.setAttribute('data-section', section);
605
- modalSectionEl.setAttribute('data-category', selectedCategory);
606
-
607
- // Set the default quantity to 1
608
- document.getElementById('quantityInput').value = 1;
609
-
610
- // Fetch customization options based on the section
611
- fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
612
- .then(response => response.json())
613
- .then(data => {
614
- const addonsList = document.getElementById('addons-list');
615
- addonsList.innerHTML = ''; // Clear previous content
616
-
617
- if (!data.success || !data.addons || data.addons.length === 0) {
618
- addonsList.innerHTML = '<p>No customization options available.</p>';
619
- return;
620
- }
621
-
622
- // Display customization options inside styled divs
623
- data.addons.forEach(addon => {
624
- const sectionDiv = document.createElement('div');
625
- sectionDiv.classList.add('addon-section'); // Add styling class
626
-
627
- // Add section title
628
- const title = document.createElement('h6');
629
- title.innerText = addon.name;
630
- sectionDiv.appendChild(title);
631
-
632
- // Create options list
633
- const optionsContainer = document.createElement('div');
634
- addon.options.forEach((option, index) => {
635
- const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
636
- const listItem = document.createElement('div');
637
- listItem.classList.add('form-check');
638
- listItem.innerHTML = `
639
- <input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
640
- data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
641
- <label class="form-check-label" for="${optionId}">
642
- ${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
643
- </label>
644
- `;
645
- optionsContainer.appendChild(listItem);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
646
  });
647
- sectionDiv.appendChild(optionsContainer);
648
- addonsList.appendChild(sectionDiv);
 
 
649
  });
650
- })
651
- .catch(err => {
652
- console.error('Error fetching add-ons:', err);
653
- document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
654
- });
655
- }
656
  function handleToggle(source) {
657
  const form = document.getElementById("filter-form");
658
  const veg = document.getElementById("veg-toggle");
 
593
  <script>
594
  // Show item details and fetch customization options
595
  function showItemDetails(name, price, image, description, section, selectedCategory) {
596
+ // Fetch previous order details for the current user
597
+ fetch(`/fetch_previous_order?email=${encodeURIComponent(userEmail)}`)
598
+ .then(response => response.json())
599
+ .then(data => {
600
+ if (!data.success) {
601
+ console.error("Error fetching previous order");
602
+ return;
603
+ }
604
+
605
+ const previousOrder = data.previousOrder;
606
+
607
+ // Find the specific item in the previous order
608
+ const previousItem = previousOrder.find(item => item.name === name);
609
+
610
+ // Set the modal details as usual
611
+ document.getElementById('modal-name').innerText = name;
612
+ document.getElementById('modal-price').innerText = `$${price}`;
613
+ document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
614
+ document.getElementById('modal-description').innerText = description || 'No description available.';
615
+ document.getElementById('addons-list').innerHTML = 'Loading customization options...';
616
+ document.getElementById('modal-instructions').value = '';
617
+ const modalSectionEl = document.getElementById('modal-section');
618
+ modalSectionEl.setAttribute('data-section', section);
619
+ modalSectionEl.setAttribute('data-category', selectedCategory);
620
+
621
+ // Set the default quantity to 1 (or based on previous order)
622
+ document.getElementById('quantityInput').value = previousItem ? previousItem.quantity : 1;
623
+
624
+ // Fetch customization options based on the section
625
+ fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
626
+ .then(response => response.json())
627
+ .then(data => {
628
+ const addonsList = document.getElementById('addons-list');
629
+ addonsList.innerHTML = ''; // Clear previous content
630
+
631
+ if (!data.success || !data.addons || data.addons.length === 0) {
632
+ addonsList.innerHTML = '<p>No customization options available.</p>';
633
+ return;
634
+ }
635
+
636
+ // Pre-select the add-ons based on previous selection
637
+ data.addons.forEach(addon => {
638
+ const sectionDiv = document.createElement('div');
639
+ sectionDiv.classList.add('addon-section'); // Add styling class
640
+
641
+ // Add section title
642
+ const title = document.createElement('h6');
643
+ title.innerText = addon.name;
644
+ sectionDiv.appendChild(title);
645
+
646
+ // Create options list
647
+ const optionsContainer = document.createElement('div');
648
+ addon.options.forEach((option, index) => {
649
+ const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
650
+ const listItem = document.createElement('div');
651
+ listItem.classList.add('form-check');
652
+
653
+ // Check if this option was selected before
654
+ const checked = previousItem.addons.includes(option); // Pre-select based on previous addons
655
+
656
+ listItem.innerHTML = `
657
+ <input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}" ${checked ? 'checked' : ''}
658
+ data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
659
+ <label class="form-check-label" for="${optionId}">
660
+ ${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
661
+ </label>
662
+ `;
663
+ optionsContainer.appendChild(listItem);
664
+ });
665
+
666
+ sectionDiv.appendChild(optionsContainer);
667
+ addonsList.appendChild(sectionDiv);
668
  });
669
+ })
670
+ .catch(err => {
671
+ console.error('Error fetching add-ons:', err);
672
+ document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
673
  });
674
+ })
675
+ .catch(err => {
676
+ console.error('Error fetching previous order:', err);
677
+ });
678
+ }
679
+
680
  function handleToggle(source) {
681
  const form = document.getElementById("filter-form");
682
  const veg = document.getElementById("veg-toggle");