Spaces:
Sleeping
Sleeping
Update templates/menu.html
Browse files- templates/menu.html +126 -14
templates/menu.html
CHANGED
@@ -13,9 +13,11 @@
|
|
13 |
margin: 0;
|
14 |
padding: 0;
|
15 |
}
|
|
|
16 |
.container {
|
17 |
max-width: 900px;
|
18 |
}
|
|
|
19 |
.menu-card {
|
20 |
max-width: 350px;
|
21 |
border-radius: 15px;
|
@@ -23,28 +25,34 @@
|
|
23 |
background-color: #fff;
|
24 |
margin: auto;
|
25 |
}
|
|
|
26 |
.menu-image {
|
27 |
height: 200px;
|
28 |
width: 100%;
|
29 |
object-fit: cover;
|
30 |
border-radius: 15px 15px 0 0;
|
31 |
}
|
|
|
32 |
.card-title {
|
33 |
font-size: 1.2rem;
|
34 |
font-weight: bold;
|
35 |
}
|
|
|
36 |
.card-text {
|
37 |
font-size: 1rem;
|
38 |
color: #6c757d;
|
39 |
}
|
|
|
40 |
.btn-primary {
|
41 |
font-size: 0.9rem;
|
42 |
border-radius: 20px;
|
43 |
width: 100px;
|
44 |
}
|
|
|
45 |
.filter-container {
|
46 |
margin-bottom: 15px;
|
47 |
}
|
|
|
48 |
.addons-container {
|
49 |
max-height: 150px;
|
50 |
overflow-y: auto;
|
@@ -53,22 +61,27 @@
|
|
53 |
background-color: #f8f9fa;
|
54 |
border-radius: 5px;
|
55 |
}
|
|
|
56 |
.addons-container::-webkit-scrollbar {
|
57 |
width: 6px;
|
58 |
}
|
|
|
59 |
.addons-container::-webkit-scrollbar-thumb {
|
60 |
background-color: #aaa;
|
61 |
border-radius: 3px;
|
62 |
}
|
|
|
63 |
.addons-container::-webkit-scrollbar-track {
|
64 |
background-color: #f1f1f1;
|
65 |
}
|
|
|
66 |
.view-cart-container {
|
67 |
position: fixed;
|
68 |
bottom: 20px;
|
69 |
right: 20px;
|
70 |
z-index: 999;
|
71 |
}
|
|
|
72 |
.view-cart-button {
|
73 |
background-color: #007bff;
|
74 |
color: #fff;
|
@@ -82,10 +95,74 @@
|
|
82 |
align-items: center;
|
83 |
justify-content: center;
|
84 |
}
|
|
|
85 |
.view-cart-button:hover {
|
86 |
background-color: #0056b3;
|
87 |
text-decoration: none;
|
88 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
</style>
|
90 |
</head>
|
91 |
<body>
|
@@ -155,7 +232,7 @@
|
|
155 |
<h6>Add-ons</h6>
|
156 |
<div id="addons-list" class="addons-container">Loading add-ons...</div>
|
157 |
</div>
|
158 |
-
</div>
|
159 |
<div class="modal-footer">
|
160 |
<button type="button" class="btn btn-primary" onclick="addToCartFromModal()">Add to Cart</button>
|
161 |
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
@@ -166,6 +243,17 @@
|
|
166 |
|
167 |
<!-- JavaScript -->
|
168 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
function showItemDetails(name, price, image, description) {
|
170 |
// Set modal content dynamically
|
171 |
document.getElementById('modal-name').innerText = name;
|
@@ -173,16 +261,19 @@
|
|
173 |
document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
|
174 |
document.getElementById('modal-description').innerText = description || 'No description available.';
|
175 |
document.getElementById('addons-list').innerHTML = 'Loading add-ons...';
|
|
|
176 |
// Fetch add-ons dynamically based on item Name
|
177 |
fetch(`/api/addons?item_name=${encodeURIComponent(name)}`)
|
178 |
.then(response => response.json())
|
179 |
.then(data => {
|
180 |
const addonsList = document.getElementById('addons-list');
|
181 |
addonsList.innerHTML = ''; // Clear previous content
|
|
|
182 |
if (!data.success || !data.addons || data.addons.length === 0) {
|
183 |
addonsList.innerHTML = 'No add-ons available.';
|
184 |
return;
|
185 |
}
|
|
|
186 |
// Populate the add-ons list
|
187 |
data.addons.forEach(addon => {
|
188 |
const listItem = document.createElement('div');
|
@@ -199,28 +290,27 @@
|
|
199 |
});
|
200 |
}
|
201 |
function addToCartFromModal() {
|
202 |
-
const itemName = document.getElementById('modal-name').innerText;
|
203 |
-
const itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
204 |
-
const itemImage = document.getElementById('modal-img').src;
|
205 |
const selectedAddOns = Array.from(
|
206 |
document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
|
207 |
-
).map(addon => addon.value);
|
208 |
|
209 |
-
|
|
|
210 |
if (!itemName || !itemPrice) {
|
211 |
alert('Failed to add item to cart. Please try again.');
|
212 |
return;
|
213 |
}
|
214 |
|
215 |
-
// Create the payload to send to the backend
|
216 |
const cartPayload = {
|
217 |
-
itemName: itemName,
|
218 |
itemPrice: itemPrice,
|
219 |
-
itemImage: itemImage,
|
220 |
addons: selectedAddOns
|
221 |
};
|
222 |
|
223 |
-
// Send the payload to the server
|
224 |
fetch('/cart/add', {
|
225 |
method: 'POST',
|
226 |
headers: {
|
@@ -230,9 +320,10 @@
|
|
230 |
})
|
231 |
.then(response => response.json())
|
232 |
.then(data => {
|
|
|
233 |
if (data.success) {
|
234 |
-
|
235 |
-
|
236 |
} else {
|
237 |
console.error('Error adding item to cart:', data.error);
|
238 |
alert(data.error || 'Failed to add item to cart.');
|
@@ -240,13 +331,34 @@
|
|
240 |
})
|
241 |
.catch(err => {
|
242 |
console.error('Error adding item to cart:', err);
|
243 |
-
alert('
|
244 |
});
|
245 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
|
247 |
</script>
|
248 |
|
249 |
<!-- Bootstrap JS -->
|
250 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
</body>
|
252 |
</html>
|
|
|
13 |
margin: 0;
|
14 |
padding: 0;
|
15 |
}
|
16 |
+
|
17 |
.container {
|
18 |
max-width: 900px;
|
19 |
}
|
20 |
+
|
21 |
.menu-card {
|
22 |
max-width: 350px;
|
23 |
border-radius: 15px;
|
|
|
25 |
background-color: #fff;
|
26 |
margin: auto;
|
27 |
}
|
28 |
+
|
29 |
.menu-image {
|
30 |
height: 200px;
|
31 |
width: 100%;
|
32 |
object-fit: cover;
|
33 |
border-radius: 15px 15px 0 0;
|
34 |
}
|
35 |
+
|
36 |
.card-title {
|
37 |
font-size: 1.2rem;
|
38 |
font-weight: bold;
|
39 |
}
|
40 |
+
|
41 |
.card-text {
|
42 |
font-size: 1rem;
|
43 |
color: #6c757d;
|
44 |
}
|
45 |
+
|
46 |
.btn-primary {
|
47 |
font-size: 0.9rem;
|
48 |
border-radius: 20px;
|
49 |
width: 100px;
|
50 |
}
|
51 |
+
|
52 |
.filter-container {
|
53 |
margin-bottom: 15px;
|
54 |
}
|
55 |
+
|
56 |
.addons-container {
|
57 |
max-height: 150px;
|
58 |
overflow-y: auto;
|
|
|
61 |
background-color: #f8f9fa;
|
62 |
border-radius: 5px;
|
63 |
}
|
64 |
+
|
65 |
.addons-container::-webkit-scrollbar {
|
66 |
width: 6px;
|
67 |
}
|
68 |
+
|
69 |
.addons-container::-webkit-scrollbar-thumb {
|
70 |
background-color: #aaa;
|
71 |
border-radius: 3px;
|
72 |
}
|
73 |
+
|
74 |
.addons-container::-webkit-scrollbar-track {
|
75 |
background-color: #f1f1f1;
|
76 |
}
|
77 |
+
|
78 |
.view-cart-container {
|
79 |
position: fixed;
|
80 |
bottom: 20px;
|
81 |
right: 20px;
|
82 |
z-index: 999;
|
83 |
}
|
84 |
+
|
85 |
.view-cart-button {
|
86 |
background-color: #007bff;
|
87 |
color: #fff;
|
|
|
95 |
align-items: center;
|
96 |
justify-content: center;
|
97 |
}
|
98 |
+
|
99 |
.view-cart-button:hover {
|
100 |
background-color: #0056b3;
|
101 |
text-decoration: none;
|
102 |
}
|
103 |
+
|
104 |
+
/* Toast container for messages */
|
105 |
+
.toast-container {
|
106 |
+
position: fixed;
|
107 |
+
top: 10px;
|
108 |
+
right: 10px;
|
109 |
+
z-index: 1055; /* Ensure it appears above other elements */
|
110 |
+
width: auto;
|
111 |
+
max-width: 300px;
|
112 |
+
}
|
113 |
+
|
114 |
+
/* Toast box */
|
115 |
+
.toast {
|
116 |
+
background-color: #28a745; /* Success green background */
|
117 |
+
color: #fff; /* White text */
|
118 |
+
padding: 10px 20px;
|
119 |
+
border-radius: 8px;
|
120 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
121 |
+
font-size: 0.9rem;
|
122 |
+
font-weight: bold;
|
123 |
+
display: flex;
|
124 |
+
align-items: center;
|
125 |
+
justify-content: space-between;
|
126 |
+
}
|
127 |
+
|
128 |
+
/* Toast close button */
|
129 |
+
.toast .btn-close {
|
130 |
+
color: #fff;
|
131 |
+
background: transparent;
|
132 |
+
border: none;
|
133 |
+
font-size: 1.2rem;
|
134 |
+
font-weight: bold;
|
135 |
+
cursor: pointer;
|
136 |
+
}
|
137 |
+
|
138 |
+
.toast .btn-close:hover {
|
139 |
+
color: #ccc; /* Light gray on hover */
|
140 |
+
}
|
141 |
+
|
142 |
+
/* Smooth slide-in and fade-out animations */
|
143 |
+
@keyframes slideIn {
|
144 |
+
from {
|
145 |
+
transform: translateY(-20px);
|
146 |
+
opacity: 0;
|
147 |
+
}
|
148 |
+
to {
|
149 |
+
transform: translateY(0);
|
150 |
+
opacity: 1;
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
@keyframes fadeOut {
|
155 |
+
from {
|
156 |
+
opacity: 1;
|
157 |
+
}
|
158 |
+
to {
|
159 |
+
opacity: 0;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
.toast {
|
164 |
+
animation: slideIn 0.5s ease-out, fadeOut 3s 2s ease-out forwards;
|
165 |
+
}
|
166 |
</style>
|
167 |
</head>
|
168 |
<body>
|
|
|
232 |
<h6>Add-ons</h6>
|
233 |
<div id="addons-list" class="addons-container">Loading add-ons...</div>
|
234 |
</div>
|
235 |
+
</div>
|
236 |
<div class="modal-footer">
|
237 |
<button type="button" class="btn btn-primary" onclick="addToCartFromModal()">Add to Cart</button>
|
238 |
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
|
243 |
|
244 |
<!-- JavaScript -->
|
245 |
<script>
|
246 |
+
|
247 |
+
// Attach event listener to close button
|
248 |
+
document.addEventListener('DOMContentLoaded', function () {
|
249 |
+
document.querySelector('.btn-close').addEventListener('click', function () {
|
250 |
+
const triggerButton = document.querySelector('[data-bs-target="#itemModal"]');
|
251 |
+
if (triggerButton) {
|
252 |
+
triggerButton.focus(); // Return focus to the trigger button
|
253 |
+
}
|
254 |
+
});
|
255 |
+
});
|
256 |
+
|
257 |
function showItemDetails(name, price, image, description) {
|
258 |
// Set modal content dynamically
|
259 |
document.getElementById('modal-name').innerText = name;
|
|
|
261 |
document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
|
262 |
document.getElementById('modal-description').innerText = description || 'No description available.';
|
263 |
document.getElementById('addons-list').innerHTML = 'Loading add-ons...';
|
264 |
+
|
265 |
// Fetch add-ons dynamically based on item Name
|
266 |
fetch(`/api/addons?item_name=${encodeURIComponent(name)}`)
|
267 |
.then(response => response.json())
|
268 |
.then(data => {
|
269 |
const addonsList = document.getElementById('addons-list');
|
270 |
addonsList.innerHTML = ''; // Clear previous content
|
271 |
+
|
272 |
if (!data.success || !data.addons || data.addons.length === 0) {
|
273 |
addonsList.innerHTML = 'No add-ons available.';
|
274 |
return;
|
275 |
}
|
276 |
+
|
277 |
// Populate the add-ons list
|
278 |
data.addons.forEach(addon => {
|
279 |
const listItem = document.createElement('div');
|
|
|
290 |
});
|
291 |
}
|
292 |
function addToCartFromModal() {
|
293 |
+
const itemName = document.getElementById('modal-name').innerText;
|
294 |
+
const itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
295 |
+
const itemImage = document.getElementById('modal-img').src;
|
296 |
const selectedAddOns = Array.from(
|
297 |
document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
|
298 |
+
).map(addon => addon.value);
|
299 |
|
300 |
+
console.log("Add to cart payload:", { itemName, itemPrice, itemImage, selectedAddOns });
|
301 |
+
|
302 |
if (!itemName || !itemPrice) {
|
303 |
alert('Failed to add item to cart. Please try again.');
|
304 |
return;
|
305 |
}
|
306 |
|
|
|
307 |
const cartPayload = {
|
308 |
+
itemName: itemName,
|
309 |
itemPrice: itemPrice,
|
310 |
+
itemImage: itemImage,
|
311 |
addons: selectedAddOns
|
312 |
};
|
313 |
|
|
|
314 |
fetch('/cart/add', {
|
315 |
method: 'POST',
|
316 |
headers: {
|
|
|
320 |
})
|
321 |
.then(response => response.json())
|
322 |
.then(data => {
|
323 |
+
console.log("Server response:", data);
|
324 |
if (data.success) {
|
325 |
+
// Show a toast notification instead of redirecting
|
326 |
+
showToast('Item added to cart successfully!');
|
327 |
} else {
|
328 |
console.error('Error adding item to cart:', data.error);
|
329 |
alert(data.error || 'Failed to add item to cart.');
|
|
|
331 |
})
|
332 |
.catch(err => {
|
333 |
console.error('Error adding item to cart:', err);
|
334 |
+
alert('This item is already there in cart.');
|
335 |
});
|
336 |
+
}
|
337 |
+
|
338 |
+
// Helper function to show toast notification
|
339 |
+
function showToast(message) {
|
340 |
+
const toastEl = document.getElementById('cartToast');
|
341 |
+
const toastBody = document.querySelector('#cartToast .toast-body');
|
342 |
+
toastBody.innerText = message; // Update toast message
|
343 |
+
const toast = new bootstrap.Toast(toastEl);
|
344 |
+
toast.show();
|
345 |
+
}
|
346 |
|
347 |
</script>
|
348 |
|
349 |
<!-- Bootstrap JS -->
|
350 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
351 |
+
|
352 |
+
<div class="toast-container position-fixed top-0 end-0 p-3" style="z-index: 1055;">
|
353 |
+
<div id="cartToast" class="toast align-items-center text-bg-success" role="alert" aria-live="assertive" aria-atomic="true">
|
354 |
+
<div class="d-flex">
|
355 |
+
<div class="toast-body">
|
356 |
+
Item added to cart successfully!
|
357 |
+
</div>
|
358 |
+
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
359 |
+
</div>
|
360 |
+
</div>
|
361 |
+
</div>
|
362 |
+
|
363 |
</body>
|
364 |
</html>
|