easyappointments/assets/js/pages/calendar.min.js

1 line
2.8 KiB
JavaScript
Executable File

"use strict";App.Pages.Calendar=function(){var $insertWorkingPlanException=$("#insert-working-plan-exception"),moment=window.moment;return document.addEventListener("DOMContentLoaded",function(){"table"===vars("calendar_view")?App.Utils.CalendarTableView.initialize():App.Utils.CalendarDefaultView.initialize(),App.Pages.Calendar.addEventListeners()}),{addEventListeners:function(){var $calendarPage=$("#calendar-page");$calendarPage.on("click","#toggle-fullscreen",function(event){var $toggleFullscreen=$(event.target),element=document.documentElement,isFullScreen=document.fullScreenElement||document.mozFullScreen||document.webkitIsFullScreen||!1;isFullScreen?(document.exitFullscreen?document.exitFullscreen():document.msExitFullscreen?document.msExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen(),$toggleFullscreen.removeClass("btn-success").addClass("btn-light")):(element.requestFullscreen?element.requestFullscreen():element.msRequestFullscreen?element.msRequestFullscreen():element.mozRequestFullScreen?element.mozRequestFullScreen():element.webkitRequestFullscreen&&element.webkitRequestFullscreen(),$toggleFullscreen.removeClass("btn-light").addClass("btn-success"))}),$insertWorkingPlanException.on("click",function(){var providerId=$("#select-filter-item").val();if(providerId!==App.Utils.CalendarDefaultView.FILTER_TYPE_ALL){var provider=vars("available_providers").find(function(availableProvider){return+availableProvider.id===+providerId});if(!provider)throw new Error("Provider could not be found: "+providerId);App.Components.WorkingPlanExceptionsModal.add().done(function(date,workingPlanException){App.Http.Calendar.saveWorkingPlanException(date,workingPlanException,providerId,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,vars("available_providers")){var availableProvider=vars("available_providers")[index];if(+availableProvider.id===+providerId){vars("available_providers")[index].settings.working_plan_exceptions=JSON.stringify(workingPlanExceptions);break}}$("#select-filter-item").trigger("change")},null)})}})},getSelectionEndDate:function(info){var startMoment=moment(info.start),endMoment=moment(info.end),startTillEndDiff=endMoment.diff(startMoment),startTillEndDuration=moment.duration(startTillEndDiff),durationInMinutes=startTillEndDuration.asMinutes();if(durationInMinutes<=15){var serviceId=$("#select-service").val(),service=vars("available_services").find(function(availableService){return+availableService.id===+serviceId});service&&endMoment.add(service.duration-durationInMinutes,"minutes")}return endMoment.toDate()}}}();