Lines 464-469
$("#placeBookingModal").on("show.bs.modal", function (e) {
Link Here
|
464 |
}); |
464 |
}); |
465 |
} |
465 |
} |
466 |
|
466 |
|
|
|
467 |
// Create a bookings store keyed on date |
468 |
let bookingsByDate = {}; |
469 |
// Iterate through the bookings array |
470 |
bookings.forEach(booking => { |
471 |
const start_date = flatpickr.parseDate(booking.start_date); |
472 |
const end_date = flatpickr.parseDate(booking.end_date); |
473 |
const item_id = booking.item_id; |
474 |
|
475 |
// Iterate through each date within the range of start_date and end_date |
476 |
let currentDate = new Date(start_date); |
477 |
while (currentDate <= end_date) { |
478 |
const currentDateStr = currentDate |
479 |
.toISOString() |
480 |
.split("T")[0]; |
481 |
|
482 |
// If the date key doesn't exist in the hash, create an empty array for it |
483 |
if (!bookingsByDate[currentDateStr]) { |
484 |
bookingsByDate[currentDateStr] = []; |
485 |
} |
486 |
|
487 |
// Push the booking ID to the array corresponding to the date key |
488 |
bookingsByDate[currentDateStr].push(item_id); |
489 |
|
490 |
// Move to the next day |
491 |
currentDate.setDate(currentDate.getDate() + 1); |
492 |
} |
493 |
}); |
494 |
|
495 |
// Set onDayCreate for flatpickr |
496 |
let dayCreateExists = periodPicker.config.onDayCreate.filter( |
497 |
f => f.name === "dayCreate" |
498 |
); |
499 |
if (dayCreateExists.length === 0) { |
500 |
periodPicker.config.onDayCreate.push(function dayCreate( |
501 |
dObj, |
502 |
dStr, |
503 |
instance, |
504 |
dayElem |
505 |
) { |
506 |
const currentDate = dayElem.dateObj |
507 |
.toISOString() |
508 |
.split("T")[0]; |
509 |
|
510 |
if (bookingsByDate[currentDate]) { |
511 |
const dots = document.createElement("span"); |
512 |
dots.className = "event-dots"; |
513 |
dayElem.appendChild(dots); |
514 |
bookingsByDate[currentDate].forEach(item => { |
515 |
const dot = document.createElement("span"); |
516 |
dot.className = "event item_" + item; |
517 |
dots.appendChild(dot); |
518 |
}); |
519 |
} |
520 |
}); |
521 |
} |
522 |
|
467 |
// Enable flatpickr now we have date function populated |
523 |
// Enable flatpickr now we have date function populated |
468 |
periodPicker.redraw(); |
524 |
periodPicker.redraw(); |
469 |
$("#period_fields :input").prop("disabled", false); |
525 |
$("#period_fields :input").prop("disabled", false); |
470 |
- |
|
|