Use the array find method directly.

This commit is contained in:
Alex Tselegidis 2020-05-07 19:00:33 +02:00
parent 70948615df
commit 7af93aba76
4 changed files with 31 additions and 32 deletions

View file

@ -25,9 +25,9 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
function updateTimezone() {
var providerId = $('#select-provider').val();
var provider = GlobalVariables.availableProviders.filter(function(availableProvider) {
var provider = GlobalVariables.availableProviders.find(function(availableProvider) {
return Number(availableProvider.id) === Number(providerId);
}).shift();
});
if (provider && provider.timezone) {
$('.provider-timezone').text(GlobalVariables.timezones[provider.timezone]);
@ -145,12 +145,10 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
+ $('#select-filter-item').val() + '"]').prop('selected', true);
}
var serviceDuration = 0;
$.each(GlobalVariables.availableServices, function (index, service) {
if (Number(service.id) === Number($dialog.find('#select-service').val())) {
serviceDuration = service.duration;
return false; // exit loop
}
var serviceId = $dialog.find('#select-service').val();
var service = GlobalVariables.availableServices.find(function(availableService) {
return Number(availableService.id) === Number(serviceId);
});
var start = new Date();
@ -167,7 +165,7 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
}
$dialog.find('#start-datetime').val(GeneralFunctions.formatDate(start, GlobalVariables.dateFormat, true));
$dialog.find('#end-datetime').val(GeneralFunctions.formatDate(start.addMinutes(serviceDuration),
$dialog.find('#end-datetime').val(GeneralFunctions.formatDate(start.addMinutes(service.duration),
GlobalVariables.dateFormat, true));
// Display modal form.
@ -205,10 +203,13 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
* Event: Select Existing Customer From List "Click"
*/
$('#manage-appointment').on('click', '#existing-customers-list div', function () {
var id = $(this).attr('data-id');
var customerId = $(this).attr('data-id');
$.each(GlobalVariables.customers, function (index, customer) {
if (Number(customer.id) === Number(id)) {
var customer = GlobalVariables.customers.find(function (customer) {
return Number(customer.id) === Number(customerId);
});
if (customer) {
$('#customer-id').val(customer.id);
$('#first-name').val(customer.first_name);
$('#last-name').val(customer.last_name);
@ -218,11 +219,9 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
$('#city').val(customer.city);
$('#zip-code').val(customer.zip_code);
$('#customer-notes').val(customer.notes);
return false;
}
});
$('#select-customer').trigger('click'); // hide list
$('#select-customer').trigger('click'); // Hide the list.
});
/**

View file

@ -234,9 +234,9 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
var providerId = $('#select-filter-item').val();
var provider = GlobalVariables.availableProviders.filter(function(availableProvider) {
var provider = GlobalVariables.availableProviders.find(function(availableProvider) {
return Number(availableProvider.id) === Number(providerId);
}).shift();
});
if (provider && provider.timezone) {
$('.provider-timezone').text(GlobalVariables.timezones[provider.timezone]);

View file

@ -721,9 +721,9 @@ window.FrontendBook = window.FrontendBook || {};
$serviceDescription.empty();
var service = GlobalVariables.availableServices.filter(function(availableService) {
var service = GlobalVariables.availableServices.find(function(availableService) {
return Number(availableService.id) === Number(serviceId);
}).shift();
});
if (!service) {
return;

View file

@ -43,9 +43,9 @@ window.FrontendBookApi = window.FrontendBookApi || {};
// Default value of duration (in minutes).
var serviceDuration = 15;
var service = GlobalVariables.availableServices.filter(function(availableService) {
var service = GlobalVariables.availableServices.find(function(availableService) {
return Number(availableService.id) === Number(serviceId);
}).shift();
});
if (service) {
serviceDuration = service.duration;
@ -78,9 +78,9 @@ window.FrontendBookApi = window.FrontendBookApi || {};
providerId = GlobalVariables.availableProviders[0].id; // Use first available provider.
}
var provider = GlobalVariables.availableProviders.filter(function(availableProvider) {
var provider = GlobalVariables.availableProviders.find(function(availableProvider) {
return Number(providerId) === Number(availableProvider.id);
}).shift();
});
if (!provider) {
throw new Error('Could not find provider.');