From e0f49c1d54371505afb32967d1534216377ee826 Mon Sep 17 00:00:00 2001 From: alext Date: Wed, 8 Nov 2017 15:17:29 +0100 Subject: [PATCH] Added calendar select functionality. --- .../js/backend_calendar_default_view.js | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/assets/js/backend_calendar_default_view.js b/src/assets/js/backend_calendar_default_view.js index f08bb2a6..b9d0e651 100644 --- a/src/assets/js/backend_calendar_default_view.js +++ b/src/assets/js/backend_calendar_default_view.js @@ -1051,7 +1051,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {}; height: _getCalendarHeight(), editable: true, firstDay: 1, // Monday - snapDuration: '00:15:00', + snapDuration: '00:30:00', timeFormat: 'h:mm A', slotLabelFormat : 'h(:mm) A', allDayText: EALang.all_day, @@ -1063,6 +1063,43 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {}; right: 'agendaDay,agendaWeek,month' }, + // Selectable + selectable: true, + selectHelper: true, + select: function(start, end, jsEvent, view) { + if (!start.hasTime() || !end.hasTime()) { + return; + } + + $('#insert-appointment').trigger('click'); + + // Preselect service & provider. + if ($('#select-filter-item option:selected').attr('type') === FILTER_TYPE_SERVICE) { + var service = GlobalVariables.availableServices.find(function (service) { + return service.id == $('#select-filter-item').val() + }); + $('#select-service').val(service.id).trigger('change'); + + } else { + var provider = GlobalVariables.availableProviders.find(function (provider) { + return provider.id == $('#select-filter-item').val(); + }); + + var service = GlobalVariables.availableServices.find(function (service) { + return provider.services.indexOf(service.id) !== -1 + }); + + $('#select-service').val(service.id).trigger('change'); + $('#select-provider').val(provider.id).trigger('change'); + } + + // Preselect time + $('#start-datetime').datepicker('setDate', new Date(start.format('YYYY-MM-DD HH:mm:ss'))); + $('#end-datetime').datepicker('setDate', new Date(end.format('YYYY-MM-DD HH:mm:ss'))); + + return false; + }, + // Translations monthNames: [EALang.january, EALang.february, EALang.march, EALang.april, EALang.may, EALang.june, EALang.july, EALang.august,