|
Lines 631-636
$("#placeBookingModal").on("show.bs.modal", function (e) {
Link Here
|
| 631 |
}); |
631 |
}); |
| 632 |
} |
632 |
} |
| 633 |
|
633 |
|
|
|
634 |
// Create a bookings store keyed on date |
| 635 |
let bookingsByDate = {}; |
| 636 |
// Iterate through the bookings array |
| 637 |
bookings.forEach(booking => { |
| 638 |
const start_date = flatpickr.parseDate(booking.start_date); |
| 639 |
const end_date = flatpickr.parseDate(booking.end_date); |
| 640 |
const item_id = booking.item_id; |
| 641 |
|
| 642 |
// Iterate through each date within the range of start_date and end_date |
| 643 |
let currentDate = new Date(start_date); |
| 644 |
while (currentDate <= end_date) { |
| 645 |
const currentDateStr = currentDate |
| 646 |
.toISOString() |
| 647 |
.split("T")[0]; |
| 648 |
|
| 649 |
// If the date key doesn't exist in the hash, create an empty array for it |
| 650 |
if (!bookingsByDate[currentDateStr]) { |
| 651 |
bookingsByDate[currentDateStr] = []; |
| 652 |
} |
| 653 |
|
| 654 |
// Push the booking ID to the array corresponding to the date key |
| 655 |
bookingsByDate[currentDateStr].push(item_id); |
| 656 |
|
| 657 |
// Move to the next day |
| 658 |
currentDate.setDate(currentDate.getDate() + 1); |
| 659 |
} |
| 660 |
}); |
| 661 |
|
| 662 |
// Set onDayCreate for flatpickr |
| 663 |
let dayCreateExists = periodPicker.config.onDayCreate.filter( |
| 664 |
f => f.name === "dayCreate" |
| 665 |
); |
| 666 |
if (dayCreateExists.length === 0) { |
| 667 |
periodPicker.config.onDayCreate.push(function dayCreate( |
| 668 |
dObj, |
| 669 |
dStr, |
| 670 |
instance, |
| 671 |
dayElem |
| 672 |
) { |
| 673 |
const currentDate = dayElem.dateObj |
| 674 |
.toISOString() |
| 675 |
.split("T")[0]; |
| 676 |
|
| 677 |
if (bookingsByDate[currentDate]) { |
| 678 |
const dots = document.createElement("span"); |
| 679 |
dots.className = "event-dots"; |
| 680 |
dayElem.appendChild(dots); |
| 681 |
bookingsByDate[currentDate].forEach(item => { |
| 682 |
const dot = document.createElement("span"); |
| 683 |
dot.className = "event item_" + item; |
| 684 |
dots.appendChild(dot); |
| 685 |
}); |
| 686 |
} |
| 687 |
}); |
| 688 |
} |
| 689 |
|
| 634 |
// Enable flatpickr now we have date function populated |
690 |
// Enable flatpickr now we have date function populated |
| 635 |
periodPicker.redraw(); |
691 |
periodPicker.redraw(); |
| 636 |
$("#period_fields :input").prop("disabled", false); |
692 |
$("#period_fields :input").prop("disabled", false); |
| 637 |
- |
|
|