nagasurendra commited on
Commit
ab61941
·
verified ·
1 Parent(s): d26c25a

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +41 -91
templates/menu.html CHANGED
@@ -710,115 +710,65 @@ function updateCartDisplay(cart) {
710
  }
711
 
712
  document.addEventListener('DOMContentLoaded', function () {
713
- // Get references to the quantity buttons and the input field
714
  const decreaseBtn = document.getElementById('decreaseQuantity');
715
  const increaseBtn = document.getElementById('increaseQuantity');
716
  const quantityInput = document.getElementById('quantityInput');
717
-
718
- // Add event listener to decrease button
719
  decreaseBtn.addEventListener('click', function () {
720
  let currentQuantity = parseInt(quantityInput.value);
721
  if (currentQuantity > 1) {
722
- currentQuantity--;
723
- quantityInput.value = currentQuantity;
724
  }
725
  });
726
 
727
- // Add event listener to increase button
728
  increaseBtn.addEventListener('click', function () {
729
  let currentQuantity = parseInt(quantityInput.value);
730
- currentQuantity++;
731
- quantityInput.value = currentQuantity;
732
  });
733
  });
734
- function renderAddonOptions(addon) {
735
- const { name, options, max_selections } = addon;
736
-
737
- let selectionContainer = document.createElement('div');
738
- selectionContainer.classList.add('addon-container');
739
-
740
- // Create a label for the addon
741
- let addonLabel = document.createElement('label');
742
- addonLabel.innerHTML = name;
743
- selectionContainer.appendChild(addonLabel);
744
-
745
- // Create the options as checkboxes or radio buttons based on max_selections
746
- options.forEach(option => {
747
- let optionLabel = document.createElement('label');
748
- let inputElement;
749
-
750
- // If max_selections is 1, use radio buttons for single selection
751
- if (max_selections === 1) {
752
- inputElement = document.createElement('input');
753
- inputElement.type = 'radio';
754
- inputElement.name = name;
755
- inputElement.value = option;
756
- inputElement.id = `${name}-${option}`;
757
- } else {
758
- inputElement = document.createElement('input');
759
- inputElement.type = 'checkbox';
760
- inputElement.value = option;
761
- inputElement.id = `${name}-${option}`;
762
- }
763
-
764
- optionLabel.appendChild(inputElement);
765
- optionLabel.appendChild(document.createTextNode(option));
766
- selectionContainer.appendChild(optionLabel);
767
- });
768
 
769
- document.body.appendChild(selectionContainer);
770
- }
771
- function handleSelectionChange(event, maxSelections) {
772
- const selectedOptions = document.querySelectorAll(`input[name="${event.target.name}"]:checked`);
773
- const allOptions = document.querySelectorAll(`input[name="${event.target.name}"]`);
774
-
775
- if (maxSelections === 1 && selectedOptions.length > 1) {
776
- // If it's a single selection, uncheck others if any
777
- allOptions.forEach(option => {
778
- if (option !== event.target) {
779
- option.disabled = true;
780
- }
781
- });
782
- } else {
783
- // Re-enable all options if the user is allowed to select multiple
784
- allOptions.forEach(option => {
785
- option.disabled = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
786
  });
787
- }
788
- }
789
 
790
- // Attach this to the 'change' event listener for the radio/checkbox inputs
791
- document.querySelectorAll('input').forEach(input => {
792
- input.addEventListener('change', (event) => {
793
- handleSelectionChange(event, addon.max_selections);
794
  });
795
- });
796
-
797
- // Function to round reward points to a single digit
798
- function roundRewardPoints() {
799
- // Get the reward points element
800
- let rewardPointsElement = document.getElementById('reward-points');
801
-
802
- // Check if the element exists in the DOM
803
- if (rewardPointsElement) {
804
- let rewardPointsText = rewardPointsElement.innerText.trim(); // Get and trim the value to remove any extra spaces
805
-
806
- // Check if the innerText is a valid number
807
- let rewardPoints = parseFloat(rewardPointsText);
808
-
809
- // If it's a valid number, round it to 1 decimal place
810
- if (!isNaN(rewardPoints)) {
811
- rewardPointsElement.innerText = rewardPoints.toFixed(1); // Round to 1 decimal place
812
- } else {
813
- console.error("Reward points value is not a valid number:", rewardPointsText);
814
- }
815
- } else {
816
- console.error("Reward points element is missing.");
817
- }
818
  }
819
- // Run the function when the page loads
820
- window.onload = roundRewardPoints;
821
-
822
  </script>
823
 
824
  <!-- Bootstrap JS -->
 
710
  }
711
 
712
  document.addEventListener('DOMContentLoaded', function () {
 
713
  const decreaseBtn = document.getElementById('decreaseQuantity');
714
  const increaseBtn = document.getElementById('increaseQuantity');
715
  const quantityInput = document.getElementById('quantityInput');
716
+
717
+ // Add event listeners for quantity control
718
  decreaseBtn.addEventListener('click', function () {
719
  let currentQuantity = parseInt(quantityInput.value);
720
  if (currentQuantity > 1) {
721
+ quantityInput.value = currentQuantity - 1;
 
722
  }
723
  });
724
 
 
725
  increaseBtn.addEventListener('click', function () {
726
  let currentQuantity = parseInt(quantityInput.value);
727
+ quantityInput.value = currentQuantity + 1;
 
728
  });
729
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
730
 
731
+ // Function to dynamically create addon options and enforce max selection
732
+ function loadAddons(addons) {
733
+ const addonsContainer = document.getElementById('addons-list');
734
+ addonsContainer.innerHTML = ""; // Clear previous content
735
+
736
+ addons.forEach(addon => {
737
+ const maxSelections = addon.max_selections || 1; // Default to 1 if not provided
738
+ const optionsContainer = document.createElement('div');
739
+ optionsContainer.classList.add('addon-group');
740
+
741
+ const title = document.createElement('h6');
742
+ title.textContent = addon.name;
743
+ optionsContainer.appendChild(title);
744
+
745
+ addon.options.forEach(option => {
746
+ const label = document.createElement('label');
747
+ label.classList.add('addon-option');
748
+
749
+ const checkbox = document.createElement('input');
750
+ checkbox.type = 'checkbox';
751
+ checkbox.value = option;
752
+ checkbox.name = addon.name; // Group by addon name
753
+
754
+ label.appendChild(checkbox);
755
+ label.appendChild(document.createTextNode(" " + option));
756
+ optionsContainer.appendChild(label);
757
+
758
+ // Enforce max selection rule
759
+ checkbox.addEventListener('change', function () {
760
+ if (maxSelections === 1) {
761
+ // If max selection is 1, uncheck all other checkboxes in the group
762
+ document.querySelectorAll(`input[name="${addon.name}"]`).forEach(cb => {
763
+ if (cb !== checkbox) cb.checked = false;
764
+ });
765
+ }
766
+ });
767
  });
 
 
768
 
769
+ addonsContainer.appendChild(optionsContainer);
 
 
 
770
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
771
  }
 
 
 
772
  </script>
773
 
774
  <!-- Bootstrap JS -->