1 line
36 KiB
JavaScript
Executable File
1 line
36 KiB
JavaScript
Executable File
"use strict";function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread(e){for(var t,r=1;r<arguments.length;r++)t=null==arguments[r]?{}:arguments[r],r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))});return e}function _defineProperty(obj,key,value){return key=_toPropertyKey(key),key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+""}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}App.Utils.CalendarDefaultView=function(){function addEventListeners(){$reloadAppointments.on("click",function(){var calendarView=fullCalendar.view;$popoverTarget&&$popoverTarget.popover("dispose"),refreshCalendarAppointments($calendar,$selectFilterItem.val(),$selectFilterItem.find("option:selected").attr("type"),calendarView.activeStart,calendarView.activeEnd)}),$calendarPage.on("click",".close-popover",function(){$popoverTarget&&$popoverTarget.popover("dispose")}),$calendarPage.on("click",".edit-popover",function(event){$popoverTarget&&$popoverTarget.popover("dispose");var startMoment,endMoment,data=lastFocusedEventData.extendedProps.data;if(data.hasOwnProperty("workingPlanException")){var originalDate=lastFocusedEventData.extendedProps.data.date,workingPlanException=lastFocusedEventData.extendedProps.data.workingPlanException,provider=lastFocusedEventData.extendedProps.data.provider;App.Components.WorkingPlanExceptionsModal.edit(originalDate,workingPlanException).done(function(date,workingPlanException){var successCallback=function successCallback(){App.Layouts.Backend.displayNotification(lang("working_plan_exception_saved"));var workingPlanExceptions=JSON.parse(provider.settings.working_plan_exceptions)||{};for(var index in workingPlanExceptions[date]=workingPlanException,date!==originalDate&&delete workingPlanExceptions[originalDate],vars("available_providers")){var availableProvider=vars("available_providers")[index];if(+availableProvider.id===+provider.id){availableProvider.settings.working_plan_exceptions=JSON.stringify(workingPlanExceptions);break}}$reloadAppointments.trigger("click")};App.Http.Calendar.saveWorkingPlanException(date,workingPlanException,provider.id,successCallback,null,originalDate)})}else if(!lastFocusedEventData.extendedProps.data.is_unavailability){var appointment=lastFocusedEventData.extendedProps.data;App.Components.AppointmentsModal.resetModal(),$appointmentsModal.find(".modal-header h3").text(lang("edit_appointment_title")),$appointmentsModal.find("#appointment-id").val(appointment.id),$appointmentsModal.find("#select-service").val(appointment.id_services).trigger("change"),$appointmentsModal.find("#select-provider").val(appointment.id_users_provider),startMoment=moment(appointment.start_datetime),App.Utils.UI.setDateTimePickerValue($appointmentsModal.find("#start-datetime"),startMoment.toDate()),endMoment=moment(appointment.end_datetime),App.Utils.UI.setDateTimePickerValue($appointmentsModal.find("#end-datetime"),endMoment.toDate());var customer=appointment.customer;$appointmentsModal.find("#customer-id").val(appointment.id_users_customer),$appointmentsModal.find("#first-name").val(customer.first_name),$appointmentsModal.find("#last-name").val(customer.last_name),$appointmentsModal.find("#email").val(customer.email),$appointmentsModal.find("#phone-number").val(customer.phone_number),$appointmentsModal.find("#address").val(customer.address),$appointmentsModal.find("#city").val(customer.city),$appointmentsModal.find("#zip-code").val(customer.zip_code),$appointmentsModal.find("#language").val(customer.language),$appointmentsModal.find("#timezone").val(customer.timezone),$appointmentsModal.find("#appointment-location").val(appointment.location),$appointmentsModal.find("#appointment-status").val(appointment.status),$appointmentsModal.find("#appointment-notes").val(appointment.notes),$appointmentsModal.find("#customer-notes").val(customer.notes),$appointmentsModal.find("#custom-field-1").val(customer.custom_field_1),$appointmentsModal.find("#custom-field-2").val(customer.custom_field_2),$appointmentsModal.find("#custom-field-3").val(customer.custom_field_3),$appointmentsModal.find("#custom-field-4").val(customer.custom_field_4),$appointmentsModal.find("#custom-field-5").val(customer.custom_field_5),App.Components.ColorSelection.setColor($appointmentsModal.find("#appointment-color"),appointment.color),$appointmentsModal.modal("show")}else{var unavailability=lastFocusedEventData.extendedProps.data;unavailability.start_datetime=moment(lastFocusedEventData.start).format("YYYY-MM-DD HH:mm:ss"),startMoment=moment(unavailability.start_datetime),unavailability.end_datetime=moment(lastFocusedEventData.end).format("YYYY-MM-DD HH:mm:ss"),endMoment=moment(unavailability.end_datetime),App.Components.UnavailabilitiesModal.resetModal(),$unavailabilitiesModal.find(".modal-header h3").text(lang("edit_unavailability_title")),App.Utils.UI.setDateTimePickerValue($unavailabilitiesModal.find("#unavailability-start"),startMoment.toDate()),App.Utils.UI.setDateTimePickerValue($unavailabilitiesModal.find("#unavailability-end"),endMoment.toDate()),$unavailabilitiesModal.find("#unavailability-id").val(unavailability.id),$unavailabilitiesModal.find("#unavailability-provider").val(unavailability.id_users_provider),$unavailabilitiesModal.find("#unavailability-notes").val(unavailability.notes),$unavailabilitiesModal.modal("show")}}),$calendarPage.on("click",".delete-popover",function(event){if($popoverTarget&&$popoverTarget.popover("dispose"),void 0!==lastFocusedEventData.extendedProps.data.workingPlanException){var providerId=$selectFilterItem.val(),provider=vars("available_providers").find(function(availableProvider){return+availableProvider.id===+providerId});if(!provider)throw new Error("Provider could not be found: "+providerId);var successCallback=function successCallback(){App.Layouts.Backend.displayNotification(lang("working_plan_exception_deleted"));var workingPlanExceptions=JSON.parse(provider.settings.working_plan_exceptions)||{};for(var index in delete workingPlanExceptions[date],vars("available_providers")){var availableProvider=vars("available_providers")[index];if(+availableProvider.id===+providerId){availableProvider.settings.working_plan_exceptions=JSON.stringify(workingPlanExceptions);break}}$reloadAppointments.trigger("click")},date=moment(lastFocusedEventData.start).format("YYYY-MM-DD");App.Http.Calendar.deleteWorkingPlanException(date,providerId,successCallback)}else if(!lastFocusedEventData.extendedProps.data.is_unavailability){var buttons=[{text:lang("cancel"),click:function click(event,messageModal){messageModal.hide()}},{text:lang("delete"),click:function click(event,messageModal){var appointmentId=lastFocusedEventData.extendedProps.data.id,cancellationReason=$("#cancellation-reason").val();App.Http.Calendar.deleteAppointment(appointmentId,cancellationReason).done(function(){messageModal.hide(),$reloadAppointments.trigger("click")})}}];App.Utils.Message.show(lang("delete_appointment_title"),lang("write_appointment_removal_reason"),buttons),$("<textarea/>",{class:"form-control w-100",id:"cancellation-reason",rows:"3"}).appendTo("#message-modal .modal-body")}else{var unavailabilityId=lastFocusedEventData.extendedProps.data.id;App.Http.Calendar.deleteUnavailability(unavailabilityId).done(function(){$reloadAppointments.trigger("click")})}}),$selectFilterItem.on("change",function(){var providerId=$selectFilterItem.val(),provider=vars("available_providers").find(function(availableProvider){return+availableProvider.id===+providerId});provider&&provider.timezone&&$(".provider-timezone").text(vars("timezones")[provider.timezone]),$("#insert-working-plan-exception").toggle(providerId===App.Utils.CalendarDefaultView.FILTER_TYPE_PROVIDER),$reloadAppointments.trigger("click"),window.localStorage.setItem("EasyAppointments.SelectFilterItem",$selectFilterItem.val())})}function getCalendarHeight(){var result=window.innerHeight-$footer.outerHeight()-$header.outerHeight()-$calendarToolbar.outerHeight()-60;return 780<result?result:780}function getEventNotes(event){if(!event.extendedProps||!event.extendedProps.data||!event.extendedProps.data.notes)return"-";var notes=event.extendedProps.data.notes;return 100<notes.length?notes.substring(0,100)+"...":notes}function onEventClick(info){var $target=$(info.el);$popoverTarget&&$popoverTarget.popover("dispose");var $html,displayEdit,displayDelete;if($target.hasClass("fc-unavailability")){displayEdit=$target.hasClass("fc-custom")&&!0===vars("privileges").appointments.edit?"":"d-none",displayDelete=$target.hasClass("fc-custom")&&!0===vars("privileges").appointments["delete"]?"me-2":"d-none";var startDateTimeObject=info.event.start,endDateTimeObject=info.event.end||info.event.start;info.event.extendedProps.data&&(startDateTimeObject=new Date(info.event.extendedProps.data.start_datetime),endDateTimeObject=new Date(info.event.extendedProps.data.end_datetime)),$html=$("<div/>",{html:[$("<strong/>",{class:"d-inline-block me-2",text:lang("start")}),$("<span/>",{text:App.Utils.Date.format(moment(startDateTimeObject).format("YYYY-MM-DD HH:mm:ss"),vars("date_format"),vars("time_format"),!0)}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("end")}),$("<span/>",{text:App.Utils.Date.format(moment(endDateTimeObject).format("YYYY-MM-DD HH:mm:ss"),vars("date_format"),vars("time_format"),!0)}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("notes")}),$("<span/>",{text:getEventNotes(info.event)}),$("<br/>"),App.Utils.CalendarEventPopover.renderCustomContent(info),$("<hr/>"),$("<div/>",{class:"d-flex justify-content-center",html:[$("<button/>",{class:"close-popover btn btn-outline-secondary me-2",html:[$("<i/>",{class:"fas fa-ban me-2"}),$("<span/>",{text:lang("close")})]}),$("<button/>",{class:"delete-popover btn btn-outline-secondary "+displayDelete,html:[$("<i/>",{class:"fas fa-trash-alt me-2"}),$("<span/>",{text:lang("delete")})]}),$("<button/>",{class:"edit-popover btn btn-primary "+displayEdit,html:[$("<i/>",{class:"fas fa-edit me-2"}),$("<span/>",{text:lang("edit")})]})]})]})}else if($target.hasClass("fc-working-plan-exception")){displayDelete=$target.hasClass("fc-custom")&&!0===vars("privileges").appointments["delete"]?"me-2":"d-none";var _info$event$extendedP=info.event.extendedProps.data,date=_info$event$extendedP.date,workingPlanException=_info$event$extendedP.workingPlanException,provider=_info$event$extendedP.provider,startTime=null===workingPlanException||void 0===workingPlanException?void 0:workingPlanException.start,endTime=null===workingPlanException||void 0===workingPlanException?void 0:workingPlanException.end;$html=$("<div/>",{html:[$("<strong/>",{class:"d-inline-block me-2",text:lang("provider")}),$("<span/>",{text:"".concat(provider.first_name," ").concat(provider.last_name)}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("start")}),$("<span/>",{text:startTime?App.Utils.Date.format("".concat(date," ").concat(startTime),vars("date_format"),vars("time_format"),!0):"-"}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("end")}),$("<span/>",{text:endTime?App.Utils.Date.format("".concat(date," ").concat(endTime),vars("date_format"),vars("time_format"),!0):"-"}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("timezone")}),$("<span/>",{text:startTime?vars("timezones")[provider.timezone]:"-"}),$("<br/>"),App.Utils.CalendarEventPopover.renderCustomContent(info),$("<hr/>"),$("<div/>",{class:"d-flex justify-content-between",html:[$("<button/>",{class:"close-popover btn btn-outline-secondary me-2",html:[$("<i/>",{class:"fas fa-ban me-2"}),$("<span/>",{text:lang("close")})]}),$("<button/>",{class:"delete-popover btn btn-outline-secondary "+displayDelete,html:[$("<i/>",{class:"fas fa-trash-alt me-2"}),$("<span/>",{text:lang("delete")})]}),$("<button/>",{class:"edit-popover btn btn-primary",html:[$("<i/>",{class:"fas fa-edit me-2"}),$("<span/>",{text:lang("edit")})]})]})]})}else{displayEdit=!0===vars("privileges").appointments.edit?"":"d-none",displayDelete=!0===vars("privileges").appointments["delete"]?"me-2":"d-none";var customerInfo=[];info.event.extendedProps.data.customer.first_name&&customerInfo.push(info.event.extendedProps.data.customer.first_name),info.event.extendedProps.data.customer.last_name&&customerInfo.push(info.event.extendedProps.data.customer.last_name),$html=$("<div/>",{html:[$("<strong/>",{class:"d-inline-block me-2",text:lang("start")}),$("<span/>",{text:App.Utils.Date.format(moment(info.event.start).format("YYYY-MM-DD HH:mm:ss"),vars("date_format"),vars("time_format"),!0)}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("end")}),$("<span/>",{text:App.Utils.Date.format(moment(info.event.end).format("YYYY-MM-DD HH:mm:ss"),vars("date_format"),vars("time_format"),!0)}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("timezone")}),$("<span/>",{text:vars("timezones")[info.event.extendedProps.data.provider.timezone]}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("status")}),$("<span/>",{text:info.event.extendedProps.data.status||"-"}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("service")}),$("<span/>",{text:info.event.extendedProps.data.service.name}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("provider")}),App.Utils.CalendarEventPopover.renderMapIcon(info.event.extendedProps.data.provider),$("<span/>",{text:info.event.extendedProps.data.provider.first_name+" "+info.event.extendedProps.data.provider.last_name}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("customer")}),App.Utils.CalendarEventPopover.renderMapIcon(info.event.extendedProps.data.customer),$("<span/>",{class:"d-inline-block",text:customerInfo.length?customerInfo.join(" "):"-"}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("email")}),App.Utils.CalendarEventPopover.renderMailIcon(info.event.extendedProps.data.customer.email),$("<span/>",{class:"d-inline-block",text:info.event.extendedProps.data.customer.email||"-"}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("phone")}),App.Utils.CalendarEventPopover.renderPhoneIcon(info.event.extendedProps.data.customer.phone_number),$("<span/>",{class:"d-inline-block",text:info.event.extendedProps.data.customer.phone_number||"-"}),$("<br/>"),$("<strong/>",{class:"d-inline-block me-2",text:lang("notes")}),$("<span/>",{text:getEventNotes(info.event)}),$("<br/>"),App.Utils.CalendarEventPopover.renderCustomContent(info),$("<hr/>"),$("<div/>",{class:"d-flex justify-content-center",html:[$("<button/>",{class:"close-popover btn btn-outline-secondary me-2",html:[$("<i/>",{class:"fas fa-ban me-2"}),$("<span/>",{text:lang("close")})]}),$("<button/>",{class:"delete-popover btn btn-outline-secondary "+displayDelete,html:[$("<i/>",{class:"fas fa-trash-alt me-2"}),$("<span/>",{text:lang("delete")})]}),$("<button/>",{class:"edit-popover btn btn-primary "+displayEdit,html:[$("<i/>",{class:"fas fa-edit me-2"}),$("<span/>",{text:lang("edit")})]})]})]})}$target.popover({placement:"top",title:App.Utils.String.escapeHtml(info.event.title),content:$html,html:!0,container:"#calendar",trigger:"manual"}),lastFocusedEventData=info.event,$target.popover("show"),$popoverTarget=$target;var $popover=$calendarPage.find(".popover");0<$popover.length&&200>$popover.position().top&&$popover.css("top","200px")}function onEventResize(info){if(!1===vars("privileges").appointments.edit)return info.revert(),void App.Layouts.Backend.displayNotification(lang("no_privileges_edit_appointments"));var successCallback;if($notification.is(":visible")&&$notification.hide("bind"),!info.event.extendedProps.data.is_unavailability){info.event.extendedProps.data.end_datetime=moment(info.event.extendedProps.data.end_datetime).add({days:info.endDelta.days,milliseconds:info.endDelta.milliseconds}).format("YYYY-MM-DD HH:mm:ss");var appointment=_objectSpread({},info.event.extendedProps.data);appointment.is_unavailability=+appointment.is_unavailability,delete appointment.customer,delete appointment.provider,delete appointment.service,successCallback=function successCallback(){var undoFunction=function undoFunction(){appointment.end_datetime=info.event.extendedProps.data.end_datetime=moment(appointment.end_datetime).add({days:-info.endDelta.days,milliseconds:-info.endDelta.milliseconds}).format("YYYY-MM-DD HH:mm:ss"),App.Http.Calendar.saveAppointment(appointment).done(function(){$notification.hide("blind")}),info.revert()};App.Layouts.Backend.displayNotification(lang("appointment_updated"),[{label:lang("undo"),function:undoFunction}]),info.event.setProp("data",info.event.extendedProps.data)},App.Http.Calendar.saveAppointment(appointment,null,successCallback)}else{var unavailability={id:info.event.extendedProps.data.id,start_datetime:moment(info.event.start).format("YYYY-MM-DD HH:mm:ss"),end_datetime:moment(info.event.end).format("YYYY-MM-DD HH:mm:ss"),id_users_provider:info.event.extendedProps.data.id_users_provider};info.event.extendedProps.data.end_datetime=unavailability.end_datetime,successCallback=function successCallback(){var undoFunction=function undoFunction(){unavailability.end_datetime=info.event.extendedProps.data.end_datetime=moment(unavailability.end_datetime).add({days:-info.endDelta.days,milliseconds:-info.endDelta.milliseconds}).format("YYYY-MM-DD HH:mm:ss"),App.Http.Calendar.saveUnavailability(unavailability).done(function(){$notification.hide("blind")}),info.revert()};App.Layouts.Backend.displayNotification(lang("unavailability_updated"),[{label:lang("undo"),function:undoFunction}]),info.event.setProp("data",info.event.extendedProps.data)},App.Http.Calendar.saveUnavailability(unavailability,successCallback,null)}}function onWindowResize(){fullCalendar.setOption("height",getCalendarHeight())}function onDateClick(info){info.allDay&&(fullCalendar.changeView("timeGridDay"),fullCalendar.gotoDate(info.date))}function onEventDrop(info){if(!1===vars("privileges").appointments.edit)return info.revert(),void App.Layouts.Backend.displayNotification(lang("no_privileges_edit_appointments"));$notification.is(":visible")&&$notification.hide("bind");var successCallback;if(!info.event.extendedProps.data.is_unavailability){var appointment=_objectSpread({},info.event.extendedProps.data);delete appointment.customer,delete appointment.provider,delete appointment.service,appointment.start_datetime=moment(appointment.start_datetime).add({days:info.delta.days,millisecond:info.delta.milliseconds}).format("YYYY-MM-DD HH:mm:ss"),appointment.end_datetime=moment(appointment.end_datetime).add({days:info.delta.days,millisecond:info.delta.milliseconds}).format("YYYY-MM-DD HH:mm:ss"),appointment.is_unavailability=0,info.event.extendedProps.data.start_datetime=appointment.start_datetime,info.event.extendedProps.data.end_datetime=appointment.end_datetime,successCallback=function successCallback(){var undoFunction=function undoFunction(){appointment.start_datetime=moment(appointment.start_datetime).add({days:-info.delta.days,milliseconds:-info.delta.milliseconds}).format("YYYY-MM-DD HH:mm:ss"),appointment.end_datetime=moment(appointment.end_datetime).add({days:-info.delta.days,milliseconds:-info.delta.milliseconds}).format("YYYY-MM-DD HH:mm:ss"),info.event.extendedProps.data.start_datetime=appointment.start_datetime,info.event.extendedProps.data.end_datetime=appointment.end_datetime,App.Http.Calendar.saveAppointment(appointment).done(function(){$notification.hide("blind")}),info.revert()};App.Layouts.Backend.displayNotification(lang("appointment_updated"),[{label:lang("undo"),function:undoFunction}])},App.Http.Calendar.saveAppointment(appointment,null,successCallback)}else{var unavailability={id:info.event.extendedProps.data.id,start_datetime:moment(info.event.start).format("YYYY-MM-DD HH:mm:ss"),end_datetime:moment(info.event.end).format("YYYY-MM-DD HH:mm:ss"),id_users_provider:info.event.extendedProps.data.id_users_provider};successCallback=function successCallback(){var undoFunction=function undoFunction(){unavailability.start_datetime=moment(unavailability.start_datetime).add({days:-info.delta.days,milliseconds:-info.delta.milliseconds}).format("YYYY-MM-DD HH:mm:ss"),unavailability.end_datetime=moment(unavailability.end_datetime).add({days:-info.delta.days,milliseconds:-info.delta.milliseconds}).format("YYYY-MM-DD HH:mm:ss"),unavailability.is_unavailability=1,info.event.extendedProps.data.start_datetime=unavailability.start_datetime,info.event.extendedProps.data.end_datetime=unavailability.end_datetime,App.Http.Calendar.saveUnavailability(unavailability).done(function(){$notification.hide("blind")}),info.revert()};App.Layouts.Backend.displayNotification(lang("unavailability_updated"),[{label:lang("undo"),function:undoFunction}])},App.Http.Calendar.saveUnavailability(unavailability,successCallback)}}function onSelect(info){if(!info.allDay){var isProviderDisplayed="provider"===$selectFilterItem.find("option:selected").attr("type"),buttons=[{text:lang("unavailability"),click:function click(event,messageModal){$("#insert-unavailability").trigger("click"),isProviderDisplayed?$("#unavailability-provider").val($selectFilterItem.val()):$("#unavailability-provider option:first").prop("selected",!0),$("#unavailability-provider").trigger("change"),App.Utils.UI.setDateTimePickerValue($("#unavailability-start"),info.start),App.Utils.UI.setDateTimePickerValue($("#unavailability-end"),info.end),messageModal.hide()}},{text:lang("appointment"),click:function click(event,messageModal){$("#insert-appointment").trigger("click");var service;if(isProviderDisplayed){var provider=vars("available_providers").find(function(availableProvider){return+availableProvider.id===+$selectFilterItem.val()});provider&&(service=vars("available_services").find(function(availableService){return-1!==provider.services.indexOf(availableService.id)}),service&&$appointmentsModal.find("#select-service").val(service.id)),$appointmentsModal.find("#select-service").val()||$("#select-service option:first").prop("selected",!0),$appointmentsModal.find("#select-service").trigger("change"),provider&&$appointmentsModal.find("#select-provider").val(provider.id),$appointmentsModal.find("#select-provider").val()||$appointmentsModal.find("#select-provider option:first").prop("selected",!0),$appointmentsModal.find("#select-provider").trigger("change")}else service=vars("available_services").find(function(availableService){return+availableService.id===+$selectFilterItem.val()}),service&&$appointmentsModal.find("#select-service").val(service.id).trigger("change");App.Utils.UI.setDateTimePickerValue($("#start-datetime"),info.start),App.Utils.UI.setDateTimePickerValue($("#end-datetime"),App.Pages.Calendar.getSelectionEndDate(info)),messageModal.hide()}}];return App.Utils.Message.show(lang("add_new_event"),lang("what_kind_of_event"),buttons),$("#message-modal .modal-footer").addClass("justify-content-between").find(".btn").css("width","calc(50% - 10px)"),fullCalendar.unselect(),!1}}function onDatesSet(){null===$selectFilterItem.val()||(refreshCalendarAppointments($calendar,$selectFilterItem.val(),$("#select-filter-item option:selected").attr("type"),fullCalendar.view.activeStart,fullCalendar.view.activeEnd),$(window).trigger("resize"),$(".close-popover").each(function(index,closePopoverButton){$popoverTarget&&$popoverTarget.popover("dispose")}),$(".fv-events").each(function(index,eventEl){$(eventEl).popover()}))}function refreshCalendarAppointments($calendar,recordId,filterType,startDate,endDate){$("#loading").css("visibility","hidden");var calendarEventSource=[];startDate=moment(startDate).format("YYYY-MM-DD"),endDate=moment(endDate).format("YYYY-MM-DD"),App.Http.Calendar.getCalendarAppointments(recordId,startDate,endDate,filterType).done(function(response){var _response$blocked_per,calendarEventSources=fullCalendar.getEventSources();calendarEventSources.forEach(function(calendarEventSource){return calendarEventSource.remove()}),response.appointments.forEach(function(appointment){var title=[appointment.service.name],customerInfo=[];appointment.customer.first_name&&customerInfo.push(appointment.customer.first_name),appointment.customer.last_name&&customerInfo.push(appointment.customer.last_name),customerInfo.length&&title.push(customerInfo.join(" "));var appointmentEvent={id:appointment.id,title:title.join(" - "),start:moment(appointment.start_datetime).toDate(),end:moment(appointment.end_datetime).toDate(),allDay:!1,color:appointment.color,data:appointment};calendarEventSource.push(appointmentEvent)}),response.unavailabilities.forEach(function(unavailability){var notes=unavailability.notes?" - "+unavailability.notes:"";unavailability.notes&&30<unavailability.notes.length&&(notes=" - "+unavailability.notes.substring(0,30)+"...");var unavailabilityEvent={title:lang("unavailability")+notes,start:moment(unavailability.start_datetime).toDate(),end:moment(unavailability.end_datetime).toDate(),allDay:!1,color:"#879DB4",editable:!0,className:"fc-unavailability fc-custom",data:unavailability};calendarEventSource.push(unavailabilityEvent)}),null===response||void 0===response||null===(_response$blocked_per=response.blocked_periods)||void 0===_response$blocked_per||_response$blocked_per.forEach(function(blockedPeriod){var blockedPeriodEvent={title:blockedPeriod.name,start:moment(blockedPeriod.start_datetime).toDate(),end:moment(blockedPeriod.end_datetime).toDate(),allDay:!0,backgroundColor:"#d65069",borderColor:"#d65069",textColor:"#ffffff",editable:!1,className:"fc-blocked-period fc-unavailability",data:blockedPeriod};calendarEventSource.push(blockedPeriodEvent)});var calendarView=fullCalendar.view;if("dayGridMonth"!==calendarView.type)for(var unavailabilityEvent,breakStart,breakEnd,workingPlanExceptionStart,workingPlanExceptionEnd,weekdayNumber,weekdayName,weekdayDate,workingPlanExceptionEvent,startHour,endHour,workDateStart,workDateEnd,provider=vars("available_providers").find(function(availableProvider){return+availableProvider.id===+recordId}),workingPlan=JSON.parse(provider?provider.settings.working_plan:vars("company_working_plan")),workingPlanExceptions=JSON.parse(provider?provider.settings.working_plan_exceptions:"{}"),firstWeekdayNumber=App.Utils.Date.getWeekdayId(vars("first_weekday")),sortedWorkingPlan=App.Utils.Date.sortWeekDictionary(workingPlan,firstWeekdayNumber),calendarDate=moment(calendarView.currentStart).clone();calendarDate.toDate()<calendarView.currentEnd;){if(weekdayNumber=parseInt(calendarDate.format("d")),weekdayName=App.Utils.Date.getWeekdayName(weekdayNumber),weekdayDate=calendarDate.format("YYYY-MM-DD"),workingPlanExceptions&&workingPlanExceptions.hasOwnProperty(weekdayDate)){var _sortedWorkingPlan$we,_sortedWorkingPlan$we2;sortedWorkingPlan[weekdayName]=workingPlanExceptions[weekdayDate];var startTime=(null===(_sortedWorkingPlan$we=sortedWorkingPlan[weekdayName])||void 0===_sortedWorkingPlan$we?void 0:_sortedWorkingPlan$we.start)||"00:00",endTime=(null===(_sortedWorkingPlan$we2=sortedWorkingPlan[weekdayName])||void 0===_sortedWorkingPlan$we2?void 0:_sortedWorkingPlan$we2.end)||"00:00";workingPlanExceptionStart="".concat(weekdayDate," ").concat(startTime),workingPlanExceptionEnd="".concat(weekdayDate," ").concat(endTime),workingPlanExceptionEvent={title:lang("working_plan_exception"),start:moment(workingPlanExceptionStart,"YYYY-MM-DD HH:mm",!0).toDate(),end:moment(workingPlanExceptionEnd,"YYYY-MM-DD HH:mm",!0).add(1,"day").toDate(),allDay:!0,color:"#879DB4",editable:!1,className:"fc-working-plan-exception fc-custom",data:{date:weekdayDate,workingPlanException:workingPlanExceptions[weekdayDate],provider:provider}},calendarEventSource.push(workingPlanExceptionEvent)}if(null===sortedWorkingPlan[weekdayName]){unavailabilityEvent={title:lang("not_working"),start:calendarDate.clone().toDate(),end:calendarDate.clone().add(1,"day").toDate(),allDay:!1,color:"#BEBEBE",editable:!1,display:"background",className:"fc-unavailability"},calendarEventSource.push(unavailabilityEvent),calendarDate.add(1,"day");continue}startHour=sortedWorkingPlan[weekdayName].start.split(":"),workDateStart=calendarDate.clone(),workDateStart.hour(parseInt(startHour[0])),workDateStart.minute(parseInt(startHour[1])),calendarDate.toDate()<workDateStart.toDate()&&(unavailabilityEvent={title:lang("not_working"),start:calendarDate.clone().toDate(),end:moment(calendarDate.format("YYYY-MM-DD")+" "+sortedWorkingPlan[weekdayName].start+":00").toDate(),allDay:!1,color:"#BEBEBE",editable:!1,display:"background",className:"fc-unavailability"},calendarEventSource.push(unavailabilityEvent)),endHour=sortedWorkingPlan[weekdayName].end.split(":"),workDateEnd=calendarDate.clone(),workDateEnd.hour(parseInt(endHour[0])),workDateEnd.minute(parseInt(endHour[1])),calendarView.currentEnd>workDateEnd.toDate()&&(unavailabilityEvent={title:lang("not_working"),start:moment(calendarDate.format("YYYY-MM-DD")+" "+sortedWorkingPlan[weekdayName].end+":00").toDate(),end:calendarDate.clone().add(1,"day").toDate(),allDay:!1,color:"#BEBEBE",editable:!1,display:"background",className:"fc-unavailability"},calendarEventSource.push(unavailabilityEvent)),sortedWorkingPlan[weekdayName].breaks.forEach(function(breakPeriod){var breakStartString=breakPeriod.start.split(":");breakStart=calendarDate.clone(),breakStart.hour(parseInt(breakStartString[0])),breakStart.minute(parseInt(breakStartString[1]));var breakEndString=breakPeriod.end.split(":");breakEnd=calendarDate.clone(),breakEnd.hour(parseInt(breakEndString[0])),breakEnd.minute(parseInt(breakEndString[1]));var unavailabilityEvent={title:lang("break"),start:moment(calendarDate.format("YYYY-MM-DD")+" "+breakPeriod.start).toDate(),end:moment(calendarDate.format("YYYY-MM-DD")+" "+breakPeriod.end).toDate(),allDay:!1,color:"#BEBEBE",editable:!1,display:"background",className:"fc-unavailability fc-break"};calendarEventSource.push(unavailabilityEvent)}),calendarDate.add(1,"day")}}).always(function(){$("#loading").css("visibility",""),fullCalendar.addEventSource(calendarEventSource)})}var $popoverTarget,lastFocusedEventData,$calendarPage=$("#calendar-page"),$reloadAppointments=$("#reload-appointments"),$calendar=$("#calendar"),$selectFilterItem=$("#select-filter-item"),$appointmentsModal=$("#appointments-modal"),$unavailabilitiesModal=$("#unavailabilities-modal"),$header=$("#header"),$footer=$("#footer"),$notification=$("#notification"),$calendarToolbar=$("#calendar-toolbar"),moment=window.moment,fullCalendar=null;return{initialize:function initialize(){var columnFormat={};switch(vars("date_format")){case"DMY":columnFormat="ddd D/M";break;case"MDY":case"YMD":columnFormat="ddd M/D";break;default:throw new Error("Invalid date format setting provided!",vars("date_format"))}var timeFormat="",slotTimeFormat="";switch(vars("time_format")){case"military":timeFormat="HH:mm",slotTimeFormat="HH:mm";break;case"regular":timeFormat="h:mm a",slotTimeFormat="h a";break;default:throw new Error("Invalid time format setting provided!",vars("time_format"))}var initialView=468>window.innerWidth?"timeGridDay":"timeGridWeek",firstWeekday=vars("first_weekday"),firstWeekdayNumber=App.Utils.Date.getWeekdayId(firstWeekday);fullCalendar=new FullCalendar.Calendar($calendar[0],{initialView:initialView,locale:vars("language_code"),nowIndicator:!0,height:getCalendarHeight(),editable:!0,firstDay:firstWeekdayNumber,slotDuration:"00:15:00",snapDuration:"00:15:00",scrollTime:"07:00:00",slotLabelInterval:"01:00",eventTimeFormat:timeFormat,eventTextColor:"#333",eventColor:"#7cbae8",slotLabelFormat:slotTimeFormat,allDayContent:lang("all_day"),selectable:!0,selectMirror:!0,themeSystem:"bootstrap5",headerToolbar:{left:"prev,next today",center:"title",right:"timeGridDay,timeGridWeek,dayGridMonth"},buttonText:{today:lang("today"),day:lang("day"),week:lang("week"),month:lang("month")},windowResize:onWindowResize,datesSet:onDatesSet,dateClick:onDateClick,eventClick:onEventClick,eventResize:onEventResize,eventDrop:onEventDrop,select:onSelect}),fullCalendar.render(),$calendar.data("fullCalendar",fullCalendar),onWindowResize(),$selectFilterItem.append(new Option(lang("all"),"all",!0,!0)),$("#insert-working-plan-exception").hide(),0<vars("available_providers").length&&$("<optgroup/>",{label:lang("providers"),type:"providers-group",html:vars("available_providers").map(function(availableProvider){var settings=availableProvider.settings;return $("<option/>",{value:availableProvider.id,type:"provider","google-sync":settings.google_sync,"caldav-sync":settings.caldav_sync,text:availableProvider.first_name+" "+availableProvider.last_name})})}).appendTo("#select-filter-item"),0<vars("available_services").length&&$("<optgroup/>",{label:lang("services"),type:"services-group",html:vars("available_services").map(function(availableService){return $("<option/>",{value:availableService.id,type:"service",text:availableService.name})})}).appendTo("#select-filter-item"),vars("role_slug")===App.Layouts.Backend.DB_SLUG_PROVIDER&&$selectFilterItem.find("optgroup:eq(0)").find("option[value=\""+vars("user_id")+"\"]").prop("selected",!0),addEventListeners();var localSelectFilterItemValue=window.localStorage.getItem("EasyAppointments.SelectFilterItem");if(localSelectFilterItemValue&&$selectFilterItem.find("option[value=\"".concat(localSelectFilterItemValue,"\"]")).length?$selectFilterItem.val(localSelectFilterItemValue).trigger("change"):$reloadAppointments.trigger("click"),vars("edit_appointment")){var appointment=vars("edit_appointment");App.Components.AppointmentsModal.resetModal(),$appointmentsModal.find(".modal-header h3").text(lang("edit_appointment_title")),$appointmentsModal.find("#appointment-id").val(appointment.id),$appointmentsModal.find("#select-service").val(appointment.id_services).trigger("change"),$appointmentsModal.find("#select-provider").val(appointment.id_users_provider);var startDatetimeMoment=moment(appointment.start_datetime);App.Utils.UI.setDateTimePickerValue($appointmentsModal.find("#start-datetime"),startDatetimeMoment.toDate());var endDatetimeMoment=moment(appointment.end_datetime);App.Utils.UI.setDateTimePickerValue($appointmentsModal.find("#end-datetime"),endDatetimeMoment.toDate());var customer=appointment.customer;$appointmentsModal.find("#customer-id").val(appointment.id_users_customer),$appointmentsModal.find("#first-name").val(customer.first_name),$appointmentsModal.find("#last-name").val(customer.last_name),$appointmentsModal.find("#email").val(customer.email),$appointmentsModal.find("#phone-number").val(customer.phone_number),$appointmentsModal.find("#address").val(customer.address),$appointmentsModal.find("#city").val(customer.city),$appointmentsModal.find("#zip-code").val(customer.zip_code),$appointmentsModal.find("#language").val(customer.language),$appointmentsModal.find("#timezone").val(customer.timezone),$appointmentsModal.find("#appointment-location").val(appointment.location),$appointmentsModal.find("#appointment-status").val(appointment.status),$appointmentsModal.find("#appointment-notes").val(appointment.notes),$appointmentsModal.find("#customer-notes").val(customer.notes),$appointmentsModal.find("#custom-field-1").val(customer.custom_field_1),$appointmentsModal.find("#custom-field-2").val(customer.custom_field_2),$appointmentsModal.find("#custom-field-3").val(customer.custom_field_3),$appointmentsModal.find("#custom-field-4").val(customer.custom_field_4),$appointmentsModal.find("#custom-field-5").val(customer.custom_field_5),App.Components.ColorSelection.setColor($appointmentsModal.find("#appointment-color"),appointment.color),$appointmentsModal.modal("show"),fullCalendar.gotoDate(moment(appointment.start_datetime).toDate())}$selectFilterItem.find("option").length||$("#calendar-actions button").prop("disabled",!0),setInterval(function(){$(".popover").length||refreshCalendarAppointments($calendar,$selectFilterItem.val(),$selectFilterItem.find("option:selected").attr("type"),fullCalendar.view.activeStart,fullCalendar.view.activeEnd)},6e4)},FILTER_TYPE_ALL:"all",FILTER_TYPE_PROVIDER:"provider",FILTER_TYPE_SERVICE:"service"}}(); |