File size: 12,934 Bytes
cfd7e45
6cca62e
cfd7e45
6cca62e
 
cfd7e45
6cca62e
 
 
 
 
 
 
 
 
f915041
6cca62e
 
 
f915041
6cca62e
 
 
 
 
 
 
f915041
6cca62e
 
 
 
 
 
f915041
6cca62e
 
 
 
f915041
6cca62e
 
 
 
f915041
6cca62e
 
 
 
 
f915041
6cca62e
 
 
f915041
6cca62e
 
 
 
 
 
 
 
f915041
6cca62e
 
 
f915041
6cca62e
 
 
 
f915041
6cca62e
 
 
f915041
6cca62e
 
 
 
 
 
f915041
6cca62e
 
 
 
 
 
 
 
 
 
 
 
 
f915041
6cca62e
 
 
 
f915041
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6cca62e
cfd7e45
 
6cca62e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cfd7e45
6cca62e
 
cfd7e45
6cca62e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f915041
6cca62e
 
 
 
 
 
 
 
 
 
f915041
 
 
 
 
 
 
 
 
 
 
6cca62e
 
 
 
 
 
 
f915041
6cca62e
 
 
 
 
 
f915041
6cca62e
 
 
 
f915041
6cca62e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f915041
 
 
6cca62e
 
f915041
6cca62e
f915041
 
6cca62e
 
 
 
 
 
f915041
6cca62e
f915041
6cca62e
 
 
 
 
 
 
 
 
 
 
 
f915041
6cca62e
f915041
 
6cca62e
 
 
 
 
 
 
f915041
6cca62e
f915041
 
 
 
 
 
 
 
 
 
6cca62e
 
 
 
 
f915041
 
 
 
 
 
 
 
 
 
 
 
