Replace GlobalVariables use with App.Vars.* values.

This commit is contained in:
Alex Tselegidis 2022-01-17 18:00:25 +01:00
parent 46f0a27998
commit 7a9aa3d91d
4 changed files with 32 additions and 36 deletions

View file

@ -94,11 +94,11 @@ App.Pages.Booking = (function () {
// Initialize page's components (tooltips, datepickers etc).
tippy('[data-tippy-content]');
const weekDayId = App.Utils.Date.getWeekdayId(GlobalVariables.firstWeekday);
const weekdayId = App.Utils.Date.getWeekdayId(App.Vars.first_weekday);
$selectDate.datepicker({
dateFormat: 'dd-mm-yy',
firstDay: weekDayId,
firstDay: weekdayId,
minDate: 0,
defaultDate: moment().toDate(),
@ -171,11 +171,7 @@ App.Pages.Booking = (function () {
// If the manage mode is true, the appointments data should be loaded by default.
if (manageMode) {
applyAppointmentData(
GlobalVariables.appointmentData,
GlobalVariables.providerData,
GlobalVariables.customerData
);
applyAppointmentData(App.Vars.appointment_data, App.Vars.provider_data, App.Vars.customer_data);
} else {
// Check if a specific service was selected (via URL parameter).
const selectedServiceId = App.Utils.Url.queryParam('service');
@ -191,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 GlobalVariables.availableProviders) {
const provider = GlobalVariables.availableProviders[index];
for (const index in App.Vars.available_providers) {
const provider = App.Vars.available_providers[index];
if (provider.id === selectedProviderId && provider.services.length > 0) {
$selectService.val(provider.services[0]).trigger('change');
@ -253,7 +249,7 @@ App.Pages.Booking = (function () {
$selectProvider.empty();
GlobalVariables.availableProviders.forEach((provider) => {
App.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))
@ -265,7 +261,7 @@ App.Pages.Booking = (function () {
});
// Add the "Any Provider" entry.
if ($selectProvider.find('option').length >= 1 && GlobalVariables.displayAnyProvider === '1') {
if ($selectProvider.find('option').length >= 1 && App.Vars.display_any_provider === '1') {
$selectProvider.prepend(new Option('- ' + App.Lang.any_provider + ' -', 'any-provider', true, true));
}
@ -457,7 +453,7 @@ App.Pages.Booking = (function () {
{
text: App.Lang.delete,
click: () => {
App.Http.Booking.deletePersonalInformation(GlobalVariables.customerToken);
App.Http.Booking.deletePersonalInformation(App.Vars.customer_token);
}
}
];
@ -487,7 +483,7 @@ App.Pages.Booking = (function () {
* Event: Refresh captcha image.
*/
$captchaTitle.on('click', 'button', () => {
$('.captcha-image').attr('src', GlobalVariables.baseUrl + '/index.php/captcha?' + Date.now());
$('.captcha-image').attr('src', App.Utils.Url.siteUrl('captcha?' + Date.now()));
});
$selectDate.on('mousedown', '.ui-datepicker-calendar td', () => {
@ -693,10 +689,10 @@ App.Pages.Booking = (function () {
data.manage_mode = manageMode;
if (manageMode) {
data.appointment.id = GlobalVariables.appointmentData.id;
data.customer.id = GlobalVariables.customerData.id;
data.appointment.id = App.Vars.appointment_data.id;
data.customer.id = App.Vars.customer_data.id;
}
$('input[name="csrfToken"]').val(GlobalVariables.csrfToken);
$('input[name="csrfToken"]').val(App.Vars.csrf_token);
$('input[name="post_data"]').val(JSON.stringify(data));
}

View file

@ -162,7 +162,7 @@ App.Pages.Installation = (function () {
}
// Validate the base URL setting (must not contain any trailing slash).
if (GlobalVariables.baseUrl.slice(-1) === '/') {
if (App.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.'

View file

@ -159,8 +159,8 @@ App.Utils.CalendarTableView = (function () {
workingPlanExceptions[date] = workingPlanException;
for (const index in GlobalVariables.availableProviders) {
const availableProvider = GlobalVariables.availableProviders[index];
for (const index in App.Vars.available_providers) {
const availableProvider = App.Vars.available_providers[index];
if (Number(availableProvider.id) === Number(provider.id)) {
availableProvider.settings.working_plan_exceptions =
@ -403,13 +403,13 @@ App.Utils.CalendarTableView = (function () {
}
});
const providers = GlobalVariables.availableProviders.filter(
const providers = App.Vars.available_providers.filter(
(provider) =>
App.Vars.role_slug === App.Layouts.Backend.DB_SLUG_ADMIN ||
(App.Vars.role_slug === App.Layouts.Backend.DB_SLUG_SECRETARY &&
GlobalVariables.secretaryProviders.indexOf(provider.id) !== -1) ||
App.Vars.secretary_providers.indexOf(provider.id) !== -1) ||
(App.Vars.role_slug === App.Layouts.Backend.DB_SLUG_PROVIDER &&
Number(provider.id) === Number(GlobalVariables.user.id))
Number(provider.id) === Number(App.Vars.user_id))
);
// Create providers and service filters.
@ -435,7 +435,7 @@ App.Utils.CalendarTableView = (function () {
});
} else {
providers.forEach((provider) => {
if (Number(provider.id) === Number(GlobalVariables.user.id)) {
if (Number(provider.id) === Number(App.Vars.user_id)) {
$filterProvider.append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
}
});
@ -443,7 +443,7 @@ App.Utils.CalendarTableView = (function () {
$filterProvider.select2();
const services = GlobalVariables.availableServices.filter((service) => {
const services = App.Vars.available_services.filter((service) => {
const provider = providers.find((provider) => provider.services.indexOf(service.id) !== -1);
return App.Vars.role_slug === App.Layouts.Backend.DB_SLUG_ADMIN || provider;
@ -558,7 +558,7 @@ App.Utils.CalendarTableView = (function () {
const filterProviderIds = $filterProvider.val();
const filterServiceIds = $filterService.val();
let providers = GlobalVariables.availableProviders.filter((provider) => {
let providers = App.Vars.available_providers.filter((provider) => {
const servedServiceIds = provider.services.filter((serviceId) => {
const matches = filterServiceIds.filter(
(filterServiceId) => Number(serviceId) === Number(filterServiceId)
@ -581,8 +581,8 @@ App.Utils.CalendarTableView = (function () {
});
if (App.Vars.role_slug === 'provider') {
GlobalVariables.availableProviders.forEach((provider) => {
if (Number(provider.id) === Number(GlobalVariables.user.id)) {
App.Vars.available_providers.forEach((provider) => {
if (Number(provider.id) === Number(App.Vars.user_id)) {
providers = [provider];
}
});
@ -590,8 +590,8 @@ App.Utils.CalendarTableView = (function () {
if (App.Vars.role_slug === 'secretary') {
providers = [];
GlobalVariables.availableProviders.forEach((provider) => {
if (GlobalVariables.secretaryProviders.indexOf(provider.id) > -1) {
App.Vars.available_providers.forEach((provider) => {
if (App.Vars.secretary_providers.indexOf(provider.id) > -1) {
providers.push(provider);
}
});
@ -674,7 +674,7 @@ App.Utils.CalendarTableView = (function () {
let timeFormat = '';
let slotTimeFormat = '';
switch (GlobalVariables.timeFormat) {
switch (App.Vars.time_format) {
case 'military':
timeFormat = 'H:mm';
slotTimeFormat = 'H(:mm)';
@ -684,7 +684,7 @@ App.Utils.CalendarTableView = (function () {
slotTimeFormat = 'h(:mm) a';
break;
default:
throw new Error('Invalid time format setting provided!' + GlobalVariables.timeFormat);
throw new Error('Invalid time format setting provided!' + App.Vars.time_format);
}
const firstWeekday = App.Vars.first_weekday;
@ -719,11 +719,11 @@ App.Utils.CalendarTableView = (function () {
const $providerColumn = $(jsEvent.target).parents('.provider-column');
const providerId = $providerColumn.data('provider').id;
const provider = GlobalVariables.availableProviders.find(
const provider = App.Vars.available_providers.find(
(provider) => Number(provider.id) === Number(providerId)
);
const service = GlobalVariables.availableServices.find(
const service = App.Vars.available_services.find(
(service) => provider.services.indexOf(service.id) !== -1
);

View file

@ -289,10 +289,10 @@ window.GeneralFunctions = window.GeneralFunctions || {};
$(document).on('click', 'li.language', function () {
// Change language with ajax call and refresh page.
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_change_language';
var url = App.Vars.base_url + '/index.php/backend_api/ajax_change_language';
var data = {
csrf_token: GlobalVariables.csrfToken,
csrf_token: App.Vars.csrf_token,
language: $(this).attr('data-language')
};
@ -362,7 +362,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
* @return {String} Returns the formatted date string.
*/
exports.formatDate = function (date, dateFormatSetting, addHours) {
var timeFormat = GlobalVariables.timeFormat === 'regular' ? 'h:mm a' : 'HH:mm';
var timeFormat = App.Vars.time_format === 'regular' ? 'h:mm a' : 'HH:mm';
var hours = addHours ? ' ' + timeFormat : '';
var result;
var parsedDateMoment = moment(date);