Spaces:
Sleeping
Sleeping
Update templates/menu.html
Browse files- templates/menu.html +83 -21
templates/menu.html
CHANGED
|
@@ -396,6 +396,12 @@
|
|
| 396 |
font-weight: bold;
|
| 397 |
line-height: 30px;
|
| 398 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
/* Mobile View Adjustments */
|
| 400 |
@media (max-width: 576px) {
|
| 401 |
.fixed-top-bar {
|
|
@@ -522,6 +528,13 @@
|
|
| 522 |
<button class="btn btn-outline-secondary decrease-btn" onclick="decreaseQuantity(this)">-</button>
|
| 523 |
<span class="quantity-display">1</span>
|
| 524 |
<button class="btn btn-outline-secondary increase-btn" onclick="increaseQuantity(this)">+</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
</div>
|
| 526 |
{% else %}
|
| 527 |
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#itemModal"
|
|
@@ -1113,7 +1126,12 @@
|
|
| 1113 |
},
|
| 1114 |
body: JSON.stringify(cartPayload)
|
| 1115 |
})
|
| 1116 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1117 |
.then(data => {
|
| 1118 |
if (data.success) {
|
| 1119 |
alert('Item added to cart successfully!');
|
|
@@ -1122,12 +1140,13 @@
|
|
| 1122 |
const modalInstance = bootstrap.Modal.getInstance(modal);
|
| 1123 |
modalInstance.hide();
|
| 1124 |
} else {
|
|
|
|
| 1125 |
alert(data.error || 'Failed to add item to cart.');
|
| 1126 |
}
|
| 1127 |
})
|
| 1128 |
.catch(err => {
|
| 1129 |
console.error('Error adding item to cart:', err);
|
| 1130 |
-
alert('An error occurred while adding the item to the cart
|
| 1131 |
});
|
| 1132 |
}
|
| 1133 |
|
|
@@ -1166,13 +1185,19 @@
|
|
| 1166 |
},
|
| 1167 |
body: JSON.stringify(cartPayload)
|
| 1168 |
})
|
| 1169 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1170 |
.then(data => {
|
| 1171 |
if (data.success) {
|
| 1172 |
alert('Item added to cart successfully!');
|
| 1173 |
updateCartUI(data.cart);
|
| 1174 |
quantityDisplay.innerText = 1; // Set initial quantity
|
| 1175 |
} else {
|
|
|
|
| 1176 |
alert(data.error || 'Failed to add item to cart.');
|
| 1177 |
// Revert UI if addition fails
|
| 1178 |
addButton.style.display = 'block';
|
|
@@ -1181,7 +1206,7 @@
|
|
| 1181 |
})
|
| 1182 |
.catch(err => {
|
| 1183 |
console.error('Error adding item to cart:', err);
|
| 1184 |
-
alert('An error occurred while adding the item to the cart
|
| 1185 |
// Revert UI if addition fails
|
| 1186 |
addButton.style.display = 'block';
|
| 1187 |
quantitySelector.style.display = 'none';
|
|
@@ -1191,10 +1216,13 @@
|
|
| 1191 |
function increaseQuantity(button) {
|
| 1192 |
const buttonContainer = button.closest('.button-container');
|
| 1193 |
const quantityDisplay = buttonContainer.querySelector('.quantity-display');
|
| 1194 |
-
|
|
|
|
|
|
|
| 1195 |
|
| 1196 |
-
quantity
|
| 1197 |
-
|
|
|
|
| 1198 |
|
| 1199 |
const itemName = buttonContainer.getAttribute('data-item-name');
|
| 1200 |
const itemPrice = parseFloat(buttonContainer.getAttribute('data-item-price'));
|
|
@@ -1210,9 +1238,12 @@
|
|
| 1210 |
category: category,
|
| 1211 |
addons: [],
|
| 1212 |
instructions: '',
|
| 1213 |
-
quantity:
|
| 1214 |
};
|
| 1215 |
|
|
|
|
|
|
|
|
|
|
| 1216 |
fetch('/cart/add', {
|
| 1217 |
method: 'POST',
|
| 1218 |
headers: {
|
|
@@ -1220,21 +1251,33 @@
|
|
| 1220 |
},
|
| 1221 |
body: JSON.stringify(cartPayload)
|
| 1222 |
})
|
| 1223 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1224 |
.then(data => {
|
| 1225 |
if (data.success) {
|
|
|
|
| 1226 |
updateCartUI(data.cart);
|
| 1227 |
} else {
|
|
|
|
| 1228 |
alert(data.error || 'Failed to add item to cart.');
|
| 1229 |
-
|
| 1230 |
-
|
|
|
|
| 1231 |
}
|
| 1232 |
})
|
| 1233 |
.catch(err => {
|
| 1234 |
console.error('Error adding item to cart:', err);
|
| 1235 |
-
alert('An error occurred while adding the item to the cart
|
| 1236 |
-
|
| 1237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1238 |
});
|
| 1239 |
}
|
| 1240 |
|
|
@@ -1254,7 +1297,12 @@
|
|
| 1254 |
'Content-Type': 'application/json',
|
| 1255 |
}
|
| 1256 |
})
|
| 1257 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1258 |
.then(data => {
|
| 1259 |
if (data.success) {
|
| 1260 |
updateCartUI(data.cart);
|
|
@@ -1262,12 +1310,13 @@
|
|
| 1262 |
addButton.style.display = 'block';
|
| 1263 |
quantitySelector.style.display = 'none';
|
| 1264 |
} else {
|
|
|
|
| 1265 |
alert(data.error || 'Failed to remove item from cart.');
|
| 1266 |
}
|
| 1267 |
})
|
| 1268 |
.catch(err => {
|
| 1269 |
console.error('Error removing item from cart:', err);
|
| 1270 |
-
alert('An error occurred while removing the item from the cart
|
| 1271 |
});
|
| 1272 |
} else {
|
| 1273 |
quantity--;
|
|
@@ -1280,20 +1329,26 @@
|
|
| 1280 |
'Content-Type': 'application/json',
|
| 1281 |
}
|
| 1282 |
})
|
| 1283 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1284 |
.then(data => {
|
| 1285 |
if (data.success) {
|
| 1286 |
updateCartUI(data.cart);
|
| 1287 |
} else {
|
|
|
|
| 1288 |
alert(data.error || 'Failed to remove item from cart.');
|
| 1289 |
-
quantity++;
|
| 1290 |
quantityDisplay.innerText = quantity;
|
| 1291 |
}
|
| 1292 |
})
|
| 1293 |
.catch(err => {
|
| 1294 |
console.error('Error removing item from cart:', err);
|
| 1295 |
-
alert('An error occurred while removing the item from the cart
|
| 1296 |
-
quantity++;
|
| 1297 |
quantityDisplay.innerText = quantity;
|
| 1298 |
});
|
| 1299 |
}
|
|
@@ -1369,10 +1424,17 @@
|
|
| 1369 |
|
| 1370 |
// Fetch initial cart state to update UI
|
| 1371 |
fetch('/cart/get')
|
| 1372 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1373 |
.then(data => {
|
| 1374 |
if (data.success) {
|
| 1375 |
updateCartUI(data.cart);
|
|
|
|
|
|
|
| 1376 |
}
|
| 1377 |
})
|
| 1378 |
.catch(err => console.error('Error fetching cart:', err));
|
|
|
|
| 396 |
font-weight: bold;
|
| 397 |
line-height: 30px;
|
| 398 |
}
|
| 399 |
+
.quantity-selector .quantity-to-add {
|
| 400 |
+
width: 50px;
|
| 401 |
+
height: 30px;
|
| 402 |
+
font-size: 14px;
|
| 403 |
+
padding: 0 5px;
|
| 404 |
+
}
|
| 405 |
/* Mobile View Adjustments */
|
| 406 |
@media (max-width: 576px) {
|
| 407 |
.fixed-top-bar {
|
|
|
|
| 528 |
<button class="btn btn-outline-secondary decrease-btn" onclick="decreaseQuantity(this)">-</button>
|
| 529 |
<span class="quantity-display">1</span>
|
| 530 |
<button class="btn btn-outline-secondary increase-btn" onclick="increaseQuantity(this)">+</button>
|
| 531 |
+
<select class="quantity-to-add">
|
| 532 |
+
<option value="1">1</option>
|
| 533 |
+
<option value="3">3</option>
|
| 534 |
+
<option value="5">5</option>
|
| 535 |
+
<option value="10">10</option>
|
| 536 |
+
<option value="20">20</option>
|
| 537 |
+
</select>
|
| 538 |
</div>
|
| 539 |
{% else %}
|
| 540 |
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#itemModal"
|
|
|
|
| 1126 |
},
|
| 1127 |
body: JSON.stringify(cartPayload)
|
| 1128 |
})
|
| 1129 |
+
.then(response => {
|
| 1130 |
+
if (!response.ok) {
|
| 1131 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 1132 |
+
}
|
| 1133 |
+
return response.json();
|
| 1134 |
+
})
|
| 1135 |
.then(data => {
|
| 1136 |
if (data.success) {
|
| 1137 |
alert('Item added to cart successfully!');
|
|
|
|
| 1140 |
const modalInstance = bootstrap.Modal.getInstance(modal);
|
| 1141 |
modalInstance.hide();
|
| 1142 |
} else {
|
| 1143 |
+
console.error('Failed to add item to cart:', data.error);
|
| 1144 |
alert(data.error || 'Failed to add item to cart.');
|
| 1145 |
}
|
| 1146 |
})
|
| 1147 |
.catch(err => {
|
| 1148 |
console.error('Error adding item to cart:', err);
|
| 1149 |
+
alert('An error occurred while adding the item to the cart: ' + err.message);
|
| 1150 |
});
|
| 1151 |
}
|
| 1152 |
|
|
|
|
| 1185 |
},
|
| 1186 |
body: JSON.stringify(cartPayload)
|
| 1187 |
})
|
| 1188 |
+
.then(response => {
|
| 1189 |
+
if (!response.ok) {
|
| 1190 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 1191 |
+
}
|
| 1192 |
+
return response.json();
|
| 1193 |
+
})
|
| 1194 |
.then(data => {
|
| 1195 |
if (data.success) {
|
| 1196 |
alert('Item added to cart successfully!');
|
| 1197 |
updateCartUI(data.cart);
|
| 1198 |
quantityDisplay.innerText = 1; // Set initial quantity
|
| 1199 |
} else {
|
| 1200 |
+
console.error('Failed to add item to cart:', data.error);
|
| 1201 |
alert(data.error || 'Failed to add item to cart.');
|
| 1202 |
// Revert UI if addition fails
|
| 1203 |
addButton.style.display = 'block';
|
|
|
|
| 1206 |
})
|
| 1207 |
.catch(err => {
|
| 1208 |
console.error('Error adding item to cart:', err);
|
| 1209 |
+
alert('An error occurred while adding the item to the cart: ' + err.message);
|
| 1210 |
// Revert UI if addition fails
|
| 1211 |
addButton.style.display = 'block';
|
| 1212 |
quantitySelector.style.display = 'none';
|
|
|
|
| 1216 |
function increaseQuantity(button) {
|
| 1217 |
const buttonContainer = button.closest('.button-container');
|
| 1218 |
const quantityDisplay = buttonContainer.querySelector('.quantity-display');
|
| 1219 |
+
const quantityToAddSelect = buttonContainer.querySelector('.quantity-to-add');
|
| 1220 |
+
const quantityToAdd = parseInt(quantityToAddSelect.value);
|
| 1221 |
+
let currentQuantity = parseInt(quantityDisplay.innerText);
|
| 1222 |
|
| 1223 |
+
// Update the displayed quantity
|
| 1224 |
+
currentQuantity += quantityToAdd;
|
| 1225 |
+
quantityDisplay.innerText = currentQuantity;
|
| 1226 |
|
| 1227 |
const itemName = buttonContainer.getAttribute('data-item-name');
|
| 1228 |
const itemPrice = parseFloat(buttonContainer.getAttribute('data-item-price'));
|
|
|
|
| 1238 |
category: category,
|
| 1239 |
addons: [],
|
| 1240 |
instructions: '',
|
| 1241 |
+
quantity: quantityToAdd // Add the selected quantity
|
| 1242 |
};
|
| 1243 |
|
| 1244 |
+
// Disable the button to prevent multiple clicks
|
| 1245 |
+
button.disabled = true;
|
| 1246 |
+
|
| 1247 |
fetch('/cart/add', {
|
| 1248 |
method: 'POST',
|
| 1249 |
headers: {
|
|
|
|
| 1251 |
},
|
| 1252 |
body: JSON.stringify(cartPayload)
|
| 1253 |
})
|
| 1254 |
+
.then(response => {
|
| 1255 |
+
if (!response.ok) {
|
| 1256 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 1257 |
+
}
|
| 1258 |
+
return response.json();
|
| 1259 |
+
})
|
| 1260 |
.then(data => {
|
| 1261 |
if (data.success) {
|
| 1262 |
+
alert(`Added ${quantityToAdd} item(s) to cart successfully!`);
|
| 1263 |
updateCartUI(data.cart);
|
| 1264 |
} else {
|
| 1265 |
+
console.error('Failed to add item to cart:', data.error);
|
| 1266 |
alert(data.error || 'Failed to add item to cart.');
|
| 1267 |
+
// Revert quantity if addition fails
|
| 1268 |
+
currentQuantity -= quantityToAdd;
|
| 1269 |
+
quantityDisplay.innerText = currentQuantity;
|
| 1270 |
}
|
| 1271 |
})
|
| 1272 |
.catch(err => {
|
| 1273 |
console.error('Error adding item to cart:', err);
|
| 1274 |
+
alert('An error occurred while adding the item to the cart: ' + err.message);
|
| 1275 |
+
// Revert quantity if addition fails
|
| 1276 |
+
currentQuantity -= quantityToAdd;
|
| 1277 |
+
quantityDisplay.innerText = currentQuantity;
|
| 1278 |
+
})
|
| 1279 |
+
.finally(() => {
|
| 1280 |
+
button.disabled = false; // Re-enable the button
|
| 1281 |
});
|
| 1282 |
}
|
| 1283 |
|
|
|
|
| 1297 |
'Content-Type': 'application/json',
|
| 1298 |
}
|
| 1299 |
})
|
| 1300 |
+
.then(response => {
|
| 1301 |
+
if (!response.ok) {
|
| 1302 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 1303 |
+
}
|
| 1304 |
+
return response.json();
|
| 1305 |
+
})
|
| 1306 |
.then(data => {
|
| 1307 |
if (data.success) {
|
| 1308 |
updateCartUI(data.cart);
|
|
|
|
| 1310 |
addButton.style.display = 'block';
|
| 1311 |
quantitySelector.style.display = 'none';
|
| 1312 |
} else {
|
| 1313 |
+
console.error('Failed to remove item from cart:', data.error);
|
| 1314 |
alert(data.error || 'Failed to remove item from cart.');
|
| 1315 |
}
|
| 1316 |
})
|
| 1317 |
.catch(err => {
|
| 1318 |
console.error('Error removing item from cart:', err);
|
| 1319 |
+
alert('An error occurred while removing the item from the cart: ' + err.message);
|
| 1320 |
});
|
| 1321 |
} else {
|
| 1322 |
quantity--;
|
|
|
|
| 1329 |
'Content-Type': 'application/json',
|
| 1330 |
}
|
| 1331 |
})
|
| 1332 |
+
.then(response => {
|
| 1333 |
+
if (!response.ok) {
|
| 1334 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 1335 |
+
}
|
| 1336 |
+
return response.json();
|
| 1337 |
+
})
|
| 1338 |
.then(data => {
|
| 1339 |
if (data.success) {
|
| 1340 |
updateCartUI(data.cart);
|
| 1341 |
} else {
|
| 1342 |
+
console.error('Failed to remove item from cart:', data.error);
|
| 1343 |
alert(data.error || 'Failed to remove item from cart.');
|
| 1344 |
+
quantity++;
|
| 1345 |
quantityDisplay.innerText = quantity;
|
| 1346 |
}
|
| 1347 |
})
|
| 1348 |
.catch(err => {
|
| 1349 |
console.error('Error removing item from cart:', err);
|
| 1350 |
+
alert('An error occurred while removing the item from the cart: ' + err.message);
|
| 1351 |
+
quantity++;
|
| 1352 |
quantityDisplay.innerText = quantity;
|
| 1353 |
});
|
| 1354 |
}
|
|
|
|
| 1424 |
|
| 1425 |
// Fetch initial cart state to update UI
|
| 1426 |
fetch('/cart/get')
|
| 1427 |
+
.then(response => {
|
| 1428 |
+
if (!response.ok) {
|
| 1429 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 1430 |
+
}
|
| 1431 |
+
return response.json();
|
| 1432 |
+
})
|
| 1433 |
.then(data => {
|
| 1434 |
if (data.success) {
|
| 1435 |
updateCartUI(data.cart);
|
| 1436 |
+
} else {
|
| 1437 |
+
console.error('Failed to fetch cart:', data.error);
|
| 1438 |
}
|
| 1439 |
})
|
| 1440 |
.catch(err => console.error('Error fetching cart:', err));
|