nagasurendra commited on
Commit
2ab5486
·
verified ·
1 Parent(s): cf96d01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -23
app.py CHANGED
@@ -129,35 +129,32 @@ modal_and_cart_js = """
129
  };
130
  let finalized = false;
131
  function openModal(name, image, description, price) {
 
 
 
 
132
  const modal = document.getElementById('modal');
133
- const buttonRect = event.target.getBoundingClientRect();
134
-
135
  if (window.innerWidth <= 768) {
136
  modal.style.width = '90%';
137
  } else {
138
  modal.style.width = '30%';
139
  }
140
-
141
- const modalTop = window.scrollY + buttonRect.top + buttonRect.height + 20;
142
- const modalLeft = window.scrollX + buttonRect.left + buttonRect.width / 2 - modal.offsetWidth / 2;
143
-
144
- modal.style.display = 'block';
145
- modal.style.position = 'absolute';
146
- modal.style.top = `${modalTop}px`;
147
- modal.style.left = `${modalLeft}px`;
148
-
149
- document.getElementById('modal-name').innerText = name;
150
  document.getElementById('modal-image').src = image;
 
151
  document.getElementById('modal-description').innerText = description;
152
- document.getElementById('modal-price').innerText = `$${price}`;
 
 
 
 
153
  }
154
-
155
- function closeModal() {
156
- document.getElementById('modal').style.display = 'none';
157
- }
158
- </script>
159
-
160
-
161
  function closeModal() {
162
  document.getElementById('modal').style.display = 'none';
163
  }
@@ -216,7 +213,6 @@ modal_and_cart_js = """
216
  cartHTML += `<button style='margin-top: 10px; background-color: #007bff; color: white; border: none; padding: 10px; border-radius: 5px; width: 100%; cursor: pointer;' onclick='submitCart()'>Submit</button>`;
217
  document.getElementById('floating-cart').innerHTML = cartHTML;
218
  }
219
-
220
  function updateItemQuantity(index, newQuantity) {
221
  const quantity = parseInt(newQuantity) || 1;
222
  cart[index].quantity = quantity;
@@ -326,8 +322,8 @@ def app():
326
 
327
  # Modal window
328
  modal_window = gr.HTML("""
329
- <div id="modal" style="display: none; position: absolute; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
330
- <div style="text-align: right;">
331
  <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
332
  </div>
333
  <img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
 
129
  };
130
  let finalized = false;
131
  function openModal(name, image, description, price) {
132
+ if (finalized) {
133
+ alert("You cannot add more items after finalizing your order.");
134
+ return;
135
+ }
136
  const modal = document.getElementById('modal');
137
+ modal.style.display = 'block';
138
+ modal.style.position = 'fixed';
139
  if (window.innerWidth <= 768) {
140
  modal.style.width = '90%';
141
  } else {
142
  modal.style.width = '30%';
143
  }
144
+ const currentTop = parseInt(window.getComputedStyle(modal).top, 10);
145
+ const newTop = currentTop + 15;
146
+ modal.style.top = `${newTop}px`;
147
+ modal.style.left = '50%';
148
+ modal.style.transform = 'translate(-50%, -50%)';
 
 
 
 
 
149
  document.getElementById('modal-image').src = image;
150
+ document.getElementById('modal-name').innerText = name;
151
  document.getElementById('modal-description').innerText = description;
152
+ document.getElementById('modal-price').innerText = price;
153
+ const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
154
+ extrasInputs.forEach(input => input.checked = false);
155
+ document.getElementById('quantity').value = 1;
156
+ document.getElementById('special-instructions').value = '';
157
  }
 
 
 
 
 
 
 
158
  function closeModal() {
159
  document.getElementById('modal').style.display = 'none';
160
  }
 
213
  cartHTML += `<button style='margin-top: 10px; background-color: #007bff; color: white; border: none; padding: 10px; border-radius: 5px; width: 100%; cursor: pointer;' onclick='submitCart()'>Submit</button>`;
214
  document.getElementById('floating-cart').innerHTML = cartHTML;
215
  }
 
216
  function updateItemQuantity(index, newQuantity) {
217
  const quantity = parseInt(newQuantity) || 1;
218
  cart[index].quantity = quantity;
 
322
 
323
  # Modal window
324
  modal_window = gr.HTML("""
325
+ <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;">
326
+ <div style="text-align: right;">
327
  <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
328
  </div>
329
  <img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />