mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-25 09:23:08 +03:00
Add additional handling for the next days filter
This commit is contained in:
parent
fe7b406cb3
commit
ebb682f518
2 changed files with 22 additions and 17 deletions
|
@ -233,9 +233,9 @@ App.Http.Booking = (function () {
|
|||
* @param {Number} providerId The selected provider ID.
|
||||
* @param {Number} serviceId The selected service ID.
|
||||
* @param {String} selectedDateString Y-m-d value of the selected date.
|
||||
* @param {Number} monthChangeStep Whether to add or subtract months.
|
||||
* @param {Number} [monthChangeStep] Whether to add or subtract months.
|
||||
*/
|
||||
function getUnavailableDates(providerId, serviceId, selectedDateString, monthChangeStep) {
|
||||
function getUnavailableDates(providerId, serviceId, selectedDateString, monthChangeStep = 1) {
|
||||
if (processingUnavailableDates) {
|
||||
return;
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ App.Http.Booking = (function () {
|
|||
searchedMonthStart = selectedDateString;
|
||||
}
|
||||
|
||||
if (searchedMonthCounter >= 3) {
|
||||
if (searchedMonthCounter >= 2) {
|
||||
// Need to mark the current month dates as unavailable
|
||||
const selectedDateMoment = moment(searchedMonthStart);
|
||||
const startOfMonthMoment = selectedDateMoment.clone().startOf('month');
|
||||
|
@ -278,7 +278,7 @@ App.Http.Booking = (function () {
|
|||
unavailableDates.push(startOfMonthMoment.format('YYYY-MM-DD'));
|
||||
startOfMonthMoment.add(monthChangeStep, 'days'); // Move to the next day
|
||||
}
|
||||
applyUnavailableDates(unavailableDates, searchedMonthStart, false);
|
||||
applyUnavailableDates(unavailableDates, searchedMonthStart, true);
|
||||
searchedMonthStart = undefined;
|
||||
searchedMonthCounter = 0;
|
||||
return; // Stop searching
|
||||
|
@ -312,6 +312,17 @@ App.Http.Booking = (function () {
|
|||
const selectedDate = selectedDateMoment.toDate();
|
||||
const numberOfDays = selectedDateMoment.daysInMonth();
|
||||
|
||||
// If all the days are unavailable then hide the appointments hours.
|
||||
if (unavailableDates.length === numberOfDays) {
|
||||
$availableHours.text(lang('no_available_hours'));
|
||||
}
|
||||
|
||||
// Grey out unavailable dates.
|
||||
$('#select-date')[0]._flatpickr.set(
|
||||
'disable',
|
||||
unavailableDates.map((unavailableDate) => new Date(unavailableDate)),
|
||||
);
|
||||
|
||||
if (setDate && !vars('manage_mode')) {
|
||||
for (let i = 1; i <= numberOfDays; i++) {
|
||||
const currentDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), i);
|
||||
|
@ -324,17 +335,6 @@ App.Http.Booking = (function () {
|
|||
}
|
||||
}
|
||||
|
||||
// If all the days are unavailable then hide the appointments hours.
|
||||
if (unavailableDates.length === numberOfDays) {
|
||||
$availableHours.text(lang('no_available_hours'));
|
||||
}
|
||||
|
||||
// Grey out unavailable dates.
|
||||
$('#select-date')[0]._flatpickr.set(
|
||||
'disable',
|
||||
unavailableDates.map((unavailableDate) => new Date(unavailableDate)),
|
||||
);
|
||||
|
||||
const dateQueryParam = App.Utils.Url.queryParam('date');
|
||||
|
||||
if (dateQueryParam) {
|
||||
|
|
|
@ -321,10 +321,15 @@ App.Pages.Booking = (function () {
|
|||
$selectProvider.on('change', (event) => {
|
||||
const $target = $(event.target);
|
||||
|
||||
const todayDateTimeObject = new Date();
|
||||
const todayDateTimeMoment = moment(todayDateTimeObject);
|
||||
|
||||
App.Utils.UI.setDateTimePickerValue($selectDate, todayDateTimeObject);
|
||||
|
||||
App.Http.Booking.getUnavailableDates(
|
||||
$target.val(),
|
||||
$selectService.val(),
|
||||
moment(App.Utils.UI.getDateTimePickerValue($selectDate)).format('YYYY-MM-DD'),
|
||||
todayDateTimeMoment.format('YYYY-MM-DD'),
|
||||
);
|
||||
updateConfirmFrame();
|
||||
});
|
||||
|
@ -887,7 +892,7 @@ App.Pages.Booking = (function () {
|
|||
}
|
||||
|
||||
if (Number(service.price) > 0) {
|
||||
additionalInfoParts.push(`${lang('price')}: ${service.price} ${service.currency}`);
|
||||
additionalInfoParts.push(`${lang('price')}: ${Number(service.price).toFixed(2)} ${service.currency}`);
|
||||
}
|
||||
|
||||
if (service.location) {
|
||||
|
|
Loading…
Reference in a new issue