From 63c81dc09c103f504ef825085a247f94558c8561 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 17 Jan 2022 05:14:36 +0100 Subject: [PATCH] Code refactoring and improvements for the booking HTTP client. --- assets/js/http/booking_http_client.js | 31 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/assets/js/http/booking_http_client.js b/assets/js/http/booking_http_client.js index 6e4b1c3c..fc3e1f32 100755 --- a/assets/js/http/booking_http_client.js +++ b/assets/js/http/booking_http_client.js @@ -17,6 +17,11 @@ * Old Name: FrontendBookApi */ App.Http.Booking = (function () { + const $selectService = $('#select-service'); + const $selectProvider = $('#select-provider'); + const $availableHours = $('#available-hours'); + const $captchaHint = $('#captcha-hint'); + const $captchaTitle = $('.captcha-title'); let unavailableDatesBackup; let selectedDateStringBackup; let processingUnavailabilities = false; @@ -30,10 +35,10 @@ App.Http.Booking = (function () { * @param {String} selectedDate The selected date of the available hours we need. */ function getAvailableHours(selectedDate) { - $('#available-hours').empty(); + $availableHours.empty(); // Find the selected service duration (it is going to be send within the "data" object). - const serviceId = $('#select-service').val(); + const serviceId = $selectService.val(); // Default value of duration (in minutes). let serviceDuration = 15; @@ -54,8 +59,8 @@ App.Http.Booking = (function () { const data = { csrf_token: App.Vars.csrf_token, - service_id: $('#select-service').val(), - provider_id: $('#select-provider').val(), + service_id: $selectService.val(), + provider_id: $selectProvider.val(), selected_date: selectedDate, service_duration: serviceDuration, manage_mode: App.Pages.Booking.manageMode, @@ -66,7 +71,7 @@ App.Http.Booking = (function () { // The response contains the available hours for the selected provider and service. Fill the available // hours div with response data. if (response.length > 0) { - let providerId = $('#select-provider').val(); + let providerId = $selectProvider.val(); if (providerId === 'any-provider') { for (const availableProvider of App.Vars.available_providers) { @@ -98,7 +103,7 @@ App.Http.Booking = (function () { return; // Due to the selected timezone the available hour belongs to another date. } - $('#available-hours').append( + $availableHours.append( $('