nagasurendra commited on
Commit
da85a51
·
verified ·
1 Parent(s): 76df88b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -152,6 +152,7 @@ def modal_js():
152
  <script>
153
  let cart = [];
154
  let totalCartCost = 0;
 
155
  function openModal(name, image2, description, price) {
156
  const modal = document.getElementById('modal');
157
  modal.style.display = 'block';
@@ -168,9 +169,11 @@ def modal_js():
168
  document.getElementById('special-instructions').value = '';
169
  resetAddOns(); // Reset add-ons when opening the modal
170
  }
 
171
  function closeModal() {
172
  document.getElementById('modal').style.display = 'none';
173
  }
 
174
  function addToCart() {
175
  const name = document.getElementById('modal-name').innerText;
176
  const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
@@ -184,17 +187,19 @@ def modal_js():
184
  }));
185
  const extrasCost = extras.reduce((total, extra) => total + (extra.price * extra.quantity), 0);
186
  const totalCost = (price * quantity) + extrasCost;
187
- // Add the item to the cart with its specific add-ons
188
  cart.push({ name, price, quantity, extras, instructions, totalCost });
189
- totalCartCost += totalCost; // Update the total cost of the cart
190
  updateCartButton();
191
- updateCartTotalCost(); // Update total cost displayed
192
  closeModal();
193
  }
 
194
  function updateCartButton() {
195
  const cartButton = document.getElementById('cart-button');
196
  cartButton.innerText = `View Cart (${cart.length} items)`;
197
  }
 
198
  function openCartModal() {
199
  const cartModal = document.getElementById('cart-modal');
200
  const cartItemsContainer = document.getElementById('cart-items');
@@ -214,36 +219,40 @@ def modal_js():
214
  });
215
  cartModal.style.display = 'block';
216
  }
 
217
  function closeCartModal() {
218
  document.getElementById('cart-modal').style.display = 'none';
219
  }
 
220
  function removeFromCart(index) {
221
- totalCartCost -= cart[index].totalCost; // Deduct the cost of the removed item from total cost
222
  cart.splice(index, 1);
223
  updateCartButton();
224
- updateCartTotalCost(); // Update total cost displayed
225
  openCartModal();
226
  }
 
227
  function updateCartItem(index, type, value) {
228
  if (type === 'item') {
229
  cart[index].quantity = parseInt(value);
230
  } else if (type === 'extra') {
231
- cart[index].extras[0].quantity = parseInt(value); // Assuming one add-on for simplicity
232
  }
233
  const item = cart[index];
234
  const price = item.price;
235
  const extrasCost = item.extras.reduce((total, extra) => total + (extra.price * extra.quantity), 0);
236
  item.totalCost = (price * item.quantity) + extrasCost;
237
  document.getElementById(`item-${index}-total`).innerText = item.totalCost.toFixed(2);
238
- updateCartTotalCost(); // Update total cost displayed
239
  }
 
240
  function updateCartTotalCost() {
241
  const totalCostElement = document.getElementById('cart-total-cost');
242
  totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
243
  totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
244
  }
 
245
  function proceedToCheckout() {
246
- // Display checkout summary
247
  let checkoutSummary = "<h1>Checkout Summary</h1>";
248
  cart.forEach(item => {
249
  checkoutSummary += `
@@ -265,16 +274,18 @@ def modal_js():
265
  updateCartButton();
266
  updateCartTotalCost();
267
  }
 
268
  function goBackToMenu() {
269
  document.getElementById('menu-page').style.display = 'block';
270
  document.getElementById('cart-modal').style.display = 'none';
271
  }
272
- // Reset all selected add-ons when opening a new item modal
273
  function resetAddOns() {
274
  const checkboxes = document.querySelectorAll('input[name="biryani-extra"]');
275
- checkboxes.forEach(checkbox => checkbox.checked = false); // Uncheck all add-ons
276
  }
277
  </script>
 
278
  """
279
  return modal_script
280
 
 
152
  <script>
153
  let cart = [];
154
  let totalCartCost = 0;
155
+
156
  function openModal(name, image2, description, price) {
157
  const modal = document.getElementById('modal');
158
  modal.style.display = 'block';
 
169
  document.getElementById('special-instructions').value = '';
170
  resetAddOns(); // Reset add-ons when opening the modal
171
  }
172
+
173
  function closeModal() {
174
  document.getElementById('modal').style.display = 'none';
175
  }
176
+
177
  function addToCart() {
178
  const name = document.getElementById('modal-name').innerText;
179
  const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
 
187
  }));
188
  const extrasCost = extras.reduce((total, extra) => total + (extra.price * extra.quantity), 0);
189
  const totalCost = (price * quantity) + extrasCost;
190
+
191
  cart.push({ name, price, quantity, extras, instructions, totalCost });
192
+ totalCartCost += totalCost;
193
  updateCartButton();
194
+ updateCartTotalCost();
195
  closeModal();
196
  }
197
+
198
  function updateCartButton() {
199
  const cartButton = document.getElementById('cart-button');
200
  cartButton.innerText = `View Cart (${cart.length} items)`;
201
  }
202
+
203
  function openCartModal() {
204
  const cartModal = document.getElementById('cart-modal');
205
  const cartItemsContainer = document.getElementById('cart-items');
 
219
  });
220
  cartModal.style.display = 'block';
221
  }
222
+
223
  function closeCartModal() {
224
  document.getElementById('cart-modal').style.display = 'none';
225
  }
226
+
227
  function removeFromCart(index) {
228
+ totalCartCost -= cart[index].totalCost;
229
  cart.splice(index, 1);
230
  updateCartButton();
231
+ updateCartTotalCost();
232
  openCartModal();
233
  }
234
+
235
  function updateCartItem(index, type, value) {
236
  if (type === 'item') {
237
  cart[index].quantity = parseInt(value);
238
  } else if (type === 'extra') {
239
+ cart[index].extras[0].quantity = parseInt(value);
240
  }
241
  const item = cart[index];
242
  const price = item.price;
243
  const extrasCost = item.extras.reduce((total, extra) => total + (extra.price * extra.quantity), 0);
244
  item.totalCost = (price * item.quantity) + extrasCost;
245
  document.getElementById(`item-${index}-total`).innerText = item.totalCost.toFixed(2);
246
+ updateCartTotalCost();
247
  }
248
+
249
  function updateCartTotalCost() {
250
  const totalCostElement = document.getElementById('cart-total-cost');
251
  totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
252
  totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
253
  }
254
+
255
  function proceedToCheckout() {
 
256
  let checkoutSummary = "<h1>Checkout Summary</h1>";
257
  cart.forEach(item => {
258
  checkoutSummary += `
 
274
  updateCartButton();
275
  updateCartTotalCost();
276
  }
277
+
278
  function goBackToMenu() {
279
  document.getElementById('menu-page').style.display = 'block';
280
  document.getElementById('cart-modal').style.display = 'none';
281
  }
282
+
283
  function resetAddOns() {
284
  const checkboxes = document.querySelectorAll('input[name="biryani-extra"]');
285
+ checkboxes.forEach(checkbox => checkbox.checked = false);
286
  }
287
  </script>
288
+
289
  """
290
  return modal_script
291