diff --git a/changelog.md b/changelog.md index 8db80db..f3a8389 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## unreleased +* Don't fetch available days when no products have been selected + ## 1.2.0 (2019-12-03) * Show error when input is higher than allowed * Allow selecting only a few package IDs diff --git a/src/booking.js b/src/booking.js index bfa84e2..87937e0 100644 --- a/src/booking.js +++ b/src/booking.js @@ -959,7 +959,7 @@ class RecrasBooking {
- +
@@ -1010,82 +1010,75 @@ class RecrasBooking { this.appendHtml(html); } showDateTimeSelection(pack) { - let startDate = new Date(); - let endDate = new Date(); - endDate.setMonth(endDate.getMonth() + 3); + this.addDateTimeSelectionHtml(); + this.showDiscountFields(); - return this.getAvailableDays(pack.id, startDate, endDate) - .then(() => { - this.addDateTimeSelectionHtml(); - this.showDiscountFields(); - - if (this.options.getPreFilledAmounts()) { - this.preFillAmounts(this.options.getPreFilledAmounts()); - } - - let pikadayOptions = Object.assign( - RecrasCalendarHelper.defaultOptions(), - { - disableDayFn: (day) => { - let dateFmt = RecrasDateHelper.datePartOnly(day); - return this.availableDays.indexOf(dateFmt) === -1; - }, - field: this.findElement('.recras-onlinebooking-date'), - i18n: RecrasCalendarHelper.i18n(this.languageHelper), - onDraw: (pika) => { - let lastMonthYear = pika.calendars[pika.calendars.length - 1]; - let lastDay = new Date(lastMonthYear.year, lastMonthYear.month, 31); - - let lastAvailableDay = this.availableDays.reduce((acc, curVal) => { - return curVal > acc ? curVal : acc; - }, ''); - if (!lastAvailableDay) { - lastAvailableDay = new Date(); - } else { - lastAvailableDay = new Date(lastAvailableDay); - } - if (lastAvailableDay > lastDay) { - return; - } - - let newEndDate = RecrasDateHelper.clone(lastAvailableDay); - newEndDate.setFullYear(lastMonthYear.year); - newEndDate.setMonth(lastMonthYear.month + 2); - - this.getAvailableDays(pack.id, lastAvailableDay, newEndDate); - }, - onSelect: (date) => { - this.loadingIndicatorShow(this.findElement('label[for="recras-onlinebooking-time"]')); - this.eventHelper.sendEvent(RecrasEventHelper.PREFIX_BOOKING, RecrasEventHelper.EVENT_BOOKING_DATE_SELECTED); - this.selectedDate = date; - this.getAvailableTimes(pack.id, date).then(times => { - times = times.map(time => RecrasDateHelper.timePartOnly(new Date(time))); - this.showTimes(times); - this.loadingIndicatorHide(); - this.selectSingleTime(); - }); - this.maybeDisableBookButton(); - }, + if (this.options.getPreFilledAmounts()) { + this.preFillAmounts(this.options.getPreFilledAmounts()); + } + let pikadayOptions = Object.assign( + RecrasCalendarHelper.defaultOptions(), + { + disableDayFn: (day) => { + let dateFmt = RecrasDateHelper.datePartOnly(day); + return this.availableDays.indexOf(dateFmt) === -1; + }, + field: this.findElement('.recras-onlinebooking-date'), + i18n: RecrasCalendarHelper.i18n(this.languageHelper), + onDraw: (pika) => { + let lastMonthYear = pika.calendars[pika.calendars.length - 1]; + let lastDay = new Date(lastMonthYear.year, lastMonthYear.month, 31); + + let lastAvailableDay = this.availableDays.reduce((acc, curVal) => { + return curVal > acc ? curVal : acc; + }, ''); + if (!lastAvailableDay) { + lastAvailableDay = new Date(); + } else { + lastAvailableDay = new Date(lastAvailableDay); } - ); + if (lastAvailableDay > lastDay) { + return; + } + + let newEndDate = RecrasDateHelper.clone(lastAvailableDay); + newEndDate.setFullYear(lastMonthYear.year); + newEndDate.setMonth(lastMonthYear.month + 2); + + this.getAvailableDays(pack.id, lastAvailableDay, newEndDate); + }, + onSelect: (date) => { + this.loadingIndicatorShow(this.findElement('label[for="recras-onlinebooking-time"]')); + this.eventHelper.sendEvent(RecrasEventHelper.PREFIX_BOOKING, RecrasEventHelper.EVENT_BOOKING_DATE_SELECTED); + this.selectedDate = date; + this.getAvailableTimes(pack.id, date).then(times => { + times = times.map(time => RecrasDateHelper.timePartOnly(new Date(time))); + this.showTimes(times); + this.loadingIndicatorHide(); + this.selectSingleTime(); + }); + this.findElement('#discountcode').removeAttribute('disabled'); + this.maybeDisableBookButton(); + }, + } + ); - this.datePicker = new Pikaday(pikadayOptions); + this.datePicker = new Pikaday(pikadayOptions); - this.findElement('.recras-onlinebooking-time').addEventListener('change', () => { - this.eventHelper.sendEvent(RecrasEventHelper.PREFIX_BOOKING, RecrasEventHelper.EVENT_BOOKING_TIME_SELECTED); - this.selectedTime = this.findElement('.recras-onlinebooking-time').value; + this.findElement('.recras-onlinebooking-time').addEventListener('change', () => { + this.eventHelper.sendEvent(RecrasEventHelper.PREFIX_BOOKING, RecrasEventHelper.EVENT_BOOKING_TIME_SELECTED); + this.selectedTime = this.findElement('.recras-onlinebooking-time').value; - this.nextSectionActive('.recras-datetime', '.recras-discounts'); - this.nextSectionActive(null, '.recras-contactform'); + this.nextSectionActive('.recras-datetime', '.recras-discounts'); + this.nextSectionActive(null, '.recras-contactform'); - this.selectedDate = RecrasDateHelper.setTimeForDate(this.selectedDate, this.selectedTime); - if (this.options.getPreviewTimes() === true) { - this.previewTimes(); - } + this.selectedDate = RecrasDateHelper.setTimeForDate(this.selectedDate, this.selectedTime); + if (this.options.getPreviewTimes() === true) { + this.previewTimes(); + } - this.maybeDisableBookButton(); - }); - }); + this.maybeDisableBookButton(); + }); } showPackages(packages) {