From 23ac39797ba98311371fd55b7dab7e001a51d066 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Tue, 8 Dec 2020 09:57:22 +0200 Subject: [PATCH] Default values in the appointment modal, when inserting a new appointment from the table view --- assets/js/backend_calendar_appointments_modal.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/assets/js/backend_calendar_appointments_modal.js b/assets/js/backend_calendar_appointments_modal.js index 645e07cf..94db17e0 100755 --- a/assets/js/backend_calendar_appointments_modal.js +++ b/assets/js/backend_calendar_appointments_modal.js @@ -133,9 +133,13 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa $dialog.find('#select-service').val(providers[0].services[0]).trigger('change'); $dialog.find('#select-provider').val(providerId); } + } else if ($('#select-filter-item option:selected').attr('type') === 'service') { + $dialog.find('#select-service option[value="' + $('#select-filter-item').val() + '"]') + .prop('selected', true); } else { - $dialog.find('#select-service option[value="' - + $('#select-filter-item').val() + '"]').prop('selected', true); + $dialog.find('#select-service option:first') + .prop('selected', true) + .trigger('change'); } var serviceId = $dialog.find('#select-service').val(); @@ -144,6 +148,8 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa return Number(availableService.id) === Number(serviceId); }); + var duration = service ? service.duration : 60; + var start = new Date(); var currentMin = parseInt(start.toString('mm')); @@ -158,7 +164,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(service.duration), + $dialog.find('#end-datetime').val(GeneralFunctions.formatDate(start.addMinutes(duration), GlobalVariables.dateFormat, true)); // Display modal form. @@ -293,8 +299,10 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa return Number(availableService.id) === Number(serviceId); }); + var duration = service ? service.duration : 60; + var start = $('#start-datetime').datetimepicker('getDate'); - $('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + service.duration * 60000)); + $('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + duration * 60000)); // Update the providers select box.