Add missing selector const and convert remaining functions to arrow functions

This commit is contained in:
Alex Tselegidis 2022-01-17 21:32:17 +01:00
parent 3ca5fa6de6
commit 2feb0d5c99

View file

@ -16,6 +16,7 @@
*/ */
App.Pages.Services = (function () { App.Pages.Services = (function () {
const $services = $('#services'); const $services = $('#services');
const $id = $('#service-id');
const $name = $('#service-name'); const $name = $('#service-name');
const $duration = $('#service-duration'); const $duration = $('#service-duration');
const $price = $('#service-price'); const $price = $('#service-price');
@ -38,7 +39,7 @@ App.Pages.Services = (function () {
* *
* @param {jQuery.Event} event * @param {jQuery.Event} event
*/ */
$services.on('submit', '#filter-services form', function (event) { $services.on('submit', '#filter-services form', (event) => {
event.preventDefault(); event.preventDefault();
const key = $filterServices.find('.key').val(); const key = $filterServices.find('.key').val();
$filterServices.find('.selected').removeClass('selected'); $filterServices.find('.selected').removeClass('selected');
@ -51,17 +52,15 @@ App.Pages.Services = (function () {
* *
* Display the selected service data to the user. * Display the selected service data to the user.
*/ */
$services.on('click', '.service-row', function () { $services.on('click', '.service-row', (event) => {
if ($filterServices.find('.filter').prop('disabled')) { if ($filterServices.find('.filter').prop('disabled')) {
$filterServices.find('.results').css('color', '#AAA'); $filterServices.find('.results').css('color', '#AAA');
return; // exit because we are on edit mode return; // exit because we are on edit mode
} }
const serviceId = $(this).attr('data-id'); const serviceId = $(event.currentTarget).attr('data-id');
const service = filterResults.find(function (filterResult) { const service = filterResults.find((filterResult) => Number(filterResult.id) === Number(serviceId));
return Number(filterResult.id) === Number(serviceId);
});
// Add dedicated provider link. // Add dedicated provider link.
const dedicatedUrl = App.Utils.Url.siteUrl('?service=' + encodeURIComponent(service.id)); const dedicatedUrl = App.Utils.Url.siteUrl('?service=' + encodeURIComponent(service.id));
@ -79,14 +78,14 @@ App.Pages.Services = (function () {
display(service); display(service);
$filterServices.find('.selected').removeClass('selected'); $filterServices.find('.selected').removeClass('selected');
$(this).addClass('selected'); $(event.currentTarget).addClass('selected');
$('#edit-service, #delete-service').prop('disabled', false); $('#edit-service, #delete-service').prop('disabled', false);
}); });
/** /**
* Event: Add New Service Button "Click" * Event: Add New Service Button "Click"
*/ */
$services.on('click', '#add-service', function () { $services.on('click', '#add-service', () => {
resetForm(); resetForm();
$services.find('.add-edit-delete-group').hide(); $services.find('.add-edit-delete-group').hide();
$services.find('.save-cancel-group').show(); $services.find('.save-cancel-group').show();
@ -109,7 +108,7 @@ App.Pages.Services = (function () {
* *
* Cancel add or edit of a service record. * Cancel add or edit of a service record.
*/ */
$services.on('click', '#cancel-service', function () { $services.on('click', '#cancel-service', () => {
const id = $id.val(); const id = $id.val();
resetForm(); resetForm();
@ -122,7 +121,7 @@ App.Pages.Services = (function () {
/** /**
* Event: Save Service Button "Click" * Event: Save Service Button "Click"
*/ */
$services.on('click', '#save-service', function () { $services.on('click', '#save-service', () => {
const service = { const service = {
name: $name.val(), name: $name.val(),
duration: $duration.val(), duration: $duration.val(),
@ -149,7 +148,7 @@ App.Pages.Services = (function () {
/** /**
* Event: Edit Service Button "Click" * Event: Edit Service Button "Click"
*/ */
$services.on('click', '#edit-service', function () { $services.on('click', '#edit-service', () => {
$services.find('.add-edit-delete-group').hide(); $services.find('.add-edit-delete-group').hide();
$services.find('.save-cancel-group').show(); $services.find('.save-cancel-group').show();
$services.find('.record-details').find('input, select, textarea').prop('disabled', false); $services.find('.record-details').find('input, select, textarea').prop('disabled', false);
@ -160,7 +159,7 @@ App.Pages.Services = (function () {
/** /**
* Event: Delete Service Button "Click" * Event: Delete Service Button "Click"
*/ */
$services.on('click', '#delete-service', function () { $services.on('click', '#delete-service', () => {
const serviceId = $id.val(); const serviceId = $id.val();
const buttons = [ const buttons = [
{ {
@ -371,9 +370,7 @@ App.Pages.Services = (function () {
$filterServices.find('.service-row[data-id="' + id + '"]').addClass('selected'); $filterServices.find('.service-row[data-id="' + id + '"]').addClass('selected');
if (show) { if (show) {
const service = filterResults.find(function (filterResult) { const service = filterResults.find((filterResult) => Number(filterResult.id) === Number(id));
return Number(filterResult.id) === Number(id);
});
display(service); display(service);