From 6e53af035606b1a203677e2d9b9c8016fe18f430 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis <alextselegidis@gmail.com> Date: Tue, 18 Jan 2022 11:14:45 +0100 Subject: [PATCH] Convert remaining functions to arrow functions in JS files. --- assets/js/components/appointments_modal.js | 20 ++++--- .../working_plan_exceptions_modal.js | 14 ++--- assets/js/layouts/backend_layout.js | 2 +- assets/js/pages/admins.js | 40 +++++++------- assets/js/pages/booking.js | 6 +-- assets/js/pages/booking_confirmation.js | 6 +-- assets/js/pages/booking_settings.js | 8 +-- assets/js/pages/business_settings.js | 2 +- assets/js/pages/installation.js | 2 +- assets/js/pages/providers.js | 50 ++++++++---------- assets/js/utils/general_functions.js | 52 ++++++++----------- 11 files changed, 94 insertions(+), 108 deletions(-) diff --git a/assets/js/components/appointments_modal.js b/assets/js/components/appointments_modal.js index a8c64a4a..956c1b7b 100755 --- a/assets/js/components/appointments_modal.js +++ b/assets/js/components/appointments_modal.js @@ -48,9 +48,9 @@ App.Components.AppointmentsModal = (function () { function updateTimezone() { const providerId = $selectProvider.val(); - const provider = vars('available_providers').find(function (availableProvider) { - return Number(availableProvider.id) === Number(providerId); - }); + const provider = vars('available_providers').find( + (availableProvider) => Number(availableProvider.id) === Number(providerId) + ); if (provider && provider.timezone) { $('.provider-timezone').text(vars('timezones')[provider.timezone]); @@ -205,7 +205,7 @@ App.Components.AppointmentsModal = (function () { /** * Event: Pick Existing Customer Button "Click" * - * @param {jQuery.Event} + * @param {jQuery.Event} event */ $selectCustomer.on('click', (event) => { if (!$existingCustomersList.is(':visible')) { @@ -213,7 +213,7 @@ App.Components.AppointmentsModal = (function () { $existingCustomersList.empty(); $existingCustomersList.slideDown('slow'); $filterExistingCustomers.fadeIn('slow').val(''); - vars('customers').forEach(function (customer) { + vars('customers').forEach((customer) => { $('<div/>', { 'data-id': customer.id, 'text': customer.first_name + ' ' + customer.last_name @@ -234,9 +234,7 @@ App.Components.AppointmentsModal = (function () { $appointmentsModal.on('click', '#existing-customers-list div', (event) => { const customerId = $(event.target).attr('data-id'); - const customer = vars('customers').find(function (customer) { - return Number(customer.id) === Number(customerId); - }); + const customer = vars('customers').find((customer) => Number(customer.id) === Number(customerId)); if (customer) { $customerId.val(customer.id); @@ -267,7 +265,7 @@ App.Components.AppointmentsModal = (function () { const keyword = $(event.target).val().toLowerCase(); - filterExistingCustomersTimeout = setTimeout(function () { + filterExistingCustomersTimeout = setTimeout(() => { $('#loading').css('visibility', 'hidden'); App.Http.Customers.search(keyword, 50) @@ -313,7 +311,7 @@ App.Components.AppointmentsModal = (function () { } }); }) - .always(function () { + .always(() => { $('#loading').css('visibility', ''); }); }, 1000); @@ -507,7 +505,7 @@ App.Components.AppointmentsModal = (function () { hourText: lang('hour'), minuteText: lang('minutes'), firstDay: firstWeekDayNumber, - onClose: function () { + onClose: () => { const serviceId = $selectService.val(); // Automatically update the #end-datetime DateTimePicker based on service duration. diff --git a/assets/js/components/working_plan_exceptions_modal.js b/assets/js/components/working_plan_exceptions_modal.js index 9e213a02..2ef5dccd 100644 --- a/assets/js/components/working_plan_exceptions_modal.js +++ b/assets/js/components/working_plan_exceptions_modal.js @@ -81,7 +81,7 @@ App.Components.WorkingPlanExceptionsModal = (function () { function getBreaks() { const breaks = []; - $breaks.find('tbody tr').each(function (index, tr) { + $breaks.find('tbody tr').each((index, tr) => { const $tr = $(tr); if ($tr.find('input:text').length) { @@ -98,7 +98,7 @@ App.Components.WorkingPlanExceptionsModal = (function () { }); // Sort breaks increasingly by hour within day - breaks.sort(function (break1, break2) { + breaks.sort((break1, break2) => { // We can do a direct string comparison since we have time based on 24 hours clock. return break1.start.localeCompare(break2.start); }); @@ -141,7 +141,7 @@ App.Components.WorkingPlanExceptionsModal = (function () { */ function editableTimeCell($target) { $target.editable( - function (value) { + (value) => { // Do not return the value because the user needs to press the "Save" button. return value; }, @@ -159,12 +159,12 @@ App.Components.WorkingPlanExceptionsModal = (function () { 'text': lang('cancel') }).get(0).outerHTML, onblur: 'ignore', - onreset: function () { + onreset: () => { if (!enableCancel) { return false; // disable ESC button } }, - onsubmit: function () { + onsubmit: () => { if (!enableSubmit) { return false; // disable Enter button } @@ -205,7 +205,7 @@ App.Components.WorkingPlanExceptionsModal = (function () { $start.timepicker('setDate', moment(workingPlanException.start, 'HH:mm').toDate()); $end.timepicker('setDate', moment(workingPlanException.end, 'HH:mm').toDate()); - workingPlanException.breaks.forEach(function (workingPlanExceptionBreak) { + workingPlanException.breaks.forEach((workingPlanExceptionBreak) => { renderBreakRow(workingPlanExceptionBreak).appendTo($breaks.find('tbody')); }); @@ -308,7 +308,7 @@ App.Components.WorkingPlanExceptionsModal = (function () { // Reset previous editable table cells. const $previousEdits = $(this).closest('table').find('.editable'); - $previousEdits.each(function (index, editable) { + $previousEdits.each((index, editable) => { if (editable.reset) { editable.reset(); } diff --git a/assets/js/layouts/backend_layout.js b/assets/js/layouts/backend_layout.js index a13d7c56..2c90a60e 100644 --- a/assets/js/layouts/backend_layout.js +++ b/assets/js/layouts/backend_layout.js @@ -65,7 +65,7 @@ window.App.Layouts.Backend = (function () { if (!actions) { actions = []; - setTimeout(function () { + setTimeout(() => { $notification.fadeOut(); }, 5000); } diff --git a/assets/js/pages/admins.js b/assets/js/pages/admins.js index 907149e1..108263b3 100644 --- a/assets/js/pages/admins.js +++ b/assets/js/pages/admins.js @@ -46,9 +46,11 @@ App.Pages.Admins = (function () { * * When the admin leaves the username input field we will need to check if the username * is not taken by another record in the system. + * + * @param {jQuery.Event} event */ - $admins.on('blur', '#username', function () { - const $input = $(this); + $admins.on('blur', '#username', (event) => { + const $input = $(event.currentTarget); if ($input.prop('readonly') === true || $input.val() === '') { return; @@ -85,7 +87,7 @@ App.Pages.Admins = (function () { * * @param {jQuery.Event} event */ - $admins.on('submit', '#filter-admins form', function (event) { + $admins.on('submit', '#filter-admins form', (event) => { event.preventDefault(); const key = $('#filter-admins .key').val(); $('#filter-admins .selected').removeClass('selected'); @@ -98,7 +100,7 @@ App.Pages.Admins = (function () { * * Display the selected admin data to the user. */ - $admins.on('click', '.admin-row', function (event) { + $admins.on('click', '.admin-row', (event) => { if ($('#filter-admins .filter').prop('disabled')) { $('#filter-admins .results').css('color', '#AAA'); return; // exit because we are currently on edit mode @@ -106,9 +108,7 @@ App.Pages.Admins = (function () { const adminId = $(event.currentTarget).attr('data-id'); - const admin = filterResults.find(function (filterResult) { - return Number(filterResult.id) === Number(adminId); - }); + const admin = filterResults.find((filterResult) => Number(filterResult.id) === Number(adminId)); display(admin); $('#filter-admins .selected').removeClass('selected'); @@ -119,7 +119,7 @@ App.Pages.Admins = (function () { /** * Event: Add New Admin Button "Click" */ - $admins.on('click', '#add-admin', function () { + $admins.on('click', '#add-admin', () => { resetForm(); $admins.find('.add-edit-delete-group').hide(); $admins.find('.save-cancel-group').show(); @@ -133,7 +133,7 @@ App.Pages.Admins = (function () { /** * Event: Edit Admin Button "Click" */ - $admins.on('click', '#edit-admin', function () { + $admins.on('click', '#edit-admin', () => { $admins.find('.add-edit-delete-group').hide(); $admins.find('.save-cancel-group').show(); $admins.find('.record-details').find('input, textarea').prop('disabled', false); @@ -146,19 +146,19 @@ App.Pages.Admins = (function () { /** * Event: Delete Admin Button "Click" */ - $admins.on('click', '#delete-admin', function () { + $admins.on('click', '#delete-admin', () => { const adminId = $id.val(); const buttons = [ { text: lang('cancel'), - click: function () { + click: () => { $('#message-box').dialog('close'); } }, { text: lang('delete'), - click: function () { + click: () => { remove(adminId); $('#message-box').dialog('close'); } @@ -171,7 +171,7 @@ App.Pages.Admins = (function () { /** * Event: Save Admin Button "Click" */ - $admins.on('click', '#save-admin', function () { + $admins.on('click', '#save-admin', () => { const admin = { first_name: $firstName.val(), last_name: $lastName.val(), @@ -213,7 +213,7 @@ App.Pages.Admins = (function () { * * Cancel add or edit of an admin record. */ - $admins.on('click', '#cancel-admin', function () { + $admins.on('click', '#cancel-admin', () => { const id = $id.val(); resetForm(); @@ -264,7 +264,7 @@ App.Pages.Admins = (function () { // Validate required fields. let missingRequired = false; - $admins.find('.required').each(function (index, requiredField) { + $admins.find('.required').each((index, requiredField) => { if (!$(requiredField).val()) { $(requiredField).addClass('is-invalid'); missingRequired = true; @@ -363,8 +363,8 @@ App.Pages.Admins = (function () { $filterAdmins.find('.results').empty(); - response.forEach(function (admin) { - $('#filter-admins .results').append(getFilterHtml(admin)).append($('<hr/>')); + response.forEach((admin) => { + $filterAdmins.find('.results').append(getFilterHtml(admin)).append($('<hr/>')); }); if (!response.length) { @@ -378,7 +378,7 @@ App.Pages.Admins = (function () { 'type': 'button', 'class': 'btn btn-outline-secondary w-100 load-more text-center', 'text': lang('load_more'), - 'click': function () { + 'click': () => { filterLimit += 20; filter(keyword, selectId, show); } @@ -437,9 +437,7 @@ App.Pages.Admins = (function () { $filterAdmins.find('.admin-row[data-id="' + id + '"]').addClass('selected'); if (show) { - const admin = filterResults.find(function (filterResult) { - return Number(filterResult.id) === Number(id); - }); + const admin = filterResults.find((filterResult) => Number(filterResult.id) === Number(id)); display(admin); diff --git a/assets/js/pages/booking.js b/assets/js/pages/booking.js index de29fcb9..5e5841a7 100644 --- a/assets/js/pages/booking.js +++ b/assets/js/pages/booking.js @@ -784,9 +784,9 @@ App.Pages.Booking = (function () { $serviceDescription.empty(); - const service = vars('available_services').find(function (availableService) { - return Number(availableService.id) === Number(serviceId); - }); + const service = vars('available_services').find( + (availableService) => Number(availableService.id) === Number(serviceId) + ); if (!service) { return; diff --git a/assets/js/pages/booking_confirmation.js b/assets/js/pages/booking_confirmation.js index ef41666e..acdd2daf 100644 --- a/assets/js/pages/booking_confirmation.js +++ b/assets/js/pages/booking_confirmation.js @@ -55,13 +55,13 @@ App.Pages.BookingConfirmation = (function () { ] }; - gapi.client.load('calendar', 'v3', function () { + gapi.client.load('calendar', 'v3', () => { const request = gapi.client.calendar.events.insert({ calendarId: 'primary', resource: resource }); - request.execute(function (response) { + request.execute((response) => { if (response.error) { throw new Error('Could not add the event to Google Calendar.'); } @@ -120,7 +120,7 @@ App.Pages.BookingConfirmation = (function () { * be added to the "primary" calendar. In order to use the API the javascript client library provided by * Google is necessary. */ - $addToGoogleCalendar.on('click', function () { + $addToGoogleCalendar.on('click', () => { gapi.client.setApiKey(vars('google_api_key')); gapi.auth.authorize( diff --git a/assets/js/pages/booking_settings.js b/assets/js/pages/booking_settings.js index f390aad0..e90fbfab 100644 --- a/assets/js/pages/booking_settings.js +++ b/assets/js/pages/booking_settings.js @@ -125,14 +125,14 @@ App.Pages.BookingSettings = (function () { * Update the UI based on the initial values. */ function applyInitialState() { - $bookingSettings.find('.display-switch').each(function (index, displaySwitch) { - const $displaySwitch = $(displaySwitch); + $bookingSettings.find('.display-switch').each((index, displaySwitchEl) => { + const $displaySwitch = $(displaySwitchEl); updateDisplaySwitch($displaySwitch); }); - $bookingSettings.find('.require-switch').each(function (index, requireSwitch) { - const $requireSwitch = $(requireSwitch); + $bookingSettings.find('.require-switch').each((index, requireSwitchEl) => { + const $requireSwitch = $(requireSwitchEl); updateRequireSwitch($requireSwitch); }); diff --git a/assets/js/pages/business_settings.js b/assets/js/pages/business_settings.js index d857949e..d3974224 100644 --- a/assets/js/pages/business_settings.js +++ b/assets/js/pages/business_settings.js @@ -117,7 +117,7 @@ App.Pages.BusinessSettings = (function () { .done(() => { App.Layouts.Backend.displayNotification(lang('working_plans_got_updated')); }) - .always(function () { + .always(() => { $('#message-box').dialog('close'); }); } diff --git a/assets/js/pages/installation.js b/assets/js/pages/installation.js index 9409af7d..e4545855 100644 --- a/assets/js/pages/installation.js +++ b/assets/js/pages/installation.js @@ -65,7 +65,7 @@ App.Pages.Installation = (function () { .addClass('alert-success') .prop('hidden', false); - setTimeout(function () { + setTimeout(() => { window.location.href = App.Utils.Url.siteUrl('calendar'); }, 1000); }); diff --git a/assets/js/pages/providers.js b/assets/js/pages/providers.js index 32aa002c..ef813137 100755 --- a/assets/js/pages/providers.js +++ b/assets/js/pages/providers.js @@ -49,7 +49,7 @@ App.Pages.Providers = (function () { * * @param {jQuery.Event} event */ - $providers.on('submit', '#filter-providers form', function (event) { + $providers.on('submit', '#filter-providers form', (event) => { event.preventDefault(); const key = $('#filter-providers .key').val(); $('.selected').removeClass('selected'); @@ -62,16 +62,14 @@ App.Pages.Providers = (function () { * * Display the selected provider data to the user. */ - $providers.on('click', '.provider-row', function (event) { + $providers.on('click', '.provider-row', (event) => { if ($filterProviders.find('.filter').prop('disabled')) { $filterProviders.find('.results').css('color', '#AAA'); return; // Exit because we are currently on edit mode. } const providerId = $(event.currentTarget).attr('data-id'); - const provider = filterResults.find(function (filterResult) { - return Number(filterResult.id) === Number(providerId); - }); + const provider = filterResults.find((filterResult) => Number(filterResult.id) === Number(providerId)); display(provider); $filterProviders.find('.selected').removeClass('selected'); @@ -82,7 +80,7 @@ App.Pages.Providers = (function () { /** * Event: Add New Provider Button "Click" */ - $providers.on('click', '#add-provider', function () { + $providers.on('click', '#add-provider', () => { resetForm(); $filterProviders.find('button').prop('disabled', true); $filterProviders.find('.results').css('color', '#AAA'); @@ -106,7 +104,7 @@ App.Pages.Providers = (function () { /** * Event: Edit Provider Button "Click" */ - $providers.on('click', '#edit-provider', function () { + $providers.on('click', '#edit-provider', () => { $providers.find('.add-edit-delete-group').hide(); $providers.find('.save-cancel-group').show(); $filterProviders.find('button').prop('disabled', true); @@ -126,19 +124,19 @@ App.Pages.Providers = (function () { /** * Event: Delete Provider Button "Click" */ - $providers.on('click', '#delete-provider', function () { + $providers.on('click', '#delete-provider', () => { const providerId = $id.val(); const buttons = [ { text: lang('cancel'), - click: function () { + click: () => { $('#message-box').dialog('close'); } }, { text: lang('delete'), - click: function () { + click: () => { remove(providerId); $('#message-box').dialog('close'); } @@ -151,7 +149,7 @@ App.Pages.Providers = (function () { /** * Event: Save Provider Button "Click" */ - $providers.on('click', '#save-provider', function () { + $providers.on('click', '#save-provider', () => { const provider = { first_name: $firstName.val(), last_name: $lastName.val(), @@ -175,9 +173,9 @@ App.Pages.Providers = (function () { // Include provider services. provider.services = []; - $('#provider-services input:checkbox').each(function (index, checkbox) { - if ($(checkbox).prop('checked')) { - provider.services.push($(checkbox).attr('data-id')); + $('#provider-services input:checkbox').each((index, checkboxEl) => { + if ($(checkboxEl).prop('checked')) { + provider.services.push($(checkboxEl).attr('data-id')); } }); @@ -203,7 +201,7 @@ App.Pages.Providers = (function () { * * Cancel add or edit of an provider record. */ - $providers.on('click', '#cancel-provider', function () { + $providers.on('click', '#cancel-provider', () => { const id = $('#filter-providers .selected').attr('data-id'); resetForm(); if (id) { @@ -214,14 +212,14 @@ App.Pages.Providers = (function () { /** * Event: Display Provider Details "Click" */ - $providers.on('shown.bs.tab', 'a[data-toggle="tab"]', function () { + $providers.on('shown.bs.tab', 'a[data-toggle="tab"]', () => { App.Layouts.Backend.placeFooterToBottom(); }); /** * Event: Reset Working Plan Button "Click". */ - $providers.on('click', '#reset-working-plan', function () { + $providers.on('click', '#reset-working-plan', () => { $('.breaks tbody').empty(); $('.working-plan-exceptions tbody').empty(); $('.work-start, .work-end').val(''); @@ -272,9 +270,9 @@ App.Pages.Providers = (function () { // Validate required fields. let missingRequired = false; - $providers.find('.required').each(function (index, requiredField) { - if (!$(requiredField).val()) { - $(requiredField).addClass('is-invalid'); + $providers.find('.required').each((index, requiredFieldEl) => { + if (!$(requiredFieldEl).val()) { + $(requiredFieldEl).addClass('is-invalid'); missingRequired = true; } }); @@ -387,7 +385,7 @@ App.Pages.Providers = (function () { $('#provider-services a').remove(); $('#provider-services input:checkbox').prop('checked', false); - provider.services.forEach(function (providerServiceId) { + provider.services.forEach((providerServiceId) => { const $checkbox = $('#provider-services input[data-id="' + providerServiceId + '"]'); if (!$checkbox.length) { @@ -440,7 +438,7 @@ App.Pages.Providers = (function () { filterResults = response; $filterProviders.find('.results').empty(); - response.forEach(function (provider) { + response.forEach((provider) => { $('#filter-providers .results').append(getFilterHtml(provider)).append($('<hr/>')); }); @@ -455,7 +453,7 @@ App.Pages.Providers = (function () { 'type': 'button', 'class': 'btn btn-outline-secondary w-100 load-more text-center', 'text': lang('load_more'), - 'click': function () { + 'click': () => { filterLimit += 20; filter(keyword, selectId, show); } @@ -512,9 +510,7 @@ App.Pages.Providers = (function () { // Display record in form (if display = true). if (show) { - const provider = filterResults.find(function (filterResult) { - return Number(filterResult.id) === Number(id); - }); + const provider = filterResults.find((filterResult) => Number(filterResult.id) === Number(id)); display(provider); @@ -533,7 +529,7 @@ App.Pages.Providers = (function () { filter(''); addEventListeners(); - vars('services').forEach(function (service) { + vars('services').forEach((service) => { $('<div/>', { 'class': 'checkbox', 'html': [ diff --git a/assets/js/utils/general_functions.js b/assets/js/utils/general_functions.js index c89ab76b..645dd65d 100755 --- a/assets/js/utils/general_functions.js +++ b/assets/js/utils/general_functions.js @@ -19,13 +19,13 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @module GeneralFunctions */ (function (exports) { - 'use strict'; + ('use strict'); /** * Register global error handler. */ - document.addEventListener('DOMContentLoaded', function () { - $(document).ajaxError(function (event, jqxhr, settings, thrownError) { + document.addEventListener('DOMContentLoaded', () => { + $(document).ajaxError((event, jqxhr, settings, thrownError) => { GeneralFunctions.ajaxFailureHandler(jqxhr, settings, thrownError); }); }); @@ -38,7 +38,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @param {String} message The message of the dialog. * @param {Array} buttons Contains the dialog buttons along with their functions. */ - exports.displayMessageBox = function (title, message, buttons = null) { + exports.displayMessageBox = (title, message, buttons = null) => { if (!title) { title = '- No Title Provided -'; } @@ -51,7 +51,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; buttons = [ { text: lang('close'), - click: function () { + click: () => { $('#message-box').dialog('close'); } } @@ -93,7 +93,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * * @param {Object} elementHandle The object that is going to be centered. */ - exports.centerElementOnPage = function (elementHandle) { + exports.centerElementOnPage = (elementHandle) => { // Center main frame vertical middle $(window).resize(function () { var elementLeft = ($(window).width() - elementHandle.outerWidth()) / 2; @@ -119,7 +119,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @return {String} Returns the parameter value. */ - exports.getUrlParameter = function (url, parameterName) { + exports.getUrlParameter = (url, parameterName) => { var parsedUrl = url.substr(url.indexOf('?')).slice(1).split('&'); for (var index in parsedUrl) { @@ -147,7 +147,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @return {String} Returns the transformed string. */ - exports.ISODateString = function (date) { + exports.ISODateString = (date) => { function pad(n) { return n < 10 ? '0' + n : n; } @@ -180,7 +180,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @return {Object} Returns an exact copy of the provided element. */ - exports.clone = function (originalObject) { + exports.clone = (originalObject) => { // Handle the 3 simple types, and null or undefined if (!originalObject || typeof originalObject !== 'object') { return originalObject; @@ -228,7 +228,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @return {Boolean} Returns the validation result. */ - exports.validateEmail = function (email) { + exports.validateEmail = (email) => { var re = /(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/; return re.test(email); @@ -241,9 +241,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * * @return {String} Returns the capitalized string. */ - exports.upperCaseFirstLetter = function (value) { - return value.charAt(0).toUpperCase() + value.slice(1); - }; + exports.upperCaseFirstLetter = (value) => value.charAt(0).toUpperCase() + value.slice(1); /** * Enable Language Selection @@ -255,7 +253,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * * @deprecated Since 1.5 */ - exports.enableLanguageSelection = function ($element) { + exports.enableLanguageSelection = ($element) => { console.warn( `Call of deprecated GeneralFunctions.enableLanguageSelection method! Please use the App.Utils.Lang.enableLanguageSelection instead as this method will be removed soon.` ); @@ -269,7 +267,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @param {String} textStatus * @param {Object} errorThrown */ - exports.ajaxFailureHandler = function (jqXHR, textStatus, errorThrown) { + exports.ajaxFailureHandler = (jqXHR, textStatus, errorThrown) => { console.error('Unexpected HTTP Error: ', jqXHR, textStatus, errorThrown); var response; @@ -304,9 +302,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * * @return {String} Returns the escaped string. */ - exports.escapeHtml = function (content) { - return $('<div/>').text(content).html(); - }; + exports.escapeHtml = (content) => $('<div/>').text(content).html(); /** * Format a given date according to the date format setting. @@ -317,7 +313,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @return {String} Returns the formatted date string. */ - exports.formatDate = function (date, dateFormatSetting, addHours) { + exports.formatDate = (date, dateFormatSetting, addHours) => { var timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm'; var hours = addHours ? ' ' + timeFormat : ''; var result; @@ -353,7 +349,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @return {Number} Returns the ID of the weekday. */ - exports.getWeekDayId = function (weekDayName) { + exports.getWeekDayId = (weekDayName) => { var result; switch (weekDayName.toLowerCase()) { @@ -406,7 +402,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @return {String} Returns the name of the weekday. */ - exports.getWeekdayName = function (weekDayId) { + exports.getWeekdayName = (weekDayId) => { var result; switch (weekDayId) { @@ -453,7 +449,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @return {Object} Returns a sorted dictionary */ - exports.sortWeekDictionary = function (weekDictionary, startDayId) { + exports.sortWeekDictionary = (weekDictionary, startDayId) => { var sortedWeekDictionary = {}; for (var i = startDayId; i < startDayId + 7; i++) { @@ -471,7 +467,7 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * * @return {string} The rendered HTML. */ - exports.renderMapIcon = function (user) { + exports.renderMapIcon = (user) => { var data = []; if (user.address) { @@ -516,8 +512,8 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * * @return {string} The rendered HTML. */ - exports.renderMailIcon = function (email) { - return $('<div/>', { + exports.renderMailIcon = (email) => + $('<div/>', { 'html': [ $('<a/>', { 'href': 'mailto:' + email, @@ -530,7 +526,6 @@ window.GeneralFunctions = window.GeneralFunctions || {}; }) ] }).html(); - }; /** * Render a phone icon. @@ -539,8 +534,8 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * * @return {string} The rendered HTML. */ - exports.renderPhoneIcon = function (phone) { - return $('<div/>', { + exports.renderPhoneIcon = (phone) => + $('<div/>', { 'html': [ $('<a/>', { 'href': 'tel:' + phone, @@ -553,5 +548,4 @@ window.GeneralFunctions = window.GeneralFunctions || {}; }) ] }).html(); - }; })(window.GeneralFunctions);