Skip to content

Commit

Permalink
fix cancel booking function
Browse files Browse the repository at this point in the history
  • Loading branch information
brentchang committed Jul 28, 2024
1 parent 1c8b13a commit 53a1a96
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 66 deletions.
9 changes: 6 additions & 3 deletions controllers/BensonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ const getOrderListPageAction = async (req, res) => {
res.redirect('/login');
return;
}
const activeOrder = await getActiveOrder(req.session.username)
// console.log(activeOrder);
var activeOrder = await getActiveOrder(req.session.username)
// console.log(activeOrder);


// Ensure activeOrder is an array
if (!Array.isArray(activeOrder)) {
activeOrder = [activeOrder];
}

const pastOrders = await getPastOrders(req.session.username)
console.log(pastOrders);
Expand Down
99 changes: 36 additions & 63 deletions views/orderListPage.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -195,69 +195,42 @@
</footer>
<% if (typeof(activeOrder)!='undefined'&& activeOrder.length>0) { %>
<script>
document.addEventListener('DOMContentLoaded', function() {
var modal = document.getElementById('cancelModal');
// var cancelBtn = document.querySelector('.btn-cancel');
var confirmCancelBtn = document.getElementById('confirmCancel');
var closeModalBtn = document.getElementById('closeModal');
// Select all cancel buttons
// var cancelBtns = document.querySelectorAll('.btn-cancel');
<% activeOrder.forEach(activeOrder => { %>
var cancelBtn<%- activeOrder.order_num %> = document.getElementById('btn-cancel-<%- activeOrder.order_num %>');
cancelBtn<%- activeOrder.order_num %>.dataset.orderNum = '<%- activeOrder.order_num %>';
cancelBtn<%- activeOrder.order_num %>.onclick = function(event) {
event.preventDefault();
modal.style.display = 'block';
// Store the order number in the confirm button's dataset
confirmCancelBtn.dataset.orderNum = cancelBtn.dataset.orderNum;
}
<% }) %>
// var closeBtn = document.querySelector('.close');
// cancelBtn.onclick = function(event) {
// event.preventDefault();
// modal.style.display = 'block';
// // Store the order number in the confirm button's dataset
// confirmCancelBtn.dataset.orderNum = cancelBtn.dataset.orderNum;
// }
// // Iterate over each cancel button to add click event
// cancelBtns.forEach(function(cancelBtn) {
// cancelBtn.onclick = function(event) {
// event.preventDefault();
// modal.style.display = 'block';
// // Store the order number in the confirm button's dataset
// confirmCancelBtn.dataset.orderNum = cancelBtn.dataset.orderNum;
// }
// });
// When the user clicks on <span> (x), close the modal
closeBtn.onclick = function() {
modal.style.display = 'none';
}
// When the user clicks No, close the modal
closeModalBtn.onclick = function() {
modal.style.display = 'none';
}
// When the user clicks Yes, redirect to the cancel API
confirmCancelBtn.onclick = function() {
var orderNum = confirmCancelBtn.dataset.orderNum;
window.location.href = '/order/cancel/' + orderNum;
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
}
});
document.addEventListener('DOMContentLoaded', function() {
var modal = document.getElementById('cancelModal');
var confirmCancelBtn = document.getElementById('confirmCancel');
var closeModalBtn = document.getElementById('closeModal');
// Select all cancel buttons
var cancelBtns = document.querySelectorAll('.btn-cancel');
// Iterate over each cancel button to add click event
cancelBtns.forEach(function(cancelBtn) {
cancelBtn.onclick = function(event) {
event.preventDefault();
modal.style.display = 'block';
// Store the order number in the confirm button's dataset
confirmCancelBtn.dataset.orderNum = cancelBtn.id.replace('btn-cancel-', '');
}
});
// When the user clicks on <span> (x), close the modal
closeModalBtn.onclick = function() {
modal.style.display = 'none';
}
// When the user clicks Yes, redirect to the cancel API
confirmCancelBtn.onclick = function() {
var orderNum = confirmCancelBtn.dataset.orderNum;
window.location.href = '/order/cancel/' + orderNum;
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
}
});
</script>
<% } %>
</body>
Expand Down

0 comments on commit 53a1a96

Please sign in to comment.