lokesh341 commited on
Commit
b0e1d1d
·
verified ·
1 Parent(s): 52b3d7d

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +94 -138
templates/menu.html CHANGED
@@ -836,12 +836,7 @@
836
  data-item-section="{{ item.Section__c | default(section) }}"
837
  data-item-category="{{ selected_category }}">
838
  {% if item.Section__c == 'Soft Drinks' %}
839
- <button class="btn btn-primary add-to-cart-btn" onclick="handleSoftDrinkAdd(this)">ADD</button>
840
- <div class="quantity-selector" style="display: none;">
841
- <button class="btn btn-outline-secondary decrease-btn" onclick="decreaseQuantity(this)">-</button>
842
- <span class="quantity-display">0</span>
843
- <button class="btn btn-outline-secondary increase-btn" onclick="increaseQuantity(this)">+</button>
844
- </div>
845
  {% else %}
846
  <button class="btn btn-primary"
847
  data-bs-toggle="modal"
@@ -913,9 +908,37 @@
913
  </div>
914
  </div>
915
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
916
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
917
  <script>
918
  let isProcessingRequest = false;
 
919
 
920
  const menuItems = [
921
  {% for section, items in ordered_menu.items() %}
@@ -1080,68 +1103,32 @@
1080
  };
1081
  }
1082
 
1083
- function handleSoftDrinkAdd(button) {
 
1084
  const buttonContainer = button.closest('.button-container');
1085
- const quantitySelector = buttonContainer.querySelector('.quantity-selector');
1086
- const addButton = buttonContainer.querySelector('.add-to-cart-btn');
1087
- const quantityDisplay = quantitySelector.querySelector('.quantity-display');
1088
 
1089
- addButton.style.display = 'none';
1090
- quantitySelector.style.display = 'flex';
 
1091
 
1092
- if (parseInt(quantityDisplay.innerText) === 0) {
1093
- quantityDisplay.innerText = '1';
1094
- updateCartQuantity(buttonContainer, 1);
1095
- }
1096
  }
1097
 
1098
- function increaseQuantity(button) {
1099
- if (isProcessingRequest) return;
1100
- isProcessingRequest = true;
1101
-
1102
- const buttonContainer = button.closest('.button-container');
1103
- const quantityDisplay = buttonContainer.querySelector('.quantity-display');
1104
- let currentQuantity = parseInt(quantityDisplay.innerText) || 0;
1105
-
1106
- if (currentQuantity < 10) {
1107
- const newQuantity = currentQuantity + 1;
1108
- quantityDisplay.innerText = newQuantity;
1109
- debouncedUpdateCart(buttonContainer, newQuantity);
1110
- } else {
1111
- console.log('Maximum quantity of 10 reached for Soft Drinks');
1112
- isProcessingRequest = false;
1113
- }
1114
- }
1115
-
1116
- function decreaseQuantity(button) {
1117
- if (isProcessingRequest) return;
1118
- isProcessingRequest = true;
1119
-
1120
- const buttonContainer = button.closest('.button-container');
1121
- const quantityDisplay = buttonContainer.querySelector('.quantity-display');
1122
- const addButton = buttonContainer.querySelector('.add-to-cart-btn');
1123
- const quantitySelector = buttonContainer.querySelector('.quantity-selector');
1124
- const currentQuantity = parseInt(quantityDisplay.innerText) || 0;
1125
-
1126
- if (currentQuantity <= 1) {
1127
- quantityDisplay.innerText = '0';
1128
- addButton.style.display = 'block';
1129
- quantitySelector.style.display = 'none';
1130
- updateCartQuantity(buttonContainer, 0);
1131
- } else {
1132
- const newQuantity = currentQuantity - 1;
1133
- quantityDisplay.innerText = newQuantity;
1134
- debouncedUpdateCart(buttonContainer, newQuantity);
1135
- }
1136
- }
1137
-
1138
- function updateCartQuantity(buttonContainer, newQuantity) {
1139
  const itemName = buttonContainer.getAttribute('data-item-name');
1140
  const itemPrice = parseFloat(buttonContainer.getAttribute('data-item-price'));
1141
  const itemImage = buttonContainer.getAttribute('data-item-image');
1142
  const section = buttonContainer.getAttribute('data-item-section');
1143
  const selectedCategory = buttonContainer.getAttribute('data-item-category');
1144
-
1145
  const cartPayload = {
1146
  itemName: itemName,
1147
  itemPrice: itemPrice,
@@ -1150,65 +1137,39 @@
1150
  category: selectedCategory,
1151
  addons: [],
1152
  instructions: '',
1153
- quantity: newQuantity
1154
  };
1155
-
1156
- if (newQuantity > 0) {
1157
- fetch('/cart/add', {
1158
- method: 'POST',
1159
- headers: {
1160
- 'Content-Type': 'application/json',
1161
- },
1162
- body: JSON.stringify(cartPayload)
1163
- })
1164
- .then(response => response.json())
1165
- .then(data => {
1166
- if (data.success) {
1167
- updateCartUI(data.cart);
1168
- } else {
1169
- console.error('Failed to update cart:', data.error);
1170
- const cart = addToCartLocalStorage(cartPayload);
1171
- updateCartUI(cart);
1172
- }
1173
- })
1174
- .catch(err => {
1175
- console.error('Error updating cart:', err);
1176
  const cart = addToCartLocalStorage(cartPayload);
1177
  updateCartUI(cart);
1178
- })
1179
- .finally(() => {
1180
- isProcessingRequest = false;
1181
- });
1182
- } else {
1183
- fetch(`/cart/remove?item_name=${encodeURIComponent(itemName)}&instructions=&addons=[]`, {
1184
- method: 'POST',
1185
- headers: {
1186
- 'Content-Type': 'application/json',
1187
- }
1188
- })
1189
- .then(response => response.json())
1190
- .then(data => {
1191
- if (data.success) {
1192
- updateCartUI(data.cart);
1193
- } else {
1194
- console.error('Failed to remove item:', data.error);
1195
- const cart = removeFromCartLocalStorage(itemName, 1, '', []);
1196
- updateCartUI(cart);
1197
- }
1198
- })
1199
- .catch(err => {
1200
- console.error('Error removing item:', err);
1201
- const cart = removeFromCartLocalStorage(itemName, 1, '', []);
1202
- updateCartUI(cart);
1203
- })
1204
- .finally(() => {
1205
- isProcessingRequest = false;
1206
- });
1207
- }
1208
  }
