2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web 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>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
2015-10-09 00:12:59 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
2015-07-20 22:41:24 +03:00
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2016-04-26 22:51:16 +03:00
|
|
|
window.FrontendBook = window.FrontendBook || {};
|
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2016-04-26 22:51:16 +03:00
|
|
|
* Frontend Book
|
|
|
|
*
|
2016-05-14 13:07:16 +03:00
|
|
|
* This module contains functions that implement the book appointment page functionality. Once the
|
|
|
|
* initialize() method is called the page is fully functional and can serve the appointment booking
|
|
|
|
* process.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-04-26 22:51:16 +03:00
|
|
|
* @module FrontendBook
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
(function (exports) {
|
2016-04-26 22:51:16 +03:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-24 18:27:16 +03:00
|
|
|
/**
|
|
|
|
* Contains terms and conditions consent.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
var termsAndConditionsConsent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains privacy policy consent.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
var privacyPolicyConsent;
|
|
|
|
|
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
|
|
|
*/
|
2016-04-26 22:51:16 +03:00
|
|
|
exports.manageMode = false;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
|
|
|
* This method initializes the book appointment page.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2020-05-12 21:52:32 +03:00
|
|
|
* @param {Boolean} defaultEventHandlers (OPTIONAL) Determines whether the default
|
2016-10-10 19:29:48 +03:00
|
|
|
* event handlers will be bound to the dom elements.
|
2016-05-14 13:07:16 +03:00
|
|
|
* @param {Boolean} manageMode (OPTIONAL) Determines whether the customer is going
|
2013-06-28 17:23:17 +03:00
|
|
|
* to make changes to an existing appointment rather than booking a new one.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
exports.initialize = function (defaultEventHandlers, manageMode) {
|
|
|
|
defaultEventHandlers = defaultEventHandlers || true;
|
2016-04-26 22:51:16 +03:00
|
|
|
manageMode = manageMode || false;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-06-24 17:58:03 +03:00
|
|
|
if (GlobalVariables.displayCookieNotice) {
|
|
|
|
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: {
|
|
|
|
message: EALang.website_using_cookies_to_ensure_best_experience,
|
|
|
|
dismiss: 'OK'
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.cc-link').replaceWith(
|
|
|
|
$('<a/>', {
|
|
|
|
'data-toggle': 'modal',
|
|
|
|
'data-target': '#cookie-notice-modal',
|
|
|
|
'href': '#',
|
|
|
|
'class': 'cc-link',
|
|
|
|
'text': $('.cc-link').text()
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2016-01-01 22:57:44 +02:00
|
|
|
|
2013-06-12 18:31:16 +03:00
|
|
|
FrontendBook.manageMode = manageMode;
|
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
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
var weekDayId = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday);
|
2018-06-29 01:41:17 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
$('#select-date').datepicker({
|
2013-07-02 20:18:19 +03:00
|
|
|
dateFormat: 'dd-mm-yy',
|
2020-10-20 16:03:48 +03:00
|
|
|
firstDay: weekDayId,
|
2013-07-02 20:18:19 +03:00
|
|
|
minDate: 0,
|
|
|
|
defaultDate: Date.today(),
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-05-14 13:07:16 +03:00
|
|
|
dayNames: [
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.sunday, EALang.monday, EALang.tuesday, EALang.wednesday,
|
|
|
|
EALang.thursday, EALang.friday, EALang.saturday],
|
|
|
|
dayNamesShort: [EALang.sunday.substr(0, 3), EALang.monday.substr(0, 3),
|
|
|
|
EALang.tuesday.substr(0, 3), EALang.wednesday.substr(0, 3),
|
|
|
|
EALang.thursday.substr(0, 3), EALang.friday.substr(0, 3),
|
|
|
|
EALang.saturday.substr(0, 3)],
|
|
|
|
dayNamesMin: [EALang.sunday.substr(0, 2), EALang.monday.substr(0, 2),
|
|
|
|
EALang.tuesday.substr(0, 2), EALang.wednesday.substr(0, 2),
|
|
|
|
EALang.thursday.substr(0, 2), EALang.friday.substr(0, 2),
|
|
|
|
EALang.saturday.substr(0, 2)],
|
2017-09-11 17:09:15 +03:00
|
|
|
monthNames: [EALang.january, EALang.february, EALang.march, EALang.april,
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.may, EALang.june, EALang.july, EALang.august, EALang.september,
|
|
|
|
EALang.october, EALang.november, EALang.december],
|
2017-09-11 17:09:15 +03:00
|
|
|
prevText: EALang.previous,
|
|
|
|
nextText: EALang.next,
|
|
|
|
currentText: EALang.now,
|
|
|
|
closeText: EALang.close,
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
onSelect: function (dateText, instance) {
|
2018-01-02 13:20:11 +03:00
|
|
|
FrontendBookApi.getAvailableHours($(this).datepicker('getDate').toString('yyyy-MM-dd'));
|
2016-05-14 12:36:17 +03:00
|
|
|
FrontendBook.updateConfirmFrame();
|
2016-03-31 21:08:21 +03:00
|
|
|
},
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
onChangeMonthYear: function (year, month, instance) {
|
2016-03-31 21:08:21 +03:00
|
|
|
var currentDate = new Date(year, month - 1, 1);
|
2016-04-27 22:57:11 +03:00
|
|
|
FrontendBookApi.getUnavailableDates($('#select-provider').val(), $('#select-service').val(),
|
2018-01-23 12:08:37 +03:00
|
|
|
currentDate.toString('yyyy-MM-dd'));
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
|
|
|
});
|
2013-12-20 19:44:44 +02:00
|
|
|
|
2020-03-29 17:20:30 +03:00
|
|
|
$('#select-timezone').val(Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
|
|
|
2016-07-16 22:06:55 +03:00
|
|
|
// Bind the event handlers (might not be necessary every time we use this class).
|
2020-05-06 20:23:49 +03:00
|
|
|
if (defaultEventHandlers) {
|
|
|
|
bindEventHandlers();
|
2013-05-20 20:21:58 +03:00
|
|
|
}
|
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.
|
2013-06-12 18:31:16 +03:00
|
|
|
if (FrontendBook.manageMode) {
|
2020-05-06 20:23:49 +03:00
|
|
|
applyAppointmentData(GlobalVariables.appointmentData,
|
2018-01-23 12:08:37 +03:00
|
|
|
GlobalVariables.providerData, GlobalVariables.customerData);
|
2013-06-03 17:42:19 +03:00
|
|
|
} else {
|
2016-07-16 22:06:55 +03:00
|
|
|
var $selectProvider = $('#select-provider');
|
2018-01-23 12:08:37 +03:00
|
|
|
var $selectService = $('#select-service');
|
2016-07-16 22:06:55 +03:00
|
|
|
|
2016-07-17 12:43:52 +03:00
|
|
|
// Check if a specific service was selected (via URL parameter).
|
2016-07-16 22:06:55 +03:00
|
|
|
var selectedServiceId = GeneralFunctions.getUrlParameter(location.href, 'service');
|
|
|
|
|
|
|
|
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.
|
2016-07-16 22:06:55 +03:00
|
|
|
var selectedProviderId = GeneralFunctions.getUrlParameter(location.href, '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.
|
2016-07-17 12:43:52 +03:00
|
|
|
for (var index in GlobalVariables.availableProviders) {
|
2018-01-23 12:08:37 +03:00
|
|
|
var provider = GlobalVariables.availableProviders[index];
|
2016-07-17 12:43:52 +03:00
|
|
|
|
|
|
|
if (provider.id === selectedProviderId && provider.services.length > 0) {
|
|
|
|
$selectService
|
|
|
|
.val(provider.services[0])
|
|
|
|
.trigger('change');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 22:06:55 +03:00
|
|
|
if (selectedProviderId && $selectProvider.find('option[value="' + selectedProviderId + '"]').length > 0) {
|
|
|
|
$selectProvider
|
|
|
|
.val(selectedProviderId)
|
|
|
|
.trigger('change');
|
|
|
|
}
|
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
}
|
2016-04-26 22:51:16 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2016-04-26 22:51:16 +03:00
|
|
|
* This method binds the necessary event handlers for the book appointments page.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
function bindEventHandlers() {
|
2020-03-29 17:20:30 +03:00
|
|
|
/**
|
|
|
|
* Event: Timezone "Changed"
|
|
|
|
*/
|
|
|
|
$('#select-timezone').on('change', function () {
|
|
|
|
var date = $('#select-date').datepicker('getDate');
|
|
|
|
|
|
|
|
if (!date) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FrontendBookApi.getAvailableHours(date.toString('yyyy-MM-dd'));
|
|
|
|
|
|
|
|
FrontendBook.updateConfirmFrame();
|
|
|
|
});
|
|
|
|
|
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
|
|
|
*/
|
2020-09-07 10:53:39 +03:00
|
|
|
$('#select-provider').on('change', function () {
|
2016-04-27 22:57:11 +03:00
|
|
|
FrontendBookApi.getUnavailableDates($(this).val(), $('#select-service').val(),
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#select-date').datepicker('getDate').toString('yyyy-MM-dd'));
|
2016-05-14 12:36:17 +03:00
|
|
|
FrontendBook.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
|
|
|
*/
|
2020-09-07 10:53:39 +03:00
|
|
|
$('#select-service').on('change', function () {
|
2020-05-06 20:15:11 +03:00
|
|
|
var serviceId = $('#select-service').val();
|
2020-05-12 21:52:32 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
$('#select-provider').empty();
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
GlobalVariables.availableProviders.forEach(function (provider) {
|
|
|
|
// If the current provider is able to provide the selected service, add him to the list box.
|
|
|
|
var canServeService = provider.services.filter(function (providerServiceId) {
|
|
|
|
return Number(providerServiceId) === Number(serviceId);
|
|
|
|
}).length > 0;
|
|
|
|
|
|
|
|
if (canServeService) {
|
|
|
|
$('#select-provider').append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
|
|
|
|
}
|
2013-04-20 20:20:16 +03:00
|
|
|
});
|
|
|
|
|
2015-10-28 00:49:05 +03:00
|
|
|
// Add the "Any Provider" entry.
|
2020-04-06 21:36:22 +03:00
|
|
|
if ($('#select-provider option').length >= 1 && GlobalVariables.displayAnyProvider === '1') {
|
2022-03-08 19:00:33 +03:00
|
|
|
$('#select-provider').prepend(new Option('- ' + EALang.any_provider + ' -', 'any-provider', true, true));
|
2015-10-28 00:49:05 +03:00
|
|
|
}
|
|
|
|
|
2016-04-27 22:57:11 +03:00
|
|
|
FrontendBookApi.getUnavailableDates($('#select-provider').val(), $(this).val(),
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#select-date').datepicker('getDate').toString('yyyy-MM-dd'));
|
2016-05-14 12:36:17 +03:00
|
|
|
FrontendBook.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.
|
2016-10-10 19:29:48 +03:00
|
|
|
* Some special tasks might be performed, depending the current wizard step.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2020-09-07 10:53:39 +03:00
|
|
|
$('.button-next').on('click', function () {
|
2020-12-14 21:40:32 +03:00
|
|
|
// If we are on the first step and there is not provider selected do not continue with the next step.
|
2020-05-06 20:15:11 +03:00
|
|
|
if ($(this).attr('data-step_index') === '1' && !$('#select-provider').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.
|
2013-05-20 20:21:58 +03:00
|
|
|
if ($(this).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',
|
|
|
|
'text': EALang.appointment_hour_missing,
|
|
|
|
})
|
|
|
|
.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.
|
2013-05-20 20:21:58 +03:00
|
|
|
if ($(this).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 {
|
2016-05-14 12:36:17 +03:00
|
|
|
FrontendBook.updateConfirmFrame();
|
2018-06-24 18:27:16 +03:00
|
|
|
|
|
|
|
var $acceptToTermsAndConditions = $('#accept-to-terms-and-conditions');
|
|
|
|
if ($acceptToTermsAndConditions.length && $acceptToTermsAndConditions.prop('checked') === true) {
|
|
|
|
var newTermsAndConditionsConsent = {
|
|
|
|
first_name: $('#first-name').val(),
|
|
|
|
last_name: $('#last-name').val(),
|
|
|
|
email: $('#email').val(),
|
|
|
|
type: 'terms-and-conditions'
|
|
|
|
};
|
|
|
|
|
|
|
|
if (JSON.stringify(newTermsAndConditionsConsent) !== JSON.stringify(termsAndConditionsConsent)) {
|
|
|
|
termsAndConditionsConsent = newTermsAndConditionsConsent;
|
|
|
|
FrontendBookApi.saveConsent(termsAndConditionsConsent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var $acceptToPrivacyPolicy = $('#accept-to-privacy-policy');
|
|
|
|
if ($acceptToPrivacyPolicy.length && $acceptToPrivacyPolicy.prop('checked') === true) {
|
|
|
|
var newPrivacyPolicyConsent = {
|
|
|
|
first_name: $('#first-name').val(),
|
|
|
|
last_name: $('#last-name').val(),
|
|
|
|
email: $('#email').val(),
|
|
|
|
type: 'privacy-policy'
|
|
|
|
};
|
|
|
|
|
|
|
|
if (JSON.stringify(newPrivacyPolicyConsent) !== JSON.stringify(privacyPolicyConsent)) {
|
|
|
|
privacyPolicyConsent = newPrivacyPolicyConsent;
|
|
|
|
FrontendBookApi.saveConsent(privacyPolicyConsent);
|
|
|
|
}
|
|
|
|
}
|
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).
|
2013-04-20 20:20:16 +03:00
|
|
|
var nextTabIndex = parseInt($(this).attr('data-step_index')) + 1;
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$(this).parents().eq(1).hide('fade', function () {
|
2013-04-20 20:20:16 +03:00
|
|
|
$('.active-step').removeClass('active-step');
|
|
|
|
$('#step-' + nextTabIndex).addClass('active-step');
|
2013-06-03 17:42:19 +03:00
|
|
|
$('#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
|
|
|
*/
|
2020-09-07 10:53:39 +03:00
|
|
|
$('.button-back').on('click', function () {
|
2013-04-20 20:20:16 +03:00
|
|
|
var prevTabIndex = parseInt($(this).attr('data-step_index')) - 1;
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$(this).parents().eq(1).hide('fade', function () {
|
2013-04-20 20:20:16 +03:00
|
|
|
$('.active-step').removeClass('active-step');
|
|
|
|
$('#step-' + prevTabIndex).addClass('active-step');
|
2013-06-03 17:42:19 +03:00
|
|
|
$('#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
|
|
|
*
|
2013-05-20 20:21:58 +03:00
|
|
|
* Triggered whenever the user clicks on an available hour
|
|
|
|
* for his appointment.
|
2013-04-20 20:20:16 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#available-hours').on('click', '.available-hour', function () {
|
2013-04-20 20:20:16 +03:00
|
|
|
$('.selected-hour').removeClass('selected-hour');
|
|
|
|
$(this).addClass('selected-hour');
|
2016-05-14 12:36:17 +03:00
|
|
|
FrontendBook.updateConfirmFrame();
|
2013-04-20 20:20:16 +03:00
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-12 18:31:16 +03:00
|
|
|
if (FrontendBook.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
|
|
|
*/
|
2020-09-07 10:53:39 +03:00
|
|
|
$('#cancel-appointment').on('click', function (event) {
|
2017-09-23 04:49:46 +03:00
|
|
|
var buttons = [
|
2020-08-31 17:26:28 +03:00
|
|
|
{
|
|
|
|
text: EALang.cancel,
|
|
|
|
click: function () {
|
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',
|
2018-01-23 12:08:37 +03:00
|
|
|
click: function () {
|
2017-09-23 04:49:46 +03:00
|
|
|
if ($('#cancel-reason').val() === '') {
|
2020-08-31 17:26:28 +03:00
|
|
|
$('#cancel-reason').css('border', '2px solid #DC3545');
|
2017-09-23 04:49:46 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$('#cancel-appointment-form textarea').val($('#cancel-reason').val());
|
|
|
|
$('#cancel-appointment-form').submit();
|
|
|
|
}
|
2013-06-10 18:51:23 +03:00
|
|
|
}
|
2017-09-23 04:49:46 +03:00
|
|
|
];
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
GeneralFunctions.displayMessageBox(EALang.cancel_appointment_title,
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.write_appointment_removal_reason, buttons);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-08-31 17:26:28 +03:00
|
|
|
$('<textarea/>', {
|
|
|
|
'class': 'form-control',
|
|
|
|
'id': 'cancel-reason',
|
|
|
|
'rows': '3',
|
|
|
|
'css': {
|
|
|
|
'width': '100%'
|
|
|
|
}
|
|
|
|
})
|
2020-09-07 11:08:18 +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
|
|
|
|
|
|
|
$('#delete-personal-information').on('click', function () {
|
|
|
|
var buttons = [
|
|
|
|
{
|
2020-08-31 17:26:28 +03:00
|
|
|
text: EALang.cancel,
|
2018-06-24 20:08:45 +03:00
|
|
|
click: function () {
|
2020-09-07 11:08:18 +03:00
|
|
|
$('#message-box').dialog('close');
|
2018-06-24 20:08:45 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2020-08-31 17:26:28 +03:00
|
|
|
text: EALang.delete,
|
2018-06-24 20:08:45 +03:00
|
|
|
click: function () {
|
2020-08-31 17:26:28 +03:00
|
|
|
FrontendBookApi.deletePersonalInformation(GlobalVariables.customerToken);
|
2018-06-24 20:08:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
GeneralFunctions.displayMessageBox(EALang.delete_personal_information,
|
|
|
|
EALang.delete_personal_information_prompt, buttons);
|
|
|
|
});
|
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
|
|
|
*/
|
2020-12-09 22:28:26 +03:00
|
|
|
$('#book-appointment-submit').on('click', function () {
|
2016-04-27 22:57:11 +03:00
|
|
|
FrontendBookApi.registerAppointment();
|
2013-06-28 17:23:17 +03:00
|
|
|
});
|
2015-10-22 00:29:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Refresh captcha image.
|
2016-05-14 13:07:16 +03:00
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
2015-10-22 00:29:20 +03:00
|
|
|
*/
|
2020-12-14 11:48:36 +03:00
|
|
|
$('.captcha-title button').on('click', function (event) {
|
2015-10-22 00:29:20 +03:00
|
|
|
$('.captcha-image').attr('src', GlobalVariables.baseUrl + '/index.php/captcha?' + Date.now());
|
|
|
|
});
|
2016-07-19 00:23:53 +03:00
|
|
|
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#select-date').on('mousedown', '.ui-datepicker-calendar td', function (event) {
|
|
|
|
setTimeout(function () {
|
2016-07-19 00:23:53 +03:00
|
|
|
FrontendBookApi.applyPreviousUnavailableDates(); // New jQuery UI version will replace the td elements.
|
|
|
|
}, 300); // There is no draw event unfortunately.
|
|
|
|
})
|
2018-02-23 17:33:41 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-04-20 20:20:16 +03:00
|
|
|
/**
|
2016-10-10 19:29:48 +03:00
|
|
|
* This function validates the customer's data input. The user cannot continue
|
2013-06-29 00:54:12 +03:00
|
|
|
* 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() {
|
2018-06-24 17:58:03 +03:00
|
|
|
$('#wizard-frame-3 .has-error').removeClass('has-error');
|
|
|
|
$('#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.
|
2013-06-29 00:54:12 +03:00
|
|
|
var missingRequiredField = false;
|
2020-05-12 21:52:32 +03:00
|
|
|
$('.required').each(function (index, requiredField) {
|
|
|
|
if (!$(requiredField).val()) {
|
|
|
|
$(requiredField).parents('.form-group').addClass('has-error');
|
2013-06-29 00:54:12 +03:00
|
|
|
missingRequiredField = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (missingRequiredField) {
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error(EALang.fields_are_required);
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-06-24 17:58:03 +03:00
|
|
|
var $acceptToTermsAndConditions = $('#accept-to-terms-and-conditions');
|
|
|
|
if ($acceptToTermsAndConditions.length && !$acceptToTermsAndConditions.prop('checked')) {
|
2020-07-01 16:02:11 +03:00
|
|
|
$acceptToTermsAndConditions.parents('.form-check').addClass('text-danger');
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error(EALang.fields_are_required);
|
2018-06-24 17:58:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var $acceptToPrivacyPolicy = $('#accept-to-privacy-policy');
|
|
|
|
if ($acceptToPrivacyPolicy.length && !$acceptToPrivacyPolicy.prop('checked')) {
|
2020-07-01 16:02:11 +03:00
|
|
|
$acceptToPrivacyPolicy.parents('.form-check').addClass('text-danger');
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error(EALang.fields_are_required);
|
2018-06-24 17:58:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
// Validate email address.
|
2013-06-29 00:54:12 +03:00
|
|
|
if (!GeneralFunctions.validateEmail($('#email').val())) {
|
2015-04-09 22:50:16 +03:00
|
|
|
$('#email').parents('.form-group').addClass('has-error');
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error(EALang.invalid_email);
|
2013-06-29 00:54:12 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
exports.updateConfirmFrame = function () {
|
2017-10-31 14:56:29 +03:00
|
|
|
if ($('.selected-hour').text() === '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
// Appointment Details
|
2013-04-20 20:20:16 +03:00
|
|
|
var selectedDate = $('#select-date').datepicker('getDate');
|
2016-05-14 13:07:16 +03:00
|
|
|
|
2013-05-17 16:09:10 +03:00
|
|
|
if (selectedDate !== null) {
|
2015-12-02 00:25:59 +02:00
|
|
|
selectedDate = GeneralFunctions.formatDate(selectedDate, GlobalVariables.dateFormat);
|
2013-04-20 20:20:16 +03:00
|
|
|
}
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
var serviceId = $('#select-service').val();
|
2019-10-27 20:04:32 +03:00
|
|
|
var servicePrice = '';
|
|
|
|
var serviceCurrency = '';
|
2016-05-14 13:07:16 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
GlobalVariables.availableServices.forEach(function (service, index) {
|
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;
|
|
|
|
return false; // break loop
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
$('#appointment-details').empty();
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<div/>', {
|
|
|
|
'html': [
|
|
|
|
$('<h4/>', {
|
2020-09-28 14:26:12 +03:00
|
|
|
'text': EALang.appointment
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<p/>', {
|
|
|
|
'html': [
|
2020-09-28 14:26:12 +03:00
|
|
|
$('<span/>', {
|
|
|
|
'text': EALang.service + ': ' + $('#select-service option:selected').text()
|
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
|
|
|
'text': EALang.provider + ': ' + $('#select-provider option:selected').text()
|
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
|
|
|
'text': EALang.start + ': ' + selectedDate + ' ' + $('.selected-hour').text()
|
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2020-12-09 15:17:45 +03:00
|
|
|
'text': EALang.timezone + ': ' + $('#select-timezone option:selected').text()
|
2020-09-28 14:26:12 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
|
|
|
'text': EALang.price + ': ' + servicePrice + ' ' + serviceCurrency,
|
|
|
|
'prop': {
|
|
|
|
'hidden': !servicePrice
|
|
|
|
}
|
|
|
|
}),
|
2020-05-07 19:47:14 +03:00
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
.appendTo('#appointment-details');
|
2013-04-20 20:20:16 +03:00
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
// Customer Details
|
2016-10-10 19:29:48 +03:00
|
|
|
var firstName = GeneralFunctions.escapeHtml($('#first-name').val());
|
|
|
|
var lastName = GeneralFunctions.escapeHtml($('#last-name').val());
|
2016-07-15 21:52:21 +03:00
|
|
|
var phoneNumber = GeneralFunctions.escapeHtml($('#phone-number').val());
|
|
|
|
var email = GeneralFunctions.escapeHtml($('#email').val());
|
|
|
|
var address = GeneralFunctions.escapeHtml($('#address').val());
|
|
|
|
var city = GeneralFunctions.escapeHtml($('#city').val());
|
|
|
|
var zipCode = GeneralFunctions.escapeHtml($('#zip-code').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/>)', {
|
2020-09-28 14:26:12 +03:00
|
|
|
'text': EALang.customer
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<p/>', {
|
|
|
|
'html': [
|
2020-09-28 14:26:12 +03:00
|
|
|
$('<span/>', {
|
|
|
|
'text': EALang.customer + ': ' + firstName + ' ' + lastName
|
|
|
|
}),
|
|
|
|
$('<br/>'),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
|
|
|
'text': EALang.phone_number + ': ' + phoneNumber
|
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
|
|
|
'text': EALang.email + ': ' + email
|
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2020-08-15 14:28:49 +03:00
|
|
|
'text': address ? EALang.address + ': ' + address : ''
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2020-08-15 14:28:49 +03:00
|
|
|
'text': city ? EALang.city + ': ' + city : ''
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
2020-08-15 14:28:49 +03:00
|
|
|
'text': zipCode ? EALang.zip_code + ': ' + zipCode : ''
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
.appendTo('#customer-details');
|
|
|
|
|
|
|
|
|
|
|
|
// Update appointment form data for submission to server when the user confirms the appointment.
|
2020-05-06 20:15:11 +03:00
|
|
|
var data = {};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
data.customer = {
|
2016-04-26 22:51:16 +03:00
|
|
|
last_name: $('#last-name').val(),
|
|
|
|
first_name: $('#first-name').val(),
|
|
|
|
email: $('#email').val(),
|
|
|
|
phone_number: $('#phone-number').val(),
|
|
|
|
address: $('#address').val(),
|
|
|
|
city: $('#city').val(),
|
2020-03-29 17:20:30 +03:00
|
|
|
zip_code: $('#zip-code').val(),
|
|
|
|
timezone: $('#select-timezone').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 = {
|
2016-04-26 22:51:16 +03:00
|
|
|
start_datetime: $('#select-date').datepicker('getDate').toString('yyyy-MM-dd')
|
2020-12-09 15:17:45 +03:00
|
|
|
+ ' ' + Date.parse($('.selected-hour').data('value') || '').toString('HH:mm') + ':00',
|
2020-05-06 20:23:49 +03:00
|
|
|
end_datetime: calculateEndDatetime(),
|
2016-04-26 22:51:16 +03:00
|
|
|
notes: $('#notes').val(),
|
|
|
|
is_unavailable: false,
|
|
|
|
id_users_provider: $('#select-provider').val(),
|
|
|
|
id_services: $('#select-service').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.manage_mode = FrontendBook.manageMode;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-12 18:31:16 +03:00
|
|
|
if (FrontendBook.manageMode) {
|
2020-05-06 20:15:11 +03:00
|
|
|
data.appointment.id = GlobalVariables.appointmentData.id;
|
|
|
|
data.customer.id = GlobalVariables.customerData.id;
|
2013-06-08 12:54:45 +03:00
|
|
|
}
|
2015-05-28 00:26:36 +03:00
|
|
|
$('input[name="csrfToken"]').val(GlobalVariables.csrfToken);
|
2020-05-06 20:15:11 +03:00
|
|
|
$('input[name="post_data"]').val(JSON.stringify(data));
|
2016-10-10 19:29:48 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method calculates the end datetime of the current appointment.
|
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.
|
2020-05-06 20:15:11 +03:00
|
|
|
var serviceId = $('#select-service').val();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
var service = GlobalVariables.availableServices.find(function (availableService) {
|
|
|
|
return Number(availableService.id) === Number(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
|
|
|
// Add the duration to the start datetime.
|
2015-10-09 00:12:59 +03:00
|
|
|
var startDatetime = $('#select-date').datepicker('getDate').toString('dd-MM-yyyy')
|
2020-10-21 21:35:40 +03:00
|
|
|
+ ' ' + Date.parse($('.selected-hour').data('value') || '').toString('HH:mm');
|
2013-05-20 20:21:58 +03:00
|
|
|
startDatetime = Date.parseExact(startDatetime, 'dd-MM-yyyy HH:mm');
|
2020-05-06 20:15:11 +03:00
|
|
|
var endDatetime;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
if (service.duration && startDatetime) {
|
|
|
|
endDatetime = startDatetime.add({'minutes': parseInt(service.duration)});
|
2013-04-20 20:20:16 +03:00
|
|
|
} else {
|
|
|
|
endDatetime = new Date();
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-05-17 16:09:10 +03:00
|
|
|
return endDatetime.toString('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
|
2017-11-02 16:19:54 +03:00
|
|
|
$('#select-service').val(appointment.id_services).trigger('change');
|
|
|
|
$('#select-provider').val(appointment.id_users_provider);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
// Set Appointment Date
|
2015-10-09 00:12:59 +03:00
|
|
|
$('#select-date').datepicker('setDate',
|
2018-01-23 12:08:37 +03:00
|
|
|
Date.parseExact(appointment.start_datetime, 'yyyy-MM-dd HH:mm:ss'));
|
2020-08-31 17:35:27 +03:00
|
|
|
FrontendBookApi.getAvailableHours(moment(appointment.start_datetime).format('YYYY-MM-DD'));
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
// Apply Customer's Data
|
2017-11-02 16:19:54 +03:00
|
|
|
$('#last-name').val(customer.last_name);
|
|
|
|
$('#first-name').val(customer.first_name);
|
|
|
|
$('#email').val(customer.email);
|
|
|
|
$('#phone-number').val(customer.phone_number);
|
|
|
|
$('#address').val(customer.address);
|
|
|
|
$('#city').val(customer.city);
|
|
|
|
$('#zip-code').val(customer.zip_code);
|
2020-12-14 21:40:32 +03:00
|
|
|
if (customer.timezone) {
|
|
|
|
$('#select-timezone').val(customer.timezone)
|
|
|
|
}
|
2017-11-02 16:19:54 +03:00
|
|
|
var appointmentNotes = (appointment.notes !== null)
|
2018-01-23 12:08:37 +03:00
|
|
|
? appointment.notes : '';
|
2013-06-08 12:54:45 +03:00
|
|
|
$('#notes').val(appointmentNotes);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-05-14 12:36:17 +03:00
|
|
|
FrontendBook.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
|
|
|
/**
|
2015-10-09 00:12:59 +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) {
|
|
|
|
var $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
|
|
|
|
2020-12-09 15:17:45 +03:00
|
|
|
var service = GlobalVariables.availableServices.find(function (availableService) {
|
2020-05-07 19:47:14 +03:00
|
|
|
return Number(availableService.id) === Number(serviceId);
|
2020-05-07 20:00:33 +03:00
|
|
|
});
|
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
|
|
|
|
})
|
|
|
|
.appendTo($serviceDescription);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
if (service.description) {
|
|
|
|
$('<br/>')
|
|
|
|
.appendTo($serviceDescription);
|
2019-06-08 18:03:32 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2021-07-19 16:14:37 +03:00
|
|
|
'html': GeneralFunctions.escapeHtml(service.description).replaceAll('\n', '<br/>')
|
2020-05-07 19:47:14 +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) {
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<br/>')
|
|
|
|
.appendTo($serviceDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (service.duration) {
|
|
|
|
$('<span/>', {
|
|
|
|
'text': '[' + EALang.duration + ' ' + service.duration + ' ' + EALang.minutes + ']'
|
|
|
|
})
|
|
|
|
.appendTo($serviceDescription);
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
if (Number(service.price) > 0) {
|
|
|
|
$('<span/>', {
|
|
|
|
'text': '[' + EALang.price + ' ' + service.price + ' ' + service.currency + ']'
|
|
|
|
})
|
|
|
|
.appendTo($serviceDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (service.location) {
|
|
|
|
$('<span/>', {
|
|
|
|
'text': '[' + EALang.location + ' ' + service.location + ']'
|
|
|
|
})
|
|
|
|
.appendTo($serviceDescription);
|
|
|
|
}
|
2016-04-26 22:51:16 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:51:16 +03:00
|
|
|
})(window.FrontendBook);
|