Spaces:
Sleeping
Sleeping
Update templates/menu.html
Browse files- templates/menu.html +310 -642
templates/menu.html
CHANGED
|
@@ -4,10 +4,8 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Menu</title>
|
| 7 |
-
<!-- Bootstrap CSS -->
|
| 8 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 9 |
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
|
| 10 |
-
<!-- Preload Critical Resources -->
|
| 11 |
<link rel="preload" href="/static/placeholder.mp4" as="video">
|
| 12 |
{% for section, items in ordered_menu.items() %}
|
| 13 |
{% for item in items[:1] %}
|
|
@@ -15,8 +13,66 @@
|
|
| 15 |
{% endfor %}
|
| 16 |
{% endfor %}
|
| 17 |
<style>
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
</style>
|
| 21 |
</head>
|
| 22 |
<body>
|
|
@@ -28,7 +84,7 @@
|
|
| 28 |
<div class="dropdown-menu">
|
| 29 |
<a href="{{ url_for('user_details.customer_details') }}" class="dropdown-item">View Profile</a>
|
| 30 |
<a href="{{ url_for('orderhistory.order_history') }}" class="dropdown-item">Order History</a>
|
| 31 |
-
<a href="{{ url_for('combined_summary.combined_summary') }}" class="dropdown-item">
|
| 32 |
<a href="{{ url_for('logout') }}" class="dropdown-item">Logout</a>
|
| 33 |
</div>
|
| 34 |
</div>
|
|
@@ -42,7 +98,6 @@
|
|
| 42 |
<form method="get" action="/menu" class="text-center mb-4" id="filter-form">
|
| 43 |
<label class="form-label fw-bold">Filters:</label>
|
| 44 |
<div class="toggle-container">
|
| 45 |
-
<!-- Veg Only Toggle -->
|
| 46 |
<input type="checkbox" id="veg-toggle" name="veg"
|
| 47 |
{% if selected_category == "Veg" %}checked{% endif %}
|
| 48 |
class="custom-toggle" onchange="handleToggle('veg')"
|
|
@@ -50,7 +105,6 @@
|
|
| 50 |
<label for="veg-toggle">Veg</label>
|
| 51 |
</div>
|
| 52 |
<div class="toggle-container">
|
| 53 |
-
<!-- Customized Dish Toggle -->
|
| 54 |
<input type="radio" id="category-CustomizedDish" name="category" value="Customized Dish"
|
| 55 |
{% if selected_category == "Customized Dish" %}checked{% endif %}
|
| 56 |
class="custom-toggle" onchange="handleToggle('custom')"
|
|
@@ -64,11 +118,9 @@
|
|
| 64 |
<div id="custom-dish-form" class="mt-4">
|
| 65 |
<div class="chat-container">
|
| 66 |
<div class="chat-header">🍳 Chef Bot</div>
|
| 67 |
-
<div class="chat-messages" id="chatMessages">
|
| 68 |
-
<!-- Initial message will be set by JavaScript based on session -->
|
| 69 |
-
</div>
|
| 70 |
<div class="chat-input">
|
| 71 |
-
<input type="text" id="userInput" placeholder="Type your
|
| 72 |
<button onclick="sendMessage()">Send</button>
|
| 73 |
</div>
|
| 74 |
</div>
|
|
@@ -122,8 +174,8 @@
|
|
| 122 |
onclick="showItemDetails('{{ item.Name | default('Unnamed Item') }}', '{{ item.Price__c | default('0.00') }}', '{{ item.Image2__c | default(item.Image1__c) }}', '{{ item.Description__c | default('No description') }}', '{{ item.Section__c | default(section) }}', '{{ selected_category }}')">
|
| 123 |
ADD
|
| 124 |
</button>
|
| 125 |
-
{% if item.Section__c != 'Apetizer' and item.Section__c != 'Customized
|
| 126 |
-
<span class="customisable-text">
|
| 127 |
{% endif %}
|
| 128 |
{% endif %}
|
| 129 |
</div>
|
|
@@ -233,31 +285,7 @@
|
|
| 233 |
let isProcessingRequest = false;
|
| 234 |
let currentSoftDrinkButton = null;
|
| 235 |
let baseItemPrice = 0;
|
| 236 |
-
|
| 237 |
-
{% for section, items in ordered_menu.items() %}
|
| 238 |
-
{% for item in items %}
|
| 239 |
-
{
|
| 240 |
-
name: "{{ item.Name | default('Unnamed Item') }}",
|
| 241 |
-
section: "{{ item.Section__c | default(section) }}"
|
| 242 |
-
},
|
| 243 |
-
{% endfor %}
|
| 244 |
-
{% endfor %}
|
| 245 |
-
];
|
| 246 |
-
const ingredientsList = [
|
| 247 |
-
"Basmati Rice", "Bell Pepper", "Biryani Masala", "Butter", "Capsicum", "Cauliflower",
|
| 248 |
-
"Chickpea Flour (Besan)", "Chickpea Flour (for batter)", "Chickpeas (Channa)", "Chili Powder",
|
| 249 |
-
"Chili Sauce", "Coconut Milk", "Coriander Powder", "Cornflour", "Cream", "Cumin Powder",
|
| 250 |
-
"Cumin Seeds", "Curd (Yogurt)", "Curry Leaves", "Fish (e.g., King Fish or Salmon)",
|
| 251 |
-
"Fresh Coriander Leaves", "Garam Masala", "Garlic", "Ghee (Clarified Butter)", "Ginger",
|
| 252 |
-
"Ginger-Garlic Paste", "Goat Meat (Mutton)", "Green Chilies", "Honey",
|
| 253 |
-
"Kasuri Methi (dried fenugreek leaves)", "Lemon Juice", "Mango Puree", "Mint Leaves",
|
| 254 |
-
"Mixed Vegetables (Carrot, Peas, Potato, Cauliflower)", "Mixed Vegetables (Carrot, Peas, Potato)",
|
| 255 |
-
"Mustard Seeds", "Mutton (Goat Meat)", "Oil", "Oil (for frying)", "Onion",
|
| 256 |
-
"Paneer (Indian Cottage Cheese)", "Peas", "Potatoes", "Prawns", "Red Chili Powder",
|
| 257 |
-
"Rice Flour", "Saffron", "Salt", "Soy Sauce", "Spring Onion", "Tamarind (for sourness)",
|
| 258 |
-
"Tomato Ketchup", "Tomatoes", "Turmeric Powder", "Vinegar", "Water", "Wheat Flour (for dough)",
|
| 259 |
-
"Whole Wheat Flour", "Yogurt (Curd)"
|
| 260 |
-
];
|
| 261 |
function addToCartLocalStorage(payload) {
|
| 262 |
let cart = JSON.parse(localStorage.getItem('cart')) || [];
|
| 263 |
const existingItem = cart.find(item =>
|
|
@@ -273,33 +301,11 @@
|
|
| 273 |
localStorage.setItem('cart', JSON.stringify(cart));
|
| 274 |
return cart;
|
| 275 |
}
|
| 276 |
-
|
| 277 |
-
let cart = JSON.parse(localStorage.getItem('cart')) || [];
|
| 278 |
-
const itemIndex = cart.findIndex(item =>
|
| 279 |
-
item.itemName === itemName &&
|
| 280 |
-
item.instructions === instructions &&
|
| 281 |
-
JSON.stringify(item.addons) === JSON.stringify(addons)
|
| 282 |
-
);
|
| 283 |
-
if (itemIndex !== -1) {
|
| 284 |
-
if (quantityToRemove >= cart[itemIndex].quantity) {
|
| 285 |
-
cart.splice(itemIndex, 1);
|
| 286 |
-
} else {
|
| 287 |
-
cart[itemIndex].quantity -= quantityToRemove;
|
| 288 |
-
}
|
| 289 |
-
}
|
| 290 |
-
localStorage.setItem('cart', JSON.stringify(cart));
|
| 291 |
-
return cart;
|
| 292 |
-
}
|
| 293 |
function getCartLocalStorage() {
|
| 294 |
return JSON.parse(localStorage.getItem('cart')) || [];
|
| 295 |
}
|
| 296 |
-
|
| 297 |
-
let timeout;
|
| 298 |
-
return function (...args) {
|
| 299 |
-
clearTimeout(timeout);
|
| 300 |
-
timeout = setTimeout(() => func.apply(this, args), wait);
|
| 301 |
-
};
|
| 302 |
-
}
|
| 303 |
function updateModalPrice() {
|
| 304 |
const selectedAddOns = Array.from(
|
| 305 |
document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
|
|
@@ -308,12 +314,14 @@
|
|
| 308 |
const totalPrice = baseItemPrice + totalAddOnPrice;
|
| 309 |
document.getElementById('modal-price').innerText = `$${totalPrice.toFixed(2)}`;
|
| 310 |
}
|
|
|
|
| 311 |
function updateSoftDrinkQuantity(delta) {
|
| 312 |
const quantityInput = document.getElementById('soft-drink-quantity');
|
| 313 |
let currentQuantity = parseInt(quantityInput.value) || 1;
|
| 314 |
currentQuantity = Math.max(1, currentQuantity + delta);
|
| 315 |
quantityInput.value = currentQuantity;
|
| 316 |
}
|
|
|
|
| 317 |
function showSoftDrinkModal(button) {
|
| 318 |
currentSoftDrinkButton = button;
|
| 319 |
const buttonContainer = button.closest('.button-container');
|
|
@@ -322,13 +330,14 @@
|
|
| 322 |
const itemImage = buttonContainer.getAttribute('data-item-image');
|
| 323 |
|
| 324 |
document.getElementById('soft-drink-name').textContent = itemName;
|
| 325 |
-
document.getElementById('soft-drink-price').textContent =
|
| 326 |
document.getElementById('soft-drink-quantity').value = '1';
|
| 327 |
document.getElementById('soft-drink-image').src = itemImage || '/static/placeholder.jpg';
|
| 328 |
|
| 329 |
const modal = new bootstrap.Modal(document.getElementById('softDrinkModal'));
|
| 330 |
modal.show();
|
| 331 |
}
|
|
|
|
| 332 |
function addSoftDrinkToCart() {
|
| 333 |
if (!currentSoftDrinkButton) return;
|
| 334 |
|
|
@@ -354,9 +363,7 @@
|
|
| 354 |
|
| 355 |
fetch('/cart/add', {
|
| 356 |
method: 'POST',
|
| 357 |
-
headers: {
|
| 358 |
-
'Content-Type': 'application/json',
|
| 359 |
-
},
|
| 360 |
body: JSON.stringify(cartPayload)
|
| 361 |
})
|
| 362 |
.then(response => response.json())
|
|
@@ -381,6 +388,7 @@
|
|
| 381 |
modal.hide();
|
| 382 |
});
|
| 383 |
}
|
|
|
|
| 384 |
function updateCartUI(cart) {
|
| 385 |
if (!Array.isArray(cart)) {
|
| 386 |
console.error('Invalid cart data:', cart);
|
|
@@ -398,7 +406,7 @@
|
|
| 398 |
}
|
| 399 |
|
| 400 |
window.most_common_addons = {{ most_common_addons | tojson }};
|
| 401 |
-
|
| 402 |
function showItemDetails(name, price, image, description, section, selectedCategory) {
|
| 403 |
document.getElementById('modal-name').innerText = name;
|
| 404 |
baseItemPrice = parseFloat(price) || 0;
|
|
@@ -407,18 +415,16 @@
|
|
| 407 |
modalImg.src = image || '/static/placeholder.jpg';
|
| 408 |
document.getElementById('modal-description').innerText = description || 'No description available.';
|
| 409 |
document.getElementById('addons-list').innerHTML = '';
|
| 410 |
-
document.getElementById('addons-list').classList.add('addon-loading');
|
| 411 |
document.getElementById('modal-instructions').value = '';
|
| 412 |
const modalSectionEl = document.getElementById('modal-section');
|
| 413 |
modalSectionEl.setAttribute('data-section', section);
|
| 414 |
modalSectionEl.setAttribute('data-category', selectedCategory);
|
| 415 |
document.getElementById('quantityInput').value = 1;
|
|
|
|
| 416 |
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
| 417 |
.then(response => response.json())
|
| 418 |
.then(data => {
|
| 419 |
const addonsList = document.getElementById('addons-list');
|
| 420 |
-
addonsList.classList.remove('addon-loading');
|
| 421 |
-
addonsList.innerHTML = '';
|
| 422 |
if (!data.success || !data.addons || data.addons.length === 0) {
|
| 423 |
addonsList.innerHTML = '<p>No customization options available.</p>';
|
| 424 |
return;
|
|
@@ -448,74 +454,20 @@
|
|
| 448 |
sectionDiv.appendChild(optionsContainer);
|
| 449 |
addonsList.appendChild(sectionDiv);
|
| 450 |
});
|
| 451 |
-
const addonSections = addonsList.querySelectorAll('.addon-section');
|
| 452 |
-
addonSections.forEach(section => {
|
| 453 |
-
const title = section.querySelector('h6');
|
| 454 |
-
const options = section.querySelector('.addon-options');
|
| 455 |
-
title.addEventListener('click', () => {
|
| 456 |
-
section.classList.toggle('collapsed');
|
| 457 |
-
options.classList.toggle('collapsed');
|
| 458 |
-
});
|
| 459 |
-
});
|
| 460 |
document.querySelectorAll('.addon-option').forEach(checkbox => {
|
| 461 |
checkbox.addEventListener('change', updateModalPrice);
|
| 462 |
});
|
| 463 |
-
document.querySelectorAll('.addon-option').forEach(checkbox => {
|
| 464 |
-
checkbox.addEventListener('change', function () {
|
| 465 |
-
const groupName = this.getAttribute('data-group');
|
| 466 |
-
const isMultiSelectGroup = ["Extra Toppings", "Choose Raita/Sides", "Select Dip/Sauce", "Extra Add-ons", "Make it a Combo", "Beverages", "Sauces"].includes(groupName);
|
| 467 |
-
if (!isMultiSelectGroup && this.checked) {
|
| 468 |
-
document.querySelectorAll(`.addon-option[data-group="${groupName}"]`).forEach(otherCheckbox => {
|
| 469 |
-
if (otherCheckbox !== this) {
|
| 470 |
-
otherCheckbox.checked = false;
|
| 471 |
-
}
|
| 472 |
-
});
|
| 473 |
-
}
|
| 474 |
-
});
|
| 475 |
-
});
|
| 476 |
-
if (window.most_common_addons && window.most_common_addons.length > 0) {
|
| 477 |
-
const checkboxes = document.querySelectorAll('.addon-option');
|
| 478 |
-
const categorySelection = {
|
| 479 |
-
"Select Spice Level": null,
|
| 480 |
-
"Choose Spice Level": null,
|
| 481 |
-
"Raita/Sides": [],
|
| 482 |
-
};
|
| 483 |
-
for (let spice of window.most_common_addons) {
|
| 484 |
-
const isSpiceLevel = ["Mild", "Medium", "Spicy", "Extra Spicy"].includes(spice);
|
| 485 |
-
if (isSpiceLevel) {
|
| 486 |
-
checkboxes.forEach(checkbox => {
|
| 487 |
-
const checkboxName = checkbox.getAttribute('data-name').trim();
|
| 488 |
-
const checkboxGroup = checkbox.getAttribute('data-group');
|
| 489 |
-
if ((checkboxGroup === "Select Spice Level" || checkboxGroup === "Choose Spice Level") &&
|
| 490 |
-
checkboxName === spice && categorySelection[checkboxGroup] === null) {
|
| 491 |
-
console.log(`Pre-selecting highest-count spice level: ${checkboxName}`);
|
| 492 |
-
checkbox.checked = true;
|
| 493 |
-
categorySelection[checkboxGroup] = checkboxName;
|
| 494 |
-
}
|
| 495 |
-
});
|
| 496 |
-
if (categorySelection["Select Spice Level"] || categorySelection["Choose Spice Level"]) break;
|
| 497 |
-
}
|
| 498 |
-
}
|
| 499 |
-
checkboxes.forEach(checkbox => {
|
| 500 |
-
const checkboxName = checkbox.getAttribute('data-name').trim();
|
| 501 |
-
const checkboxGroup = checkbox.getAttribute('data-group');
|
| 502 |
-
if (checkboxGroup === "Raita/Sides" && window.most_common_addons.includes(checkboxName)) {
|
| 503 |
-
console.log(`Pre-selecting add-on: ${checkboxName}`);
|
| 504 |
-
checkbox.checked = true;
|
| 505 |
-
categorySelection["Raita/Sides"].push(checkboxName);
|
| 506 |
-
}
|
| 507 |
-
});
|
| 508 |
-
}
|
| 509 |
})
|
| 510 |
.catch(err => {
|
| 511 |
console.error('Error fetching add-ons:', err);
|
| 512 |
-
document.getElementById('addons-list').classList.remove('addon-loading');
|
| 513 |
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
| 514 |
});
|
| 515 |
}
|
|
|
|
| 516 |
function addToCartFromModal() {
|
| 517 |
if (isProcessingRequest) return;
|
| 518 |
isProcessingRequest = true;
|
|
|
|
| 519 |
const modalSectionEl = document.getElementById('modal-section');
|
| 520 |
const section = modalSectionEl.getAttribute('data-section');
|
| 521 |
const selectedCategory = modalSectionEl.getAttribute('data-category');
|
|
@@ -530,12 +482,7 @@
|
|
| 530 |
name: addon.getAttribute('data-name'),
|
| 531 |
price: parseFloat(addon.getAttribute('data-price')) || 0
|
| 532 |
}));
|
| 533 |
-
|
| 534 |
-
console.error('Invalid cart item data:', { itemName, itemPrice, section, itemImage, quantity });
|
| 535 |
-
alert('Invalid item data. Please try again.');
|
| 536 |
-
isProcessingRequest = false;
|
| 537 |
-
return;
|
| 538 |
-
}
|
| 539 |
const cartPayload = {
|
| 540 |
itemName: itemName,
|
| 541 |
itemPrice: itemPrice,
|
|
@@ -546,11 +493,10 @@
|
|
| 546 |
instructions: instructions,
|
| 547 |
quantity: quantity
|
| 548 |
};
|
|
|
|
| 549 |
fetch('/cart/add', {
|
| 550 |
method: 'POST',
|
| 551 |
-
headers: {
|
| 552 |
-
'Content-Type': 'application/json',
|
| 553 |
-
},
|
| 554 |
body: JSON.stringify(cartPayload)
|
| 555 |
})
|
| 556 |
.then(response => response.json())
|
|
@@ -578,6 +524,7 @@
|
|
| 578 |
isProcessingRequest = false;
|
| 579 |
});
|
| 580 |
}
|
|
|
|
| 581 |
function handleToggle(source) {
|
| 582 |
const form = document.getElementById("filter-form");
|
| 583 |
const veg = document.getElementById("veg-toggle");
|
|
@@ -591,9 +538,6 @@
|
|
| 591 |
veg.checked = false;
|
| 592 |
}
|
| 593 |
}
|
| 594 |
-
if (!custom.checked && !veg.checked) {
|
| 595 |
-
custom.checked = false;
|
| 596 |
-
}
|
| 597 |
form.submit();
|
| 598 |
}
|
| 599 |
|
|
@@ -609,129 +553,14 @@
|
|
| 609 |
dropdownMenu.style.display = 'none';
|
| 610 |
}
|
| 611 |
});
|
| 612 |
-
|
| 613 |
-
dropdownItems.forEach(item => {
|
| 614 |
-
item.addEventListener('click', function () {
|
| 615 |
-
dropdownMenu.style.display = 'none';
|
| 616 |
-
});
|
| 617 |
-
});
|
| 618 |
const searchBar = document.getElementById('searchBar');
|
| 619 |
searchBar.addEventListener('click', function () {
|
| 620 |
window.location.href = '/search';
|
| 621 |
});
|
| 622 |
-
|
| 623 |
-
if (selectedItem) {
|
| 624 |
-
try {
|
| 625 |
-
const { name, section } = JSON.parse(selectedItem);
|
| 626 |
-
const menuCards = document.querySelectorAll('.menu-card');
|
| 627 |
-
let targetCard = null;
|
| 628 |
-
let buttonContainer = null;
|
| 629 |
-
menuCards.forEach(card => {
|
| 630 |
-
const itemName = card.getAttribute('data-item-name');
|
| 631 |
-
const itemSection = card.getAttribute('data-item-section');
|
| 632 |
-
if (itemName === name && itemSection === section) {
|
| 633 |
-
targetCard = card;
|
| 634 |
-
buttonContainer = card.querySelector('.button-container');
|
| 635 |
-
card.classList.add('highlighted');
|
| 636 |
-
card.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
| 637 |
-
const toggleLink = card.querySelector('.toggle-details');
|
| 638 |
-
if (toggleLink) {
|
| 639 |
-
toggleLink.click();
|
| 640 |
-
}
|
| 641 |
-
}
|
| 642 |
-
});
|
| 643 |
-
if (buttonContainer) {
|
| 644 |
-
if (section === 'Soft Drinks') {
|
| 645 |
-
showSoftDrinkModal(buttonContainer.querySelector('.add-to-cart-btn'));
|
| 646 |
-
} else {
|
| 647 |
-
const name = buttonContainer.getAttribute('data-item-name');
|
| 648 |
-
const price = buttonContainer.getAttribute('data-item-price');
|
| 649 |
-
const image = buttonContainer.getAttribute('data-item-image2');
|
| 650 |
-
const description = buttonContainer.getAttribute('data-item-description');
|
| 651 |
-
const category = buttonContainer.getAttribute('data-item-category');
|
| 652 |
-
showItemDetails(name, price, image, description, section, category);
|
| 653 |
-
const modal = new bootstrap.Modal(document.getElementById('itemModal'));
|
| 654 |
-
modal.show();
|
| 655 |
-
}
|
| 656 |
-
}
|
| 657 |
-
} catch (err) {
|
| 658 |
-
console.error('Error parsing selected item:', err);
|
| 659 |
-
}
|
| 660 |
-
localStorage.removeItem('selectedItem');
|
| 661 |
-
}
|
| 662 |
-
const menuCards = document.querySelectorAll('.menu-card');
|
| 663 |
-
const menuVideos = document.querySelectorAll('.menu-video');
|
| 664 |
-
const cardObserver = new IntersectionObserver((entries, observer) => {
|
| 665 |
-
entries.forEach(entry => {
|
| 666 |
-
if (entry.isIntersecting) {
|
| 667 |
-
entry.target.classList.add('visible');
|
| 668 |
-
observer.unobserve(entry.target);
|
| 669 |
-
}
|
| 670 |
-
});
|
| 671 |
-
}, {
|
| 672 |
-
root: null,
|
| 673 |
-
rootMargin: '0px',
|
| 674 |
-
threshold: 0.1
|
| 675 |
-
});
|
| 676 |
-
const videoObserver = new IntersectionObserver((entries, observer) => {
|
| 677 |
-
entries.forEach(entry => {
|
| 678 |
-
if (entry.isIntersecting) {
|
| 679 |
-
const video = entry.target;
|
| 680 |
-
const src = video.getAttribute('data-src');
|
| 681 |
-
if (src && !video.querySelector('source[src="' + src + '"]')) {
|
| 682 |
-
const nextSibling = video.nextElementSibling;
|
| 683 |
-
if (nextSibling && nextSibling.tagName === 'SOURCE') {
|
| 684 |
-
nextSibling.src = src;
|
| 685 |
-
} else {
|
| 686 |
-
const source = video.querySelector('source');
|
| 687 |
-
if (source) {
|
| 688 |
-
source.src = src;
|
| 689 |
-
}
|
| 690 |
-
}
|
| 691 |
-
video.load();
|
| 692 |
-
}
|
| 693 |
-
video.classList.add('loaded');
|
| 694 |
-
observer.unobserve(video);
|
| 695 |
-
}
|
| 696 |
-
});
|
| 697 |
-
}, {
|
| 698 |
-
root: null,
|
| 699 |
-
rootMargin: '200px',
|
| 700 |
-
threshold: 0.01
|
| 701 |
-
});
|
| 702 |
-
menuCards.forEach(card => cardObserver.observe(card));
|
| 703 |
-
menuVideos.forEach(video => videoObserver.observe(video));
|
| 704 |
-
const toggleLinks = document.querySelectorAll('.toggle-details');
|
| 705 |
-
toggleLinks.forEach(link => {
|
| 706 |
-
link.addEventListener('click', function () {
|
| 707 |
-
const itemName = this.getAttribute('data-item-name').replace(/ /g, '-');
|
| 708 |
-
const detailsDiv = document.getElementById(`details-${itemName}`);
|
| 709 |
-
const isCurrentlyShown = detailsDiv.classList.contains('show');
|
| 710 |
-
document.querySelectorAll('.item-details.show').forEach(otherDetails => {
|
| 711 |
-
if (otherDetails !== detailsDiv) {
|
| 712 |
-
otherDetails.classList.remove('show');
|
| 713 |
-
const otherLink = document.querySelector(`.toggle-details[data-item-name="${otherDetails.id.replace('details-', '').replace(/-/g, ' ')}"]`);
|
| 714 |
-
if (otherLink) {
|
| 715 |
-
otherLink.innerText = 'Show Details';
|
| 716 |
-
}
|
| 717 |
-
}
|
| 718 |
-
});
|
| 719 |
-
if (!isCurrentlyShown) {
|
| 720 |
-
detailsDiv.classList.add('show');
|
| 721 |
-
this.innerText = 'Hide Details';
|
| 722 |
-
} else {
|
| 723 |
-
detailsDiv.classList.remove('show');
|
| 724 |
-
this.innerText = 'Show Details';
|
| 725 |
-
}
|
| 726 |
-
});
|
| 727 |
-
});
|
| 728 |
fetch('/cart/get')
|
| 729 |
-
.then(response =>
|
| 730 |
-
if (!response.ok) {
|
| 731 |
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 732 |
-
}
|
| 733 |
-
return response.json();
|
| 734 |
-
})
|
| 735 |
.then(data => {
|
| 736 |
if (data.success) {
|
| 737 |
updateCartUI(data.cart);
|
|
@@ -746,12 +575,7 @@
|
|
| 746 |
const cart = getCartLocalStorage();
|
| 747 |
updateCartUI(cart);
|
| 748 |
});
|
| 749 |
-
|
| 750 |
-
preloadedVideos.forEach(link => {
|
| 751 |
-
const video = document.createElement('video');
|
| 752 |
-
video.src = link.href;
|
| 753 |
-
video.preload = 'auto';
|
| 754 |
-
});
|
| 755 |
const decreaseBtn = document.getElementById('decreaseQuantity');
|
| 756 |
const increaseBtn = document.getElementById('increaseQuantity');
|
| 757 |
const quantityInput = document.getElementById('quantityInput');
|
|
@@ -766,12 +590,13 @@
|
|
| 766 |
quantityInput.value = quantity;
|
| 767 |
});
|
| 768 |
});
|
|
|
|
| 769 |
let currentStep = 'greeting';
|
| 770 |
let conversation = [];
|
| 771 |
let selectedIngredients = [];
|
| 772 |
let selectedMenuItem = null;
|
| 773 |
-
let cart = [];
|
| 774 |
const userName = "{{ user_name }}";
|
|
|
|
| 775 |
window.onload = function() {
|
| 776 |
if (userName) {
|
| 777 |
conversation.push({ role: 'bot', message: `Nice to meet you, ${userName}! 😊 Let's create your perfect meal! What type of food would you prefer?` });
|
|
@@ -785,29 +610,25 @@
|
|
| 785 |
displayConversation();
|
| 786 |
}
|
| 787 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
function addMessage(role, message) {
|
| 789 |
const chatMessages = document.getElementById('chatMessages');
|
| 790 |
-
if (!chatMessages) {
|
| 791 |
-
console.error('Chat messages container not found!');
|
| 792 |
-
return;
|
| 793 |
-
}
|
| 794 |
const messageDiv = document.createElement('div');
|
| 795 |
messageDiv.className = role === 'bot' ? 'bot-message' : 'user-message';
|
| 796 |
messageDiv.textContent = message;
|
| 797 |
chatMessages.appendChild(messageDiv);
|
| 798 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 799 |
}
|
| 800 |
-
|
| 801 |
-
const chatMessages = document.getElementById('chatMessages');
|
| 802 |
-
chatMessages.innerHTML = '';
|
| 803 |
-
conversation.forEach(msg => {
|
| 804 |
-
const messageDiv = document.createElement('div');
|
| 805 |
-
messageDiv.className = msg.role === 'bot' ? 'bot-message' : 'user-message';
|
| 806 |
-
messageDiv.textContent = msg.message;
|
| 807 |
-
chatMessages.appendChild(messageDiv);
|
| 808 |
-
});
|
| 809 |
-
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 810 |
-
}
|
| 811 |
function sendMessage() {
|
| 812 |
const userInput = document.getElementById('userInput').value.trim();
|
| 813 |
if (userInput) {
|
|
@@ -815,120 +636,135 @@
|
|
| 815 |
conversation.push({ role: 'user', message: userInput });
|
| 816 |
document.getElementById('userInput').value = '';
|
| 817 |
setTimeout(() => handleResponse(userInput), 500);
|
| 818 |
-
} else {
|
| 819 |
-
console.warn('Empty message!');
|
| 820 |
}
|
| 821 |
}
|
|
|
|
| 822 |
function handleResponse(userInput) {
|
| 823 |
-
const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
|
| 824 |
let botResponse = '';
|
| 825 |
let options = [];
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
|
|
|
|
|
|
|
|
|
| 832 |
} else if (lastMessage.includes('vegetarian')) {
|
| 833 |
-
|
| 834 |
-
console.log("Food preference selected: Vegetarian");
|
| 835 |
botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
|
| 836 |
fetchIngredients('vegetarian');
|
| 837 |
return;
|
| 838 |
-
} else if (lastMessage.includes('
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
fetchIngredients(lastMessage.toLowerCase());
|
| 843 |
return;
|
| 844 |
} else if (lastMessage.includes('yes') && selectedMenuItem) {
|
|
|
|
| 845 |
botResponse = 'Here are some ingredients to customize your dish:';
|
| 846 |
-
|
| 847 |
return;
|
| 848 |
} else if (lastMessage.includes('no') && selectedMenuItem) {
|
| 849 |
submitCustomizationIngredients();
|
| 850 |
return;
|
| 851 |
-
} else if (lastMessage.includes('yes') && currentStep === 'post_cart') {
|
| 852 |
-
botResponse = `Let's get started again! What type of food would you prefer this time?`;
|
| 853 |
-
options = [
|
| 854 |
-
{ text: 'Vegetarian', class: 'green' },
|
| 855 |
-
{ text: 'Non-Vegetarian', class: 'red' }
|
| 856 |
-
];
|
| 857 |
-
currentStep = 'food_type';
|
| 858 |
-
addMessage('bot', botResponse);
|
| 859 |
-
displayOptions(options);
|
| 860 |
-
return;
|
| 861 |
-
} else if (lastMessage.includes('non-vegetarian') && currentStep === 'food_type') {
|
| 862 |
-
conversation.push({ role: 'user', message: 'Non-Vegetarian' });
|
| 863 |
-
console.log("Food preference selected: Non-Vegetarian");
|
| 864 |
-
botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
|
| 865 |
-
fetchIngredients('non-vegetarian');
|
| 866 |
-
return;
|
| 867 |
-
} else if (lastMessage.includes('vegetarian') && currentStep === 'food_type') {
|
| 868 |
-
conversation.push({ role: 'user', message: 'Vegetarian' });
|
| 869 |
-
console.log("Food preference selected: Vegetarian");
|
| 870 |
-
botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
|
| 871 |
-
fetchIngredients('vegetarian');
|
| 872 |
-
return;
|
| 873 |
-
} else if (lastMessage.includes('no') && currentStep === 'post_cart') {
|
| 874 |
-
addMessage('bot', 'Awesome! 🧾 Here’s your final cart:');
|
| 875 |
-
displayCart();
|
| 876 |
-
addMessage('bot', 'Thank you for your order! 👨🍳🍲');
|
| 877 |
-
currentStep = 'end';
|
| 878 |
-
return;
|
| 879 |
}
|
|
|
|
| 880 |
addMessage('bot', botResponse);
|
| 881 |
if (options.length > 0) {
|
| 882 |
displayOptions(options);
|
| 883 |
}
|
| 884 |
-
displayCart();
|
| 885 |
}
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
}
|
|
|
|
| 906 |
function fetchIngredientsForCustomization(foodPreference) {
|
| 907 |
fetch('/get_ingredients', {
|
| 908 |
method: 'POST',
|
| 909 |
headers: { 'Content-Type': 'application/json' },
|
| 910 |
body: JSON.stringify({ dietary_preference: foodPreference })
|
| 911 |
})
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 920 |
}
|
| 921 |
-
}
|
| 922 |
-
.
|
| 923 |
-
|
| 924 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 925 |
}
|
|
|
|
| 926 |
function displayCustomizationIngredients(ingredients) {
|
| 927 |
const chatMessages = document.getElementById('chatMessages');
|
| 928 |
-
if (!chatMessages) {
|
| 929 |
-
console.error('Chat messages container not found for customization ingredients!');
|
| 930 |
-
return;
|
| 931 |
-
}
|
| 932 |
let ingredientsList = document.querySelector('.customization-ingredients-list');
|
| 933 |
if (!ingredientsList) {
|
| 934 |
ingredientsList = document.createElement('div');
|
|
@@ -937,6 +773,7 @@
|
|
| 937 |
} else {
|
| 938 |
ingredientsList.innerHTML = '';
|
| 939 |
}
|
|
|
|
| 940 |
ingredients.forEach(ingredient => {
|
| 941 |
const item = document.createElement('div');
|
| 942 |
item.className = 'ingredient-item';
|
|
@@ -948,7 +785,7 @@
|
|
| 948 |
const button = document.createElement('button');
|
| 949 |
button.textContent = 'Add';
|
| 950 |
button.onclick = () => {
|
| 951 |
-
if (!selectedIngredients.some(
|
| 952 |
selectedIngredients.push({ name: ingredient.name, image_url: ingredient.image_url });
|
| 953 |
displaySelectedCustomizationIngredients();
|
| 954 |
}
|
|
@@ -958,14 +795,38 @@
|
|
| 958 |
item.appendChild(button);
|
| 959 |
ingredientsList.appendChild(item);
|
| 960 |
});
|
|
|
|
| 961 |
displaySelectedCustomizationIngredients();
|
| 962 |
}
|
| 963 |
-
|
|
|
|
| 964 |
const chatMessages = document.getElementById('chatMessages');
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 968 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 969 |
let selectedArea = document.querySelector('.selected-customization-ingredients');
|
| 970 |
if (!selectedArea) {
|
| 971 |
selectedArea = document.createElement('div');
|
|
@@ -974,31 +835,28 @@
|
|
| 974 |
} else {
|
| 975 |
selectedArea.innerHTML = '';
|
| 976 |
}
|
|
|
|
| 977 |
const selectedIngredientsText = selectedIngredients.length > 0
|
| 978 |
-
? `${selectedMenuItem.name} with ${selectedIngredients.map(
|
| 979 |
: selectedMenuItem.name;
|
| 980 |
const ingredientsDiv = document.createElement('div');
|
| 981 |
ingredientsDiv.textContent = selectedIngredientsText;
|
| 982 |
selectedArea.appendChild(ingredientsDiv);
|
|
|
|
| 983 |
selectedIngredients.forEach(ingredient => {
|
| 984 |
const div = document.createElement('div');
|
| 985 |
div.textContent = ingredient.name;
|
| 986 |
const removeButton = document.createElement('button');
|
| 987 |
removeButton.textContent = 'X';
|
| 988 |
-
removeButton.
|
| 989 |
-
removeButton.style.padding = '2px 5px';
|
| 990 |
-
removeButton.style.backgroundColor = '#dc3545';
|
| 991 |
-
removeButton.style.color = '#ffffff';
|
| 992 |
-
removeButton.style.border = 'none';
|
| 993 |
-
removeButton.style.borderRadius = '4px';
|
| 994 |
-
removeButton.style.cursor = 'pointer';
|
| 995 |
removeButton.onclick = () => {
|
| 996 |
-
selectedIngredients = selectedIngredients.filter(
|
| 997 |
displaySelectedCustomizationIngredients();
|
| 998 |
};
|
| 999 |
div.appendChild(removeButton);
|
| 1000 |
selectedArea.appendChild(div);
|
| 1001 |
});
|
|
|
|
| 1002 |
if (!document.querySelector('.submit-customization-button')) {
|
| 1003 |
const textarea = document.createElement('textarea');
|
| 1004 |
textarea.placeholder = 'Enter any special instructions...';
|
|
@@ -1010,18 +868,85 @@
|
|
| 1010 |
selectedArea.appendChild(submitButton);
|
| 1011 |
}
|
| 1012 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1013 |
function submitCustomizationIngredients() {
|
| 1014 |
if (!selectedMenuItem) {
|
| 1015 |
addMessage('bot', 'No dish selected. Please choose a dish first.');
|
| 1016 |
return;
|
| 1017 |
}
|
| 1018 |
-
|
| 1019 |
const textarea = document.querySelector('.selected-customization-ingredients textarea');
|
| 1020 |
const instructions = textarea ? textarea.value.trim() : '';
|
| 1021 |
-
const ingredientsList = selectedIngredients.map(
|
| 1022 |
-
const itemPrice = 10.00; // Fixed price for custom dishes
|
| 1023 |
const itemImage = selectedMenuItem.image_url || 'https://via.placeholder.com/120';
|
| 1024 |
-
|
| 1025 |
const customDishPayload = {
|
| 1026 |
menu_item: selectedMenuItem,
|
| 1027 |
ingredients: selectedIngredients,
|
|
@@ -1029,8 +954,8 @@
|
|
| 1029 |
itemPrice: itemPrice,
|
| 1030 |
itemImage: itemImage
|
| 1031 |
};
|
| 1032 |
-
|
| 1033 |
-
//
|
| 1034 |
fetch('/menu/save_custom_dish', {
|
| 1035 |
method: 'POST',
|
| 1036 |
headers: { 'Content-Type': 'application/json' },
|
|
@@ -1041,7 +966,8 @@
|
|
| 1041 |
if (!data.success) {
|
| 1042 |
throw new Error(data.error || 'Failed to save custom dish');
|
| 1043 |
}
|
| 1044 |
-
|
|
|
|
| 1045 |
const cartPayload = {
|
| 1046 |
itemName: selectedMenuItem.name,
|
| 1047 |
itemPrice: itemPrice,
|
|
@@ -1053,6 +979,7 @@
|
|
| 1053 |
quantity: 1,
|
| 1054 |
ingredients: ingredientsList
|
| 1055 |
};
|
|
|
|
| 1056 |
return fetch('/cart/add', {
|
| 1057 |
method: 'POST',
|
| 1058 |
headers: { 'Content-Type': 'application/json' },
|
|
@@ -1064,8 +991,7 @@
|
|
| 1064 |
if (data.success) {
|
| 1065 |
addMessage('bot', 'Customization submitted successfully! Item added to cart.');
|
| 1066 |
updateCartUI(data.cart);
|
| 1067 |
-
|
| 1068 |
-
// Redirect to the menu page to see the custom dish
|
| 1069 |
window.location.href = '/menu?category=Customized+Dish';
|
| 1070 |
} else {
|
| 1071 |
throw new Error(data.error || 'Failed to add item to cart');
|
|
@@ -1075,263 +1001,9 @@
|
|
| 1075 |
addMessage('bot', `Error: ${error.message}`);
|
| 1076 |
});
|
| 1077 |
}
|
| 1078 |
-
|
| 1079 |
-
fetch('/get_ingredients', {
|
| 1080 |
-
method: 'POST',
|
| 1081 |
-
headers: { 'Content-Type': 'application/json' },
|
| 1082 |
-
body: JSON.stringify({ dietary_preference: foodPreference })
|
| 1083 |
-
})
|
| 1084 |
-
.then(response => response.json())
|
| 1085 |
-
.then(data => {
|
| 1086 |
-
if (data.error) {
|
| 1087 |
-
addMessage('bot', `Sorry, there was an error fetching ingredients: ${data.error}`);
|
| 1088 |
-
} else {
|
| 1089 |
-
const ingredients = data.ingredients || [];
|
| 1090 |
-
addMessage('bot', 'Please select ingredients:');
|
| 1091 |
-
displayIngredientsList(ingredients);
|
| 1092 |
-
displaySelectedIngredients();
|
| 1093 |
-
}
|
| 1094 |
-
})
|
| 1095 |
-
.catch(error => {
|
| 1096 |
-
addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
|
| 1097 |
-
});
|
| 1098 |
-
}
|
| 1099 |
-
function fetchMenuItems(params) {
|
| 1100 |
-
fetch('/get_menu_items', {
|
| 1101 |
-
method: 'POST',
|
| 1102 |
-
headers: { 'Content-Type': 'application/json' },
|
| 1103 |
-
body: JSON.stringify(params)
|
| 1104 |
-
})
|
| 1105 |
-
.then(response => response.json())
|
| 1106 |
-
.then(data => {
|
| 1107 |
-
if (data.error) {
|
| 1108 |
-
addMessage('bot', `Sorry, there was an error fetching menu items: ${data.error}`);
|
| 1109 |
-
} else {
|
| 1110 |
-
const menuItems = data.menu_items || [];
|
| 1111 |
-
addMessage('bot', 'Here are some dishes based on your selection:');
|
| 1112 |
-
displayMenuItems(menuItems);
|
| 1113 |
-
}
|
| 1114 |
-
})
|
| 1115 |
-
.catch(error => {
|
| 1116 |
-
addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
|
| 1117 |
-
});
|
| 1118 |
-
}
|
| 1119 |
-
function displayIngredientsList(ingredients) {
|
| 1120 |
-
const chatMessages = document.getElementById('chatMessages');
|
| 1121 |
-
if (!chatMessages) {
|
| 1122 |
-
console.error('Chat messages container not found for ingredients!');
|
| 1123 |
-
return;
|
| 1124 |
-
}
|
| 1125 |
-
let ingredientsList = document.querySelector('.ingredients-list');
|
| 1126 |
-
if (!ingredientsList) {
|
| 1127 |
-
ingredientsList = document.createElement('div');
|
| 1128 |
-
ingredientsList.className = 'ingredients-list';
|
| 1129 |
-
chatMessages.appendChild(ingredientsList);
|
| 1130 |
-
} else {
|
| 1131 |
-
ingredientsList.innerHTML = '';
|
| 1132 |
-
}
|
| 1133 |
-
ingredients.forEach(ingredient => {
|
| 1134 |
-
const item = document.createElement('div');
|
| 1135 |
-
item.className = 'ingredient-item';
|
| 1136 |
-
const img = document.createElement('img');
|
| 1137 |
-
img.src = ingredient.image_url || 'https://via.placeholder.com/120';
|
| 1138 |
-
img.alt = ingredient.name;
|
| 1139 |
-
const name = document.createElement('div');
|
| 1140 |
-
name.textContent = ingredient.name;
|
| 1141 |
-
const button = document.createElement('button');
|
| 1142 |
-
button.textContent = 'Add';
|
| 1143 |
-
button.onclick = () => {
|
| 1144 |
-
if (!selectedIngredients.some(item => item.name === ingredient.name)) {
|
| 1145 |
-
selectedIngredients.push(ingredient);
|
| 1146 |
-
displaySelectedIngredients();
|
| 1147 |
-
}
|
| 1148 |
-
};
|
| 1149 |
-
item.appendChild(img);
|
| 1150 |
-
item.appendChild(name);
|
| 1151 |
-
item.appendChild(button);
|
| 1152 |
-
ingredientsList.appendChild(item);
|
| 1153 |
-
});
|
| 1154 |
-
}
|
| 1155 |
-
function displayMenuItems(menuItems) {
|
| 1156 |
-
const chatMessages = document.getElementById('chatMessages');
|
| 1157 |
-
if (!chatMessages) {
|
| 1158 |
-
console.error('Chat messages container not found for menu items!');
|
| 1159 |
-
return;
|
| 1160 |
-
}
|
| 1161 |
-
let menuItemsList = document.querySelector('.menu-items-list');
|
| 1162 |
-
if (!menuItemsList) {
|
| 1163 |
-
menuItemsList = document.createElement('div');
|
| 1164 |
-
menuItemsList.className = 'menu-items-list';
|
| 1165 |
-
chatMessages.appendChild(menuItemsList);
|
| 1166 |
-
} else {
|
| 1167 |
-
menuItemsList.innerHTML = '';
|
| 1168 |
-
}
|
| 1169 |
-
menuItems.forEach(item => {
|
| 1170 |
-
const menuItem = document.createElement('div');
|
| 1171 |
-
menuItem.className = 'menu-item';
|
| 1172 |
-
const img = document.createElement('img');
|
| 1173 |
-
img.src = item.image_url || 'https://via.placeholder.com/120';
|
| 1174 |
-
img.alt = item.name;
|
| 1175 |
-
const name = document.createElement('div');
|
| 1176 |
-
name.textContent = item.name;
|
| 1177 |
-
const button = document.createElement('button');
|
| 1178 |
-
button.textContent = 'Add to Cart';
|
| 1179 |
-
button.onclick = () => {
|
| 1180 |
-
selectedMenuItem = item;
|
| 1181 |
-
addMessage('bot', `World-class selection! Would you like to customize your dish further?`);
|
| 1182 |
-
const options = [
|
| 1183 |
-
{ text: 'Yes', class: 'green' },
|
| 1184 |
-
{ text: 'No', class: 'red' }
|
| 1185 |
-
];
|
| 1186 |
-
displayOptions(options);
|
| 1187 |
-
};
|
| 1188 |
-
menuItem.appendChild(img);
|
| 1189 |
-
menuItem.appendChild(name);
|
| 1190 |
-
menuItem.appendChild(button);
|
| 1191 |
-
menuItemsList.appendChild(menuItem);
|
| 1192 |
-
});
|
| 1193 |
-
}
|
| 1194 |
-
function displaySelectedIngredients() {
|
| 1195 |
-
const chatMessages = document.getElementById('chatMessages');
|
| 1196 |
-
if (!chatMessages) {
|
| 1197 |
-
console.error('Chat messages container not found for selected ingredients!');
|
| 1198 |
-
return;
|
| 1199 |
-
}
|
| 1200 |
-
let selectedArea = document.querySelector('.selected-ingredients');
|
| 1201 |
-
if (!selectedArea) {
|
| 1202 |
-
selectedArea = document.createElement('div');
|
| 1203 |
-
selectedArea.className = 'selected-ingredients';
|
| 1204 |
-
chatMessages.appendChild(selectedArea);
|
| 1205 |
-
} else {
|
| 1206 |
-
selectedArea.innerHTML = '';
|
| 1207 |
-
}
|
| 1208 |
-
selectedIngredients.forEach(ingredient => {
|
| 1209 |
-
const div = document.createElement('div');
|
| 1210 |
-
div.textContent = ingredient.name;
|
| 1211 |
-
const removeButton = document.createElement('button');
|
| 1212 |
-
removeButton.textContent = 'X';
|
| 1213 |
-
removeButton.style.marginLeft = '5px';
|
| 1214 |
-
removeButton.style.padding = '2px 5px';
|
| 1215 |
-
removeButton.style.backgroundColor = '#dc3545';
|
| 1216 |
-
removeButton.style.color = '#ffffff';
|
| 1217 |
-
removeButton.style.border = 'none';
|
| 1218 |
-
removeButton.style.borderRadius = '4px';
|
| 1219 |
-
removeButton.style.cursor = 'pointer';
|
| 1220 |
-
removeButton.onclick = () => {
|
| 1221 |
-
selectedIngredients = selectedIngredients.filter(item => item.name !== ingredient.name);
|
| 1222 |
-
displaySelectedIngredients();
|
| 1223 |
-
};
|
| 1224 |
-
div.appendChild(removeButton);
|
| 1225 |
-
selectedArea.appendChild(div);
|
| 1226 |
-
});
|
| 1227 |
-
if (selectedIngredients.length > 0) {
|
| 1228 |
-
let submitButton = document.querySelector('.submit-button');
|
| 1229 |
-
if (!submitButton) {
|
| 1230 |
-
submitButton = document.createElement('button');
|
| 1231 |
-
submitButton.className = 'submit-button';
|
| 1232 |
-
submitButton.textContent = 'Submit Ingredients';
|
| 1233 |
-
submitButton.onclick = submitIngredients;
|
| 1234 |
-
chatMessages.appendChild(submitButton);
|
| 1235 |
-
}
|
| 1236 |
-
}
|
| 1237 |
-
}
|
| 1238 |
-
function submitIngredients() {
|
| 1239 |
-
if (selectedIngredients.length === 0) {
|
| 1240 |
-
addMessage('bot', 'No ingredients selected. Please choose some ingredients.');
|
| 1241 |
-
return;
|
| 1242 |
-
}
|
| 1243 |
-
const ingredientNames = selectedIngredients.map(ingredient => ingredient.name.toLowerCase()).join(' ');
|
| 1244 |
-
fetchMenuItems({ ingredient_names: ingredientNames });
|
| 1245 |
-
}
|
| 1246 |
-
function addToCart(item) {
|
| 1247 |
-
cart.push(item);
|
| 1248 |
-
console.log('Cart:', cart);
|
| 1249 |
-
displayCart();
|
| 1250 |
-
}
|
| 1251 |
-
function displayCart() {
|
| 1252 |
-
const chatMessages = document.getElementById('chatMessages');
|
| 1253 |
-
if (!chatMessages) {
|
| 1254 |
-
console.error('Chat messages container not found for cart!');
|
| 1255 |
-
return;
|
| 1256 |
-
}
|
| 1257 |
-
let cartArea = document.querySelector('.cart-items');
|
| 1258 |
-
if (!cartArea) {
|
| 1259 |
-
cartArea = document.createElement('div');
|
| 1260 |
-
cartArea.className = 'cart-items';
|
| 1261 |
-
chatMessages.appendChild(cartArea);
|
| 1262 |
-
} else {
|
| 1263 |
-
cartArea.innerHTML = '';
|
| 1264 |
-
}
|
| 1265 |
-
if (cart.length > 0) {
|
| 1266 |
-
const label = document.createElement('div');
|
| 1267 |
-
label.textContent = 'Cart:';
|
| 1268 |
-
cartArea.appendChild(label);
|
| 1269 |
-
cart.forEach((item, index) => {
|
| 1270 |
-
const itemDiv = document.createElement('div');
|
| 1271 |
-
itemDiv.className = 'cart-item';
|
| 1272 |
-
const img = document.createElement('img');
|
| 1273 |
-
img.src = item.image_url || 'https://via.placeholder.com/30';
|
| 1274 |
-
img.alt = item.name;
|
| 1275 |
-
const name = document.createElement('div');
|
| 1276 |
-
const text = item.instructions
|
| 1277 |
-
? `${item.name} (${item.instructions})`
|
| 1278 |
-
: item.name;
|
| 1279 |
-
name.textContent = item.ingredients.length > 0
|
| 1280 |
-
? `${text} with ${item.ingredients.map(i => i.name).join(', ')}`
|
| 1281 |
-
: text;
|
| 1282 |
-
const removeButton = document.createElement('button');
|
| 1283 |
-
removeButton.className = 'remove-button';
|
| 1284 |
-
removeButton.textContent = 'X';
|
| 1285 |
-
removeButton.onclick = () => {
|
| 1286 |
-
cart.splice(index, 1);
|
| 1287 |
-
displayCart();
|
| 1288 |
-
};
|
| 1289 |
-
itemDiv.appendChild(img);
|
| 1290 |
-
itemDiv.appendChild(name);
|
| 1291 |
-
itemDiv.appendChild(removeButton);
|
| 1292 |
-
cartArea.appendChild(itemDiv);
|
| 1293 |
-
});
|
| 1294 |
-
let submitCartButton = document.querySelector('.submit-cart-button');
|
| 1295 |
-
if (!submitCartButton) {
|
| 1296 |
-
submitCartButton = document.createElement('button');
|
| 1297 |
-
submitCartButton.className = 'submit-cart-button';
|
| 1298 |
-
submitCartButton.textContent = 'Submit Cart';
|
| 1299 |
-
submitCartButton.onclick = submitCart;
|
| 1300 |
-
cartArea.appendChild(submitCartButton);
|
| 1301 |
-
}
|
| 1302 |
-
}
|
| 1303 |
-
}
|
| 1304 |
-
function submitCart() {
|
| 1305 |
-
if (cart.length === 0) {
|
| 1306 |
-
addMessage('bot', 'Your cart is empty!');
|
| 1307 |
-
return;
|
| 1308 |
-
}
|
| 1309 |
-
fetch('/submit_customization_ingredients', {
|
| 1310 |
-
method: 'POST',
|
| 1311 |
-
headers: { 'Content-Type': 'application/json' },
|
| 1312 |
-
body: JSON.stringify({ items: cart })
|
| 1313 |
-
})
|
| 1314 |
-
.then(response => response.json())
|
| 1315 |
-
.then(data => {
|
| 1316 |
-
if (data.success) {
|
| 1317 |
-
addMessage('bot', 'Cart submitted successfully!');
|
| 1318 |
-
cart = [];
|
| 1319 |
-
displayCart();
|
| 1320 |
-
} else {
|
| 1321 |
-
addMessage('bot', `Error submitting cart: ${data.error}`);
|
| 1322 |
-
}
|
| 1323 |
-
})
|
| 1324 |
-
.catch(error => {
|
| 1325 |
-
addMessage('bot', `Error submitting cart: ${error.message}`);
|
| 1326 |
-
});
|
| 1327 |
-
}
|
| 1328 |
function displayOptions(options) {
|
| 1329 |
const chatMessages = document.getElementById('chatMessages');
|
| 1330 |
-
if (!chatMessages) {
|
| 1331 |
-
console.error('Chat messages container not found for options!');
|
| 1332 |
-
return;
|
| 1333 |
-
}
|
| 1334 |
-
console.log('Displaying options:', options);
|
| 1335 |
options.forEach(opt => {
|
| 1336 |
const button = document.createElement('button');
|
| 1337 |
button.textContent = opt.text;
|
|
@@ -1339,14 +1011,11 @@
|
|
| 1339 |
button.onclick = () => {
|
| 1340 |
addMessage('user', opt.text);
|
| 1341 |
conversation.push({ role: 'user', message: opt.text });
|
| 1342 |
-
|
| 1343 |
-
setTimeout(() => handleResponse(opt.text), 500);
|
| 1344 |
};
|
| 1345 |
chatMessages.appendChild(button);
|
| 1346 |
});
|
| 1347 |
-
chatMessages.appendChild(document.createElement('br'));
|
| 1348 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 1349 |
-
console.log('Options displayed');
|
| 1350 |
}
|
| 1351 |
|
| 1352 |
document.getElementById('userInput').addEventListener('keypress', function(e) {
|
|
@@ -1354,7 +1023,6 @@
|
|
| 1354 |
sendMessage();
|
| 1355 |
}
|
| 1356 |
});
|
| 1357 |
-
console.log('Script loaded successfully');
|
| 1358 |
</script>
|
| 1359 |
</body>
|
| 1360 |
</html>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Menu</title>
|
|
|
|
| 7 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
|
|
|
|
| 9 |
<link rel="preload" href="/static/placeholder.mp4" as="video">
|
| 10 |
{% for section, items in ordered_menu.items() %}
|
| 11 |
{% for item in items[:1] %}
|
|
|
|
| 13 |
{% endfor %}
|
| 14 |
{% endfor %}
|
| 15 |
<style>
|
| 16 |
+
body { padding-top: 70px; padding-bottom: 70px; }
|
| 17 |
+
.fixed-top-bar { position: fixed; top: 0; width: 100%; background: #fff; padding: 10px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 5px rgba(0,0,0,0.1); z-index: 1000; }
|
| 18 |
+
.avatar-dropdown-container { position: relative; cursor: pointer; }
|
| 19 |
+
.avatar-icon { width: 40px; height: 40px; background-color: #007bff; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; }
|
| 20 |
+
.dropdown-menu { display: none; position: absolute; top: 45px; left: 0; background: white; border: 1px solid #ddd; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); z-index: 1000; }
|
| 21 |
+
.dropdown-item { padding: 10px 20px; display: block; color: #333; text-decoration: none; }
|
| 22 |
+
.dropdown-item:hover { background: #f8f9fa; }
|
| 23 |
+
.search-bar-container { position: relative; width: 50%; }
|
| 24 |
+
.search-bar-container input { width: 100%; padding: 8px 40px 8px 40px; border-radius: 20px; border: 1px solid #ddd; }
|
| 25 |
+
.search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: #666; }
|
| 26 |
+
.mic-icon { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); color: #666; cursor: pointer; }
|
| 27 |
+
.bottom-action-bar { position: fixed; bottom: 0; width: 100%; background: #fff; padding: 10px; display: flex; justify-content: space-around; box-shadow: 0 -2px 5px rgba(0,0,0,0.1); z-index: 1000; }
|
| 28 |
+
.btn-order-history, .btn-view-cart { background: #007bff; color: white; padding: 10px 20px; border-radius: 20px; text-decoration: none; display: flex; align-items: center; gap: 5px; }
|
| 29 |
+
.cart-icon-badge { background: #dc3545; color: white; border-radius: 50%; padding: 2px 8px; font-size: 12px; }
|
| 30 |
+
.menu-card { border: none; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,0.1); transition: transform 0.3s; }
|
| 31 |
+
.menu-card.visible { transform: scale(1); opacity: 1; }
|
| 32 |
+
.menu-video { width: 100%; height: 200px; object-fit: cover; }
|
| 33 |
+
.menu-video.loaded { background: transparent; }
|
| 34 |
+
.card-body { padding: 15px; }
|
| 35 |
+
.addbutton { display: flex; justify-content: space-between; align-items: center; }
|
| 36 |
+
.button-container { position: relative; }
|
| 37 |
+
.customisable-text { font-size: 12px; color: #007bff; margin-top: 5px; }
|
| 38 |
+
.toggle-details { text-align: center; padding: 10px; background: #f8f9fa; cursor: pointer; border-top: 1px solid #ddd; }
|
| 39 |
+
.item-details { display: none; padding: 15px; background: #fff; }
|
| 40 |
+
.item-details.show { display: block; }
|
| 41 |
+
.modal-addons h5 { font-size: 16px; margin-bottom: 10px; }
|
| 42 |
+
.addon-section { margin-bottom: 15px; }
|
| 43 |
+
.addon-section h6 { font-size: 14px; margin-bottom: 5px; cursor: pointer; }
|
| 44 |
+
.addon-options { max-height: 150px; overflow-y: auto; }
|
| 45 |
+
.addon-options.collapsed { max-height: 0; overflow: hidden; }
|
| 46 |
+
.form-check { margin-bottom: 5px; }
|
| 47 |
+
.extra-charge { color: #dc3545; font-size: 12px; }
|
| 48 |
+
.quantity-controls { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 20px 0; }
|
| 49 |
+
.quantity-controls .btn { background: #007bff; color: white; border: none; padding: 5px 15px; border-radius: 5px; }
|
| 50 |
+
.quantity-controls-footer { display: flex; gap: 10px; }
|
| 51 |
+
.quantity-controls-footer .btn { background: #007bff; color: white; border: none; padding: 5px 15px; border-radius: 5px; }
|
| 52 |
+
.chat-container { max-width: 600px; margin: 0 auto; border: 1px solid #ddd; border-radius: 10px; overflow: hidden; }
|
| 53 |
+
.chat-header { background: #007bff; color: white; padding: 10px; text-align: center; font-size: 18px; }
|
| 54 |
+
.chat-messages { max-height: 400px; overflow-y: auto; padding: 10px; }
|
| 55 |
+
.bot-message, .user-message { margin: 5px 0; padding: 10px; border-radius: 10px; }
|
| 56 |
+
.bot-message { background: #f1f1f1; align-self: flex-start; }
|
| 57 |
+
.user-message { background: #007bff; color: white; align-self: flex-end; text-align: right; }
|
| 58 |
+
.chat-input { display: flex; padding: 10px; border-top: 1px solid #ddd; }
|
| 59 |
+
.chat-input input { flex: 1; padding: 8px; border: 1px solid #ddd; border-radius: 20px; margin-right: 10px; }
|
| 60 |
+
.chat-input button { background: #007bff; color: white; border: none; padding: 8px 15px; border-radius: 20px; }
|
| 61 |
+
.ingredients-list, .menu-items-list, .selected-ingredients, .selected-customization-ingredients, .cart-items { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
|
| 62 |
+
.ingredient-item, .menu-item, .cart-item { border: 1px solid #ddd; border-radius: 5px; padding: 10px; display: flex; flex-direction: column; align-items: center; width: 120px; }
|
| 63 |
+
.ingredient-item img, .menu-item img, .cart-item img { width: 80px; height: 80px; object-fit: cover; border-radius: 5px; }
|
| 64 |
+
.ingredient-item button, .menu-item button { background: #007bff; color: white; border: none; padding: 5px 10px; border-radius: 5px; margin-top: 5px; }
|
| 65 |
+
.selected-ingredients div, .selected-customization-ingredients div { display: flex; align-items: center; margin: 5px 0; }
|
| 66 |
+
.selected-customization-ingredients textarea { width: 100%; height: 60px; margin-top: 10px; }
|
| 67 |
+
.submit-button, .submit-cart-button, .submit-customization-button { background: #28a745; color: white; border: none; padding: 10px 20px; border-radius: 5px; margin-top: 10px; }
|
| 68 |
+
.remove-button { background: #dc3545; color: white; border: none; padding: 2px 5px; border-radius: 5px; margin-left: 5px; }
|
| 69 |
+
.option-button { background: #007bff; color: white; border: none; padding: 5px 10px; border-radius: 5px; margin: 5px; }
|
| 70 |
+
.option-button.green { background: #28a745; }
|
| 71 |
+
.option-button.red { background: #dc3545; }
|
| 72 |
+
.toggle-container { display: inline-flex; align-items: center; margin: 0 10px; }
|
| 73 |
+
.custom-toggle { display: none; }
|
| 74 |
+
.custom-toggle + label { padding: 5px 10px; border: 1px solid #007bff; border-radius: 20px; cursor: pointer; transition: all 0.3s; }
|
| 75 |
+
.custom-toggle:checked + label { background: #007bff; color: white; }
|
| 76 |
</style>
|
| 77 |
</head>
|
| 78 |
<body>
|
|
|
|
| 84 |
<div class="dropdown-menu">
|
| 85 |
<a href="{{ url_for('user_details.customer_details') }}" class="dropdown-item">View Profile</a>
|
| 86 |
<a href="{{ url_for('orderhistory.order_history') }}" class="dropdown-item">Order History</a>
|
| 87 |
+
<a href="{{ url_for('combined_summary.combined_summary') }}" class="dropdown-item">My Summary</a>
|
| 88 |
<a href="{{ url_for('logout') }}" class="dropdown-item">Logout</a>
|
| 89 |
</div>
|
| 90 |
</div>
|
|
|
|
| 98 |
<form method="get" action="/menu" class="text-center mb-4" id="filter-form">
|
| 99 |
<label class="form-label fw-bold">Filters:</label>
|
| 100 |
<div class="toggle-container">
|
|
|
|
| 101 |
<input type="checkbox" id="veg-toggle" name="veg"
|
| 102 |
{% if selected_category == "Veg" %}checked{% endif %}
|
| 103 |
class="custom-toggle" onchange="handleToggle('veg')"
|
|
|
|
| 105 |
<label for="veg-toggle">Veg</label>
|
| 106 |
</div>
|
| 107 |
<div class="toggle-container">
|
|
|
|
| 108 |
<input type="radio" id="category-CustomizedDish" name="category" value="Customized Dish"
|
| 109 |
{% if selected_category == "Customized Dish" %}checked{% endif %}
|
| 110 |
class="custom-toggle" onchange="handleToggle('custom')"
|
|
|
|
| 118 |
<div id="custom-dish-form" class="mt-4">
|
| 119 |
<div class="chat-container">
|
| 120 |
<div class="chat-header">🍳 Chef Bot</div>
|
| 121 |
+
<div class="chat-messages" id="chatMessages"></div>
|
|
|
|
|
|
|
| 122 |
<div class="chat-input">
|
| 123 |
+
<input type="text" id="userInput" placeholder="Type your message...">
|
| 124 |
<button onclick="sendMessage()">Send</button>
|
| 125 |
</div>
|
| 126 |
</div>
|
|
|
|
| 174 |
onclick="showItemDetails('{{ item.Name | default('Unnamed Item') }}', '{{ item.Price__c | default('0.00') }}', '{{ item.Image2__c | default(item.Image1__c) }}', '{{ item.Description__c | default('No description') }}', '{{ item.Section__c | default(section) }}', '{{ selected_category }}')">
|
| 175 |
ADD
|
| 176 |
</button>
|
| 177 |
+
{% if item.Section__c != 'Apetizer' and item.Section__c != 'Customized Dish' %}
|
| 178 |
+
<span class="customisable-text">Customizable</span>
|
| 179 |
{% endif %}
|
| 180 |
{% endif %}
|
| 181 |
</div>
|
|
|
|
| 285 |
let isProcessingRequest = false;
|
| 286 |
let currentSoftDrinkButton = null;
|
| 287 |
let baseItemPrice = 0;
|
| 288 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
function addToCartLocalStorage(payload) {
|
| 290 |
let cart = JSON.parse(localStorage.getItem('cart')) || [];
|
| 291 |
const existingItem = cart.find(item =>
|
|
|
|
| 301 |
localStorage.setItem('cart', JSON.stringify(cart));
|
| 302 |
return cart;
|
| 303 |
}
|
| 304 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
function getCartLocalStorage() {
|
| 306 |
return JSON.parse(localStorage.getItem('cart')) || [];
|
| 307 |
}
|
| 308 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
function updateModalPrice() {
|
| 310 |
const selectedAddOns = Array.from(
|
| 311 |
document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
|
|
|
|
| 314 |
const totalPrice = baseItemPrice + totalAddOnPrice;
|
| 315 |
document.getElementById('modal-price').innerText = `$${totalPrice.toFixed(2)}`;
|
| 316 |
}
|
| 317 |
+
|
| 318 |
function updateSoftDrinkQuantity(delta) {
|
| 319 |
const quantityInput = document.getElementById('soft-drink-quantity');
|
| 320 |
let currentQuantity = parseInt(quantityInput.value) || 1;
|
| 321 |
currentQuantity = Math.max(1, currentQuantity + delta);
|
| 322 |
quantityInput.value = currentQuantity;
|
| 323 |
}
|
| 324 |
+
|
| 325 |
function showSoftDrinkModal(button) {
|
| 326 |
currentSoftDrinkButton = button;
|
| 327 |
const buttonContainer = button.closest('.button-container');
|
|
|
|
| 330 |
const itemImage = buttonContainer.getAttribute('data-item-image');
|
| 331 |
|
| 332 |
document.getElementById('soft-drink-name').textContent = itemName;
|
| 333 |
+
document.getElementById('soft-drink-price').textContent = `$${itemPrice}`;
|
| 334 |
document.getElementById('soft-drink-quantity').value = '1';
|
| 335 |
document.getElementById('soft-drink-image').src = itemImage || '/static/placeholder.jpg';
|
| 336 |
|
| 337 |
const modal = new bootstrap.Modal(document.getElementById('softDrinkModal'));
|
| 338 |
modal.show();
|
| 339 |
}
|
| 340 |
+
|
| 341 |
function addSoftDrinkToCart() {
|
| 342 |
if (!currentSoftDrinkButton) return;
|
| 343 |
|
|
|
|
| 363 |
|
| 364 |
fetch('/cart/add', {
|
| 365 |
method: 'POST',
|
| 366 |
+
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
|
|
| 367 |
body: JSON.stringify(cartPayload)
|
| 368 |
})
|
| 369 |
.then(response => response.json())
|
|
|
|
| 388 |
modal.hide();
|
| 389 |
});
|
| 390 |
}
|
| 391 |
+
|
| 392 |
function updateCartUI(cart) {
|
| 393 |
if (!Array.isArray(cart)) {
|
| 394 |
console.error('Invalid cart data:', cart);
|
|
|
|
| 406 |
}
|
| 407 |
|
| 408 |
window.most_common_addons = {{ most_common_addons | tojson }};
|
| 409 |
+
|
| 410 |
function showItemDetails(name, price, image, description, section, selectedCategory) {
|
| 411 |
document.getElementById('modal-name').innerText = name;
|
| 412 |
baseItemPrice = parseFloat(price) || 0;
|
|
|
|
| 415 |
modalImg.src = image || '/static/placeholder.jpg';
|
| 416 |
document.getElementById('modal-description').innerText = description || 'No description available.';
|
| 417 |
document.getElementById('addons-list').innerHTML = '';
|
|
|
|
| 418 |
document.getElementById('modal-instructions').value = '';
|
| 419 |
const modalSectionEl = document.getElementById('modal-section');
|
| 420 |
modalSectionEl.setAttribute('data-section', section);
|
| 421 |
modalSectionEl.setAttribute('data-category', selectedCategory);
|
| 422 |
document.getElementById('quantityInput').value = 1;
|
| 423 |
+
|
| 424 |
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
| 425 |
.then(response => response.json())
|
| 426 |
.then(data => {
|
| 427 |
const addonsList = document.getElementById('addons-list');
|
|
|
|
|
|
|
| 428 |
if (!data.success || !data.addons || data.addons.length === 0) {
|
| 429 |
addonsList.innerHTML = '<p>No customization options available.</p>';
|
| 430 |
return;
|
|
|
|
| 454 |
sectionDiv.appendChild(optionsContainer);
|
| 455 |
addonsList.appendChild(sectionDiv);
|
| 456 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
document.querySelectorAll('.addon-option').forEach(checkbox => {
|
| 458 |
checkbox.addEventListener('change', updateModalPrice);
|
| 459 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
})
|
| 461 |
.catch(err => {
|
| 462 |
console.error('Error fetching add-ons:', err);
|
|
|
|
| 463 |
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
| 464 |
});
|
| 465 |
}
|
| 466 |
+
|
| 467 |
function addToCartFromModal() {
|
| 468 |
if (isProcessingRequest) return;
|
| 469 |
isProcessingRequest = true;
|
| 470 |
+
|
| 471 |
const modalSectionEl = document.getElementById('modal-section');
|
| 472 |
const section = modalSectionEl.getAttribute('data-section');
|
| 473 |
const selectedCategory = modalSectionEl.getAttribute('data-category');
|
|
|
|
| 482 |
name: addon.getAttribute('data-name'),
|
| 483 |
price: parseFloat(addon.getAttribute('data-price')) || 0
|
| 484 |
}));
|
| 485 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
const cartPayload = {
|
| 487 |
itemName: itemName,
|
| 488 |
itemPrice: itemPrice,
|
|
|
|
| 493 |
instructions: instructions,
|
| 494 |
quantity: quantity
|
| 495 |
};
|
| 496 |
+
|
| 497 |
fetch('/cart/add', {
|
| 498 |
method: 'POST',
|
| 499 |
+
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
|
|
| 500 |
body: JSON.stringify(cartPayload)
|
| 501 |
})
|
| 502 |
.then(response => response.json())
|
|
|
|
| 524 |
isProcessingRequest = false;
|
| 525 |
});
|
| 526 |
}
|
| 527 |
+
|
| 528 |
function handleToggle(source) {
|
| 529 |
const form = document.getElementById("filter-form");
|
| 530 |
const veg = document.getElementById("veg-toggle");
|
|
|
|
| 538 |
veg.checked = false;
|
| 539 |
}
|
| 540 |
}
|
|
|
|
|
|
|
|
|
|
| 541 |
form.submit();
|
| 542 |
}
|
| 543 |
|
|
|
|
| 553 |
dropdownMenu.style.display = 'none';
|
| 554 |
}
|
| 555 |
});
|
| 556 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
const searchBar = document.getElementById('searchBar');
|
| 558 |
searchBar.addEventListener('click', function () {
|
| 559 |
window.location.href = '/search';
|
| 560 |
});
|
| 561 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
fetch('/cart/get')
|
| 563 |
+
.then(response => response.json())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 564 |
.then(data => {
|
| 565 |
if (data.success) {
|
| 566 |
updateCartUI(data.cart);
|
|
|
|
| 575 |
const cart = getCartLocalStorage();
|
| 576 |
updateCartUI(cart);
|
| 577 |
});
|
| 578 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
const decreaseBtn = document.getElementById('decreaseQuantity');
|
| 580 |
const increaseBtn = document.getElementById('increaseQuantity');
|
| 581 |
const quantityInput = document.getElementById('quantityInput');
|
|
|
|
| 590 |
quantityInput.value = quantity;
|
| 591 |
});
|
| 592 |
});
|
| 593 |
+
|
| 594 |
let currentStep = 'greeting';
|
| 595 |
let conversation = [];
|
| 596 |
let selectedIngredients = [];
|
| 597 |
let selectedMenuItem = null;
|
|
|
|
| 598 |
const userName = "{{ user_name }}";
|
| 599 |
+
|
| 600 |
window.onload = function() {
|
| 601 |
if (userName) {
|
| 602 |
conversation.push({ role: 'bot', message: `Nice to meet you, ${userName}! 😊 Let's create your perfect meal! What type of food would you prefer?` });
|
|
|
|
| 610 |
displayConversation();
|
| 611 |
}
|
| 612 |
};
|
| 613 |
+
|
| 614 |
+
function displayConversation() {
|
| 615 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 616 |
+
chatMessages.innerHTML = '';
|
| 617 |
+
conversation.forEach(msg => {
|
| 618 |
+
addMessage(msg.role, msg.message);
|
| 619 |
+
});
|
| 620 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
function addMessage(role, message) {
|
| 624 |
const chatMessages = document.getElementById('chatMessages');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 625 |
const messageDiv = document.createElement('div');
|
| 626 |
messageDiv.className = role === 'bot' ? 'bot-message' : 'user-message';
|
| 627 |
messageDiv.textContent = message;
|
| 628 |
chatMessages.appendChild(messageDiv);
|
| 629 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 630 |
}
|
| 631 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
function sendMessage() {
|
| 633 |
const userInput = document.getElementById('userInput').value.trim();
|
| 634 |
if (userInput) {
|
|
|
|
| 636 |
conversation.push({ role: 'user', message: userInput });
|
| 637 |
document.getElementById('userInput').value = '';
|
| 638 |
setTimeout(() => handleResponse(userInput), 500);
|
|
|
|
|
|
|
| 639 |
}
|
| 640 |
}
|
| 641 |
+
|
| 642 |
function handleResponse(userInput) {
|
|
|
|
| 643 |
let botResponse = '';
|
| 644 |
let options = [];
|
| 645 |
+
const lastMessage = userInput.toLowerCase();
|
| 646 |
+
|
| 647 |
+
if (currentStep === 'greeting' && !userName) {
|
| 648 |
+
currentStep = 'food_type';
|
| 649 |
+
botResponse = `Nice to meet you, ${userInput}! 😊 What type of food would you prefer?`;
|
| 650 |
+
options = [
|
| 651 |
+
{ text: 'Vegetarian', class: 'green' },
|
| 652 |
+
{ text: 'Non-Vegetarian', class: 'red' }
|
| 653 |
+
];
|
| 654 |
} else if (lastMessage.includes('vegetarian')) {
|
| 655 |
+
currentStep = 'ingredients';
|
|
|
|
| 656 |
botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
|
| 657 |
fetchIngredients('vegetarian');
|
| 658 |
return;
|
| 659 |
+
} else if (lastMessage.includes('non-vegetarian')) {
|
| 660 |
+
currentStep = 'ingredients';
|
| 661 |
+
botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
|
| 662 |
+
fetchIngredients('non-vegetarian');
|
|
|
|
| 663 |
return;
|
| 664 |
} else if (lastMessage.includes('yes') && selectedMenuItem) {
|
| 665 |
+
currentStep = 'customize';
|
| 666 |
botResponse = 'Here are some ingredients to customize your dish:';
|
| 667 |
+
fetchIngredientsForCustomization('both');
|
| 668 |
return;
|
| 669 |
} else if (lastMessage.includes('no') && selectedMenuItem) {
|
| 670 |
submitCustomizationIngredients();
|
| 671 |
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 672 |
}
|
| 673 |
+
|
| 674 |
addMessage('bot', botResponse);
|
| 675 |
if (options.length > 0) {
|
| 676 |
displayOptions(options);
|
| 677 |
}
|
|
|
|
| 678 |
}
|
| 679 |
+
|
| 680 |
+
function fetchIngredients(foodPreference) {
|
| 681 |
+
fetch('/get_ingredients', {
|
| 682 |
+
method: 'POST',
|
| 683 |
+
headers: { 'Content-Type': 'application/json' },
|
| 684 |
+
body: JSON.stringify({ dietary_preference: foodPreference })
|
| 685 |
+
})
|
| 686 |
+
.then(response => response.json())
|
| 687 |
+
.then(data => {
|
| 688 |
+
if (data.error) {
|
| 689 |
+
addMessage('bot', `Error: ${data.error}`);
|
| 690 |
+
} else {
|
| 691 |
+
const ingredients = data.ingredients || [];
|
| 692 |
+
displayIngredientsList(ingredients);
|
| 693 |
+
}
|
| 694 |
+
})
|
| 695 |
+
.catch(error => {
|
| 696 |
+
addMessage('bot', `Error fetching ingredients: ${error.message}`);
|
| 697 |
+
});
|
| 698 |
}
|
| 699 |
+
|
| 700 |
function fetchIngredientsForCustomization(foodPreference) {
|
| 701 |
fetch('/get_ingredients', {
|
| 702 |
method: 'POST',
|
| 703 |
headers: { 'Content-Type': 'application/json' },
|
| 704 |
body: JSON.stringify({ dietary_preference: foodPreference })
|
| 705 |
})
|
| 706 |
+
.then(response => response.json())
|
| 707 |
+
.then(data => {
|
| 708 |
+
if (data.error) {
|
| 709 |
+
addMessage('bot', `Error: ${data.error}`);
|
| 710 |
+
} else {
|
| 711 |
+
const ingredients = data.ingredients || [];
|
| 712 |
+
addMessage('bot', 'Please select ingredients to customize:');
|
| 713 |
+
displayCustomizationIngredients(ingredients);
|
| 714 |
+
}
|
| 715 |
+
})
|
| 716 |
+
.catch(error => {
|
| 717 |
+
addMessage('bot', `Error fetching ingredients: ${error.message}`);
|
| 718 |
+
});
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
function displayIngredientsList(ingredients) {
|
| 722 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 723 |
+
let ingredientsList = document.querySelector('.ingredients-list');
|
| 724 |
+
if (!ingredientsList) {
|
| 725 |
+
ingredientsList = document.createElement('div');
|
| 726 |
+
ingredientsList.className = 'ingredients-list';
|
| 727 |
+
chatMessages.appendChild(ingredientsList);
|
| 728 |
+
} else {
|
| 729 |
+
ingredientsList.innerHTML = '';
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
ingredients.forEach(ingredient => {
|
| 733 |
+
const item = document.createElement('div');
|
| 734 |
+
item.className = 'ingredient-item';
|
| 735 |
+
const img = document.createElement('img');
|
| 736 |
+
img.src = ingredient.image_url || 'https://via.placeholder.com/120';
|
| 737 |
+
img.alt = ingredient.name;
|
| 738 |
+
const name = document.createElement('div');
|
| 739 |
+
name.textContent = ingredient.name;
|
| 740 |
+
const button = document.createElement('button');
|
| 741 |
+
button.textContent = 'Add';
|
| 742 |
+
button.onclick = () => {
|
| 743 |
+
if (!selectedIngredients.some(i => i.name === ingredient.name)) {
|
| 744 |
+
selectedIngredients.push(ingredient);
|
| 745 |
+
displaySelectedIngredients();
|
| 746 |
}
|
| 747 |
+
};
|
| 748 |
+
item.appendChild(img);
|
| 749 |
+
item.appendChild(name);
|
| 750 |
+
item.appendChild(button);
|
| 751 |
+
ingredientsList.appendChild(item);
|
| 752 |
+
});
|
| 753 |
+
|
| 754 |
+
if (selectedIngredients.length > 0) {
|
| 755 |
+
let submitButton = document.querySelector('.submit-button');
|
| 756 |
+
if (!submitButton) {
|
| 757 |
+
submitButton = document.createElement('button');
|
| 758 |
+
submitButton.className = 'submit-button';
|
| 759 |
+
submitButton.textContent = 'Submit Ingredients';
|
| 760 |
+
submitButton.onclick = submitIngredients;
|
| 761 |
+
chatMessages.appendChild(submitButton);
|
| 762 |
+
}
|
| 763 |
+
}
|
| 764 |
}
|
| 765 |
+
|
| 766 |
function displayCustomizationIngredients(ingredients) {
|
| 767 |
const chatMessages = document.getElementById('chatMessages');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 768 |
let ingredientsList = document.querySelector('.customization-ingredients-list');
|
| 769 |
if (!ingredientsList) {
|
| 770 |
ingredientsList = document.createElement('div');
|
|
|
|
| 773 |
} else {
|
| 774 |
ingredientsList.innerHTML = '';
|
| 775 |
}
|
| 776 |
+
|
| 777 |
ingredients.forEach(ingredient => {
|
| 778 |
const item = document.createElement('div');
|
| 779 |
item.className = 'ingredient-item';
|
|
|
|
| 785 |
const button = document.createElement('button');
|
| 786 |
button.textContent = 'Add';
|
| 787 |
button.onclick = () => {
|
| 788 |
+
if (!selectedIngredients.some(i => i.name === ingredient.name)) {
|
| 789 |
selectedIngredients.push({ name: ingredient.name, image_url: ingredient.image_url });
|
| 790 |
displaySelectedCustomizationIngredients();
|
| 791 |
}
|
|
|
|
| 795 |
item.appendChild(button);
|
| 796 |
ingredientsList.appendChild(item);
|
| 797 |
});
|
| 798 |
+
|
| 799 |
displaySelectedCustomizationIngredients();
|
| 800 |
}
|
| 801 |
+
|
| 802 |
+
function displaySelectedIngredients() {
|
| 803 |
const chatMessages = document.getElementById('chatMessages');
|
| 804 |
+
let selectedArea = document.querySelector('.selected-ingredients');
|
| 805 |
+
if (!selectedArea) {
|
| 806 |
+
selectedArea = document.createElement('div');
|
| 807 |
+
selectedArea.className = 'selected-ingredients';
|
| 808 |
+
chatMessages.appendChild(selectedArea);
|
| 809 |
+
} else {
|
| 810 |
+
selectedArea.innerHTML = '';
|
| 811 |
}
|
| 812 |
+
|
| 813 |
+
selectedIngredients.forEach(ingredient => {
|
| 814 |
+
const div = document.createElement('div');
|
| 815 |
+
div.textContent = ingredient.name;
|
| 816 |
+
const removeButton = document.createElement('button');
|
| 817 |
+
removeButton.textContent = 'X';
|
| 818 |
+
removeButton.className = 'remove-button';
|
| 819 |
+
removeButton.onclick = () => {
|
| 820 |
+
selectedIngredients = selectedIngredients.filter(i => i.name !== ingredient.name);
|
| 821 |
+
displaySelectedIngredients();
|
| 822 |
+
};
|
| 823 |
+
div.appendChild(removeButton);
|
| 824 |
+
selectedArea.appendChild(div);
|
| 825 |
+
});
|
| 826 |
+
}
|
| 827 |
+
|
| 828 |
+
function displaySelectedCustomizationIngredients() {
|
| 829 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 830 |
let selectedArea = document.querySelector('.selected-customization-ingredients');
|
| 831 |
if (!selectedArea) {
|
| 832 |
selectedArea = document.createElement('div');
|
|
|
|
| 835 |
} else {
|
| 836 |
selectedArea.innerHTML = '';
|
| 837 |
}
|
| 838 |
+
|
| 839 |
const selectedIngredientsText = selectedIngredients.length > 0
|
| 840 |
+
? `${selectedMenuItem.name} with ${selectedIngredients.map(i => i.name).join(', ')}`
|
| 841 |
: selectedMenuItem.name;
|
| 842 |
const ingredientsDiv = document.createElement('div');
|
| 843 |
ingredientsDiv.textContent = selectedIngredientsText;
|
| 844 |
selectedArea.appendChild(ingredientsDiv);
|
| 845 |
+
|
| 846 |
selectedIngredients.forEach(ingredient => {
|
| 847 |
const div = document.createElement('div');
|
| 848 |
div.textContent = ingredient.name;
|
| 849 |
const removeButton = document.createElement('button');
|
| 850 |
removeButton.textContent = 'X';
|
| 851 |
+
removeButton.className = 'remove-button';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 852 |
removeButton.onclick = () => {
|
| 853 |
+
selectedIngredients = selectedIngredients.filter(i => i.name !== ingredient.name);
|
| 854 |
displaySelectedCustomizationIngredients();
|
| 855 |
};
|
| 856 |
div.appendChild(removeButton);
|
| 857 |
selectedArea.appendChild(div);
|
| 858 |
});
|
| 859 |
+
|
| 860 |
if (!document.querySelector('.submit-customization-button')) {
|
| 861 |
const textarea = document.createElement('textarea');
|
| 862 |
textarea.placeholder = 'Enter any special instructions...';
|
|
|
|
| 868 |
selectedArea.appendChild(submitButton);
|
| 869 |
}
|
| 870 |
}
|
| 871 |
+
|
| 872 |
+
function submitIngredients() {
|
| 873 |
+
if (selectedIngredients.length === 0) {
|
| 874 |
+
addMessage('bot', 'No ingredients selected. Please choose some ingredients.');
|
| 875 |
+
return;
|
| 876 |
+
}
|
| 877 |
+
const ingredientNames = selectedIngredients.map(i => i.name.toLowerCase()).join(' ');
|
| 878 |
+
fetchMenuItems({ ingredient_names: ingredientNames });
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
function fetchMenuItems(params) {
|
| 882 |
+
fetch('/get_menu_items', {
|
| 883 |
+
method: 'POST',
|
| 884 |
+
headers: { 'Content-Type': 'application/json' },
|
| 885 |
+
body: JSON.stringify(params)
|
| 886 |
+
})
|
| 887 |
+
.then(response => response.json())
|
| 888 |
+
.then(data => {
|
| 889 |
+
if (data.error) {
|
| 890 |
+
addMessage('bot', `Error: ${data.error}`);
|
| 891 |
+
} else {
|
| 892 |
+
const menuItems = data.menu_items || [];
|
| 893 |
+
addMessage('bot', 'Here are some dishes based on your selection:');
|
| 894 |
+
displayMenuItems(menuItems);
|
| 895 |
+
}
|
| 896 |
+
})
|
| 897 |
+
.catch(error => {
|
| 898 |
+
addMessage('bot', `Error fetching menu items: ${error.message}`);
|
| 899 |
+
});
|
| 900 |
+
}
|
| 901 |
+
|
| 902 |
+
function displayMenuItems(menuItems) {
|
| 903 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 904 |
+
let menuItemsList = document.querySelector('.menu-items-list');
|
| 905 |
+
if (!menuItemsList) {
|
| 906 |
+
menuItemsList = document.createElement('div');
|
| 907 |
+
menuItemsList.className = 'menu-items-list';
|
| 908 |
+
chatMessages.appendChild(menuItemsList);
|
| 909 |
+
} else {
|
| 910 |
+
menuItemsList.innerHTML = '';
|
| 911 |
+
}
|
| 912 |
+
|
| 913 |
+
menuItems.forEach(item => {
|
| 914 |
+
const menuItem = document.createElement('div');
|
| 915 |
+
menuItem.className = 'menu-item';
|
| 916 |
+
const img = document.createElement('img');
|
| 917 |
+
img.src = item.image_url || 'https://via.placeholder.com/120';
|
| 918 |
+
img.alt = item.name;
|
| 919 |
+
const name = document.createElement('div');
|
| 920 |
+
name.textContent = item.name;
|
| 921 |
+
const button = document.createElement('button');
|
| 922 |
+
button.textContent = 'Select';
|
| 923 |
+
button.onclick = () => {
|
| 924 |
+
selectedMenuItem = item;
|
| 925 |
+
addMessage('bot', `Great selection! Would you like to customize your dish further?`);
|
| 926 |
+
displayOptions([
|
| 927 |
+
{ text: 'Yes', class: 'green' },
|
| 928 |
+
{ text: 'No', class: 'red' }
|
| 929 |
+
]);
|
| 930 |
+
};
|
| 931 |
+
menuItem.appendChild(img);
|
| 932 |
+
menuItem.appendChild(name);
|
| 933 |
+
menuItem.appendChild(button);
|
| 934 |
+
menuItemsList.appendChild(menuItem);
|
| 935 |
+
});
|
| 936 |
+
}
|
| 937 |
+
|
| 938 |
function submitCustomizationIngredients() {
|
| 939 |
if (!selectedMenuItem) {
|
| 940 |
addMessage('bot', 'No dish selected. Please choose a dish first.');
|
| 941 |
return;
|
| 942 |
}
|
| 943 |
+
|
| 944 |
const textarea = document.querySelector('.selected-customization-ingredients textarea');
|
| 945 |
const instructions = textarea ? textarea.value.trim() : '';
|
| 946 |
+
const ingredientsList = selectedIngredients.map(i => i.name).join(', ');
|
| 947 |
+
const itemPrice = 10.00; // Fixed price for custom dishes
|
| 948 |
const itemImage = selectedMenuItem.image_url || 'https://via.placeholder.com/120';
|
| 949 |
+
|
| 950 |
const customDishPayload = {
|
| 951 |
menu_item: selectedMenuItem,
|
| 952 |
ingredients: selectedIngredients,
|
|
|
|
| 954 |
itemPrice: itemPrice,
|
| 955 |
itemImage: itemImage
|
| 956 |
};
|
| 957 |
+
|
| 958 |
+
// Save the custom dish in Salesforce
|
| 959 |
fetch('/menu/save_custom_dish', {
|
| 960 |
method: 'POST',
|
| 961 |
headers: { 'Content-Type': 'application/json' },
|
|
|
|
| 966 |
if (!data.success) {
|
| 967 |
throw new Error(data.error || 'Failed to save custom dish');
|
| 968 |
}
|
| 969 |
+
|
| 970 |
+
// Add to cart
|
| 971 |
const cartPayload = {
|
| 972 |
itemName: selectedMenuItem.name,
|
| 973 |
itemPrice: itemPrice,
|
|
|
|
| 979 |
quantity: 1,
|
| 980 |
ingredients: ingredientsList
|
| 981 |
};
|
| 982 |
+
|
| 983 |
return fetch('/cart/add', {
|
| 984 |
method: 'POST',
|
| 985 |
headers: { 'Content-Type': 'application/json' },
|
|
|
|
| 991 |
if (data.success) {
|
| 992 |
addMessage('bot', 'Customization submitted successfully! Item added to cart.');
|
| 993 |
updateCartUI(data.cart);
|
| 994 |
+
// Redirect to menu page to see the custom dish
|
|
|
|
| 995 |
window.location.href = '/menu?category=Customized+Dish';
|
| 996 |
} else {
|
| 997 |
throw new Error(data.error || 'Failed to add item to cart');
|
|
|
|
| 1001 |
addMessage('bot', `Error: ${error.message}`);
|
| 1002 |
});
|
| 1003 |
}
|
| 1004 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1005 |
function displayOptions(options) {
|
| 1006 |
const chatMessages = document.getElementById('chatMessages');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1007 |
options.forEach(opt => {
|
| 1008 |
const button = document.createElement('button');
|
| 1009 |
button.textContent = opt.text;
|
|
|
|
| 1011 |
button.onclick = () => {
|
| 1012 |
addMessage('user', opt.text);
|
| 1013 |
conversation.push({ role: 'user', message: opt.text });
|
| 1014 |
+
handleResponse(opt.text);
|
|
|
|
| 1015 |
};
|
| 1016 |
chatMessages.appendChild(button);
|
| 1017 |
});
|
|
|
|
| 1018 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
|
|
|
| 1019 |
}
|
| 1020 |
|
| 1021 |
document.getElementById('userInput').addEventListener('keypress', function(e) {
|
|
|
|
| 1023 |
sendMessage();
|
| 1024 |
}
|
| 1025 |
});
|
|
|
|
| 1026 |
</script>
|
| 1027 |
</body>
|
| 1028 |
</html>
|