2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2015-07-20 22:41:24 +03:00
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2022-01-18 15:01:22 +03:00
|
|
|
* @since v1.5.0
|
2015-07-20 22:41:24 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2022-01-14 11:26:44 +03:00
|
|
|
* Booking page.
|
2016-04-26 22:51:16 +03:00
|
|
|
*
|
2022-01-14 11:26:44 +03:00
|
|
|
* This module implements the functionality of the booking page
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2022-01-13 13:33:40 +03:00
|
|
|
* Old Name: FrontendBook
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2022-01-13 13:33:40 +03:00
|
|
|
App.Pages.Booking = (function () {
|
2022-01-17 07:57:52 +03:00
|
|
|
const $cookieNoticeLink = $('.cc-link');
|
|
|
|
const $selectDate = $('#select-date');
|
|
|
|
const $selectService = $('#select-service');
|
|
|
|
const $selectProvider = $('#select-provider');
|
|
|
|
const $selectTimezone = $('#select-timezone');
|
|
|
|
const $firstName = $('#first-name');
|
|
|
|
const $lastName = $('#last-name');
|
|
|
|
const $email = $('#email');
|
|
|
|
const $phoneNumber = $('#phone-number');
|
|
|
|
const $address = $('#address');
|
|
|
|
const $city = $('#city');
|
|
|
|
const $zipCode = $('#zip-code');
|
|
|
|
const $notes = $('#notes');
|
|
|
|
const $captchaTitle = $('.captcha-title');
|
|
|
|
const $availableHours = $('#available-hours');
|
|
|
|
const $bookAppointmentSubmit = $('#book-appointment-submit');
|
|
|
|
const $deletePersonalInformation = $('#delete-personal-information');
|
|
|
|
|
2018-06-24 18:27:16 +03:00
|
|
|
/**
|
|
|
|
* Contains terms and conditions consent.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2022-01-13 13:33:40 +03:00
|
|
|
let termsAndConditionsConsent;
|
2018-06-24 18:27:16 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains privacy policy consent.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2022-01-13 13:33:40 +03:00
|
|
|
let privacyPolicyConsent;
|
2018-06-24 18:27:16 +03:00
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
/**
|
|
|
|
* Determines the functionality of the page.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* @type {Boolean}
|
2013-06-03 17:42:19 +03:00
|
|
|
*/
|
2022-01-13 13:33:40 +03:00
|
|
|
let manageMode = false;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2022-01-14 11:26:44 +03:00
|
|
|
* Initialize the module.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2022-01-13 13:33:40 +03:00
|
|
|
function initialize() {
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('display_cookie_notice')) {
|
2018-06-24 17:58:03 +03:00
|
|
|
cookieconsent.initialise({
|
|
|
|
palette: {
|
|
|
|
popup: {
|
|
|
|
background: '#ffffffbd',
|
|
|
|
text: '#666666'
|
|
|
|
},
|
|
|
|
button: {
|
2020-12-08 10:59:17 +03:00
|
|
|
background: '#429a82',
|
2018-06-24 17:58:03 +03:00
|
|
|
text: '#ffffff'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
content: {
|
2022-01-18 10:22:25 +03:00
|
|
|
message: lang('website_using_cookies_to_ensure_best_experience'),
|
2018-06-24 17:58:03 +03:00
|
|
|
dismiss: 'OK'
|
2021-11-06 19:38:37 +03:00
|
|
|
}
|
2018-06-24 17:58:03 +03:00
|
|
|
});
|
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
$cookieNoticeLink.replaceWith(
|
2018-06-24 17:58:03 +03:00
|
|
|
$('<a/>', {
|
|
|
|
'data-toggle': 'modal',
|
|
|
|
'data-target': '#cookie-notice-modal',
|
|
|
|
'href': '#',
|
|
|
|
'class': 'cc-link',
|
2022-01-17 07:57:52 +03:00
|
|
|
'text': $cookieNoticeLink.text()
|
2018-06-24 17:58:03 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2016-01-01 22:57:44 +02:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
manageMode = vars('manage_mode');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-05-20 20:21:58 +03:00
|
|
|
// Initialize page's components (tooltips, datepickers etc).
|
2020-10-22 12:29:09 +03:00
|
|
|
tippy('[data-tippy-content]');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const weekdayId = App.Utils.Date.getWeekdayId(vars('first_weekday'));
|
2018-06-29 01:41:17 +03:00
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectDate.datepicker({
|
2013-07-02 20:18:19 +03:00
|
|
|
dateFormat: 'dd-mm-yy',
|
2022-01-17 20:00:25 +03:00
|
|
|
firstDay: weekdayId,
|
2013-07-02 20:18:19 +03:00
|
|
|
minDate: 0,
|
2021-11-24 10:34:26 +03:00
|
|
|
defaultDate: moment().toDate(),
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-05-14 13:07:16 +03:00
|
|
|
dayNames: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('sunday'),
|
|
|
|
lang('monday'),
|
|
|
|
lang('tuesday'),
|
|
|
|
lang('wednesday'),
|
|
|
|
lang('thursday'),
|
|
|
|
lang('friday'),
|
|
|
|
lang('saturday')
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesShort: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('sunday').substr(0, 3),
|
|
|
|
lang('monday').substr(0, 3),
|
|
|
|
lang('tuesday').substr(0, 3),
|
|
|
|
lang('wednesday').substr(0, 3),
|
|
|
|
lang('thursday').substr(0, 3),
|
|
|
|
lang('friday').substr(0, 3),
|
|
|
|
lang('saturday').substr(0, 3)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesMin: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('sunday').substr(0, 2),
|
|
|
|
lang('monday').substr(0, 2),
|
|
|
|
lang('tuesday').substr(0, 2),
|
|
|
|
lang('wednesday').substr(0, 2),
|
|
|
|
lang('thursday').substr(0, 2),
|
|
|
|
lang('friday').substr(0, 2),
|
|
|
|
lang('saturday').substr(0, 2)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
monthNames: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('january'),
|
|
|
|
lang('february'),
|
|
|
|
lang('march'),
|
|
|
|
lang('april'),
|
|
|
|
lang('may'),
|
|
|
|
lang('june'),
|
|
|
|
lang('july'),
|
|
|
|
lang('august'),
|
|
|
|
lang('september'),
|
|
|
|
lang('october'),
|
|
|
|
lang('november'),
|
|
|
|
lang('december')
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
2022-01-18 10:22:25 +03:00
|
|
|
prevText: lang('previous'),
|
|
|
|
nextText: lang('next'),
|
|
|
|
currentText: lang('now'),
|
|
|
|
closeText: lang('close'),
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
onSelect: () => {
|
|
|
|
App.Http.Booking.getAvailableHours(moment($selectDate.datepicker('getDate')).format('YYYY-MM-DD'));
|
2022-01-13 13:33:40 +03:00
|
|
|
updateConfirmFrame();
|
2016-03-31 21:08:21 +03:00
|
|
|
},
|
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
onChangeMonthYear: (year, month) => {
|
|
|
|
const currentDate = new Date(year, month - 1, 1);
|
2021-11-25 10:40:48 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Booking.getUnavailabilityDates(
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectProvider.val(),
|
|
|
|
$selectService.val(),
|
2021-11-25 10:40:48 +03:00
|
|
|
moment(currentDate).format('YYYY-MM-DD')
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
|
|
|
});
|
2013-12-20 19:44:44 +02:00
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectTimezone.val(Intl.DateTimeFormat().resolvedOptions().timeZone);
|
2020-03-29 17:20:30 +03:00
|
|
|
|
2016-07-16 22:06:55 +03:00
|
|
|
// Bind the event handlers (might not be necessary every time we use this class).
|
2022-01-17 07:57:52 +03:00
|
|
|
addEventListeners();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-07-16 22:06:55 +03:00
|
|
|
// If the manage mode is true, the appointments data should be loaded by default.
|
2022-01-13 13:33:40 +03:00
|
|
|
if (manageMode) {
|
2022-01-18 10:18:22 +03:00
|
|
|
applyAppointmentData(vars('appointment_data'), vars('provider_data'), vars('customer_data'));
|
2013-06-03 17:42:19 +03:00
|
|
|
} else {
|
2016-07-17 12:43:52 +03:00
|
|
|
// Check if a specific service was selected (via URL parameter).
|
2022-01-17 19:54:30 +03:00
|
|
|
const selectedServiceId = App.Utils.Url.queryParam('service');
|
2016-07-16 22:06:55 +03:00
|
|
|
|
|
|
|
if (selectedServiceId && $selectService.find('option[value="' + selectedServiceId + '"]').length > 0) {
|
2017-06-11 22:10:53 +03:00
|
|
|
$selectService.val(selectedServiceId);
|
2016-07-16 22:06:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$selectService.trigger('change'); // Load the available hours.
|
|
|
|
|
2020-03-29 17:20:30 +03:00
|
|
|
// Check if a specific provider was selected.
|
2022-01-17 19:54:30 +03:00
|
|
|
const selectedProviderId = App.Utils.Url.queryParam('provider');
|
2018-01-23 12:08:37 +03:00
|
|
|
|
2016-07-17 12:43:52 +03:00
|
|
|
if (selectedProviderId && $selectProvider.find('option[value="' + selectedProviderId + '"]').length === 0) {
|
2020-03-29 17:20:30 +03:00
|
|
|
// Select a service of this provider in order to make the provider available in the select box.
|
2022-01-18 10:18:22 +03:00
|
|
|
for (const index in vars('available_providers')) {
|
|
|
|
const provider = vars('available_providers')[index];
|
2016-07-17 12:43:52 +03:00
|
|
|
|
|
|
|
if (provider.id === selectedProviderId && provider.services.length > 0) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$selectService.val(provider.services[0]).trigger('change');
|
2016-07-17 12:43:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 22:06:55 +03:00
|
|
|
if (selectedProviderId && $selectProvider.find('option[value="' + selectedProviderId + '"]').length > 0) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$selectProvider.val(selectedProviderId).trigger('change');
|
2016-07-16 22:06:55 +03:00
|
|
|
}
|
2022-01-24 17:22:34 +03:00
|
|
|
|
|
|
|
if (selectedServiceId && selectedProviderId) {
|
|
|
|
$selectService.closest('.wizard-frame').find('.button-next').trigger('click');
|
|
|
|
|
|
|
|
$(document).find('.book-step:first').hide();
|
|
|
|
|
|
|
|
$(document).find('.button-back:first').css('visibility', 'hidden');
|
|
|
|
|
|
|
|
$(document)
|
|
|
|
.find('.book-step:not(:first)')
|
|
|
|
.each((index, bookStepEl) =>
|
|
|
|
$(bookStepEl)
|
|
|
|
.find('strong')
|
|
|
|
.text(index + 1)
|
|
|
|
);
|
|
|
|
}
|
2013-06-03 17:42:19 +03:00
|
|
|
}
|
2022-01-13 13:33:40 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2022-01-17 07:57:52 +03:00
|
|
|
* Add the page event listeners.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2022-01-17 07:57:52 +03:00
|
|
|
function addEventListeners() {
|
2020-03-29 17:20:30 +03:00
|
|
|
/**
|
|
|
|
* Event: Timezone "Changed"
|
|
|
|
*/
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectTimezone.on('change', () => {
|
|
|
|
const date = $selectDate.datepicker('getDate');
|
2020-03-29 17:20:30 +03:00
|
|
|
|
|
|
|
if (!date) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
App.Http.Booking.getAvailableHours(moment(date).format('YYYY-MM-DD'));
|
2020-03-29 17:20:30 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
updateConfirmFrame();
|
2020-03-29 17:20:30 +03:00
|
|
|
});
|
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2013-07-02 20:18:19 +03:00
|
|
|
* Event: Selected Provider "Changed"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* Whenever the provider changes the available appointment date - time periods must be updated.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectProvider.on('change', (event) => {
|
|
|
|
const $target = $(event.target);
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Booking.getUnavailabilityDates(
|
2022-01-24 17:08:30 +03:00
|
|
|
$target.val(),
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectService.val(),
|
|
|
|
moment($selectDate.datepicker('getDate')).format('YYYY-MM-DD')
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
2022-01-13 13:33:40 +03:00
|
|
|
updateConfirmFrame();
|
2013-04-20 20:20:16 +03:00
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2013-07-02 20:18:19 +03:00
|
|
|
* Event: Selected Service "Changed"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
|
|
|
* When the user clicks on a service, its available providers should
|
|
|
|
* become visible.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectService.on('change', (event) => {
|
|
|
|
const $target = $(event.target);
|
|
|
|
const serviceId = $selectService.val();
|
2020-05-12 21:52:32 +03:00
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectProvider.empty();
|
2013-04-20 20:20:16 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('available_providers').forEach((provider) => {
|
2020-05-12 21:52:32 +03:00
|
|
|
// If the current provider is able to provide the selected service, add him to the list box.
|
2022-01-13 13:33:40 +03:00
|
|
|
const canServeService =
|
|
|
|
provider.services.filter((providerServiceId) => Number(providerServiceId) === Number(serviceId))
|
|
|
|
.length > 0;
|
2020-05-12 21:52:32 +03:00
|
|
|
|
|
|
|
if (canServeService) {
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectProvider.append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
|
2020-05-12 21:52:32 +03:00
|
|
|
}
|
2013-04-20 20:20:16 +03:00
|
|
|
});
|
|
|
|
|
2015-10-28 00:49:05 +03:00
|
|
|
// Add the "Any Provider" entry.
|
2022-01-18 10:18:22 +03:00
|
|
|
if ($selectProvider.find('option').length >= 1 && vars('display_any_provider') === '1') {
|
2022-01-18 10:22:25 +03:00
|
|
|
$selectProvider.prepend(new Option('- ' + lang('any_provider') + ' -', 'any-provider', true, true));
|
2015-10-28 00:49:05 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Booking.getUnavailabilityDates(
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectProvider.val(),
|
|
|
|
$target.val(),
|
|
|
|
moment($selectDate.datepicker('getDate')).format('YYYY-MM-DD')
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
2022-01-13 13:33:40 +03:00
|
|
|
|
|
|
|
updateConfirmFrame();
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
updateServiceDescription(serviceId);
|
2013-04-20 20:20:16 +03:00
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2013-07-02 20:18:19 +03:00
|
|
|
* Event: Next Step Button "Clicked"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* This handler is triggered every time the user pressed the "next" button on the book wizard.
|
2022-01-13 13:33:40 +03:00
|
|
|
* Some special tasks might be performed, depending on the current wizard step.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2022-01-13 13:33:40 +03:00
|
|
|
$('.button-next').on('click', (event) => {
|
2022-01-17 07:57:52 +03:00
|
|
|
const $target = $(event.target);
|
|
|
|
|
|
|
|
// If we are on the first step and there is no provider selected do not continue with the next step.
|
|
|
|
if ($target.attr('data-step_index') === '1' && !$selectProvider.val()) {
|
2015-12-11 00:29:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-14 21:40:32 +03:00
|
|
|
// If we are on the 2nd tab then the user should have an appointment hour selected.
|
2022-01-17 07:57:52 +03:00
|
|
|
if ($target.attr('data-step_index') === '2') {
|
2020-05-06 20:15:11 +03:00
|
|
|
if (!$('.selected-hour').length) {
|
|
|
|
if (!$('#select-hour-prompt').length) {
|
2020-12-14 21:40:32 +03:00
|
|
|
$('<div/>', {
|
|
|
|
'id': 'select-hour-prompt',
|
|
|
|
'class': 'text-danger mb-4',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('appointment_hour_missing')
|
2021-11-06 19:38:37 +03:00
|
|
|
}).prependTo('#available-hours');
|
2013-05-20 20:21:58 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-12-14 21:40:32 +03:00
|
|
|
// If we are on the 3rd tab then we will need to validate the user's input before proceeding to the next
|
|
|
|
// step.
|
2022-01-17 07:57:52 +03:00
|
|
|
if ($target.attr('data-step_index') === '3') {
|
2020-05-06 20:23:49 +03:00
|
|
|
if (!validateCustomerForm()) {
|
2013-05-20 20:21:58 +03:00
|
|
|
return; // Validation failed, do not continue.
|
2013-04-20 20:20:16 +03:00
|
|
|
} else {
|
2022-01-13 13:33:40 +03:00
|
|
|
updateConfirmFrame();
|
2018-06-24 18:27:16 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
const $acceptToTermsAndConditions = $('#accept-to-terms-and-conditions');
|
2018-06-24 18:27:16 +03:00
|
|
|
if ($acceptToTermsAndConditions.length && $acceptToTermsAndConditions.prop('checked') === true) {
|
2022-01-13 13:33:40 +03:00
|
|
|
const newTermsAndConditionsConsent = {
|
2022-01-17 07:57:52 +03:00
|
|
|
first_name: $firstName.val(),
|
|
|
|
last_name: $lastName.val(),
|
|
|
|
email: $email.val(),
|
2018-06-24 18:27:16 +03:00
|
|
|
type: 'terms-and-conditions'
|
|
|
|
};
|
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
if (
|
|
|
|
JSON.stringify(newTermsAndConditionsConsent) !== JSON.stringify(termsAndConditionsConsent)
|
|
|
|
) {
|
2018-06-24 18:27:16 +03:00
|
|
|
termsAndConditionsConsent = newTermsAndConditionsConsent;
|
2022-01-13 13:33:40 +03:00
|
|
|
App.Http.Booking.saveConsent(termsAndConditionsConsent);
|
2018-06-24 18:27:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
const $acceptToPrivacyPolicy = $('#accept-to-privacy-policy');
|
2018-06-24 18:27:16 +03:00
|
|
|
if ($acceptToPrivacyPolicy.length && $acceptToPrivacyPolicy.prop('checked') === true) {
|
2022-01-13 13:33:40 +03:00
|
|
|
const newPrivacyPolicyConsent = {
|
2022-01-17 07:57:52 +03:00
|
|
|
first_name: $firstName.val(),
|
|
|
|
last_name: $lastName.val(),
|
|
|
|
email: $email.val(),
|
2018-06-24 18:27:16 +03:00
|
|
|
type: 'privacy-policy'
|
|
|
|
};
|
|
|
|
|
|
|
|
if (JSON.stringify(newPrivacyPolicyConsent) !== JSON.stringify(privacyPolicyConsent)) {
|
|
|
|
privacyPolicyConsent = newPrivacyPolicyConsent;
|
2022-01-13 13:33:40 +03:00
|
|
|
App.Http.Booking.saveConsent(privacyPolicyConsent);
|
2018-06-24 18:27:16 +03:00
|
|
|
}
|
|
|
|
}
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-05-20 20:21:58 +03:00
|
|
|
// Display the next step tab (uses jquery animation effect).
|
2022-01-17 07:57:52 +03:00
|
|
|
const nextTabIndex = parseInt($target.attr('data-step_index')) + 1;
|
2013-04-20 20:20:16 +03:00
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
$target
|
2021-11-06 19:38:37 +03:00
|
|
|
.parents()
|
|
|
|
.eq(1)
|
2022-01-13 13:33:40 +03:00
|
|
|
.hide('fade', () => {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('.active-step').removeClass('active-step');
|
|
|
|
$('#step-' + nextTabIndex).addClass('active-step');
|
|
|
|
$('#wizard-frame-' + nextTabIndex).show('fade');
|
|
|
|
});
|
2013-04-20 20:20:16 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2013-07-02 20:18:19 +03:00
|
|
|
* Event: Back Step Button "Clicked"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* This handler is triggered every time the user pressed the "back" button on the
|
|
|
|
* book wizard.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2022-01-13 13:33:40 +03:00
|
|
|
$('.button-back').on('click', (event) => {
|
|
|
|
const prevTabIndex = parseInt($(event.target).attr('data-step_index')) - 1;
|
2013-04-20 20:20:16 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
$(event.target)
|
2021-11-06 19:38:37 +03:00
|
|
|
.parents()
|
|
|
|
.eq(1)
|
2022-01-13 13:33:40 +03:00
|
|
|
.hide('fade', () => {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('.active-step').removeClass('active-step');
|
|
|
|
$('#step-' + prevTabIndex).addClass('active-step');
|
|
|
|
$('#wizard-frame-' + prevTabIndex).show('fade');
|
|
|
|
});
|
2013-04-20 20:20:16 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2013-07-02 20:18:19 +03:00
|
|
|
* Event: Available Hour "Click"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2022-01-17 07:57:52 +03:00
|
|
|
* Triggered whenever the user clicks on an available hour for his appointment.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2022-01-17 07:57:52 +03:00
|
|
|
$availableHours.on('click', '.available-hour', (event) => {
|
|
|
|
$availableHours.find('.selected-hour').removeClass('selected-hour');
|
2022-01-13 13:33:40 +03:00
|
|
|
$(event.target).addClass('selected-hour');
|
|
|
|
updateConfirmFrame();
|
2013-04-20 20:20:16 +03:00
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
if (manageMode) {
|
2013-06-10 18:51:23 +03:00
|
|
|
/**
|
|
|
|
* Event: Cancel Appointment Button "Click"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* When the user clicks the "Cancel" button this form is going to be submitted. We need
|
|
|
|
* the user to confirm this action because once the appointment is cancelled, it will be
|
|
|
|
* delete from the database.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
2013-06-10 18:51:23 +03:00
|
|
|
*/
|
2022-01-13 13:33:40 +03:00
|
|
|
$('#cancel-appointment').on('click', () => {
|
2022-01-17 07:57:52 +03:00
|
|
|
const $cancelAppointmentForm = $('#cancel-appointment-form');
|
|
|
|
|
|
|
|
let $cancelReason;
|
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
const buttons = [
|
2020-08-31 17:26:28 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
text: lang('cancel'),
|
2022-01-17 07:57:52 +03:00
|
|
|
click: () => {
|
2020-09-07 11:08:18 +03:00
|
|
|
$('#message-box').dialog('close');
|
2020-08-31 17:26:28 +03:00
|
|
|
}
|
|
|
|
},
|
2017-09-23 04:49:46 +03:00
|
|
|
{
|
|
|
|
text: 'OK',
|
2022-01-17 07:57:52 +03:00
|
|
|
click: () => {
|
|
|
|
if ($cancelReason.val() === '') {
|
|
|
|
$cancelReason.css('border', '2px solid #DC3545');
|
2017-09-23 04:49:46 +03:00
|
|
|
return;
|
|
|
|
}
|
2022-01-17 07:57:52 +03:00
|
|
|
$cancelAppointmentForm.find('textarea').val($cancelReason.val());
|
|
|
|
$cancelAppointmentForm.submit();
|
2017-09-23 04:49:46 +03:00
|
|
|
}
|
2013-06-10 18:51:23 +03:00
|
|
|
}
|
2017-09-23 04:49:46 +03:00
|
|
|
];
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-12 13:20:41 +03:00
|
|
|
App.Utils.Message.show(
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('cancel_appointment_title'),
|
|
|
|
lang('write_appointment_removal_reason'),
|
2021-11-06 19:38:37 +03:00
|
|
|
buttons
|
|
|
|
);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
$cancelReason = $('<textarea/>', {
|
2020-08-31 17:26:28 +03:00
|
|
|
'class': 'form-control',
|
|
|
|
'id': 'cancel-reason',
|
|
|
|
'rows': '3',
|
|
|
|
'css': {
|
|
|
|
'width': '100%'
|
|
|
|
}
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#message-box');
|
2020-08-31 17:26:28 +03:00
|
|
|
|
2014-01-04 00:26:10 +02:00
|
|
|
return false;
|
2013-06-10 18:51:23 +03:00
|
|
|
});
|
2018-06-24 20:08:45 +03:00
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
$deletePersonalInformation.on('click', () => {
|
2022-01-13 13:33:40 +03:00
|
|
|
const buttons = [
|
2018-06-24 20:08:45 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
text: lang('cancel'),
|
2022-01-13 13:33:40 +03:00
|
|
|
click: () => {
|
2020-09-07 11:08:18 +03:00
|
|
|
$('#message-box').dialog('close');
|
2018-06-24 20:08:45 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
text: lang('delete'),
|
2022-01-13 13:33:40 +03:00
|
|
|
click: () => {
|
2022-01-18 10:18:22 +03:00
|
|
|
App.Http.Booking.deletePersonalInformation(vars('customer_token'));
|
2018-06-24 20:08:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-01-12 13:20:41 +03:00
|
|
|
App.Utils.Message.show(
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('delete_personal_information'),
|
|
|
|
lang('delete_personal_information_prompt'),
|
2021-11-06 19:38:37 +03:00
|
|
|
buttons
|
|
|
|
);
|
2018-06-24 20:08:45 +03:00
|
|
|
});
|
2013-06-10 18:51:23 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-28 17:23:17 +03:00
|
|
|
/**
|
2013-07-02 20:18:19 +03:00
|
|
|
* Event: Book Appointment Form "Submit"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-06-28 17:23:17 +03:00
|
|
|
* Before the form is submitted to the server we need to make sure that
|
|
|
|
* in the meantime the selected appointment date/time wasn't reserved by
|
2015-10-09 00:12:59 +03:00
|
|
|
* another customer or event.
|
2016-05-14 13:07:16 +03:00
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
2013-06-28 17:23:17 +03:00
|
|
|
*/
|
2022-01-17 07:57:52 +03:00
|
|
|
$bookAppointmentSubmit.on('click', () => {
|
2022-01-13 13:33:40 +03:00
|
|
|
App.Http.Booking.registerAppointment();
|
2013-06-28 17:23:17 +03:00
|
|
|
});
|
2015-10-22 00:29:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Refresh captcha image.
|
|
|
|
*/
|
2022-01-17 07:57:52 +03:00
|
|
|
$captchaTitle.on('click', 'button', () => {
|
2022-01-17 20:00:25 +03:00
|
|
|
$('.captcha-image').attr('src', App.Utils.Url.siteUrl('captcha?' + Date.now()));
|
2015-10-22 00:29:20 +03:00
|
|
|
});
|
2016-07-19 00:23:53 +03:00
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectDate.on('mousedown', '.ui-datepicker-calendar td', () => {
|
2022-01-13 13:33:40 +03:00
|
|
|
setTimeout(() => {
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Booking.applyPreviousUnavailabilityDates();
|
2022-01-17 07:57:52 +03:00
|
|
|
}, 300);
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2018-02-23 17:33:41 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2022-01-17 07:57:52 +03:00
|
|
|
* This function validates the customer's data input. The user cannot continue without passing all the validation
|
|
|
|
* checks.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* @return {Boolean} Returns the validation result.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
function validateCustomerForm() {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#wizard-frame-3 .is-invalid').removeClass('is-invalid');
|
2018-06-24 17:58:03 +03:00
|
|
|
$('#wizard-frame-3 label.text-danger').removeClass('text-danger');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-29 00:54:12 +03:00
|
|
|
try {
|
2013-09-13 16:21:03 +03:00
|
|
|
// Validate required fields.
|
2022-01-13 13:33:40 +03:00
|
|
|
let missingRequiredField = false;
|
|
|
|
|
|
|
|
$('.required').each((index, requiredField) => {
|
2020-05-12 21:52:32 +03:00
|
|
|
if (!$(requiredField).val()) {
|
2022-01-24 20:36:12 +03:00
|
|
|
$(requiredField).addClass('is-invalid');
|
2013-06-29 00:54:12 +03:00
|
|
|
missingRequiredField = true;
|
|
|
|
}
|
|
|
|
});
|
2022-01-13 13:33:40 +03:00
|
|
|
|
2013-06-29 00:54:12 +03:00
|
|
|
if (missingRequiredField) {
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('fields_are_required'));
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
const $acceptToTermsAndConditions = $('#accept-to-terms-and-conditions');
|
2018-06-24 17:58:03 +03:00
|
|
|
if ($acceptToTermsAndConditions.length && !$acceptToTermsAndConditions.prop('checked')) {
|
2020-07-01 16:02:11 +03:00
|
|
|
$acceptToTermsAndConditions.parents('.form-check').addClass('text-danger');
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('fields_are_required'));
|
2018-06-24 17:58:03 +03:00
|
|
|
}
|
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
const $acceptToPrivacyPolicy = $('#accept-to-privacy-policy');
|
2018-06-24 17:58:03 +03:00
|
|
|
if ($acceptToPrivacyPolicy.length && !$acceptToPrivacyPolicy.prop('checked')) {
|
2020-07-01 16:02:11 +03:00
|
|
|
$acceptToPrivacyPolicy.parents('.form-check').addClass('text-danger');
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('fields_are_required'));
|
2018-06-24 17:58:03 +03:00
|
|
|
}
|
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
// Validate email address.
|
2022-01-17 19:54:30 +03:00
|
|
|
if ($email.val() && !App.Utils.Validation.email($email.val())) {
|
2022-01-24 20:36:12 +03:00
|
|
|
$email.addClass('is-invalid');
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('invalid_email'));
|
2013-06-29 00:54:12 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-24 17:48:20 +03:00
|
|
|
// Validate phone number.
|
|
|
|
const phoneNumber = $phoneNumber.val();
|
|
|
|
|
|
|
|
if (phoneNumber && !App.Utils.Validation.phone(phoneNumber)) {
|
|
|
|
$phoneNumber.addClass('is-invalid');
|
|
|
|
throw new Error(lang('invalid_phone'));
|
|
|
|
}
|
|
|
|
|
2013-06-29 00:54:12 +03:00
|
|
|
return true;
|
2020-05-06 20:15:11 +03:00
|
|
|
} catch (error) {
|
|
|
|
$('#form-message').text(error.message);
|
2013-06-29 00:54:12 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-26 22:51:16 +03:00
|
|
|
}
|
2013-04-20 20:20:16 +03:00
|
|
|
|
|
|
|
/**
|
2016-05-14 12:36:17 +03:00
|
|
|
* Every time this function is executed, it updates the confirmation page with the latest
|
2016-10-10 19:29:48 +03:00
|
|
|
* customer settings and input for the appointment booking.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2022-01-13 13:33:40 +03:00
|
|
|
function updateConfirmFrame() {
|
2022-01-17 07:57:52 +03:00
|
|
|
if ($availableHours.find('.selected-hour').text() === '') {
|
2017-10-31 14:56:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
// Appointment Details
|
2022-01-17 07:57:52 +03:00
|
|
|
let selectedDate = $selectDate.datepicker('getDate');
|
2016-05-14 13:07:16 +03:00
|
|
|
|
2013-05-17 16:09:10 +03:00
|
|
|
if (selectedDate !== null) {
|
2022-01-18 10:18:22 +03:00
|
|
|
selectedDate = App.Utils.Date.format(selectedDate, vars('date_format'), vars('time_format'));
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 07:57:52 +03:00
|
|
|
const serviceId = $selectService.val();
|
2022-01-13 13:33:40 +03:00
|
|
|
let servicePrice = '';
|
|
|
|
let serviceCurrency = '';
|
2016-05-14 13:07:16 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('available_services').forEach((service) => {
|
2020-12-09 15:17:45 +03:00
|
|
|
if (Number(service.id) === Number(serviceId) && Number(service.price) > 0) {
|
2020-05-07 19:47:14 +03:00
|
|
|
servicePrice = service.price;
|
2013-09-13 16:21:03 +03:00
|
|
|
serviceCurrency = service.currency;
|
2022-01-13 13:33:40 +03:00
|
|
|
return false; // Break loop
|
2013-09-13 16:21:03 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-24 17:22:34 +03:00
|
|
|
$(document).find('.display-selected-service').text($selectService.find('option:selected').text());
|
|
|
|
|
|
|
|
$(document).find('.display-selected-provider').text($selectProvider.find('option:selected').text());
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
$('#appointment-details').empty();
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<div/>', {
|
|
|
|
'html': [
|
|
|
|
$('<h4/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('appointment')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<p/>', {
|
|
|
|
'html': [
|
2020-09-28 14:26:12 +03:00
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('service') + ': ' + $selectService.find('option:selected').text()
|
2020-09-28 14:26:12 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('provider') + ': ' + $selectProvider.find('option:selected').text()
|
2020-09-28 14:26:12 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2022-01-17 07:57:52 +03:00
|
|
|
'text':
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('start') +
|
2022-01-17 07:57:52 +03:00
|
|
|
': ' +
|
|
|
|
selectedDate +
|
|
|
|
' ' +
|
|
|
|
$availableHours.find('.selected-hour').text()
|
2020-09-28 14:26:12 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('timezone') + ': ' + $selectTimezone.find('option:selected').text()
|
2020-09-28 14:26:12 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('price') + ': ' + servicePrice + ' ' + serviceCurrency,
|
2020-09-28 14:26:12 +03:00
|
|
|
'prop': {
|
|
|
|
'hidden': !servicePrice
|
|
|
|
}
|
2021-11-06 19:38:37 +03:00
|
|
|
})
|
2020-05-07 19:47:14 +03:00
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#appointment-details');
|
2013-04-20 20:20:16 +03:00
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
// Customer Details
|
2022-01-17 19:54:30 +03:00
|
|
|
const firstName = App.Utils.String.escapeHtml($firstName.val());
|
|
|
|
const lastName = App.Utils.String.escapeHtml($lastName.val());
|
|
|
|
const phoneNumber = App.Utils.String.escapeHtml($phoneNumber.val());
|
|
|
|
const email = App.Utils.String.escapeHtml($email.val());
|
|
|
|
const address = App.Utils.String.escapeHtml($address.val());
|
|
|
|
const city = App.Utils.String.escapeHtml($city.val());
|
|
|
|
const zipCode = App.Utils.String.escapeHtml($zipCode.val());
|
2015-11-28 13:55:03 +02:00
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
$('#customer-details').empty();
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<div/>', {
|
|
|
|
'html': [
|
|
|
|
$('<h4/>)', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('customer')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<p/>', {
|
|
|
|
'html': [
|
2020-09-28 14:26:12 +03:00
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('customer') + ': ' + firstName + ' ' + lastName
|
2020-09-28 14:26:12 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('phone_number') + ': ' + phoneNumber
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('email') + ': ' + email
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': address ? lang('address') + ': ' + address : ''
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': city ? lang('city') + ': ' + city : ''
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': zipCode ? lang('zip_code') + ': ' + zipCode : ''
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
2021-11-06 19:38:37 +03:00
|
|
|
$('<br/>')
|
2020-05-07 19:47:14 +03:00
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#customer-details');
|
2020-05-07 19:47:14 +03:00
|
|
|
|
|
|
|
// Update appointment form data for submission to server when the user confirms the appointment.
|
2022-01-13 13:33:40 +03:00
|
|
|
const data = {};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
data.customer = {
|
2022-01-17 07:57:52 +03:00
|
|
|
last_name: $lastName.val(),
|
|
|
|
first_name: $firstName.val(),
|
|
|
|
email: $email.val(),
|
|
|
|
phone_number: $phoneNumber.val(),
|
|
|
|
address: $address.val(),
|
|
|
|
city: $city.val(),
|
|
|
|
zip_code: $zipCode.val(),
|
|
|
|
timezone: $selectTimezone.val()
|
2013-05-04 00:26:04 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
data.appointment = {
|
2021-11-06 19:38:37 +03:00
|
|
|
start_datetime:
|
2022-01-17 07:57:52 +03:00
|
|
|
moment($selectDate.datepicker('getDate')).format('YYYY-MM-DD') +
|
2021-11-06 19:38:37 +03:00
|
|
|
' ' +
|
2021-11-25 10:40:48 +03:00
|
|
|
moment($('.selected-hour').data('value'), 'HH:mm').format('HH:mm') +
|
2021-11-06 19:38:37 +03:00
|
|
|
':00',
|
2020-05-06 20:23:49 +03:00
|
|
|
end_datetime: calculateEndDatetime(),
|
2022-01-17 07:57:52 +03:00
|
|
|
notes: $notes.val(),
|
2022-01-18 14:54:41 +03:00
|
|
|
is_unavailability: false,
|
2022-01-17 07:57:52 +03:00
|
|
|
id_users_provider: $selectProvider.val(),
|
|
|
|
id_services: $selectService.val()
|
2013-05-04 00:26:04 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
data.manage_mode = manageMode;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
if (manageMode) {
|
2022-01-18 10:18:22 +03:00
|
|
|
data.appointment.id = vars('appointment_data').id;
|
|
|
|
data.customer.id = vars('customer_data').id;
|
2013-06-08 12:54:45 +03:00
|
|
|
}
|
2022-01-18 10:18:22 +03:00
|
|
|
$('input[name="csrfToken"]').val(vars('csrf_token'));
|
2020-05-06 20:15:11 +03:00
|
|
|
$('input[name="post_data"]').val(JSON.stringify(data));
|
2022-01-13 13:33:40 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method calculates the end datetime of the current appointment.
|
2022-01-13 13:33:40 +03:00
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
* End datetime is depending on the service and start datetime fields.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* @return {String} Returns the end datetime in string format.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
function calculateEndDatetime() {
|
2015-10-09 00:12:59 +03:00
|
|
|
// Find selected service duration.
|
2022-01-17 07:57:52 +03:00
|
|
|
const serviceId = $selectService.val();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const service = vars('available_services').find(
|
2022-01-13 13:33:40 +03:00
|
|
|
(availableService) => Number(availableService.id) === Number(serviceId)
|
|
|
|
);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
// Add the duration to the start datetime.
|
2022-01-17 07:57:52 +03:00
|
|
|
const selectedDate = moment($selectDate.datepicker('getDate')).format('YYYY-MM-DD');
|
2021-11-24 10:34:26 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
const selectedHour = $('.selected-hour').data('value'); // HH:mm
|
2021-11-24 10:34:26 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
const startMoment = moment(selectedDate + ' ' + selectedHour);
|
2021-11-24 10:34:26 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
let endMoment;
|
2021-11-24 10:34:26 +03:00
|
|
|
|
|
|
|
if (service.duration && startMoment) {
|
|
|
|
endMoment = startMoment.clone().add({'minutes': parseInt(service.duration)});
|
2013-04-20 20:20:16 +03:00
|
|
|
} else {
|
2021-11-24 10:34:26 +03:00
|
|
|
endMoment = moment();
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
return endMoment.format('YYYY-MM-DD HH:mm:ss');
|
2016-04-26 22:51:16 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
/**
|
2015-10-09 00:12:59 +03:00
|
|
|
* This method applies the appointment's data to the wizard so
|
2013-06-03 17:42:19 +03:00
|
|
|
* that the user can start making changes on an existing record.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* @param {Object} appointment Selected appointment's data.
|
|
|
|
* @param {Object} provider Selected provider's data.
|
|
|
|
* @param {Object} customer Selected customer's data.
|
|
|
|
*
|
|
|
|
* @return {Boolean} Returns the operation result.
|
2013-06-03 17:42:19 +03:00
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
function applyAppointmentData(appointment, provider, customer) {
|
2013-06-03 17:42:19 +03:00
|
|
|
try {
|
|
|
|
// Select Service & Provider
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectService.val(appointment.id_services).trigger('change');
|
|
|
|
$selectProvider.val(appointment.id_users_provider);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
// Set Appointment Date
|
2022-01-13 13:33:40 +03:00
|
|
|
const startMoment = moment(appointment.start_datetime);
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectDate.datepicker('setDate', startMoment.toDate());
|
2022-01-13 13:33:40 +03:00
|
|
|
App.Http.Booking.getAvailableHours(startMoment.format('YYYY-MM-DD'));
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
// Apply Customer's Data
|
2022-01-17 07:57:52 +03:00
|
|
|
$lastName.val(customer.last_name);
|
|
|
|
$firstName.val(customer.first_name);
|
|
|
|
$email.val(customer.email);
|
|
|
|
$phoneNumber.val(customer.phone_number);
|
|
|
|
$address.val(customer.address);
|
|
|
|
$city.val(customer.city);
|
|
|
|
$zipCode.val(customer.zip_code);
|
2020-12-14 21:40:32 +03:00
|
|
|
if (customer.timezone) {
|
2022-01-17 07:57:52 +03:00
|
|
|
$selectTimezone.val(customer.timezone);
|
2020-12-14 21:40:32 +03:00
|
|
|
}
|
2022-01-13 13:33:40 +03:00
|
|
|
const appointmentNotes = appointment.notes !== null ? appointment.notes : '';
|
2022-01-17 07:57:52 +03:00
|
|
|
$notes.val(appointmentNotes);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-13 13:33:40 +03:00
|
|
|
updateConfirmFrame();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
return true;
|
2018-01-23 12:08:37 +03:00
|
|
|
} catch (exc) {
|
2013-06-03 17:42:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-26 22:51:16 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
/**
|
2022-01-13 13:33:40 +03:00
|
|
|
* This method updates a div's HTML content with a brief description of the
|
2016-10-10 19:29:48 +03:00
|
|
|
* user selected service (only if available in db). This is useful for the
|
2013-09-13 16:21:03 +03:00
|
|
|
* customers upon selecting the correct service.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* @param {Number} serviceId The selected service record id.
|
2013-09-13 16:21:03 +03:00
|
|
|
*/
|
2020-05-07 19:47:14 +03:00
|
|
|
function updateServiceDescription(serviceId) {
|
2022-01-13 13:33:40 +03:00
|
|
|
const $serviceDescription = $('#service-description');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$serviceDescription.empty();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2022-01-18 13:14:45 +03:00
|
|
|
const service = vars('available_services').find(
|
|
|
|
(availableService) => Number(availableService.id) === Number(serviceId)
|
|
|
|
);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
if (!service) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<strong/>', {
|
|
|
|
'text': service.name
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($serviceDescription);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
if (service.description) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('<br/>').appendTo($serviceDescription);
|
2019-06-08 18:03:32 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2022-01-17 19:54:30 +03:00
|
|
|
'html': App.Utils.String.escapeHtml(service.description).replaceAll('\n', '<br/>')
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($serviceDescription);
|
2020-05-15 16:05:30 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-15 16:05:30 +03:00
|
|
|
if (service.duration || Number(service.price) > 0 || service.location) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('<br/>').appendTo($serviceDescription);
|
2020-05-07 19:47:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (service.duration) {
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': '[' + lang('duration') + ' ' + service.duration + ' ' + lang('minutes') + ']'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($serviceDescription);
|
2020-05-07 19:47:14 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
if (Number(service.price) > 0) {
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': '[' + lang('price') + ' ' + service.price + ' ' + service.currency + ']'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($serviceDescription);
|
2020-05-07 19:47:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (service.location) {
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': '[' + lang('location') + ' ' + service.location + ']'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($serviceDescription);
|
2020-05-07 19:47:14 +03:00
|
|
|
}
|
2016-04-26 22:51:16 +03:00
|
|
|
}
|
2022-01-13 13:33:40 +03:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', initialize);
|
|
|
|
|
|
|
|
return {
|
|
|
|
manageMode,
|
|
|
|
initialize,
|
|
|
|
updateConfirmFrame
|
|
|
|
};
|
|
|
|
})();
|