Update templates/search.html
Browse files- templates/search.html +71 -33
templates/search.html
CHANGED
@@ -132,7 +132,7 @@
|
|
132 |
justify-content: center;
|
133 |
padding: 0;
|
134 |
}
|
135 |
-
/*
|
136 |
.modal-fullscreen {
|
137 |
width: 100vw;
|
138 |
max-width: none;
|
@@ -143,35 +143,46 @@
|
|
143 |
height: 100%;
|
144 |
border: none;
|
145 |
border-radius: 0;
|
|
|
146 |
}
|
147 |
.modal-body {
|
148 |
-
|
149 |
overflow-y: auto;
|
150 |
-
padding: 15px;
|
151 |
-
text-align: center;
|
152 |
}
|
153 |
.modal-footer {
|
|
|
154 |
display: flex;
|
155 |
-
align-items: center;
|
156 |
justify-content: space-between;
|
157 |
-
|
158 |
-
|
159 |
-
.modal-footer .btn-primary {
|
160 |
-
width: auto;
|
161 |
-
padding: 10px 20px;
|
162 |
-
height: 40px;
|
163 |
}
|
164 |
.addon-section {
|
165 |
background-color: #fff;
|
166 |
border: 2px solid #ffa500;
|
167 |
border-radius: 8px;
|
168 |
padding: 12px;
|
169 |
-
margin-bottom:
|
170 |
}
|
171 |
.addon-section h6 {
|
172 |
margin-bottom: 10px;
|
173 |
font-size: 1.1rem;
|
174 |
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
}
|
176 |
</style>
|
177 |
</head>
|
@@ -210,7 +221,7 @@
|
|
210 |
<button class="btn btn-primary"
|
211 |
data-bs-toggle="modal"
|
212 |
data-bs-target="#itemModal"
|
213 |
-
onclick="showItemDetails('{{ item.Name | e }}', '{{ item.Price__c }}', '{{ item.Image2__c | default(item.Image1__c) | default('/static/placeholder.jpg') }}', '{{ item.Description__c | e }}', '{{ item.IngredientsInfo__c | default('Not specified') | e }}', '{{ item.NutritionalInfo__c | default('Not available') | e }}', '{{ item.Allergens__c | default('None listed') | e }}', '{{ item.Section__c | e }}', '
|
214 |
ADD
|
215 |
</button>
|
216 |
</div>
|
@@ -220,7 +231,7 @@
|
|
220 |
</div>
|
221 |
</div>
|
222 |
|
223 |
-
<!-- Item Modal (
|
224 |
<div class="modal fade" id="itemModal" tabindex="-1" aria-labelledby="itemModalLabel" aria-hidden="true">
|
225 |
<div class="modal-dialog modal-fullscreen">
|
226 |
<div class="modal-content">
|
@@ -232,26 +243,26 @@
|
|
232 |
<img id="modal-img" class="img-fluid rounded mb-3 d-block mx-auto" alt="Item Image" style="max-height: 200px; object-fit: cover;">
|
233 |
<h5 id="modal-name" class="fw-bold text-center"></h5>
|
234 |
<p id="modal-price" class="text-muted text-center"></p>
|
235 |
-
<p id="modal-description" class="text-secondary"></p>
|
236 |
-
<div class="nutritional-info">
|
237 |
<strong>Ingredients:</strong> <span id="modal-ingredients"></span><br>
|
238 |
<strong>Nutrition:</strong> <span id="modal-nutrition"></span><br>
|
239 |
<strong>Allergens:</strong> <span id="modal-allergens"></span>
|
240 |
</div>
|
241 |
<div id="modal-addons" class="modal-addons mt-4">
|
242 |
-
<h6>Customization Options</h6>
|
243 |
<div id="addons-list" class="addons-container">Loading customization options...</div>
|
244 |
</div>
|
245 |
<div class="mt-4">
|
246 |
-
<h6>Custom Request</h6>
|
247 |
<textarea id="modal-instructions" class="form-control" placeholder="Enter any special instructions here..."></textarea>
|
248 |
</div>
|
249 |
-
<span id="modal-section" data-section="" data-category="" style="display: none;"></span>
|
250 |
</div>
|
251 |
-
<div class="modal-footer
|
252 |
-
<div class="
|
253 |
<button type="button" class="btn btn-outline-secondary" id="decreaseQuantity">-</button>
|
254 |
-
<input type="text" class="form-control
|
255 |
<button type="button" class="btn btn-outline-secondary" id="increaseQuantity">+</button>
|
256 |
</div>
|
257 |
<button type="button" class="btn btn-primary" onclick="addToCartFromModal()">Add to Cart</button>
|
@@ -350,10 +361,10 @@
|
|
350 |
quantityInput.value = currentQuantity;
|
351 |
});
|
352 |
|
353 |
-
// Item details and cart functionality
|
354 |
-
window.showItemDetails = function(name, price, image, description, ingredients, nutrition, allergens, section,
|
355 |
document.getElementById('modal-name').innerText = name;
|
356 |
-
document.getElementById('modal-price').innerText = `$${price}`;
|
357 |
const modalImg = document.getElementById('modal-img');
|
358 |
modalImg.src = image || '/static/placeholder.jpg';
|
359 |
document.getElementById('modal-description').innerText = description || 'No description available.';
|
@@ -364,9 +375,11 @@
|
|
364 |
document.getElementById('modal-instructions').value = '';
|
365 |
const modalSectionEl = document.getElementById('modal-section');
|
366 |
modalSectionEl.setAttribute('data-section', section);
|
367 |
-
modalSectionEl.setAttribute('data-category',
|
|
|
368 |
document.getElementById('quantityInput').value = 1;
|
369 |
|
|
|
370 |
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
371 |
.then(response => response.json())
|
372 |
.then(data => {
|
@@ -385,17 +398,32 @@
|
|
385 |
const optionsContainer = document.createElement('div');
|
386 |
addon.options.forEach((option, index) => {
|
387 |
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
|
|
388 |
const listItem = document.createElement('div');
|
389 |
listItem.classList.add('form-check');
|
390 |
listItem.innerHTML = `
|
391 |
-
<input type="
|
392 |
-
|
|
|
|
|
393 |
<label class="form-check-label" for="${optionId}">
|
394 |
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
395 |
</label>
|
396 |
`;
|
397 |
optionsContainer.appendChild(listItem);
|
398 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
sectionDiv.appendChild(optionsContainer);
|
400 |
addonsList.appendChild(sectionDiv);
|
401 |
});
|
@@ -414,7 +442,8 @@
|
|
414 |
const quantity = parseInt(document.getElementById('quantityInput').value);
|
415 |
const modalSectionEl = document.getElementById('modal-section');
|
416 |
const section = modalSectionEl.getAttribute('data-section');
|
417 |
-
const
|
|
|
418 |
|
419 |
const addons = [];
|
420 |
document.querySelectorAll('.addon-option:checked').forEach(checkbox => {
|
@@ -429,7 +458,7 @@
|
|
429 |
itemPrice: itemPrice,
|
430 |
itemImage: itemImage,
|
431 |
section: section,
|
432 |
-
category:
|
433 |
addons: addons,
|
434 |
instructions: instructions,
|
435 |
quantity: quantity
|
@@ -442,13 +471,22 @@
|
|
442 |
},
|
443 |
body: JSON.stringify(cartPayload)
|
444 |
})
|
445 |
-
.then(response =>
|
|
|
|
|
|
|
|
|
|
|
446 |
.then(data => {
|
447 |
if (data.success) {
|
448 |
alert('Item added to cart successfully!');
|
449 |
const modal = bootstrap.Modal.getInstance(document.getElementById('itemModal'));
|
450 |
modal.hide();
|
451 |
-
//
|
|
|
|
|
|
|
|
|
452 |
} else {
|
453 |
console.error('Failed to add item to cart:', data.error);
|
454 |
alert(data.error || 'Failed to add item to cart.');
|
@@ -456,7 +494,7 @@
|
|
456 |
})
|
457 |
.catch(err => {
|
458 |
console.error('Error adding item to cart:', err);
|
459 |
-
alert('Error adding item to cart.');
|
460 |
});
|
461 |
};
|
462 |
});
|
|
|
132 |
justify-content: center;
|
133 |
padding: 0;
|
134 |
}
|
135 |
+
/* Modal styling from menu.html */
|
136 |
.modal-fullscreen {
|
137 |
width: 100vw;
|
138 |
max-width: none;
|
|
|
143 |
height: 100%;
|
144 |
border: none;
|
145 |
border-radius: 0;
|
146 |
+
background-color: #fdf4e3;
|
147 |
}
|
148 |
.modal-body {
|
149 |
+
padding: 20px;
|
150 |
overflow-y: auto;
|
|
|
|
|
151 |
}
|
152 |
.modal-footer {
|
153 |
+
padding: 15px;
|
154 |
display: flex;
|
|
|
155 |
justify-content: space-between;
|
156 |
+
align-items: center;
|
157 |
+
border-top: none;
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
.addon-section {
|
160 |
background-color: #fff;
|
161 |
border: 2px solid #ffa500;
|
162 |
border-radius: 8px;
|
163 |
padding: 12px;
|
164 |
+
margin-bottom: 15px;
|
165 |
}
|
166 |
.addon-section h6 {
|
167 |
margin-bottom: 10px;
|
168 |
font-size: 1.1rem;
|
169 |
font-weight: bold;
|
170 |
+
color: #333;
|
171 |
+
}
|
172 |
+
.form-check {
|
173 |
+
margin-bottom: 8px;
|
174 |
+
}
|
175 |
+
.form-check-input {
|
176 |
+
margin-right: 10px;
|
177 |
+
}
|
178 |
+
.quantity-controls {
|
179 |
+
display: flex;
|
180 |
+
align-items: center;
|
181 |
+
gap: 10px;
|
182 |
+
}
|
183 |
+
.quantity-controls input {
|
184 |
+
width: 50px;
|
185 |
+
text-align: center;
|
186 |
}
|
187 |
</style>
|
188 |
</head>
|
|
|
221 |
<button class="btn btn-primary"
|
222 |
data-bs-toggle="modal"
|
223 |
data-bs-target="#itemModal"
|
224 |
+
onclick="showItemDetails('{{ item.Name | e }}', '{{ item.Price__c }}', '{{ item.Image2__c | default(item.Image1__c) | default('/static/placeholder.jpg') }}', '{{ item.Description__c | e }}', '{{ item.IngredientsInfo__c | default('Not specified') | e }}', '{{ item.NutritionalInfo__c | default('Not available') | e }}', '{{ item.Allergens__c | default('None listed') | e }}', '{{ item.Section__c | e }}', '{{ item.Veg_NonVeg__c | default('both') | e }}', '{{ 'true' if item.is_menu_item else 'false' }}')">
|
225 |
ADD
|
226 |
</button>
|
227 |
</div>
|
|
|
231 |
</div>
|
232 |
</div>
|
233 |
|
234 |
+
<!-- Item Modal (Exact replica from menu.html) -->
|
235 |
<div class="modal fade" id="itemModal" tabindex="-1" aria-labelledby="itemModalLabel" aria-hidden="true">
|
236 |
<div class="modal-dialog modal-fullscreen">
|
237 |
<div class="modal-content">
|
|
|
243 |
<img id="modal-img" class="img-fluid rounded mb-3 d-block mx-auto" alt="Item Image" style="max-height: 200px; object-fit: cover;">
|
244 |
<h5 id="modal-name" class="fw-bold text-center"></h5>
|
245 |
<p id="modal-price" class="text-muted text-center"></p>
|
246 |
+
<p id="modal-description" class="text-secondary text-center"></p>
|
247 |
+
<div class="nutritional-info text-center">
|
248 |
<strong>Ingredients:</strong> <span id="modal-ingredients"></span><br>
|
249 |
<strong>Nutrition:</strong> <span id="modal-nutrition"></span><br>
|
250 |
<strong>Allergens:</strong> <span id="modal-allergens"></span>
|
251 |
</div>
|
252 |
<div id="modal-addons" class="modal-addons mt-4">
|
253 |
+
<h6 class="text-center">Customization Options</h6>
|
254 |
<div id="addons-list" class="addons-container">Loading customization options...</div>
|
255 |
</div>
|
256 |
<div class="mt-4">
|
257 |
+
<h6 class="text-center">Custom Request</h6>
|
258 |
<textarea id="modal-instructions" class="form-control" placeholder="Enter any special instructions here..."></textarea>
|
259 |
</div>
|
260 |
+
<span id="modal-section" data-section="" data-category="" data-is-menu-item="" style="display: none;"></span>
|
261 |
</div>
|
262 |
+
<div class="modal-footer">
|
263 |
+
<div class="quantity-controls">
|
264 |
<button type="button" class="btn btn-outline-secondary" id="decreaseQuantity">-</button>
|
265 |
+
<input type="text" class="form-control" id="quantityInput" value="1" readonly>
|
266 |
<button type="button" class="btn btn-outline-secondary" id="increaseQuantity">+</button>
|
267 |
</div>
|
268 |
<button type="button" class="btn btn-primary" onclick="addToCartFromModal()">Add to Cart</button>
|
|
|
361 |
quantityInput.value = currentQuantity;
|
362 |
});
|
363 |
|
364 |
+
// Item details and cart functionality (exact from menu.html)
|
365 |
+
window.showItemDetails = function(name, price, image, description, ingredients, nutrition, allergens, section, vegNonVeg, isMenuItem) {
|
366 |
document.getElementById('modal-name').innerText = name;
|
367 |
+
document.getElementById('modal-price').innerText = `$${parseFloat(price).toFixed(2)}`;
|
368 |
const modalImg = document.getElementById('modal-img');
|
369 |
modalImg.src = image || '/static/placeholder.jpg';
|
370 |
document.getElementById('modal-description').innerText = description || 'No description available.';
|
|
|
375 |
document.getElementById('modal-instructions').value = '';
|
376 |
const modalSectionEl = document.getElementById('modal-section');
|
377 |
modalSectionEl.setAttribute('data-section', section);
|
378 |
+
modalSectionEl.setAttribute('data-category', vegNonVeg === 'Veg' ? 'Veg' : vegNonVeg === 'Non veg' ? 'Non veg' : 'All');
|
379 |
+
modalSectionEl.setAttribute('data-is-menu-item', isMenuItem);
|
380 |
document.getElementById('quantityInput').value = 1;
|
381 |
|
382 |
+
// Fetch customization options from Salesforce
|
383 |
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
384 |
.then(response => response.json())
|
385 |
.then(data => {
|
|
|
398 |
const optionsContainer = document.createElement('div');
|
399 |
addon.options.forEach((option, index) => {
|
400 |
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
401 |
+
const inputType = addon.max_selections === 1 ? 'radio' : 'checkbox';
|
402 |
const listItem = document.createElement('div');
|
403 |
listItem.classList.add('form-check');
|
404 |
listItem.innerHTML = `
|
405 |
+
<input type="${inputType}" class="form-check-input addon-option" id="${optionId}"
|
406 |
+
name="${addon.name}" value="${option}"
|
407 |
+
data-name="${option}" data-group="${addon.name}"
|
408 |
+
data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
409 |
<label class="form-check-label" for="${optionId}">
|
410 |
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
411 |
</label>
|
412 |
`;
|
413 |
optionsContainer.appendChild(listItem);
|
414 |
});
|
415 |
+
if (addon.max_selections > 1) {
|
416 |
+
const inputs = optionsContainer.querySelectorAll('input[type="checkbox"]');
|
417 |
+
inputs.forEach(input => {
|
418 |
+
input.addEventListener('change', function () {
|
419 |
+
const checkedCount = optionsContainer.querySelectorAll('input[type="checkbox"]:checked').length;
|
420 |
+
if (checkedCount > addon.max_selections) {
|
421 |
+
this.checked = false;
|
422 |
+
alert(`You can select up to ${addon.max_selections} options for ${addon.name}.`);
|
423 |
+
}
|
424 |
+
});
|
425 |
+
});
|
426 |
+
}
|
427 |
sectionDiv.appendChild(optionsContainer);
|
428 |
addonsList.appendChild(sectionDiv);
|
429 |
});
|
|
|
442 |
const quantity = parseInt(document.getElementById('quantityInput').value);
|
443 |
const modalSectionEl = document.getElementById('modal-section');
|
444 |
const section = modalSectionEl.getAttribute('data-section');
|
445 |
+
const category = modalSectionEl.getAttribute('data-category');
|
446 |
+
const isMenuItem = modalSectionEl.getAttribute('data-is-menu-item') === 'true';
|
447 |
|
448 |
const addons = [];
|
449 |
document.querySelectorAll('.addon-option:checked').forEach(checkbox => {
|
|
|
458 |
itemPrice: itemPrice,
|
459 |
itemImage: itemImage,
|
460 |
section: section,
|
461 |
+
category: category,
|
462 |
addons: addons,
|
463 |
instructions: instructions,
|
464 |
quantity: quantity
|
|
|
471 |
},
|
472 |
body: JSON.stringify(cartPayload)
|
473 |
})
|
474 |
+
.then(response => {
|
475 |
+
if (!response.ok) {
|
476 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
477 |
+
}
|
478 |
+
return response.json();
|
479 |
+
})
|
480 |
.then(data => {
|
481 |
if (data.success) {
|
482 |
alert('Item added to cart successfully!');
|
483 |
const modal = bootstrap.Modal.getInstance(document.getElementById('itemModal'));
|
484 |
modal.hide();
|
485 |
+
// Update cart UI if you have a cart badge
|
486 |
+
if (data.cart) {
|
487 |
+
console.log('Updated cart:', data.cart);
|
488 |
+
// Add cart badge update logic here if needed
|
489 |
+
}
|
490 |
} else {
|
491 |
console.error('Failed to add item to cart:', data.error);
|
492 |
alert(data.error || 'Failed to add item to cart.');
|
|
|
494 |
})
|
495 |
.catch(err => {
|
496 |
console.error('Error adding item to cart:', err);
|
497 |
+
alert('Error adding item to cart. Please check the console for details.');
|
498 |
});
|
499 |
};
|
500 |
});
|