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