1209
 
1210
- const debouncedUpdateCart = debounce(updateCartQuantity, 300);
1211
-
1212
  function updateCartUI(cart) {
1213
  if (!Array.isArray(cart)) {
1214
  console.error('Invalid cart data:', cart);
@@ -1225,32 +1186,6 @@
1225
  cartItemCount.innerText = totalQuantity;
1226
  cartItemCount.style.display = totalQuantity > 0 ? 'inline-flex' : 'none';
1227
  }
1228
-
1229
- const buttonContainers = document.querySelectorAll('.button-container');
1230
- buttonContainers.forEach(container => {
1231
- const itemName = container.getAttribute('data-item-name');
1232
- const section = container.getAttribute('data-item-section');
1233
- const quantityDisplay = container.querySelector('.quantity-display');
1234
- const addButton = container.querySelector('.add-to-cart-btn');
1235
- const quantitySelector = container.querySelector('.quantity-selector');
1236
-
1237
- const cartItem = cart.find(item =>
1238
- item.itemName === itemName &&
1239
- item.section === section &&
1240
- item.instructions === '' &&
1241
- JSON.stringify(item.addons) === JSON.stringify([])
1242
- );
1243
-
1244
- if (cartItem && cartItem.quantity > 0) {
1245
- quantityDisplay.innerText = cartItem.quantity;
1246
- addButton.style.display = 'none';
1247
- quantitySelector.style.display = 'flex';
1248
- } else {
1249
- quantityDisplay.innerText = '0';
1250
- addButton.style.display = 'block';
1251
- quantitySelector.style.display = 'none';
1252
- }
1253
- });
1254
  }
1255
 
1256
  document.addEventListener('DOMContentLoaded', function () {
@@ -1480,6 +1415,27 @@
1480
  quantityInput.value = currentQuantity;
1481
  });
1482
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1483
  const micIcon = document.getElementById('micIcon');
1484
  if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
1485
  const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
 
836
  data-item-section="{{ item.Section__c | default(section) }}"
837
  data-item-category="{{ selected_category }}">
838
  {% if item.Section__c == 'Soft Drinks' %}
839
+ <button class="btn btn-primary add-to-cart-btn" onclick="showSoftDrinkModal(this)">ADD</button>
 
 
 
 
 
840
  {% else %}
841
  <button class="btn btn-primary"
842
  data-bs-toggle="modal"
 
908
  </div>
909
  </div>
910
 
911
+ <!-- Modal for Soft Drinks Quantity Selection -->
912
+ <div class="modal fade" id="softDrinkModal" tabindex="-1" aria-labelledby="softDrinkModalLabel" aria-hidden="true">
913
+ <div class="modal-dialog modal-dialog-centered">
914
+ <div class="modal-content">
915
+ <div class="modal-header">
916
+ <h5 class="modal-title" id="softDrinkModalLabel">Select Quantity</h5>
917
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
918
+ </div>
919
+ <div class="modal-body">
920
+ <div class="text-center mb-3">
921
+ <h5 id="soft-drink-name"></h5>
922
+ <p id="soft-drink-price"></p>
923
+ </div>
924
+ <div class="d-flex justify-content-center align-items-center mb-4">
925
+ <button type="button" class="btn btn-outline-secondary" id="soft-drink-decrease">-</button>
926
+ <input type="text" class="form-control text-center mx-2" id="soft-drink-quantity" value="1" readonly style="width: 60px;">
927
+ <button type="button" class="btn btn-outline-secondary" id="soft-drink-increase">+</button>
928
+ </div>
929
+ </div>
930
+ <div class="modal-footer">
931
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
932
+ <button type="button" class="btn btn-primary" onclick="addSoftDrinkToCart()">Add to Cart</button>
933
+ </div>
934
+ </div>
935
+ </div>
936
+ </div>
937
+
938
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
939
  <script>
