Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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;
|
130 |
<div style="text-align: right;">
|
131 |
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</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%' : '
|
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
|
246 |
-
const
|
247 |
-
const extrasList = item.extras.map(extra => `${extra.name}
|
248 |
return `
|
249 |
-
<div
|
250 |
-
|
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 |
-
|
260 |
-
|
261 |
-
|
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 |
-
|
269 |
-
|
270 |
-
|
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;'>×</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
|
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;">×</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;'>×</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."),
|