lokesh341 commited on
Commit
514c2c8
·
verified ·
1 Parent(s): aec7d6b

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +158 -28
templates/menu.html CHANGED
@@ -332,6 +332,24 @@
332
  height: 40px;
333
  width: 40px;
334
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  @media (max-width: 576px) {
336
  .modal-dialog {
337
  max-width: 98%;
@@ -382,7 +400,7 @@
382
  </div>
383
  </form>
384
 
385
- <div class="container mt-4">
386
  {% if selected_category == "Customized Dish" %}
387
  <div id="custom-dish-form" class="mt-4">
388
  <h3>Create Your Custom Dish</h3>
@@ -399,40 +417,56 @@
399
  </form>
400
  </div>
401
  {% else %}
402
- {% for section, items in ordered_menu.items() %}
403
- <h3>{{ section }}</h3>
404
- <div class="row">
405
- {% for item in items %}
406
- <div class="col-md-6 mb-4">
407
- <div class="card menu-card">
408
- <img src="{{ item.Image1__c }}" class="card-img-top menu-image" alt="{{ item.Name }}"
409
- onerror="this.src='/static/placeholder.jpg';" loading="lazy">
410
- <div class="addbutton">
411
- <div class="card-body d-flex align-items-center justify-content-between">
412
- <div>
413
- <h5 class="card-title">{{ item.Name }}</h5>
414
- <p class="card-text">${{ item.Price__c }}</p>
415
- </div>
416
- <div class="d-flex flex-column align-item-center justify-content-center">
 
417
  <div>
418
- <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#itemModal"
419
- onclick="showItemDetails('{{ item.Name }}', '{{ item.Price__c }}', '{{ item.Image2__c }}', '{{ item.Description__c }}', '{{ item.Section__c }}','{{ selected_category }}')">
420
- ADD
421
- </button>
422
  </div>
423
- <div class="w-100 text-center">
424
- {% if item.Section__c != 'Apetizer' and item.Section__c != 'Customized dish' and item.Section__c !='Soft Drinks' %}
425
- <h5 class="customisable-text">Customisable</h5>
426
- {% endif %}
 
 
 
 
 
 
 
 
427
  </div>
428
  </div>
429
  </div>
430
  </div>
431
  </div>
432
- </div>
433
- {% endfor %}
 
 
 
 
 
 
 
 
 
434
  </div>
435
- {% endfor %}
436
  {% endif %}
437
  </div>
438
 
@@ -497,6 +531,93 @@
497
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
498
 
499
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
  function showItemDetails(name, price, image, description, section, selectedCategory) {
501
  document.getElementById('modal-name').innerText = name;
502
  document.getElementById('modal-price').innerText = `$${price}`;
@@ -696,7 +817,7 @@
696
 
697
  function filterMenu() {
698
  let input = document.getElementById('searchBar').value.toLowerCase();
699
- let sections = document.querySelectorAll('h3');
700
  let items = document.querySelectorAll('.menu-card');
701
  let matchedSections = new Set();
702
 
@@ -722,6 +843,15 @@
722
  sectionRow.style.display = 'none';
723
  }
724
  });
 
 
 
 
 
 
 
 
 
725
  }
726
 
727
  function addToCartFromModal() {
 
332
  height: 40px;
333
  width: 40px;
334
  }