940
  let isProcessingRequest = false;
941
+ let currentSoftDrinkButton = null;
942
 
943
  const menuItems = [
944
  {% for section, items in ordered_menu.items() %}
 
1103
  };
1104
  }
1105
 
1106
+ function showSoftDrinkModal(button) {
1107
+ currentSoftDrinkButton = button;
1108
  const buttonContainer = button.closest('.button-container');
1109
+ const itemName = buttonContainer.getAttribute('data-item-name');
1110
+ const itemPrice = buttonContainer.getAttribute('data-item-price');
 
1111
 
1112
+ document.getElementById('soft-drink-name').textContent = itemName;
1113
+ document.getElementById('soft-drink-price').textContent = `$${itemPrice}`;
1114
+ document.getElementById('soft-drink-quantity').value = '1';
1115
 
1116
+ const modal = new bootstrap.Modal(document.getElementById('softDrinkModal'));
1117
+ modal.show();
 
 
1118
  }
1119
 
1120
+ function addSoftDrinkToCart() {
1121
+ if (!currentSoftDrinkButton) return;
1122
+
1123
+ const buttonContainer = currentSoftDrinkButton.closest('.button-container');
1124
+ const quantity = parseInt(document.getElementById('soft-drink-quantity').value) || 1;
1125
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1126
  const itemName = buttonContainer.getAttribute('data-item-name');
1127
  const itemPrice = parseFloat(buttonContainer.getAttribute('data-item-price'));
1128
  const itemImage = buttonContainer.getAttribute('data-item-image');
1129
  const section = buttonContainer.getAttribute('data-item-section');
1130
  const selectedCategory = buttonContainer.getAttribute('data-item-category');
1131
+
1132
  const cartPayload = {
1133
  itemName: itemName,
1134
  itemPrice: itemPrice,
 
1137
  category: selectedCategory,
1138
  addons: [],
1139
  instructions: '',
1140
+ quantity: quantity
1141
  };
1142
+
1143
+ fetch('/cart/add', {
1144
+ method: 'POST',
1145
+ headers: {
1146
+ 'Content-Type': 'application/json',
1147
+ },
1148
+ body: JSON.stringify(cartPayload)
1149
+ })
1150
+ .then(response => response.json())
1151
+ .then(data => {
1152
+ if (data.success) {
1153
+ updateCartUI(data.cart);
1154
+ const modal = bootstrap.Modal.getInstance(document.getElementById('softDrinkModal'));
1155
+ modal.hide();
1156
+ } else {
1157
+ console.error('Failed to add item to cart:', data.error);
 
 
 
 
 
1158
  const cart = addToCartLocalStorage(cartPayload);
1159
  updateCartUI(cart);
1160
+ const modal = bootstrap.Modal.getInstance(document.getElementById('softDrinkModal'));
1161
+ modal.hide();
1162
+ }
1163
+ })
1164
+ .catch(err => {
1165
+ console.error('Error adding item to cart:', err);
1166
+ const cart = addToCartLocalStorage(cartPayload);
1167
+ updateCartUI(cart);
1168
+ const modal = bootstrap.Modal.getInstance(document.getElementById('softDrinkModal'));
1169
+ modal.hide();
1170
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1171
  }
1172
 
 
 
1173
  function updateCartUI(cart) {
1174
  if (!Array.isArray(cart)) {
1175
  console.error('Invalid cart data:', cart);
 
1186
  cartItemCount.innerText = totalQuantity;
1187
  cartItemCount.style.display = totalQuantity > 0 ? 'inline-flex' : 'none';
1188
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1189
  }
1190
 
1191
  document.addEventListener('DOMContentLoaded', function () {
 
1415
  quantityInput.value = currentQuantity;
1416
  });
1417
 
1418
+ // Soft Drinks modal quantity controls
1419
+ const softDrinkDecreaseBtn = document.getElementById('soft-drink-decrease');
1420
+ const softDrinkIncreaseBtn = document.getElementById('soft-drink-increase');
1421
+ const softDrinkQuantityInput = document.getElementById('soft-drink-quantity');
1422
+
1423
+ softDrinkDecreaseBtn.addEventListener('click', function() {
1424
+ let currentQuantity = parseInt(softDrinkQuantityInput.value);
1425
+ if (currentQuantity > 1) {
1426
+ currentQuantity--;
1427
+ softDrinkQuantityInput.value = currentQuantity;
1428
+ }
1429
+ });
1430
+
1431
+ softDrinkIncreaseBtn.addEventListener('click', function() {
1432
+ let currentQuantity = parseInt(softDrinkQuantityInput.value);
1433
+ if (currentQuantity < 10) {
1434
+ currentQuantity++;
1435
+ softDrinkQuantityInput.value = currentQuantity;
1436
+ }
1437
+ });
1438
+
1439
  const micIcon = document.getElementById('micIcon');
1440
  if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
1441
  const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;