Spaces:
Sleeping
Sleeping
Update templates/menu.html
Browse files- templates/menu.html +62 -0
templates/menu.html
CHANGED
|
@@ -731,6 +731,68 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
| 731 |
quantityInput.value = currentQuantity;
|
| 732 |
});
|
| 733 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 734 |
|
| 735 |
// Function to round reward points to a single digit
|
| 736 |
function roundRewardPoints() {
|
|
|
|
| 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() {
|