cfd7e45
6cca62e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Menu</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f8f9fa;
            margin: 0;
            padding: 0;
        }

        .container {
            max-width: 900px;
        }

        .menu-card {
            max-width: 350px;
            border-radius: 15px;
            overflow: hidden;
            background-color: #fff;
            margin: auto;
        }

        .menu-image {
            height: 200px;
            width: 100%;
            object-fit: cover;
            border-radius: 15px 15px 0 0;
        }

        .card-title {
            font-size: 1.2rem;
            font-weight: bold;
        }

        .card-text {
            font-size: 1rem;
            color: #6c757d;
        }

        .btn-primary {
            font-size: 0.9rem;
            border-radius: 20px;
            width: 100px;
        }

        .filter-container {
            margin-bottom: 15px;
        }

        .addons-container {
            max-height: 150px;
            overflow-y: auto;
            border: 1px solid #ddd;
            padding: 10px;
            background-color: #f8f9fa;
            border-radius: 5px;
        }

        .addons-container::-webkit-scrollbar {
            width: 6px;
        }

        .addons-container::-webkit-scrollbar-thumb {
            background-color: #aaa;
            border-radius: 3px;
        }

        .addons-container::-webkit-scrollbar-track {
            background-color: #f1f1f1;
        }

        .view-cart-container {
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 999;
        }

        .view-cart-button {
            background-color: #007bff;
            color: #fff;
            padding: 10px 20px;
            border-radius: 50px;
            font-size: 1rem;
            font-weight: bold;
            text-decoration: none;
            box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .view-cart-button:hover {
            background-color: #0056b3;
            text-decoration: none;
        }

       /* Toast container for messages */
.toast-container {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 1055; /* Ensure it appears above other elements */
    width: auto;
    max-width: 300px;
}

/* Toast box */
.toast {
    background-color: #28a745; /* Success green background */
    color: #fff; /* White text */
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    font-size: 0.9rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Toast close button */
.toast .btn-close {
    color: #fff;
    background: transparent;
    border: none;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
}

.toast .btn-close:hover {
    color: #ccc; /* Light gray on hover */
}

/* Smooth slide-in and fade-out animations */
@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.toast {
    animation: slideIn 0.5s ease-out, fadeOut 3s 2s ease-out forwards;
}
    </style>
</head>
<body>
    <div class="container mt-4">
        <h1 class="text-center">Menu</h1>

        <!-- Filter Section -->
        <form method="get" action="/menu" class="text-center mb-4">
            <label for="category" class="form-label fw-bold">Filter by Category:</label>
            <select id="category" name="category" class="form-select" onchange="this.form.submit()">
                <option value="All" {% if selected_category == 'All' %}selected{% endif %}>All</option>
                {% for category in categories %}
                <option value="{{ category }}" {% if selected_category == category %}selected{% endif %}>
                    {{ category }}
                </option>
                {% endfor %}
            </select>
        </form>

        <!-- Menu Items -->
        <div class="row">
            {% for item in food_items %}
            <div class="col-md-6 mb-4">
                <div class="card menu-card">
                    <img src="{{ item.Image1__c }}" class="card-img-top menu-image" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
                    <div class="card-body">
                        <h5 class="card-title">{{ item.Name }}</h5>
                        <p class="card-text">${{ item.Price__c }}</p>
                        <p class="card-text"><small class="text-muted">{{ item.Category__c }}</small></p>
                        <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#itemModal" 
                            onclick="showItemDetails('{{ item.Name }}', '{{ item.Price__c }}', '{{ item.Image1__c }}', '{{ item.Description__c }}')">
                            Add +
                        </button>
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>

    <!-- View Cart Button -->
    <div class="view-cart-container">
        <a href="/cart" class="view-cart-button">
            View Cart
        </a>
    </div>

    <!-- Modal for Item Details -->
    <div class="modal fade" id="itemModal" tabindex="-1" aria-labelledby="itemModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="itemModalLabel">Item Details</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <!-- Item Image -->
                    <img id="modal-img" class="img-fluid rounded mb-3 d-block mx-auto" alt="Item Image" style="max-height: 200px; object-fit: cover;">
                    <!-- Item Name -->
                    <h5 id="modal-name" class="fw-bold text-center"></h5>
                    <!-- Item Price -->
                    <p id="modal-price" class="text-muted text-center"></p>
                    <!-- Item Description -->
                    <p id="modal-description" class="text-secondary"></p>
                    <!-- Add-ons -->
                    <div id="modal-addons" class="modal-addons mt-4">
                        <h6>Add-ons</h6>
                        <div id="addons-list" class="addons-container">Loading add-ons...</div>
                    </div>
                </div>               
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="addToCartFromModal()">Add to Cart</button>
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

    <!-- JavaScript -->
    <script>

            // Attach event listener to close button
    document.addEventListener('DOMContentLoaded', function () {
        document.querySelector('.btn-close').addEventListener('click', function () {
            const triggerButton = document.querySelector('[data-bs-target="#itemModal"]');
            if (triggerButton) {
                triggerButton.focus(); // Return focus to the trigger button
            }
        });
    });

        function showItemDetails(name, price, image, description) {
            // Set modal content dynamically
            document.getElementById('modal-name').innerText = name;
            document.getElementById('modal-price').innerText = `$${price}`;
            document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
            document.getElementById('modal-description').innerText = description || 'No description available.';
            document.getElementById('addons-list').innerHTML = 'Loading add-ons...';

            // Fetch add-ons dynamically based on item Name
            fetch(`/api/addons?item_name=${encodeURIComponent(name)}`)
                .then(response => response.json())
                .then(data => {
                    const addonsList = document.getElementById('addons-list');
                    addonsList.innerHTML = ''; // Clear previous content

                    if (!data.success || !data.addons || data.addons.length === 0) {
                        addonsList.innerHTML = 'No add-ons available.';
                        return;
                    }

                    // Populate the add-ons list
                    data.addons.forEach(addon => {
                        const listItem = document.createElement('div');
                        listItem.innerHTML = `
                            <input type="checkbox" id="addon-${addon.Id}" value="${addon.Id}" />
                            <label for="addon-${addon.Id}">${addon.Name} - $${addon.Price__c}</label>
                        `;
                        addonsList.appendChild(listItem);
                    });
                })
                .catch(err => {
                    console.error('Error fetching add-ons:', err);
                    document.getElementById('addons-list').innerHTML = 'Unable to fetch add-ons. Please try again later.';
                });
        }
        function addToCartFromModal() {
            const itemName = document.getElementById('modal-name').innerText;
            const itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
            const itemImage = document.getElementById('modal-img').src;
            const selectedAddOns = Array.from(
                document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
            ).map(addon => addon.value);
        
            console.log("Add to cart payload:", { itemName, itemPrice, itemImage, selectedAddOns });

            if (!itemName || !itemPrice) {
                alert('Failed to add item to cart. Please try again.');
                return;
            }
        
            const cartPayload = {
                itemName: itemName,
                itemPrice: itemPrice,
                itemImage: itemImage,
                addons: selectedAddOns
            };
        
            fetch('/cart/add', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(cartPayload)
            })
                .then(response => response.json())
                .then(data => {
                    console.log("Server response:", data);
                    if (data.success) {
                        // Show a toast notification instead of redirecting
                        showToast('Item added to cart successfully!');
                    } else {
                        console.error('Error adding item to cart:', data.error);
                        alert(data.error || 'Failed to add item to cart.');
                    }
                })
                .catch(err => {
                    console.error('Error adding item to cart:', err);
                    alert('This item is already there in cart.');
                });
        }
        
        // Helper function to show toast notification
        function showToast(message) {
            const toastEl = document.getElementById('cartToast');
            const toastBody = document.querySelector('#cartToast .toast-body');
            toastBody.innerText = message; // Update toast message
            const toast = new bootstrap.Toast(toastEl);
            toast.show();
        }
        
    </script>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

    <div class="toast-container position-fixed top-0 end-0 p-3" style="z-index: 1055;">
        <div id="cartToast" class="toast align-items-center text-bg-success" role="alert" aria-live="assertive" aria-atomic="true">
            <div class="d-flex">
                <div class="toast-body">
                    Item added to cart successfully!
                </div>
                <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
            </div>
        </div>
    </div>
    
</body>
</html>