nagasurendra commited on
Commit
97d72af
·
verified ·
1 Parent(s): 7e47b7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -34
app.py CHANGED
@@ -126,7 +126,7 @@ def create_modal_window():
126
  """
127
 
128
  modal_html = f"""
129
- <div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000; width: 80%; top: 10%; left: 50%; transform: translateX(-50%);">
130
  <div style="text-align: right;">
131
  <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
132
  </div>
@@ -156,7 +156,7 @@ def modal_js():
156
  const modal = document.getElementById('modal');
157
  modal.style.display = 'block';
158
  modal.style.position = 'fixed';
159
- modal.style.width = window.innerWidth <= 768 ? '90%' : '50%';
160
  modal.style.top = `${event.clientY}px`;
161
  modal.style.left = '50%';
162
  modal.style.transform = 'translate(-50%, -50%)';
@@ -242,33 +242,24 @@ def modal_js():
242
  totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
243
  totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
244
  }
245
- function submitOrder() {
246
- const orderDetails = cart.map(item => {
247
- const extrasList = item.extras.map(extra => `${extra.name} x${extra.quantity} (+$${(extra.price * extra.quantity).toFixed(2)})`).join(', ');
248
  return `
249
- <div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
250
- <h3>${item.name}</h3>
251
- <p>Quantity: ${item.quantity}</p>
252
- <p>Extras: ${extrasList || 'None'}</p>
253
- <p>Special Instructions: ${item.instructions || 'None'}</p>
254
- <p>Total Cost: $${item.totalCost.toFixed(2)}</p>
255
- </div>
256
  `;
257
- }).join('');
258
-
259
- const finalOrderPage = document.getElementById('final-order-page');
260
- const orderDetailsContainer = document.getElementById('order-details');
261
- orderDetailsContainer.innerHTML = orderDetails;
262
-
263
- // Show the final order page and hide the cart page
264
- finalOrderPage.style.display = 'block';
265
- document.getElementById('cart-modal').style.display = 'none';
266
  }
267
-
268
- // Go back to Menu Page from Final Order Page
269
- function goBackToMenu() {
270
- document.getElementById('final-order-page').style.display = 'none';
271
- document.getElementById('menu-page').style.display = 'block';
272
  }
273
  </script>
274
  """
@@ -302,17 +293,10 @@ with gr.Blocks() as app:
302
  preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
303
  menu_output = gr.HTML()
304
  gr.HTML("<div id='cart-button' style='position: fixed; top: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>View Cart</div>")
305
- gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>&times;</button></div><h1>Your Cart</h1><div id='cart-items'></div><p id='cart-total-cost' style='font-size: 1.2em; font-weight: bold;'>Total Cart Cost: $0.00</p><button onclick='submitOrder()' style='background: #007bff; color: white; padding: 10px 20px; border-radius: 5px;'>Submit Order</button></div></div>")
306
  gr.HTML(create_modal_window())
307
  gr.HTML(modal_js())
308
 
309
- # Final Order Page
310
- with gr.Row(visible=False) as final_order_page:
311
- with gr.Column():
312
- gr.HTML("<h1 style='text-align: center;'>Final Order</h1>")
313
- order_details_output = gr.HTML()
314
- gr.HTML("<button onclick='goBackToMenu()' style='background: #28a745; color: white; padding: 10px 20px; border-radius: 5px;'>Back to Menu</button>")
315
-
316
  login_button.click(
317
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")
318
  if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),
 
126
  """
127
 
128
  modal_html = f"""
129
+ <div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
130
  <div style="text-align: right;">
131
  <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
132
  </div>
 
156
  const modal = document.getElementById('modal');
157
  modal.style.display = 'block';
158
  modal.style.position = 'fixed';
159
+ modal.style.width = window.innerWidth <= 768 ? '90%' : '30%';
160
  modal.style.top = `${event.clientY}px`;
161
  modal.style.left = '50%';
162
  modal.style.transform = 'translate(-50%, -50%)';
 
242
  totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
243
  totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
244
  }
245
+ function proceedToCheckout() {
246
+ const cartSummary = cart.map(item => {
247
+ const extrasList = item.extras.length > 0 ? item.extras.map(extra => `${extra.name} (+$${extra.price})`).join(', ') : 'None';
248
  return `
249
+ <div><strong>${item.name}</strong> - $${item.totalCost.toFixed(2)}<br>
250
+ Quantity: ${item.quantity} | Add-ons: ${extrasList} | Instructions: ${item.instructions || 'None'}</div>
 
 
 
 
 
251
  `;
252
+ }).join('<hr>');
253
+ alert("Proceeding to checkout...\n\n" + cartSummary);
254
+ cart = []; // Empty the cart after checkout
255
+ updateCartButton(); // Reset cart button text
256
+ updateCartTotalCost(); // Reset total cost
257
+ closeCartModal();
 
 
 
258
  }
259
+ // Reset all selected add-ons when opening a new item modal
260
+ function resetAddOns() {
261
+ const checkboxes = document.querySelectorAll('input[name="biryani-extra"]');
262
+ checkboxes.forEach(checkbox => checkbox.checked = false); // Uncheck all add-ons
 
263
  }
264
  </script>
265
  """
 
293
  preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
294
  menu_output = gr.HTML()
295
  gr.HTML("<div id='cart-button' style='position: fixed; top: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>View Cart</div>")
296
+ gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>&times;</button></div><h1>Your Cart</h1><div id='cart-items'></div><p id='cart-total-cost' style='font-size: 1.2em; font-weight: bold;'>Total Cart Cost: $0.00</p><button style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;' onclick='proceedToCheckout()'>Proceed to Checkout</button></div></div>")
297
  gr.HTML(create_modal_window())
298
  gr.HTML(modal_js())
299
 
 
 
 
 
 
 
 
300
  login_button.click(
301
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")
302
  if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),