From e93565500d3131a01a52cfc7571051aba4715106 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Tue, 18 Jan 2022 08:18:22 +0100 Subject: [PATCH] Replace the global App.Vars with the "vars" helper method, which is more appropriate due to the dynamic load of script vars. --- .../views/components/js_vars_script.php | 12 +- assets/js/app.js | 3 +- assets/js/components/appointments_modal.js | 52 ++++----- .../js/components/unavailabilities_modal.js | 24 ++-- .../working_plan_exceptions_modal.js | 20 ++-- assets/js/http/account_http_client.js | 6 +- assets/js/http/admins_http_client.js | 10 +- assets/js/http/appointments_http_client.js | 10 +- assets/js/http/booking_http_client.js | 32 +++--- .../js/http/booking_settings_http_client.js | 2 +- .../js/http/business_settings_http_client.js | 4 +- assets/js/http/calendar_http_client.js | 16 +-- assets/js/http/categories_http_client.js | 10 +- assets/js/http/customers_http_client.js | 10 +- .../js/http/general_settings_http_client.js | 2 +- assets/js/http/google_http_client.js | 6 +- assets/js/http/legal_settings_http_client.js | 2 +- assets/js/http/login_http_client.js | 2 +- assets/js/http/providers_http_client.js | 10 +- assets/js/http/recovery_http_client.js | 2 +- assets/js/http/secretaries_http_client.js | 10 +- assets/js/http/services_http_client.js | 10 +- assets/js/http/settings_http_client.js | 10 +- .../js/http/unavailabilities_http_client.js | 10 +- assets/js/pages/account.js | 2 +- assets/js/pages/admins.js | 4 +- assets/js/pages/booking.js | 32 +++--- assets/js/pages/booking_confirmation.js | 23 ++-- assets/js/pages/booking_settings.js | 2 +- assets/js/pages/business_settings.js | 4 +- assets/js/pages/calendar.js | 10 +- assets/js/pages/customers.js | 18 +-- assets/js/pages/general_settings.js | 2 +- assets/js/pages/installation.js | 4 +- assets/js/pages/legal_settings.js | 2 +- assets/js/pages/login.js | 2 +- assets/js/pages/providers.js | 8 +- assets/js/pages/secretaries.js | 4 +- assets/js/utils/calendar_default_view.js | 96 ++++++++-------- assets/js/utils/calendar_google_sync.js | 2 +- assets/js/utils/calendar_table_view.js | 106 +++++++++--------- assets/js/utils/general_functions.js | 4 +- assets/js/utils/lang.js | 4 +- assets/js/utils/url.js | 4 +- assets/js/utils/working_plan.js | 29 +++-- 45 files changed, 323 insertions(+), 314 deletions(-) diff --git a/application/views/components/js_vars_script.php b/application/views/components/js_vars_script.php index fb34ccf3..ad666da0 100644 --- a/application/views/components/js_vars_script.php +++ b/application/views/components/js_vars_script.php @@ -4,6 +4,16 @@ */ ?> diff --git a/assets/js/app.js b/assets/js/app.js index 793cec62..358bf447 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -21,7 +21,6 @@ window.App = (function () { Lang: {}, Layouts: {}, Pages: {}, - Utils: {}, - Vars: {} + Utils: {} }; })(); diff --git a/assets/js/components/appointments_modal.js b/assets/js/components/appointments_modal.js index 84943289..b1886df7 100755 --- a/assets/js/components/appointments_modal.js +++ b/assets/js/components/appointments_modal.js @@ -48,12 +48,12 @@ App.Components.AppointmentsModal = (function () { function updateTimezone() { const providerId = $selectProvider.val(); - const provider = App.Vars.available_providers.find(function (availableProvider) { + const provider = vars('available_providers').find(function (availableProvider) { return Number(availableProvider.id) === Number(providerId); }); if (provider && provider.timezone) { - $('.provider-timezone').text(App.Vars.timezones[provider.timezone]); + $('.provider-timezone').text(vars('timezones')[provider.timezone]); } } @@ -147,7 +147,7 @@ App.Components.AppointmentsModal = (function () { if ($selectFilterItem.find('option:selected').attr('type') === 'provider') { const providerId = $('#select-filter-item').val(); - const providers = App.Vars.available_providers.filter( + const providers = vars('available_providers').filter( (provider) => Number(provider.id) === Number(providerId) ); @@ -163,7 +163,7 @@ App.Components.AppointmentsModal = (function () { const serviceId = $selectService.val(); - const service = App.Vars.available_services.find( + const service = vars('available_services').find( (availableService) => Number(availableService.id) === Number(serviceId) ); @@ -184,14 +184,14 @@ App.Components.AppointmentsModal = (function () { } $startDatetime.val( - App.Utils.Date.format(startMoment.toDate(), App.Vars.date_format, App.Vars.time_format, true) + App.Utils.Date.format(startMoment.toDate(), vars('date_format'), vars('time_format'), true) ); $endDatetime.val( App.Utils.Date.format( startMoment.add(duration, 'minutes').toDate(), - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ) ); @@ -213,7 +213,7 @@ App.Components.AppointmentsModal = (function () { $existingCustomersList.empty(); $existingCustomersList.slideDown('slow'); $filterExistingCustomers.fadeIn('slow').val(''); - App.Vars.customers.forEach(function (customer) { + vars('customers').forEach(function (customer) { $('
', { 'data-id': customer.id, 'text': customer.first_name + ' ' + customer.last_name @@ -234,7 +234,7 @@ App.Components.AppointmentsModal = (function () { $appointmentsModal.on('click', '#existing-customers-list div', (event) => { const customerId = $(event.target).attr('data-id'); - const customer = App.Vars.customers.find(function (customer) { + const customer = vars('customers').find(function (customer) { return Number(customer.id) === Number(customerId); }); @@ -281,13 +281,13 @@ App.Components.AppointmentsModal = (function () { }).appendTo($existingCustomersList); // Verify if this customer is on the old customer list. - const result = App.Vars.customers.filter((existingCustomer) => { + const result = vars('customers').filter((existingCustomer) => { return Number(existingCustomer.id) === Number(customer.id); }); // Add it to the customer list. if (!result.length) { - App.Vars.customers.push(customer); + vars('customers').push(customer); } }); }) @@ -295,7 +295,7 @@ App.Components.AppointmentsModal = (function () { // If there is any error on the request, search by the local client database. $existingCustomersList.empty(); - App.Vars.customers.forEach((customer) => { + vars('customers').forEach((customer) => { if ( customer.first_name.toLowerCase().indexOf(keyword) !== -1 || customer.last_name.toLowerCase().indexOf(keyword) !== -1 || @@ -331,7 +331,7 @@ App.Components.AppointmentsModal = (function () { $selectProvider.empty(); // Automatically update the service duration. - const service = App.Vars.available_services.find((availableService) => { + const service = vars('available_services').find((availableService) => { return Number(availableService.id) === Number(serviceId); }); @@ -342,18 +342,18 @@ App.Components.AppointmentsModal = (function () { // Update the providers select box. - App.Vars.available_providers.forEach((provider) => { + vars('available_providers').forEach((provider) => { provider.services.forEach((providerServiceId) => { if ( - App.Vars.role_slug === App.Layouts.Backend.DB_SLUG_PROVIDER && - Number(provider.id) !== App.Vars.user_id + vars('role_slug') === App.Layouts.Backend.DB_SLUG_PROVIDER && + Number(provider.id) !== vars('user_id') ) { return; // continue } if ( - App.Vars.role_slug === App.Layouts.Backend.DB_SLUG_SECRETARY && - App.Vars.secretaryProviders.indexOf(provider.id) === -1 + vars('role_slug') === App.Layouts.Backend.DB_SLUG_SECRETARY && + vars('secretary_providers').indexOf(provider.id) === -1 ) { return; // continue } @@ -403,7 +403,7 @@ App.Components.AppointmentsModal = (function () { // Fill the providers list box with providers that can serve the appointment's service and then select the // user's provider. $selectProvider.empty(); - App.Vars.available_providers.forEach((provider) => { + vars('available_providers').forEach((provider) => { const serviceId = $selectService.val(); const canProvideService = @@ -426,7 +426,7 @@ App.Components.AppointmentsModal = (function () { // Get the selected service duration. It will be needed in order to calculate the appointment end datetime. const serviceId = $selectService.val(); - const service = App.Vars.available_services.forEach((service) => Number(service.id) === Number(serviceId)); + const service = vars('available_services').forEach((service) => Number(service.id) === Number(serviceId)); const duration = service ? service.duration : 0; @@ -434,7 +434,7 @@ App.Components.AppointmentsModal = (function () { const endDatetime = moment().add(duration, 'minutes').toDate(); let dateFormat; - switch (App.Vars.date_format) { + switch (vars('date_format')) { case 'DMY': dateFormat = 'dd/mm/yy'; break; @@ -445,16 +445,16 @@ App.Components.AppointmentsModal = (function () { dateFormat = 'yy/mm/dd'; break; default: - throw new Error('Invalid App.Vars.date_format value.'); + throw new Error('Invalid date format value.'); } - const firstWeekDay = App.Vars.first_weekday; + const firstWeekDay = vars('first_weekday'); const firstWeekDayNumber = App.Utils.Date.getWeekdayId(firstWeekDay); $startDatetime.datetimepicker({ dateFormat: dateFormat, - timeFormat: App.Vars.time_format === 'regular' ? 'h:mm tt' : 'HH:mm', + timeFormat: vars('time_format') === 'regular' ? 'h:mm tt' : 'HH:mm', // Translation dayNames: [ @@ -511,7 +511,7 @@ App.Components.AppointmentsModal = (function () { const serviceId = $selectService.val(); // Automatically update the #end-datetime DateTimePicker based on service duration. - const service = App.Vars.available_services.find( + const service = vars('available_services').find( (availableService) => Number(availableService.id) === Number(serviceId) ); @@ -523,7 +523,7 @@ App.Components.AppointmentsModal = (function () { $endDatetime.datetimepicker({ dateFormat: dateFormat, - timeFormat: App.Vars.time_format === 'regular' ? 'h:mm tt' : 'HH:mm', + timeFormat: vars('time_format') === 'regular' ? 'h:mm tt' : 'HH:mm', // Translation dayNames: [ diff --git a/assets/js/components/unavailabilities_modal.js b/assets/js/components/unavailabilities_modal.js index de3cfe5a..caddf911 100755 --- a/assets/js/components/unavailabilities_modal.js +++ b/assets/js/components/unavailabilities_modal.js @@ -129,13 +129,13 @@ App.Components.UnavailabilitiesModal = (function () { } $unavailabilityStart.val( - App.Utils.Date.format(startMoment.toDate(), App.Vars.date_format, App.Vars.time_format, true) + App.Utils.Date.format(startMoment.toDate(), vars('date_format'), vars('time_format'), true) ); $unavailabilityEnd.val( App.Utils.Date.format( startMoment.add(1, 'hour').toDate(), - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ) ); @@ -154,18 +154,18 @@ App.Components.UnavailabilitiesModal = (function () { $unavailabilityId.val(''); // Set default time values - const start = App.Utils.Date.format(moment().toDate(), App.Vars.date_format, App.Vars.time_format, true); + const start = App.Utils.Date.format(moment().toDate(), vars('date_format'), vars('time_format'), true); const end = App.Utils.Date.format( moment().add(1, 'hour').toDate(), - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ); let dateFormat; - switch (App.Vars.date_format) { + switch (vars('date_format')) { case 'DMY': dateFormat = 'dd/mm/yy'; break; @@ -177,13 +177,13 @@ App.Components.UnavailabilitiesModal = (function () { break; } - const firstWeekday = App.Vars.first_weekday; + const firstWeekday = vars('first_weekday'); const firstWeekdayId = App.Utils.Date.getWeekdayId(firstWeekday); $unavailabilityStart.datetimepicker({ dateFormat: dateFormat, - timeFormat: App.Vars.time_format === 'regular' ? 'h:mm tt' : 'HH:mm', + timeFormat: vars('time_format') === 'regular' ? 'h:mm tt' : 'HH:mm', // Translation dayNames: [ @@ -241,7 +241,7 @@ App.Components.UnavailabilitiesModal = (function () { $unavailabilityEnd.datetimepicker({ dateFormat: dateFormat, - timeFormat: App.Vars.time_format === 'regular' ? 'h:mm tt' : 'HH:mm', + timeFormat: vars('time_format') === 'regular' ? 'h:mm tt' : 'HH:mm', // Translation dayNames: [ @@ -305,8 +305,8 @@ App.Components.UnavailabilitiesModal = (function () { * Initialize the module. */ function initialize() { - for (const index in App.Vars.available_providers) { - const provider = App.Vars.available_providers[index]; + for (const index in vars('available_providers')) { + const provider = vars('available_providers')[index]; $unavailabilityProvider.append(new Option(provider.first_name + ' ' + provider.last_name, provider.id)); } diff --git a/assets/js/components/working_plan_exceptions_modal.js b/assets/js/components/working_plan_exceptions_modal.js index c8e9cef6..a595cd20 100644 --- a/assets/js/components/working_plan_exceptions_modal.js +++ b/assets/js/components/working_plan_exceptions_modal.js @@ -92,8 +92,8 @@ App.Components.WorkingPlanExceptionsModal = (function () { const end = $tr.find('.working-plan-exceptions-break-end').text(); breaks.push({ - start: moment(start, App.Vars.time_format === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm'), - end: moment(end, App.Vars.time_format === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm') + start: moment(start, vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm'), + end: moment(end, vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm') }); }); @@ -226,7 +226,7 @@ App.Components.WorkingPlanExceptionsModal = (function () { * @return {jQuery} */ function renderBreakRow(breakPeriod) { - const timeFormat = App.Vars.time_format === 'regular' ? 'h:mm a' : 'HH:mm'; + const timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm'; return $('', { 'html': [ @@ -346,16 +346,16 @@ App.Components.WorkingPlanExceptionsModal = (function () { const $tr = $(this).closest('tr'); const start = moment( $tr.find('.working-plan-exceptions-break-start input').val(), - App.Vars.time_format === 'regular' ? 'h:mm a' : 'HH:mm' + vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm' ); const end = moment( $tr.find('.working-plan-exceptions-break-end input').val(), - App.Vars.time_format === 'regular' ? 'h:mm a' : 'HH:mm' + vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm' ); if (start > end) { $tr.find('.working-plan-exceptions-break-end input').val( - start.add(1, 'hour').format(App.Vars.time_format === 'regular' ? 'h:mm a' : 'HH:mm') + start.add(1, 'hour').format(vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm') ); } @@ -394,7 +394,7 @@ App.Components.WorkingPlanExceptionsModal = (function () { function initializeDatepicker($target) { let dateFormat; - switch (App.Vars.date_format) { + switch (vars('date_format')) { case 'DMY': dateFormat = 'dd/mm/yy'; break; @@ -408,12 +408,12 @@ App.Components.WorkingPlanExceptionsModal = (function () { break; default: - throw new Error('Invalid date format setting provided: ' + App.Vars.date_format); + throw new Error('Invalid date format setting provided: ' + vars('date_format')); } $target.datepicker({ dateFormat: dateFormat, - firstDay: App.Utils.Date.getWeekdayId(App.Vars.first_weekday), + firstDay: App.Utils.Date.getWeekdayId(vars('first_weekday')), minDate: 0, defaultDate: moment().toDate(), dayNames: [ @@ -471,7 +471,7 @@ App.Components.WorkingPlanExceptionsModal = (function () { */ function initializeTimepicker($target) { $target.timepicker({ - timeFormat: App.Vars.time_format === 'regular' ? 'h:mm tt' : 'HH:mm', + timeFormat: vars('time_format') === 'regular' ? 'h:mm tt' : 'HH:mm', currentText: App.Lang.now, closeText: App.Lang.close, timeOnlyTitle: App.Lang.select_time, diff --git a/assets/js/http/account_http_client.js b/assets/js/http/account_http_client.js index d2e44f2e..344dc073 100644 --- a/assets/js/http/account_http_client.js +++ b/assets/js/http/account_http_client.js @@ -26,7 +26,7 @@ App.Http.Account = (function () { const url = App.Utils.Url.siteUrl('account/save'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), account }; @@ -45,7 +45,7 @@ App.Http.Account = (function () { const url = App.Utils.Url.siteUrl('account/validate_username'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), user_id: userId, username }; @@ -62,7 +62,7 @@ App.Http.Account = (function () { const url = App.Utils.Url.siteUrl('account/change_language'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), language }; diff --git a/assets/js/http/admins_http_client.js b/assets/js/http/admins_http_client.js index 6b7b74e2..084a3edd 100644 --- a/assets/js/http/admins_http_client.js +++ b/assets/js/http/admins_http_client.js @@ -37,7 +37,7 @@ App.Http.Admins = (function () { const url = App.Utils.Url.siteUrl('admins/create'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), admin: admin }; @@ -55,7 +55,7 @@ App.Http.Admins = (function () { const url = App.Utils.Url.siteUrl('admins/update'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), admin: admin }; @@ -73,7 +73,7 @@ App.Http.Admins = (function () { const url = App.Utils.Url.siteUrl('admins/destroy'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), admin_id: adminId }; @@ -94,7 +94,7 @@ App.Http.Admins = (function () { const url = App.Utils.Url.siteUrl('admins/search'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), keyword, limit, offset, @@ -115,7 +115,7 @@ App.Http.Admins = (function () { const url = App.Utils.Url.siteUrl('admins/find'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), admin_id: adminId }; diff --git a/assets/js/http/appointments_http_client.js b/assets/js/http/appointments_http_client.js index 9ee44c1d..d83ed4ef 100644 --- a/assets/js/http/appointments_http_client.js +++ b/assets/js/http/appointments_http_client.js @@ -37,7 +37,7 @@ App.Http.Appointments = (function () { const url = App.Utils.Url.siteUrl('appointments/create'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), appointment: appointment }; @@ -55,7 +55,7 @@ App.Http.Appointments = (function () { const url = App.Utils.Url.siteUrl('appointments/update'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), appointment: appointment }; @@ -73,7 +73,7 @@ App.Http.Appointments = (function () { const url = App.Utils.Url.siteUrl('appointments/destroy'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), appointment_id: appointmentId }; @@ -94,7 +94,7 @@ App.Http.Appointments = (function () { const url = App.Utils.Url.siteUrl('appointments/search'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), keyword, limit, offset, @@ -115,7 +115,7 @@ App.Http.Appointments = (function () { const url = App.Utils.Url.siteUrl('appointments/find'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), appointment_id: appointmentId }; diff --git a/assets/js/http/booking_http_client.js b/assets/js/http/booking_http_client.js index b861309c..c68e119c 100755 --- a/assets/js/http/booking_http_client.js +++ b/assets/js/http/booking_http_client.js @@ -43,7 +43,7 @@ App.Http.Booking = (function () { // Default value of duration (in minutes). let serviceDuration = 15; - const service = App.Vars.available_services.find( + const service = vars('available_services').find( (availableService) => Number(availableService.id) === Number(serviceId) ); @@ -52,13 +52,13 @@ App.Http.Booking = (function () { } // If the manage mode is true then the appointment's start date should return as available too. - const appointmentId = App.Pages.Booking.manageMode ? App.Vars.appointment_data.id : null; + const appointmentId = App.Pages.Booking.manageMode ? vars('appointment_data').id : null; // Make ajax post request and get the available hours. const url = App.Utils.Url.siteUrl('booking/get_available_hours'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), service_id: $selectService.val(), provider_id: $selectProvider.val(), selected_date: selectedDate, @@ -74,7 +74,7 @@ App.Http.Booking = (function () { let providerId = $selectProvider.val(); if (providerId === 'any-provider') { - for (const availableProvider of App.Vars.available_providers) { + for (const availableProvider of vars('available_providers')) { if (availableProvider.services.indexOf(Number(serviceId)) !== -1) { providerId = availableProvider.id; // Use first available provider. break; @@ -82,7 +82,7 @@ App.Http.Booking = (function () { } } - const provider = App.Vars.available_providers.find( + const provider = vars('available_providers').find( (availableProvider) => Number(providerId) === Number(availableProvider.id) ); @@ -92,7 +92,7 @@ App.Http.Booking = (function () { const providerTimezone = provider.timezone; const selectedTimezone = $('#select-timezone').val(); - const timeFormat = App.Vars.time_format === 'regular' ? 'h:mm a' : 'HH:mm'; + const timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm'; response.forEach((availableHour) => { const availableHourMoment = moment @@ -121,7 +121,7 @@ App.Http.Booking = (function () { .filter( (index, availableHourEl) => $(availableHourEl).text() === - moment(App.Vars.appointment_data.start_datetime).format(timeFormat) + moment(vars('appointment_data').start_datetime).format(timeFormat) ) .addClass('selected-hour'); } else { @@ -158,7 +158,7 @@ App.Http.Booking = (function () { const formData = JSON.parse($('input[name="post_data"]').val()); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), post_data: formData }; @@ -166,8 +166,8 @@ App.Http.Booking = (function () { data.captcha = $captchaText.val(); } - if (App.Vars.manage_mode) { - data.exclude_appointment_id = App.Vars.appointment_data.id; + if (vars('manage_mode')) { + data.exclude_appointment_id = vars('appointment_data').id; } const url = App.Utils.Url.siteUrl('booking/register'); @@ -236,7 +236,7 @@ App.Http.Booking = (function () { return; } - const appointmentId = App.Pages.Booking.manageMode ? App.Vars.appointment_data.id : null; + const appointmentId = App.Pages.Booking.manageMode ? vars('appointment_data').id : null; const url = App.Utils.Url.siteUrl('booking/get_unavailable_dates'); @@ -244,7 +244,7 @@ App.Http.Booking = (function () { provider_id: providerId, service_id: serviceId, selected_date: encodeURIComponent(selectedDateString), - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), manage_mode: App.Pages.Booking.manageMode, appointment_id: appointmentId }; @@ -275,7 +275,7 @@ App.Http.Booking = (function () { const selectedDate = selectedDateMoment.toDate(); const numberOfDays = selectedDateMoment.daysInMonth(); - if (setDate && !App.Vars.manage_mode) { + if (setDate && !vars('manage_mode')) { for (let i = 1; i <= numberOfDays; i++) { const currentDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), i); if (unavailableDates.indexOf(moment(currentDate).format('YYYY-MM-DD')) === -1) { @@ -311,7 +311,7 @@ App.Http.Booking = (function () { const url = App.Utils.Url.siteUrl('consents/save_consent'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), consent: consent }; @@ -327,12 +327,12 @@ App.Http.Booking = (function () { const url = App.Utils.Url.siteUrl('privacy/delete_personal_information'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), customer_token: customerToken }; $.post(url, data).done(() => { - window.location.href = App.Vars.base_url; + window.location.href = vars('base_url'); }); } diff --git a/assets/js/http/booking_settings_http_client.js b/assets/js/http/booking_settings_http_client.js index c06550c9..79a15ca0 100644 --- a/assets/js/http/booking_settings_http_client.js +++ b/assets/js/http/booking_settings_http_client.js @@ -26,7 +26,7 @@ App.Http.BookingSettings = (function () { const url = App.Utils.Url.siteUrl('booking_settings/save'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), booking_settings: bookingSettings }; diff --git a/assets/js/http/business_settings_http_client.js b/assets/js/http/business_settings_http_client.js index 3a3d8974..444d6737 100644 --- a/assets/js/http/business_settings_http_client.js +++ b/assets/js/http/business_settings_http_client.js @@ -26,7 +26,7 @@ App.Http.BusinessSettings = (function () { const url = App.Utils.Url.siteUrl('business_settings/save'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), business_settings: businessSettings }; @@ -44,7 +44,7 @@ App.Http.BusinessSettings = (function () { const url = App.Utils.Url.siteUrl('business_settings/apply_global_working_plan'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), working_plan: JSON.stringify(workingPlan) }; diff --git a/assets/js/http/calendar_http_client.js b/assets/js/http/calendar_http_client.js index a1e98a22..2c57dd26 100755 --- a/assets/js/http/calendar_http_client.js +++ b/assets/js/http/calendar_http_client.js @@ -34,7 +34,7 @@ App.Http.Calendar = (function () { const url = App.Utils.Url.siteUrl('calendar/save_appointment'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), appointment_data: appointment }; @@ -67,7 +67,7 @@ App.Http.Calendar = (function () { const url = App.Utils.Url.siteUrl('calendar/delete_appointment'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), appointment_id: appointmentId, delete_reason: deleteReason }; @@ -86,7 +86,7 @@ App.Http.Calendar = (function () { const url = App.Utils.Url.siteUrl('calendar/save_unavailable'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), unavailable: unavailable }; @@ -114,7 +114,7 @@ App.Http.Calendar = (function () { const url = App.Utils.Url.siteUrl('calendar/delete_unavailable'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), unavailable_id: unavailableId }; @@ -134,7 +134,7 @@ App.Http.Calendar = (function () { const url = App.Utils.Url.siteUrl('calendar/save_working_plan_exception'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), date: date, working_plan_exception: workingPlanException, provider_id: providerId @@ -167,7 +167,7 @@ App.Http.Calendar = (function () { const url = App.Utils.Url.siteUrl('calendar/delete_working_plan_exception'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), date: date, provider_id: providerId }; @@ -199,7 +199,7 @@ App.Http.Calendar = (function () { const url = App.Utils.Url.siteUrl('calendar/get_calendar_appointments'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), record_id: recordId, start_date: moment(startDate).format('YYYY-MM-DD'), end_date: moment(endDate).format('YYYY-MM-DD'), @@ -221,7 +221,7 @@ App.Http.Calendar = (function () { const url = App.Utils.Url.siteUrl('calendar/get_calendar_appointments_for_table_view'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), start_date: moment(startDate).format('YYYY-MM-DD'), end_date: moment(endDate).format('YYYY-MM-DD') }; diff --git a/assets/js/http/categories_http_client.js b/assets/js/http/categories_http_client.js index 6e64490a..79dd5db0 100644 --- a/assets/js/http/categories_http_client.js +++ b/assets/js/http/categories_http_client.js @@ -37,7 +37,7 @@ App.Http.Categories = (function () { const url = App.Utils.Url.siteUrl('categories/create'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), category: category }; @@ -55,7 +55,7 @@ App.Http.Categories = (function () { const url = App.Utils.Url.siteUrl('categories/update'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), category: category }; @@ -73,7 +73,7 @@ App.Http.Categories = (function () { const url = App.Utils.Url.siteUrl('categories/destroy'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), category_id: categoryId }; @@ -94,7 +94,7 @@ App.Http.Categories = (function () { const url = App.Utils.Url.siteUrl('categories/search'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), keyword, limit, offset, @@ -115,7 +115,7 @@ App.Http.Categories = (function () { const url = App.Utils.Url.siteUrl('categories/find'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), category_id: categoryId }; diff --git a/assets/js/http/customers_http_client.js b/assets/js/http/customers_http_client.js index 10602826..f36865ed 100644 --- a/assets/js/http/customers_http_client.js +++ b/assets/js/http/customers_http_client.js @@ -37,7 +37,7 @@ App.Http.Customers = (function () { const url = App.Utils.Url.siteUrl('customers/create'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), customer: customer }; @@ -55,7 +55,7 @@ App.Http.Customers = (function () { const url = App.Utils.Url.siteUrl('customers/update'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), customer: customer }; @@ -73,7 +73,7 @@ App.Http.Customers = (function () { const url = App.Utils.Url.siteUrl('customers/destroy'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), customer_id: customerId }; @@ -94,7 +94,7 @@ App.Http.Customers = (function () { const url = App.Utils.Url.siteUrl('customers/search'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), keyword, limit, offset, @@ -115,7 +115,7 @@ App.Http.Customers = (function () { const url = App.Utils.Url.siteUrl('customers/find'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), customer_id: customerId }; diff --git a/assets/js/http/general_settings_http_client.js b/assets/js/http/general_settings_http_client.js index f96d5ab3..96902189 100644 --- a/assets/js/http/general_settings_http_client.js +++ b/assets/js/http/general_settings_http_client.js @@ -26,7 +26,7 @@ App.Http.GeneralSettings = (function () { const url = App.Utils.Url.siteUrl('general_settings/save'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), general_settings: generalSettings }; diff --git a/assets/js/http/google_http_client.js b/assets/js/http/google_http_client.js index b15ddb96..aed43b5e 100755 --- a/assets/js/http/google_http_client.js +++ b/assets/js/http/google_http_client.js @@ -27,7 +27,7 @@ App.Http.Google = (function () { const url = App.Utils.Url.siteUrl('google/select_google_calendar'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), provider_id: providerId, calendar_id: googleCalendarId }; @@ -46,7 +46,7 @@ App.Http.Google = (function () { const url = App.Utils.Url.siteUrl('google/disable_provider_sync'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), provider_id: providerId }; @@ -64,7 +64,7 @@ App.Http.Google = (function () { const url = App.Utils.Url.siteUrl('google/get_google_calendars'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), provider_id: providerId }; diff --git a/assets/js/http/legal_settings_http_client.js b/assets/js/http/legal_settings_http_client.js index 24cd62bb..a0366829 100644 --- a/assets/js/http/legal_settings_http_client.js +++ b/assets/js/http/legal_settings_http_client.js @@ -26,7 +26,7 @@ App.Http.LegalSettings = (function () { const url = App.Utils.Url.siteUrl('legal_settings/save'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), legal_settings: legalSettings }; diff --git a/assets/js/http/login_http_client.js b/assets/js/http/login_http_client.js index 715e2116..aa1f0b39 100644 --- a/assets/js/http/login_http_client.js +++ b/assets/js/http/login_http_client.js @@ -27,7 +27,7 @@ App.Http.Login = (function () { const url = App.Utils.Url.siteUrl('login/validate'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), username, password }; diff --git a/assets/js/http/providers_http_client.js b/assets/js/http/providers_http_client.js index 85ad03a7..e22d8589 100644 --- a/assets/js/http/providers_http_client.js +++ b/assets/js/http/providers_http_client.js @@ -37,7 +37,7 @@ App.Http.Providers = (function () { const url = App.Utils.Url.siteUrl('providers/create'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), provider: provider }; @@ -55,7 +55,7 @@ App.Http.Providers = (function () { const url = App.Utils.Url.siteUrl('providers/update'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), provider: provider }; @@ -73,7 +73,7 @@ App.Http.Providers = (function () { const url = App.Utils.Url.siteUrl('providers/destroy'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), provider_id: providerId }; @@ -94,7 +94,7 @@ App.Http.Providers = (function () { const url = App.Utils.Url.siteUrl('providers/search'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), keyword, limit, offset, @@ -115,7 +115,7 @@ App.Http.Providers = (function () { const url = App.Utils.Url.siteUrl('providers/find'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), provider_id: providerId }; diff --git a/assets/js/http/recovery_http_client.js b/assets/js/http/recovery_http_client.js index ddc96180..c1f42565 100644 --- a/assets/js/http/recovery_http_client.js +++ b/assets/js/http/recovery_http_client.js @@ -27,7 +27,7 @@ App.Http.Recovery = (function () { const url = App.Utils.Url.siteUrl('recovery/perform'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), username, email }; diff --git a/assets/js/http/secretaries_http_client.js b/assets/js/http/secretaries_http_client.js index 1ba5794a..69f46053 100644 --- a/assets/js/http/secretaries_http_client.js +++ b/assets/js/http/secretaries_http_client.js @@ -37,7 +37,7 @@ App.Http.Secretaries = (function () { const url = App.Utils.Url.siteUrl('secretaries/create'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), secretary: secretary }; @@ -55,7 +55,7 @@ App.Http.Secretaries = (function () { const url = App.Utils.Url.siteUrl('secretaries/update'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), secretary: secretary }; @@ -73,7 +73,7 @@ App.Http.Secretaries = (function () { const url = App.Utils.Url.siteUrl('secretaries/destroy'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), secretary_id: secretaryId }; @@ -94,7 +94,7 @@ App.Http.Secretaries = (function () { const url = App.Utils.Url.siteUrl('secretaries/search'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), keyword, limit, offset, @@ -115,7 +115,7 @@ App.Http.Secretaries = (function () { const url = App.Utils.Url.siteUrl('secretaries/find'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), secretary_id: secretaryId }; diff --git a/assets/js/http/services_http_client.js b/assets/js/http/services_http_client.js index d305a10b..e2fe4e2a 100644 --- a/assets/js/http/services_http_client.js +++ b/assets/js/http/services_http_client.js @@ -37,7 +37,7 @@ App.Http.Services = (function () { const url = App.Utils.Url.siteUrl('services/create'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), service: service }; @@ -55,7 +55,7 @@ App.Http.Services = (function () { const url = App.Utils.Url.siteUrl('services/update'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), service: service }; @@ -73,7 +73,7 @@ App.Http.Services = (function () { const url = App.Utils.Url.siteUrl('services/destroy'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), service_id: serviceId }; @@ -94,7 +94,7 @@ App.Http.Services = (function () { const url = App.Utils.Url.siteUrl('services/search'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), keyword, limit, offset, @@ -115,7 +115,7 @@ App.Http.Services = (function () { const url = App.Utils.Url.siteUrl('services/find'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), service_id: serviceId }; diff --git a/assets/js/http/settings_http_client.js b/assets/js/http/settings_http_client.js index f7b60e32..242b9b6b 100644 --- a/assets/js/http/settings_http_client.js +++ b/assets/js/http/settings_http_client.js @@ -37,7 +37,7 @@ App.Http.Settings = (function () { const url = App.Utils.Url.siteUrl('settings/create'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), setting: setting }; @@ -55,7 +55,7 @@ App.Http.Settings = (function () { const url = App.Utils.Url.siteUrl('settings/update'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), setting: setting }; @@ -73,7 +73,7 @@ App.Http.Settings = (function () { const url = App.Utils.Url.siteUrl('settings/destroy'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), setting_id: settingId }; @@ -94,7 +94,7 @@ App.Http.Settings = (function () { const url = App.Utils.Url.siteUrl('settings/search'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), keyword, limit, offset, @@ -115,7 +115,7 @@ App.Http.Settings = (function () { const url = App.Utils.Url.siteUrl('settings/find'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), setting_id: settingId }; diff --git a/assets/js/http/unavailabilities_http_client.js b/assets/js/http/unavailabilities_http_client.js index e802d9ee..5ef6ae7d 100644 --- a/assets/js/http/unavailabilities_http_client.js +++ b/assets/js/http/unavailabilities_http_client.js @@ -37,7 +37,7 @@ App.Http.Unavailabilities = (function () { const url = App.Utils.Url.siteUrl('unavailabilities/create'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), unavailability: unavailability }; @@ -55,7 +55,7 @@ App.Http.Unavailabilities = (function () { const url = App.Utils.Url.siteUrl('unavailabilities/update'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), unavailability: unavailability }; @@ -73,7 +73,7 @@ App.Http.Unavailabilities = (function () { const url = App.Utils.Url.siteUrl('unavailabilities/destroy'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), unavailability_id: unavailabilityId }; @@ -94,7 +94,7 @@ App.Http.Unavailabilities = (function () { const url = App.Utils.Url.siteUrl('unavailabilities/search'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), keyword, limit, offset, @@ -115,7 +115,7 @@ App.Http.Unavailabilities = (function () { const url = App.Utils.Url.siteUrl('unavailabilities/find'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), unavailability_id: unavailabilityId }; diff --git a/assets/js/pages/account.js b/assets/js/pages/account.js index f4009fa3..722a08d8 100644 --- a/assets/js/pages/account.js +++ b/assets/js/pages/account.js @@ -180,7 +180,7 @@ App.Pages.Account = (function () { * Initialize the page. */ function initialize() { - const account = App.Vars.account; + const account = vars('account'); deserialize(account); diff --git a/assets/js/pages/admins.js b/assets/js/pages/admins.js index 09702b25..aaa5369e 100644 --- a/assets/js/pages/admins.js +++ b/assets/js/pages/admins.js @@ -281,9 +281,9 @@ App.Pages.Admins = (function () { throw new Error(App.Lang.passwords_mismatch); } - if ($password.val().length < App.Vars.min_password_length && $password.val() !== '') { + if ($password.val().length < vars('min_password_length') && $password.val() !== '') { $('#admin-password, #admin-password-confirm').addClass('is-invalid'); - throw new Error(App.Lang.password_length_notice.replace('$number', BackendAdmins.MIN_PASSWORD_LENGTH)); + throw new Error(App.Lang.password_length_notice.replace('$number', vars('min_password_length'))); } // Validate user email. diff --git a/assets/js/pages/booking.js b/assets/js/pages/booking.js index e9537bee..2071bdee 100644 --- a/assets/js/pages/booking.js +++ b/assets/js/pages/booking.js @@ -60,7 +60,7 @@ App.Pages.Booking = (function () { * Initialize the module. */ function initialize() { - if (App.Vars.display_cookie_notice) { + if (vars('display_cookie_notice')) { cookieconsent.initialise({ palette: { popup: { @@ -89,12 +89,12 @@ App.Pages.Booking = (function () { ); } - manageMode = App.Vars.manage_mode; + manageMode = vars('manage_mode'); // Initialize page's components (tooltips, datepickers etc). tippy('[data-tippy-content]'); - const weekdayId = App.Utils.Date.getWeekdayId(App.Vars.first_weekday); + const weekdayId = App.Utils.Date.getWeekdayId(vars('first_weekday')); $selectDate.datepicker({ dateFormat: 'dd-mm-yy', @@ -171,7 +171,7 @@ App.Pages.Booking = (function () { // If the manage mode is true, the appointments data should be loaded by default. if (manageMode) { - applyAppointmentData(App.Vars.appointment_data, App.Vars.provider_data, App.Vars.customer_data); + applyAppointmentData(vars('appointment_data'), vars('provider_data'), vars('customer_data')); } else { // Check if a specific service was selected (via URL parameter). const selectedServiceId = App.Utils.Url.queryParam('service'); @@ -187,8 +187,8 @@ App.Pages.Booking = (function () { if (selectedProviderId && $selectProvider.find('option[value="' + selectedProviderId + '"]').length === 0) { // Select a service of this provider in order to make the provider available in the select box. - for (const index in App.Vars.available_providers) { - const provider = App.Vars.available_providers[index]; + for (const index in vars('available_providers')) { + const provider = vars('available_providers')[index]; if (provider.id === selectedProviderId && provider.services.length > 0) { $selectService.val(provider.services[0]).trigger('change'); @@ -249,7 +249,7 @@ App.Pages.Booking = (function () { $selectProvider.empty(); - App.Vars.available_providers.forEach((provider) => { + vars('available_providers').forEach((provider) => { // If the current provider is able to provide the selected service, add him to the list box. const canServeService = provider.services.filter((providerServiceId) => Number(providerServiceId) === Number(serviceId)) @@ -261,7 +261,7 @@ App.Pages.Booking = (function () { }); // Add the "Any Provider" entry. - if ($selectProvider.find('option').length >= 1 && App.Vars.display_any_provider === '1') { + if ($selectProvider.find('option').length >= 1 && vars('display_any_provider') === '1') { $selectProvider.prepend(new Option('- ' + App.Lang.any_provider + ' -', 'any-provider', true, true)); } @@ -453,7 +453,7 @@ App.Pages.Booking = (function () { { text: App.Lang.delete, click: () => { - App.Http.Booking.deletePersonalInformation(App.Vars.customer_token); + App.Http.Booking.deletePersonalInformation(vars('customer_token')); } } ]; @@ -556,14 +556,14 @@ App.Pages.Booking = (function () { let selectedDate = $selectDate.datepicker('getDate'); if (selectedDate !== null) { - selectedDate = App.Utils.Date.format(selectedDate, App.Vars.date_format, App.Vars.time_format); + selectedDate = App.Utils.Date.format(selectedDate, vars('date_format'), vars('time_format')); } const serviceId = $selectService.val(); let servicePrice = ''; let serviceCurrency = ''; - App.Vars.available_services.forEach((service) => { + vars('available_services').forEach((service) => { if (Number(service.id) === Number(serviceId) && Number(service.price) > 0) { servicePrice = service.price; serviceCurrency = service.currency; @@ -689,10 +689,10 @@ App.Pages.Booking = (function () { data.manage_mode = manageMode; if (manageMode) { - data.appointment.id = App.Vars.appointment_data.id; - data.customer.id = App.Vars.customer_data.id; + data.appointment.id = vars('appointment_data').id; + data.customer.id = vars('customer_data').id; } - $('input[name="csrfToken"]').val(App.Vars.csrf_token); + $('input[name="csrfToken"]').val(vars('csrf_token')); $('input[name="post_data"]').val(JSON.stringify(data)); } @@ -707,7 +707,7 @@ App.Pages.Booking = (function () { // Find selected service duration. const serviceId = $selectService.val(); - const service = App.Vars.available_services.find( + const service = vars('available_services').find( (availableService) => Number(availableService.id) === Number(serviceId) ); @@ -784,7 +784,7 @@ App.Pages.Booking = (function () { $serviceDescription.empty(); - const service = App.Vars.available_services.find(function (availableService) { + const service = vars('available_services').find(function (availableService) { return Number(availableService.id) === Number(serviceId); }); diff --git a/assets/js/pages/booking_confirmation.js b/assets/js/pages/booking_confirmation.js index 6fda857b..875d9019 100644 --- a/assets/js/pages/booking_confirmation.js +++ b/assets/js/pages/booking_confirmation.js @@ -16,13 +16,14 @@ */ App.Pages.BookingConfirmation = (function () { const $addToGoogleCalendar = $('#add-to-google-calendar'); + /** * Handle Authorization Result * * This method handles the authorization result. If the user granted access to his data, then the * appointment is going to be added to his calendar. * - * @param {Boolean} authResult The user's authorization result. + * @param {Object} authResult The user's authorization result. */ function handleAuthResult(authResult) { try { @@ -31,15 +32,15 @@ App.Pages.BookingConfirmation = (function () { } // The user has granted access, add the appointment to his calendar. Before making the event.insert request - // the the event resource data must be prepared. - const providerData = App.Vars.provider_data; + // the event resource data must be prepared. + const providerData = vars('provider_data'); - const appointmentData = App.Vars.appointment_data; + const appointmentData = vars('appointment_data'); // Create a valid Google Calendar API resource for the new event. const resource = { - summary: App.Vars.service_data.name, - location: App.Vars.company_name, + summary: vars('service_data').name, + location: vars('company_name'), start: { dateTime: moment.tz(appointmentData.start_datetime, providerData.timezone).format() }, @@ -48,8 +49,8 @@ App.Pages.BookingConfirmation = (function () { }, attendees: [ { - email: App.Vars.provider_data.email, - displayName: App.Vars.provider_data.first_name + ' ' + App.Vars.provider_data.last_name + email: vars('provider_data').email, + displayName: vars('provider_data').first_name + ' ' + vars('provider_data').last_name } ] }; @@ -120,12 +121,12 @@ App.Pages.BookingConfirmation = (function () { * Google is necessary. */ $addToGoogleCalendar.on('click', function () { - gapi.client.setApiKey(App.Vars.google_api_key); + gapi.client.setApiKey(vars('google_api_key')); gapi.auth.authorize( { - client_id: App.Vars.google_client_id, - scope: App.Vars.google_api_scope, + client_id: vars('google_client_id'), + scope: vars('google_api_scope'), immediate: false }, handleAuthResult diff --git a/assets/js/pages/booking_settings.js b/assets/js/pages/booking_settings.js index dad29d94..e740173f 100644 --- a/assets/js/pages/booking_settings.js +++ b/assets/js/pages/booking_settings.js @@ -181,7 +181,7 @@ App.Pages.BookingSettings = (function () { * Initialize the module. */ function initialize() { - const bookingSettings = App.Vars.booking_settings; + const bookingSettings = vars('booking_settings'); deserialize(bookingSettings); diff --git a/assets/js/pages/business_settings.js b/assets/js/pages/business_settings.js index cf4a96cb..d605b577 100644 --- a/assets/js/pages/business_settings.js +++ b/assets/js/pages/business_settings.js @@ -131,13 +131,13 @@ App.Pages.BusinessSettings = (function () { * Initialize the module. */ function initialize() { - const businessSettings = App.Vars.business_settings; + const businessSettings = vars('business_settings'); deserialize(businessSettings); let companyWorkingPlan = {}; - App.Vars.business_settings.forEach((businessSetting) => { + vars('business_settings').forEach((businessSetting) => { if (businessSetting.name === 'company_working_plan') { companyWorkingPlan = JSON.parse(businessSetting.value); } diff --git a/assets/js/pages/calendar.js b/assets/js/pages/calendar.js index 8fa8342d..dd989ec8 100755 --- a/assets/js/pages/calendar.js +++ b/assets/js/pages/calendar.js @@ -59,7 +59,7 @@ App.Pages.Calendar = (function () { $insertWorkingPlanException.on('click', () => { const providerId = $('#select-filter-item').val(); - const provider = App.Vars.available_providers.find((availableProvider) => { + const provider = vars('available_providers').find((availableProvider) => { return Number(availableProvider.id) === Number(providerId); }); @@ -75,11 +75,11 @@ App.Pages.Calendar = (function () { workingPlanExceptions[date] = workingPlanException; - for (let index in App.Vars.available_providers) { - const availableProvider = App.Vars.available_providers[index]; + for (let index in vars('available_providers')) { + const availableProvider = vars('available_providers')[index]; if (Number(availableProvider.id) === Number(providerId)) { - App.Vars.available_providers[index].settings.working_plan_exceptions = + vars('available_providers')[index].settings.working_plan_exceptions = JSON.stringify(workingPlanExceptions); break; } @@ -110,7 +110,7 @@ App.Pages.Calendar = (function () { */ function initialize() { // Load and initialize the calendar view. - if (App.Vars.calendar_view === 'table') { + if (vars('calendar_view') === 'table') { App.Utils.CalendarTableView.initialize(); } else { App.Utils.CalendarDefaultView.initialize(); diff --git a/assets/js/pages/customers.js b/assets/js/pages/customers.js index 4428bddd..6882c379 100644 --- a/assets/js/pages/customers.js +++ b/assets/js/pages/customers.js @@ -274,30 +274,30 @@ App.Pages.Customers = (function () { customer.appointments.forEach((appointment) => { if ( - App.Vars.role_slug === App.Layouts.Backend.DB_SLUG_PROVIDER && - parseInt(appointment.id_users_provider) !== App.Vars.user_id + vars('role_slug') === App.Layouts.Backend.DB_SLUG_PROVIDER && + parseInt(appointment.id_users_provider) !== vars('user_id') ) { return; } if ( - App.Vars.role_slug === App.Layouts.Backend.DB_SLUG_SECRETARY && - App.Vars.secretary_providers.indexOf(appointment.id_users_provider) === -1 + vars('role_slug') === App.Layouts.Backend.DB_SLUG_SECRETARY && + vars('secretary_providers').indexOf(appointment.id_users_provider) === -1 ) { return; } const start = App.Utils.Date.format( moment(appointment.start_datetime).toDate(), - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ); const end = App.Utils.Date.format( moment(appointment.end_datetime).toDate(), - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ); @@ -342,7 +342,7 @@ App.Pages.Customers = (function () { // Timezone $('', { - 'text': App.Vars.timezones[appointment.provider.timezone] + 'text': vars('timezones')[appointment.provider.timezone] }) ] }).appendTo('#customer-appointments'); diff --git a/assets/js/pages/general_settings.js b/assets/js/pages/general_settings.js index 9d194f2b..ec251814 100644 --- a/assets/js/pages/general_settings.js +++ b/assets/js/pages/general_settings.js @@ -92,7 +92,7 @@ App.Pages.GeneralSettings = (function () { * Initialize the module. */ function initialize() { - const generalSettings = App.Vars.general_settings; + const generalSettings = vars('general_settings'); deserialize(generalSettings); diff --git a/assets/js/pages/installation.js b/assets/js/pages/installation.js index 19d09e9d..9409af7d 100644 --- a/assets/js/pages/installation.js +++ b/assets/js/pages/installation.js @@ -49,7 +49,7 @@ App.Pages.Installation = (function () { const url = App.Utils.Url.siteUrl('installation/perform'); const data = { - csrf_token: App.Vars.csrf_token, + csrf_token: vars('csrf_token'), admin: getAdminData(), company: getCompanyData() }; @@ -162,7 +162,7 @@ App.Pages.Installation = (function () { } // Validate the base URL setting (must not contain any trailing slash). - if (App.Vars.base_url.slice(-1) === '/') { + if (vars('base_url').slice(-1) === '/') { App.Utils.Message.show( 'Invalid Configuration Detected', 'Please remove any trailing slashes from your "BASE_URL" setting of the root "config.php" file and try again.' diff --git a/assets/js/pages/legal_settings.js b/assets/js/pages/legal_settings.js index 75dbbefd..c7c53c47 100644 --- a/assets/js/pages/legal_settings.js +++ b/assets/js/pages/legal_settings.js @@ -145,7 +145,7 @@ App.Pages.LegalSettings = (function () { $termsAndConditionsContent.trumbowyg(); $privacyPolicyContent.trumbowyg(); - const legalSettings = App.Vars.legal_settings; + const legalSettings = vars('legal_settings'); deserialize(legalSettings); diff --git a/assets/js/pages/login.js b/assets/js/pages/login.js index a50ae713..2999bf26 100644 --- a/assets/js/pages/login.js +++ b/assets/js/pages/login.js @@ -38,7 +38,7 @@ App.Pages.Login = (function () { App.Http.Login.validate(username, password).done((response) => { if (response.success) { - window.location.href = App.Vars.dest_url; + window.location.href = vars('dest_url'); } else { $alert.text(App.Lang.login_failed); $alert.removeClass('d-none alert-danger alert-success').addClass('alert-danger'); diff --git a/assets/js/pages/providers.js b/assets/js/pages/providers.js index 27354574..41b74513 100755 --- a/assets/js/pages/providers.js +++ b/assets/js/pages/providers.js @@ -98,7 +98,7 @@ App.Pages.Providers = (function () { $('#provider-services input:checkbox').prop('disabled', false); // Apply default working plan - const companyWorkingPlan = JSON.parse(App.Vars.company_working_plan); + const companyWorkingPlan = JSON.parse(vars('company_working_plan')); workingPlanManager.setup(companyWorkingPlan); workingPlanManager.timepickers(false); }); @@ -225,7 +225,7 @@ App.Pages.Providers = (function () { $('.breaks tbody').empty(); $('.working-plan-exceptions tbody').empty(); $('.work-start, .work-end').val(''); - const companyWorkingPlan = JSON.parse(App.Vars.company_working_plan); + const companyWorkingPlan = JSON.parse(vars('company_working_plan')); workingPlanManager.setup(companyWorkingPlan); workingPlanManager.timepickers(false); }); @@ -289,7 +289,7 @@ App.Pages.Providers = (function () { throw new Error(App.Lang.passwords_mismatch); } - if ($password.val().length < App.Vars.min_password_length && $password.val() !== '') { + if ($password.val().length < vars('min_password_length') && $password.val() !== '') { $('#provider-password, #provider-password-confirm').addClass('is-invalid'); throw new Error(App.Lang.password_length_notice.replace('$number', MIN_PASSWORD_LENGTH)); } @@ -533,7 +533,7 @@ App.Pages.Providers = (function () { filter(''); addEventListeners(); - App.Vars.services.forEach(function (service) { + vars('services').forEach(function (service) { $('
', { 'class': 'checkbox', 'html': [ diff --git a/assets/js/pages/secretaries.js b/assets/js/pages/secretaries.js index 3c627ceb..61a5b463 100644 --- a/assets/js/pages/secretaries.js +++ b/assets/js/pages/secretaries.js @@ -292,7 +292,7 @@ App.Pages.Secretaries = (function () { throw new Error('Passwords mismatch!'); } - if ($password.val().length < App.Vars.min_password_length && $password.val() !== '') { + if ($password.val().length < vars('min_password_length') && $password.val() !== '') { $('#secretary-password, #secretary-password-confirm').addClass('is-invalid'); throw new Error( 'Password must be at least ' + BackendSecretaries.MIN_PASSWORD_LENGTH + ' characters long.' @@ -475,7 +475,7 @@ App.Pages.Secretaries = (function () { filter(''); addEventListeners(); - App.Vars.providers.forEach((provider) => { + vars('providers').forEach((provider) => { $('
', { 'class': 'checkbox', 'html': [ diff --git a/assets/js/utils/calendar_default_view.js b/assets/js/utils/calendar_default_view.js index 17617eb9..e3900e4c 100755 --- a/assets/js/utils/calendar_default_view.js +++ b/assets/js/utils/calendar_default_view.js @@ -90,8 +90,8 @@ App.Utils.CalendarDefaultView = (function () { workingPlanExceptions[date] = workingPlanException; - for (const index in App.Vars.available_providers) { - const availableProvider = App.Vars.available_providers[index]; + for (const index in vars('available_providers')) { + const availableProvider = vars('available_providers')[index]; if (Number(availableProvider.id) === Number(provider.id)) { availableProvider.settings.working_plan_exceptions = @@ -181,7 +181,7 @@ App.Utils.CalendarDefaultView = (function () { if (lastFocusedEventData.data.workingPlanException) { const providerId = $selectFilterItem.val(); - const provider = App.Vars.available_providers.find( + const provider = vars('available_providers').find( (availableProvider) => Number(availableProvider.id) === Number(providerId) ); @@ -195,8 +195,8 @@ App.Utils.CalendarDefaultView = (function () { const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {}; delete workingPlanExceptions[date]; - for (const index in App.Vars.available_providers) { - const availableProvider = App.Vars.available_providers[index]; + for (const index in vars('available_providers')) { + const availableProvider = vars('available_providers')[index]; if (Number(availableProvider.id) === Number(providerId)) { availableProvider.settings.working_plan_exceptions = JSON.stringify(workingPlanExceptions); @@ -282,12 +282,12 @@ App.Utils.CalendarDefaultView = (function () { const providerId = $selectFilterItem.val(); - const provider = App.Vars.available_providers.find( + const provider = vars('available_providers').find( (availableProvider) => Number(availableProvider.id) === Number(providerId) ); if (provider && provider.timezone) { - $('.provider-timezone').text(App.Vars.timezones[provider.timezone]); + $('.provider-timezone').text(vars('timezones')[provider.timezone]); } // If the user has already the sync enabled then apply the proper style changes. @@ -360,12 +360,12 @@ App.Utils.CalendarDefaultView = (function () { ) { displayEdit = ($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom')) && - App.Vars.privileges.appointments.edit === true + vars('privileges').appointments.edit === true ? 'me-2' : 'd-none'; displayDelete = ($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom')) && - App.Vars.privileges.appointments.delete === true + vars('privileges').appointments.delete === true ? 'me-2' : 'd-none'; // Same value at the time. @@ -378,8 +378,8 @@ App.Utils.CalendarDefaultView = (function () { $('', { 'text': App.Utils.Date.format( event.start.format('YYYY-MM-DD HH:mm:ss'), - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ) }), @@ -392,8 +392,8 @@ App.Utils.CalendarDefaultView = (function () { $('', { 'text': App.Utils.Date.format( event.end.format('YYYY-MM-DD HH:mm:ss'), - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ) }), @@ -456,7 +456,7 @@ App.Utils.CalendarDefaultView = (function () { ) { displayDelete = ($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom')) && - App.Vars.privileges.appointments.delete === true + vars('privileges').appointments.delete === true ? 'me-2' : 'd-none'; @@ -478,8 +478,8 @@ App.Utils.CalendarDefaultView = (function () { $('', { 'text': App.Utils.Date.format( event.data.date + ' ' + event.data.workingPlanException.start, - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ) }), @@ -492,8 +492,8 @@ App.Utils.CalendarDefaultView = (function () { $('', { 'text': App.Utils.Date.format( event.data.date + ' ' + event.data.workingPlanException.end, - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ) }), @@ -504,7 +504,7 @@ App.Utils.CalendarDefaultView = (function () { 'text': App.Lang.timezone }), $('', { - 'text': App.Vars.timezones[event.data.provider.timezone] + 'text': vars('timezones')[event.data.provider.timezone] }), $('
'), @@ -551,8 +551,8 @@ App.Utils.CalendarDefaultView = (function () { ] }); } else { - displayEdit = App.Vars.privileges.appointments.edit === true ? 'me-2' : 'd-none'; - displayDelete = App.Vars.privileges.appointments.delete === true ? 'me-2' : 'd-none'; + displayEdit = vars('privileges').appointments.edit === true ? 'me-2' : 'd-none'; + displayDelete = vars('privileges').appointments.delete === true ? 'me-2' : 'd-none'; $html = $('
', { 'html': [ @@ -563,8 +563,8 @@ App.Utils.CalendarDefaultView = (function () { $('', { 'text': App.Utils.Date.format( event.start.format('YYYY-MM-DD HH:mm:ss'), - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ) }), @@ -577,8 +577,8 @@ App.Utils.CalendarDefaultView = (function () { $('', { 'text': App.Utils.Date.format( event.end.format('YYYY-MM-DD HH:mm:ss'), - App.Vars.date_format, - App.Vars.time_format, + vars('date_format'), + vars('time_format'), true ) }), @@ -589,7 +589,7 @@ App.Utils.CalendarDefaultView = (function () { 'text': App.Lang.timezone }), $('', { - 'text': App.Vars.timezones[event.data.provider.timezone] + 'text': vars('timezones')[event.data.provider.timezone] }), $('
'), @@ -727,7 +727,7 @@ App.Utils.CalendarDefaultView = (function () { * @see updateAppointmentData() */ function calendarEventResize(event, delta, revertFunc) { - if (App.Vars.privileges.appointments.edit === false) { + if (vars('privileges').appointments.edit === false) { revertFunc(); App.Layouts.Backend.displayNotification(App.Lang.no_privileges_edit_appointments); return; @@ -866,7 +866,7 @@ App.Utils.CalendarDefaultView = (function () { * @param {function} revertFunc */ function calendarEventDrop(event, delta, revertFunc) { - if (App.Vars.privileges.appointments.edit === false) { + if (vars('privileges').appointments.edit === false) { revertFunc(); App.Layouts.Backend.displayNotification(App.Lang.no_privileges_edit_appointments); return; @@ -1098,7 +1098,7 @@ App.Utils.CalendarDefaultView = (function () { const calendarView = $calendar.fullCalendar('getView'); if (filterType === FILTER_TYPE_PROVIDER && calendarView.name !== 'month') { - const provider = App.Vars.available_providers.find( + const provider = vars('available_providers').find( (availableProvider) => Number(availableProvider.id) === Number(recordId) ); @@ -1126,7 +1126,7 @@ App.Utils.CalendarDefaultView = (function () { // Sort the working plan starting with the first day as set in General settings to correctly align // breaks in the calendar display. - const firstWeekdayNumber = App.Utils.Date.getWeekdayId(App.Vars.first_weekday); + const firstWeekdayNumber = App.Utils.Date.getWeekdayId(vars('first_weekday')); const sortedWorkingPlan = App.Utils.Date.sortWeekDictionary(workingPlan, firstWeekdayNumber); switch (calendarView.name) { @@ -1392,7 +1392,7 @@ App.Utils.CalendarDefaultView = (function () { // Dynamic date formats. let columnFormat = {}; - switch (App.Vars.date_format) { + switch (vars('date_format')) { case 'DMY': columnFormat = 'ddd D/M'; break; @@ -1403,14 +1403,14 @@ App.Utils.CalendarDefaultView = (function () { break; default: - throw new Error('Invalid date format setting provided!', App.Vars.date_format); + throw new Error('Invalid date format setting provided!', vars('date_format')); } // Time formats let timeFormat = ''; let slotTimeFormat = ''; - switch (App.Vars.time_format) { + switch (vars('time_format')) { case 'military': timeFormat = 'H:mm'; slotTimeFormat = 'H(:mm)'; @@ -1420,12 +1420,12 @@ App.Utils.CalendarDefaultView = (function () { slotTimeFormat = 'h(:mm) a'; break; default: - throw new Error('Invalid time format setting provided!', App.Vars.time_format); + throw new Error('Invalid time format setting provided!', vars('time_format')); } const defaultView = window.innerWidth < 468 ? 'agendaDay' : 'agendaWeek'; - const firstWeekday = App.Vars.first_weekday; + const firstWeekday = vars('first_weekday'); const firstWeekdayNumber = App.Utils.Date.getWeekdayId(firstWeekday); // Initialize page calendar @@ -1461,16 +1461,16 @@ App.Utils.CalendarDefaultView = (function () { let service; if ($selectFilterItem.find('option:selected').attr('type') === FILTER_TYPE_SERVICE) { - service = App.Vars.available_services.find( + service = vars('available_services').find( (availableService) => Number(availableService.id) === Number($selectFilterItem.val()) ); $appointmentsModal.find('#select-service').val(service.id).trigger('change'); } else { - const provider = App.Vars.available_providers.find( + const provider = vars('available_providers').find( (availableProvider) => Number(availableProvider.id) === Number($selectFilterItem.val()) ); - service = App.Vars.available_services.find( + service = vars('available_services').find( (availableService) => provider.services.indexOf(availableService.id) !== -1 ); @@ -1579,11 +1579,11 @@ App.Utils.CalendarDefaultView = (function () { calendarWindowResize(); // Fill the select list boxes of the page. - if (App.Vars.available_providers.length > 0) { + if (vars('available_providers').length > 0) { $('', { 'label': App.Lang.providers, 'type': 'providers-group', - 'html': App.Vars.available_providers.map((availableProvider) => { + 'html': vars('available_providers').map((availableProvider) => { const hasGoogleSync = availableProvider.settings.google_sync === '1' ? 'true' : 'false'; return $('', { 'label': App.Lang.services, 'type': 'services-group', - 'html': App.Vars.available_services.map((availableService) => + 'html': vars('available_services').map((availableService) => $('