335
+ .loading {
336
+ display: none;
337
+ text-align: center;
338
+ margin: 20px 0;
339
+ }
340
+ .loading-spinner {
341
+ border: 4px solid #f3f3f3;
342
+ border-top: 4px solid #0FAA39;
343
+ border-radius: 50%;
344
+ width: 30px;
345
+ height: 30px;
346
+ animation: spin 1s linear infinite;
347
+ display: inline-block;
348
+ }
349
+ @keyframes spin {
350
+ 0% { transform: rotate(0deg); }
351
+ 100% { transform: rotate(360deg); }
352
+ }
353
  @media (max-width: 576px) {
354
  .modal-dialog {
355
  max-width: 98%;
 
400
  </div>
401
  </form>
402
 
403
+ <div class="container mt-4" id="menu-container">
404
  {% if selected_category == "Customized Dish" %}
405
  <div id="custom-dish-form" class="mt-4">
406
  <h3>Create Your Custom Dish</h3>
 
417
  </form>
418
  </div>
419
  {% else %}
420
+ <div id="menu-items">
421
+ {% for section, items in ordered_menu.items() %}
422
+ <h3>{{ section }}</h3>
423
+ <div class="row" data-section="{{ section }}">
424
+ {% for item in items %}
425
+ <div class="col-md-6 mb-4">
426
+ <div class="card menu-card">
427
+ <img src="{{ item.Image1__c }}"
428
+ srcset="{{ item.Image1__c }}?w=350 350w, {{ item.Image1__c }}?w=200 200w"
429
+ sizes="(max-width: 576px) 200px, 350px"
430
+ class="card-img-top menu-image"
431
+ alt="{{ item.Name }}"
432
+ onerror="this.src='/static/placeholder.jpg';"
433
+ loading="lazy">
434
+ <div class="addbutton">
435
+ <div class="card-body d-flex align-items-center justify-content-between">
436
  <div>
437
+ <h5 class="card-title">{{ item.Name }}</h5>
438
+ <p class="card-text">${{ item.Price__c }}</p>
 
 
439
  </div>
440
+ <div class="d-flex flex-column align-item-center justify-content-center">
441
+ <div>
442
+ <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#itemModal"
443
+ onclick="showItemDetails('{{ item.Name }}', '{{ item.Price__c }}', '{{ item.Image2__c }}', '{{ item.Description__c }}', '{{ item.Section__c }}','{{ selected_category }}')">
444
+ ADD
445
+ </button>
446
+ </div>
447
+ <div class="w-100 text-center">
448
+ {% if item.Section__c != 'Apetizer' and item.Section__c != 'Customized dish' and item.Section__c !='Soft Drinks' %}
449
+ <h5 class="customisable-text">Customisable</h5>
450
+ {% endif %}
451
+ </div>
452
  </div>
453
  </div>
454
  </div>
455
  </div>
456
  </div>
457
+ {% endfor %}
458
+ </div>
459
+ {% endfor %}
460
+ </div>
461
+ <div id="loading" class="loading">
462
+ <div class="loading-spinner"></div>
463
+ <p>Loading more items...</p>
464
+ </div>
465
+ {% if has_more %}
466
+ <div id="load-more" class="text-center my-4">
467
+ <button class="btn btn-primary" onclick="loadMoreItems()">Load More</button>
468
  </div>
469
+ {% endif %}
470
  {% endif %}
471
  </div>
472
 
 
531
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
532
 
533
  <script>
534
+ let currentPage = {{ page | default(1) }};
535
+ const perPage = {{ per_page | default(10) }};
536
+ const selectedCategory = '{{ selected_category }}';
537
+
538
+ function loadMoreItems() {
539
+ const loadingEl = document.getElementById('loading');
540
+ const loadMoreEl = document.getElementById('load-more');
541
+ loadingEl.style.display = 'block';
542
+ loadMoreEl.style.display = 'none';
543
+
544
+ currentPage++;
545
+ fetch(`/menu?category=${encodeURIComponent(selectedCategory)}&page=${currentPage}&per_page=${perPage}&ajax=1`)
546
+ .then(response => response.json())
547
+ .then(data => {
548
+ if (data.ordered_menu) {
549
+ appendMenuItems(data.ordered_menu);
550
+ if (!data.has_more) {
551
+ loadMoreEl.style.display = 'none';
552
+ } else {
553
+ loadMoreEl.style.display = 'block';
554
+ }
555
+ }
556
+ loadingEl.style.display = 'none';
557
+ })
558
+ .catch(err => {
559
+ console.error('Error loading more items:', err);
560
+ alert('Failed to load more items.');
561
+ loadingEl.style.display = 'none';
562
+ loadMoreEl.style.display = 'block';
563
+ });
564
+ }
565
+
566
+ function appendMenuItems(orderedMenu) {
567
+ const menuItemsContainer = document.getElementById('menu-items');
568
+ for (const [section, items] of Object.entries(orderedMenu)) {
569
+ let sectionEl = document.querySelector(`.row[data-section="${section}"]`);
570
+ if (!sectionEl) {
571
+ const sectionTitle = document.createElement('h3');
572
+ sectionTitle.innerText = section;
573
+ menuItemsContainer.appendChild(sectionTitle);
574
+
575
+ sectionEl = document.createElement('div');
576
+ sectionEl.classList.add('row');
577
+ sectionEl.setAttribute('data-section', section);
578
+ menuItemsContainer.appendChild(sectionEl);
579
+ }
580
+
581
+ items.forEach(item => {
582
+ const itemHTML = `
583
+ <div class="col-md-6 mb-4">
584
+ <div class="card menu-card">
585
+ <img src="${item.Image1__c}"
586
+ srcset="${item.Image1__c}?w=350 350w, ${item.Image1__c}?w=200 200w"
587
+ sizes="(max-width: 576px) 200px, 350px"
588
+ class="card-img-top menu-image"
589
+ alt="${item.Name}"
590
+ onerror="this.src='/static/placeholder.jpg';"
591
+ loading="lazy">
592
+ <div class="addbutton">
593
+ <div class="card-body d-flex align-items-center justify-content-between">
594
+ <div>
595
+ <h5 class="card-title">${item.Name}</h5>
596
+ <p class="card-text">$${item.Price__c}</p>
597
+ </div>
598
+ <div class="d-flex flex-column align-item-center justify-content-center">
599
+ <div>
600
+ <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#itemModal"
601
+ onclick="showItemDetails('${item.Name}', '${item.Price__c}', '${item.Image2__c}', '${item.Description__c}', '${item.Section__c}', '${selectedCategory}')">
602
+ ADD
603
+ </button>
604
+ </div>
605
+ <div class="w-100 text-center">
606
+ ${item.Section__c !== 'Apetizer' && item.Section__c !== 'Customized dish' && item.Section__c !== 'Soft Drinks'
607
+ ? '<h5 class="customisable-text">Customisable</h5>'
608
+ : ''}
609
+ </div>
610
+ </div>
611
+ </div>
612
+ </div>
613
+ </div>
614
+ </div>
615
+ `;
616
+ sectionEl.insertAdjacentHTML('beforeend', itemHTML);
617
+ });
618
+ }
619
+ }
620
+
621
  function showItemDetails(name, price, image, description, section, selectedCategory) {
622
  document.getElementById('modal-name').innerText = name;
623
  document.getElementById('modal-price').innerText = `$${price}`;
 
817
 
818
  function filterMenu() {
819
  let input = document.getElementById('searchBar').value.toLowerCase();
820
+ let sections = document.querySelectorAll('#menu-items h3');
821
  let items = document.querySelectorAll('.menu-card');
822
  let matchedSections = new Set();
823
 
 
843
  sectionRow.style.display = 'none';
844
  }
845
  });
846
+
847
+ const visibleItems = document.querySelectorAll('.menu-card:not([style*="display: none"])');
848
+ const totalItems = {{ total_items | default(0) }};
849
+ const loadMoreEl = document.getElementById('load-more');
850
+ if (visibleItems.length < totalItems && input === '') {
851
+ loadMoreEl.style.display = 'block';
852
+ } else {
853
+ loadMoreEl.style.display = 'none';
854
+ }
855
  }
856
 
857
  function addToCartFromModal() {