Spaces:
Runtime error
Runtime error
Update templates/menu.html
Browse files- templates/menu.html +214 -203
templates/menu.html
CHANGED
|
@@ -522,228 +522,239 @@ form.text-center.mb-4 {
|
|
| 522 |
|
| 523 |
<!-- JavaScript -->
|
| 524 |
<script>
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
<input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
|
| 573 |
-
data-name="${option}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
| 574 |
-
<label class="form-check-label" for="${optionId}">
|
| 575 |
-
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
| 576 |
-
</label>
|
| 577 |
-
`;
|
| 578 |
-
optionsContainer.appendChild(listItem);
|
| 579 |
});
|
| 580 |
-
|
| 581 |
-
|
|
|
|
|
|
|
| 582 |
});
|
| 583 |
-
|
| 584 |
-
.catch(err => {
|
| 585 |
-
console.error('Error fetching add-ons:', err);
|
| 586 |
-
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
| 587 |
-
});
|
| 588 |
-
}
|
| 589 |
-
|
| 590 |
-
function filterMenu() {
|
| 591 |
-
let input = document.getElementById('searchBar').value.toLowerCase(); // Get value from search bar
|
| 592 |
-
let sections = document.querySelectorAll('h3'); // Select section headers
|
| 593 |
-
let items = document.querySelectorAll('.menu-card'); // Select all items
|
| 594 |
-
let matchedSections = new Set(); // Store matched sections
|
| 595 |
-
|
| 596 |
-
console.log("Filtering menu with input:", input);
|
| 597 |
-
|
| 598 |
-
// Hide all items initially
|
| 599 |
-
items.forEach(item => {
|
| 600 |
-
let itemName = item.querySelector('.card-title').innerText.toLowerCase(); // Get item name
|
| 601 |
-
let itemSection = item.closest('.row').previousElementSibling.innerText.toLowerCase(); // Get section name
|
| 602 |
-
|
| 603 |
-
// If search matches item name or section, show the item
|
| 604 |
-
if (itemName.includes(input) || (itemSection && itemSection.includes(input))) {
|
| 605 |
-
item.style.display = 'block'; // Show item if it matches search
|
| 606 |
-
matchedSections.add(item.closest('.row')); // Add section to matched list
|
| 607 |
-
} else {
|
| 608 |
-
item.style.display = 'none'; // Hide item if not matched
|
| 609 |
-
}
|
| 610 |
-
});
|
| 611 |
-
|
| 612 |
-
// Show or hide sections based on matched items
|
| 613 |
-
sections.forEach(section => {
|
| 614 |
-
let sectionRow = section.nextElementSibling; // The row containing items
|
| 615 |
-
if (matchedSections.has(sectionRow)) {
|
| 616 |
-
section.style.display = 'block'; // Show section header
|
| 617 |
-
sectionRow.style.display = 'flex'; // Show section items
|
| 618 |
-
} else {
|
| 619 |
-
section.style.display = 'none'; // Hide section header
|
| 620 |
-
sectionRow.style.display = 'none'; // Hide section items
|
| 621 |
-
}
|
| 622 |
-
});
|
| 623 |
-
}
|
| 624 |
-
|
| 625 |
-
function addToCartFromModal() {
|
| 626 |
-
const itemName = document.getElementById('modal-name').innerText;
|
| 627 |
-
let itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
| 628 |
-
const itemImage = document.getElementById('modal-img').src;
|
| 629 |
-
const modalSectionEl = document.getElementById('modal-section');
|
| 630 |
-
const section = modalSectionEl.getAttribute('data-section');
|
| 631 |
-
const selectedCategory = modalSectionEl.getAttribute('data-category');
|
| 632 |
-
const quantity = parseInt(document.getElementById('quantityInput').value) || 1; // Default to 1 if invalid
|
| 633 |
-
|
| 634 |
-
console.log("Adding to cart with data:", { itemName, itemPrice, itemImage, section, selectedCategory, quantity });
|
| 635 |
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 639 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 640 |
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
).map(addon => ({
|
| 645 |
-
name: addon.getAttribute('data-name') || 'Default Name', // Fallback Name
|
| 646 |
-
price: parseFloat(addon.getAttribute('data-price') || 0)
|
| 647 |
-
}));
|
| 648 |
-
|
| 649 |
-
// Prepare data for the cart
|
| 650 |
-
const cartPayload = {
|
| 651 |
-
itemName: itemName,
|
| 652 |
-
itemPrice: itemPrice,
|
| 653 |
-
itemImage: itemImage,
|
| 654 |
-
section: section,
|
| 655 |
-
category: selectedCategory,
|
| 656 |
-
addons: selectedAddOns,
|
| 657 |
-
quantity: quantity, // Include the quantity
|
| 658 |
-
instructions: document.getElementById('modal-instructions').value
|
| 659 |
-
};
|
| 660 |
-
|
| 661 |
-
console.log("Cart Payload:", cartPayload);
|
| 662 |
-
|
| 663 |
-
// Send the cart data to the server
|
| 664 |
-
fetch('/cart/add', {
|
| 665 |
-
method: 'POST',
|
| 666 |
-
headers: {
|
| 667 |
-
'Content-Type': 'application/json',
|
| 668 |
-
},
|
| 669 |
-
body: JSON.stringify(cartPayload)
|
| 670 |
-
})
|
| 671 |
-
.then(response => response.json())
|
| 672 |
-
.then(data => {
|
| 673 |
-
console.log("Response from server:", data);
|
| 674 |
-
if (data.success) {
|
| 675 |
-
alert('Item added to cart successfully!');
|
| 676 |
-
updateCartUI(data.cart); // Update cart UI after adding an item
|
| 677 |
-
const modal = document.getElementById('itemModal');
|
| 678 |
-
const modalInstance = bootstrap.Modal.getInstance(modal);
|
| 679 |
-
modalInstance.hide();
|
| 680 |
-
} else {
|
| 681 |
-
alert(data.error || 'Failed to add item to cart.');
|
| 682 |
-
}
|
| 683 |
-
})
|
| 684 |
-
.catch(err => {
|
| 685 |
-
console.error('Error adding item to cart:', err);
|
| 686 |
-
alert('An error occurred while adding the item to the cart.');
|
| 687 |
-
});
|
| 688 |
-
}
|
| 689 |
|
| 690 |
-
|
| 691 |
-
|
|
|
|
|
|
|
|
|
|
| 692 |
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
|
| 698 |
-
|
| 699 |
-
|
|
|
|
|
|
|
| 700 |
}
|
|
|
|
|
|
|
|
|
|
| 701 |
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 722 |
quantityInput.value = currentQuantity;
|
| 723 |
-
|
| 724 |
-
});
|
| 725 |
});
|
| 726 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 727 |
// Function to round reward points to a single digit
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
|
|
|
|
|
|
| 740 |
} else {
|
| 741 |
-
console.error("Reward points
|
| 742 |
}
|
|
|
|
|
|
|
| 743 |
}
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
|
|
|
|
|
|
| 747 |
|
| 748 |
<!-- Bootstrap JS -->
|
| 749 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
|
| 522 |
|
| 523 |
<!-- JavaScript -->
|
| 524 |
<script>
|
| 525 |
+
function showItemDetails(name, price, image, description, section, selectedCategory) {
|
| 526 |
+
document.getElementById('modal-name').innerText = name;
|
| 527 |
+
document.getElementById('modal-price').innerText = `$${price}`;
|
| 528 |
+
document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
|
| 529 |
+
document.getElementById('modal-description').innerText = description || 'No description available.';
|
| 530 |
+
document.getElementById('addons-list').innerHTML = 'Loading customization options...';
|
| 531 |
+
document.getElementById('modal-instructions').value = '';
|
| 532 |
+
// Set section and category for reference
|
| 533 |
+
const modalSectionEl = document.getElementById('modal-section');
|
| 534 |
+
modalSectionEl.setAttribute('data-section', section);
|
| 535 |
+
modalSectionEl.setAttribute('data-category', selectedCategory);
|
| 536 |
+
// Fetch customization options based on the section
|
| 537 |
+
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
| 538 |
+
.then(response => response.json())
|
| 539 |
+
.then(data => {
|
| 540 |
+
const addonsList = document.getElementById('addons-list');
|
| 541 |
+
addonsList.innerHTML = ''; // Clear previous content
|
| 542 |
|
| 543 |
+
if (!data.success || !data.addons || data.addons.length === 0) {
|
| 544 |
+
addonsList.innerHTML = '<p>No customization options available.</p>';
|
| 545 |
+
return;
|
| 546 |
+
}
|
| 547 |
+
// Display customization options inside styled divs
|
| 548 |
+
data.addons.forEach(addon => {
|
| 549 |
+
const sectionDiv = document.createElement('div');
|
| 550 |
+
sectionDiv.classList.add('addon-section'); // Add styling class
|
| 551 |
+
// Add section title
|
| 552 |
+
const title = document.createElement('h6');
|
| 553 |
+
title.innerText = addon.name;
|
| 554 |
+
sectionDiv.appendChild(title);
|
| 555 |
+
// Create options list
|
| 556 |
+
const optionsContainer = document.createElement('div');
|
| 557 |
+
addon.options.forEach((option, index) => {
|
| 558 |
+
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
| 559 |
+
const listItem = document.createElement('div');
|
| 560 |
+
listItem.classList.add('form-check');
|
| 561 |
+
listItem.innerHTML = `
|
| 562 |
+
<input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
|
| 563 |
+
data-name="${option}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
| 564 |
+
<label class="form-check-label" for="${optionId}">
|
| 565 |
+
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
| 566 |
+
</label>
|
| 567 |
+
`;
|
| 568 |
+
optionsContainer.appendChild(listItem);
|
| 569 |
+
});
|
| 570 |
+
sectionDiv.appendChild(optionsContainer);
|
| 571 |
+
addonsList.appendChild(sectionDiv);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
});
|
| 573 |
+
})
|
| 574 |
+
.catch(err => {
|
| 575 |
+
console.error('Error fetching add-ons:', err);
|
| 576 |
+
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
| 577 |
});
|
| 578 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
|
| 580 |
+
function filterMenu() {
|
| 581 |
+
let input = document.getElementById('searchBar').value.toLowerCase(); // Get the value from search bar
|
| 582 |
+
let sections = document.querySelectorAll('h3'); // Select section headers
|
| 583 |
+
let items = document.querySelectorAll('.menu-card'); // Select all items
|
| 584 |
+
let matchedSections = new Set(); // Store matched sections
|
| 585 |
+
|
| 586 |
+
// Hide all items initially
|
| 587 |
+
items.forEach(item => {
|
| 588 |
+
let itemName = item.querySelector('.card-title').innerText.toLowerCase(); // Get item name
|
| 589 |
+
let itemSection = item.closest('.row').previousElementSibling.innerText.toLowerCase(); // Get section name
|
| 590 |
+
|
| 591 |
+
// If the search matches item name or section, show the item
|
| 592 |
+
if (itemName.includes(input) || (itemSection && itemSection.includes(input))) {
|
| 593 |
+
item.style.display = 'block'; // Show item if it matches search
|
| 594 |
+
matchedSections.add(item.closest('.row')); // Add section to matched list
|
| 595 |
+
} else {
|
| 596 |
+
item.style.display = 'none'; // Hide item if not matched
|
| 597 |
}
|
| 598 |
+
});
|
| 599 |
+
|
| 600 |
+
// Show or hide sections based on matched items
|
| 601 |
+
sections.forEach(section => {
|
| 602 |
+
let sectionRow = section.nextElementSibling; // The row containing items
|
| 603 |
+
if (matchedSections.has(sectionRow)) {
|
| 604 |
+
section.style.display = 'block'; // Show section header
|
| 605 |
+
sectionRow.style.display = 'flex'; // Show section items
|
| 606 |
+
} else {
|
| 607 |
+
section.style.display = 'none'; // Hide section header
|
| 608 |
+
sectionRow.style.display = 'none'; // Hide section items
|
| 609 |
+
}
|
| 610 |
+
});
|
| 611 |
+
}
|
| 612 |
|
| 613 |
+
function addToCartFromModal() {
|
| 614 |
+
const itemName = document.getElementById('modal-name').innerText;
|
| 615 |
+
let itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
|
| 617 |
+
// Validate item price
|
| 618 |
+
if (isNaN(itemPrice)) {
|
| 619 |
+
alert('Invalid price for the item. Please check the item details.');
|
| 620 |
+
return;
|
| 621 |
+
}
|
| 622 |
|
| 623 |
+
const itemImage = document.getElementById('modal-img').src;
|
| 624 |
+
console.log(itemName, itemPrice, itemImage); // Log values for debugging
|
| 625 |
+
const modalSectionEl = document.getElementById('modal-section');
|
| 626 |
+
const section = modalSectionEl.getAttribute('data-section');
|
| 627 |
+
const selectedCategory = modalSectionEl.getAttribute('data-category');
|
| 628 |
+
if (!itemName || !itemPrice || !section || !itemImage) {
|
| 629 |
+
console.error('Missing data for cart item:', { itemName, itemPrice, section, itemImage});
|
| 630 |
+
return;
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
// Collect selected add-ons
|
| 634 |
+
let selectedAddOns = Array.from(
|
| 635 |
+
document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
|
| 636 |
+
).map(addon => ({
|
| 637 |
+
name: addon.getAttribute('data-name') || 'Default Name', // Fallback Name
|
| 638 |
+
price: parseFloat(addon.getAttribute('data-price') || 0)
|
| 639 |
+
}));
|
| 640 |
+
|
| 641 |
+
// Get the selected quantity
|
| 642 |
+
const quantity = parseInt(document.getElementById('quantityInput').value) || 1; // Default to 1 if invalid
|
| 643 |
+
|
| 644 |
+
const instructions = document.getElementById('modal-instructions').value;
|
| 645 |
+
|
| 646 |
+
// Prepare data for the cart
|
| 647 |
+
const cartPayload = {
|
| 648 |
+
itemName: itemName,
|
| 649 |
+
itemPrice: itemPrice,
|
| 650 |
+
itemImage: itemImage,
|
| 651 |
+
section: section,
|
| 652 |
+
category: selectedCategory,
|
| 653 |
+
addons: selectedAddOns,
|
| 654 |
+
instructions: instructions,
|
| 655 |
+
quantity: quantity // Include the quantity
|
| 656 |
+
};
|
| 657 |
+
|
| 658 |
+
// Send the cart data to the server
|
| 659 |
+
fetch('/cart/add', {
|
| 660 |
+
method: 'POST',
|
| 661 |
+
headers: {
|
| 662 |
+
'Content-Type': 'application/json',
|
| 663 |
+
},
|
| 664 |
+
body: JSON.stringify(cartPayload)
|
| 665 |
+
})
|
| 666 |
+
.then(response => response.json())
|
| 667 |
+
.then(data => {
|
| 668 |
+
if (data.success) {
|
| 669 |
+
alert('Item added to cart successfully!');
|
| 670 |
+
updateCartUI(data.cart); // Update cart UI after adding an item
|
| 671 |
+
const modal = document.getElementById('itemModal');
|
| 672 |
+
const modalInstance = bootstrap.Modal.getInstance(modal);
|
| 673 |
+
modalInstance.hide();
|
| 674 |
+
} else {
|
| 675 |
+
alert(data.error || 'Failed to add item to cart.');
|
| 676 |
}
|
| 677 |
+
})
|
| 678 |
+
.catch(err => {
|
| 679 |
+
console.error('Error adding item to cart:', err);
|
| 680 |
+
alert('An error occurred while adding the item to the cart.');
|
| 681 |
+
});
|
| 682 |
+
}
|
| 683 |
|
| 684 |
+
function updateCartUI(cart) {
|
| 685 |
+
if (!Array.isArray(cart)) {
|
| 686 |
+
console.error('Invalid cart data:', cart);
|
| 687 |
+
return;
|
| 688 |
}
|
| 689 |
+
const cartIcon = document.getElementById('cart-icon');
|
| 690 |
+
cartIcon.innerText = cart.length; // Assuming cart is an array of items
|
| 691 |
+
}
|
| 692 |
|
| 693 |
+
function updateCartDisplay(cart) {
|
| 694 |
+
if (!Array.isArray(cart)) {
|
| 695 |
+
console.error('Invalid cart data:', cart);
|
| 696 |
+
return;
|
| 697 |
+
}
|
| 698 |
+
const cartCountElement = document.getElementById('cart-count');
|
| 699 |
+
cartCountElement.innerText = cart.length; // Update cart item count
|
| 700 |
+
// Optionally, show a small success notification that the item was added
|
| 701 |
+
const successNotification = document.createElement('div');
|
| 702 |
+
successNotification.classList.add('success-notification');
|
| 703 |
+
successNotification.innerText = 'Item added to cart!';
|
| 704 |
+
document.body.appendChild(successNotification);
|
| 705 |
+
setTimeout(() => {
|
| 706 |
+
successNotification.remove(); // Remove success notification after a few seconds
|
| 707 |
+
}, 2000);
|
| 708 |
+
}
|
| 709 |
+
document.addEventListener('DOMContentLoaded', function () {
|
| 710 |
+
// Get references to the quantity buttons and the input field
|
| 711 |
+
const decreaseBtn = document.getElementById('decreaseQuantity');
|
| 712 |
+
const increaseBtn = document.getElementById('increaseQuantity');
|
| 713 |
+
const quantityInput = document.getElementById('quantityInput');
|
| 714 |
+
|
| 715 |
+
// Add event listener to decrease button
|
| 716 |
+
decreaseBtn.addEventListener('click', function () {
|
| 717 |
+
let currentQuantity = parseInt(quantityInput.value);
|
| 718 |
+
if (currentQuantity > 1) {
|
| 719 |
+
currentQuantity--;
|
| 720 |
quantityInput.value = currentQuantity;
|
| 721 |
+
}
|
|
|
|
| 722 |
});
|
| 723 |
|
| 724 |
+
// Add event listener to increase button
|
| 725 |
+
increaseBtn.addEventListener('click', function () {
|
| 726 |
+
let currentQuantity = parseInt(quantityInput.value);
|
| 727 |
+
currentQuantity++;
|
| 728 |
+
quantityInput.value = currentQuantity;
|
| 729 |
+
});
|
| 730 |
+
});
|
| 731 |
+
|
| 732 |
// Function to round reward points to a single digit
|
| 733 |
+
function roundRewardPoints() {
|
| 734 |
+
// Get the reward points element
|
| 735 |
+
let rewardPointsElement = document.getElementById('reward-points');
|
| 736 |
+
|
| 737 |
+
// Check if the element exists in the DOM
|
| 738 |
+
if (rewardPointsElement) {
|
| 739 |
+
let rewardPointsText = rewardPointsElement.innerText.trim(); // Get and trim the value to remove any extra spaces
|
| 740 |
+
|
| 741 |
+
// Check if the innerText is a valid number
|
| 742 |
+
let rewardPoints = parseFloat(rewardPointsText);
|
| 743 |
+
|
| 744 |
+
// If it's a valid number, round it to 1 decimal place
|
| 745 |
+
if (!isNaN(rewardPoints)) {
|
| 746 |
+
rewardPointsElement.innerText = rewardPoints.toFixed(1); // Round to 1 decimal place
|
| 747 |
} else {
|
| 748 |
+
console.error("Reward points value is not a valid number:", rewardPointsText);
|
| 749 |
}
|
| 750 |
+
} else {
|
| 751 |
+
console.error("Reward points element is missing.");
|
| 752 |
}
|
| 753 |
+
}
|
| 754 |
+
// Run the function when the page loads
|
| 755 |
+
window.onload = roundRewardPoints;
|
| 756 |
+
|
| 757 |
+
</script>
|
| 758 |
|
| 759 |
<!-- Bootstrap JS -->
|
| 760 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
|