You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
easyappointments-archive/assets/js/backend_calendar_default_vi...

1 line
26 KiB

window.BackendCalendarDefaultView=window.BackendCalendarDefaultView||{},function(e){"use strict";var o,x="provider",d="service";function c(){var e=window.innerHeight-$("#footer").outerHeight()-$("#header").outerHeight()-$("#calendar-toolbar").outerHeight()-60;return 500<e?e:500}function r(e){if(!e.data||!e.data.notes)return"-";e=e.data.notes;return 100<e.length?e.substring(0,100)+"...":e}function m(e,a){var t;$(".popover").popover("dispose");var n=$(a.target.offsetParent),i=$(a.target).parents().eq(1),s=$(this).hasClass("fc-unavailable")||n.hasClass("fc-unavailable")||i.hasClass("fc-unavailable")?(s=(n.hasClass("fc-custom")||i.hasClass("fc-custom"))&&!0===GlobalVariables.user.privileges.appointments.edit?"mr-2":"d-none",t=(n.hasClass("fc-custom")||i.hasClass("fc-custom"))&&!0===GlobalVariables.user.privileges.appointments.delete?"mr-2":"d-none",$("<div/>",{html:[$("<strong/>",{class:"d-inline-block mr-2",text:EALang.start}),$("<span/>",{text:GeneralFunctions.formatDate(e.start.format("YYYY-MM-DD HH:mm:ss"),GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.end}),$("<span/>",{text:GeneralFunctions.formatDate(e.end.format("YYYY-MM-DD HH:mm:ss"),GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{text:EALang.notes}),$("<span/>",{text:r(e)}),$("<br/>"),$("<hr/>"),$("<div/>",{class:"d-flex justify-content-center",html:[$("<button/>",{class:"close-popover btn btn-outline-secondary mr-2",html:[$("<i/>",{class:"fas fa-ban mr-2"}),$("<span/>",{text:EALang.close})]}),$("<button/>",{class:"delete-popover btn btn-outline-secondary "+t,html:[$("<i/>",{class:"fas fa-trash-alt mr-2"}),$("<span/>",{text:EALang.delete})]}),$("<button/>",{class:"edit-popover btn btn-primary "+s,html:[$("<i/>",{class:"fas fa-edit mr-2"}),$("<span/>",{text:EALang.edit})]})]})]})):$(this).hasClass("fc-working-plan-exception")||n.hasClass("fc-working-plan-exception")||i.hasClass("fc-working-plan-exception")?(t=(n.hasClass("fc-custom")||i.hasClass("fc-custom"))&&!0===GlobalVariables.user.privileges.appointments.delete?"mr-2":"d-none",$("<div/>",{html:[$("<strong/>",{class:"d-inline-block mr-2",text:EALang.provider}),$("<span/>",{text:e.data?e.data.provider.first_name+" "+e.data.provider.last_name:"-"}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.start}),$("<span/>",{text:GeneralFunctions.formatDate(e.data.date+" "+e.data.workingPlanException.start,GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.end}),$("<span/>",{text:GeneralFunctions.formatDate(e.data.date+" "+e.data.workingPlanException.end,GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.timezone}),$("<span/>",{text:GlobalVariables.timezones[e.data.provider.timezone]}),$("<br/>"),$("<hr/>"),$("<div/>",{class:"d-flex justify-content-between",html:[$("<button/>",{class:"close-popover btn btn-outline-secondary mr-2",html:[$("<i/>",{class:"fas fa-ban mr-2"}),$("<span/>",{text:EALang.close})]}),$("<button/>",{class:"delete-popover btn btn-outline-secondary "+t,html:[$("<i/>",{class:"fas fa-trash-alt mr-2"}),$("<span/>",{text:EALang.delete})]}),$("<button/>",{class:"edit-popover btn btn-primary "+s,html:[$("<i/>",{class:"fas fa-edit mr-2"}),$("<span/>",{text:EALang.edit})]})]})]})):(s=!0===GlobalVariables.user.privileges.appointments.edit?"mr-2":"d-none",t=!0===GlobalVariables.user.privileges.appointments.delete?"mr-2":"d-none",$("<div/>",{html:[$("<strong/>",{class:"d-inline-block mr-2",text:EALang.start}),$("<span/>",{text:GeneralFunctions.formatDate(e.start.format("YYYY-MM-DD HH:mm:ss"),GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.end}),$("<span/>",{text:GeneralFunctions.formatDate(e.end.format("YYYY-MM-DD HH:mm:ss"),GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.timezone}),$("<span/>",{text:GlobalVariables.timezones[e.data.provider.timezone]}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.service}),$("<span/>",{text:e.data.service.name}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.provider}),GeneralFunctions.renderMapIcon(e.data.provider),$("<span/>",{text:e.data.provider.first_name+" "+e.data.provider.last_name}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.customer}),GeneralFunctions.renderMapIcon(e.data.customer),$("<span/>",{class:"d-inline-block ml-1",text:e.data.customer.first_name+" "+e.data.customer.last_name}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.email}),GeneralFunctions.renderMailIcon(e.data.customer.email),$("<span/>",{class:"d-inline-block ml-1",text:e.data.customer.email}),$("<br/>"),$("<strong/>",{class:"d-inline-block mr-2",text:EALang.phone}),GeneralFunctions.renderPhoneIcon(e.data.customer.phone_number),$("<span/>",{class:"d-inline-block ml-1",text:e.data.customer.phone_number}),$("<br/>"),$("<strong/>",{text:EALang.notes}),$("<span/>",{text:r(e)}),$("<br/>"),$("<hr/>"),$("<div/>",{class:"d-flex justify-content-center",html:[$("<button/>",{class:"close-popover btn btn-outline-secondary mr-2",html:[$("<i/>",{class:"fas fa-ban mr-2"}),$("<span/>",{text:EALang.close})]}),$("<button/>",{class:"delete-popover btn btn-outline-secondary "+t,html:[$("<i/>",{class:"fas fa-trash-alt mr-2"}),$("<span/>",{text:EALang.delete})]}),$("<button/>",{class:"edit-popover btn btn-primary "+s,html:[$("<i/>",{class:"fas fa-edit mr-2"}),$("<span/>",{text:EALang.edit})]})]})]}));$(a.target).popover({placement:"top",title:e.title,content:s,html:!0,container:"#calendar",trigger:"manual"}),o=e,$(a.target).popover("toggle"),0<$(".popover").length&&$(".popover").position().top<200&&$(".popover").css("top","200px")}function p(t,n,i){if(!1===GlobalVariables.user.privileges.appointments.edit)return i(),void Backend.displayNotification(EALang.no_privileges_edit_appointments);var e,s,r,a=$("#calendar");$("#notification").is(":visible")&&$("#notification").hide("bind"),!1===Boolean(Number(t.data.is_unavailable))?(t.data.end_datetime=Date.parseExact(t.data.end_datetime,"yyyy-MM-dd HH:mm:ss").add({days:n.days(),hours:n.hours(),minutes:n.minutes()}).toString("yyyy-MM-dd HH:mm:ss"),delete(s=GeneralFunctions.clone(t.data)).customer,delete s.provider,delete s.service,e=function(){Backend.displayNotification(EALang.appointment_updated,[{label:EALang.undo,function:function(){s.end_datetime=t.data.end_datetime=Date.parseExact(s.end_datetime,"yyyy-MM-dd HH:mm:ss").add({days:-n.days(),hours:-n.hours(),minutes:-n.minutes()}).toString("yyyy-MM-dd HH:mm:ss");var e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_save_appointment",a={csrfToken:GlobalVariables.csrfToken,appointment_data:JSON.stringify(s)};$.post(e,a).done(function(){$("#notification").hide("blind")}),i()}}]),$("#footer").css("position","static"),a.fullCalendar("updateEvent",t)},BackendCalendarApi.saveAppointment(s,null,e)):(r={id:t.data.id,start_datetime:t.start.format("YYYY-MM-DD HH:mm:ss"),end_datetime:t.end.format("YYYY-MM-DD HH:mm:ss"),id_users_provider:t.data.id_users_provider},t.data.end_datetime=r.end_datetime,e=function(){Backend.displayNotification(EALang.unavailable_updated,[{label:EALang.undo,function:function(){r.end_datetime=t.data.end_datetime=Date.parseExact(r.end_datetime,"yyyy-MM-dd HH:mm:ss").add({minutes:-n.minutes()}).toString("yyyy-MM-dd HH:mm:ss");var e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_save_unavailable",a={csrfToken:GlobalVariables.csrfToken,unavailable:JSON.stringify(r)};$.post(e,a).done(function(){$("#notification").hide("blind")}),i()}}]),$("#footer").css("position","static"),a.fullCalendar("updateEvent",t)},BackendCalendarApi.saveUnavailable(r,e,null))}function u(){$("#calendar").fullCalendar("option","height",c())}function b(e){e.hasTime()||($("#calendar").fullCalendar("changeView","agendaDay"),$("#calendar").fullCalendar("gotoDate",e))}function f(t,n,i){if(!1===GlobalVariables.user.privileges.appointments.edit)return i(),void Backend.displayNotification(EALang.no_privileges_edit_appointments);var s,r,e;$("#notification").is(":visible")&&$("#notification").hide("bind"),"0"===t.data.is_unavailable?(delete(s=GeneralFunctions.clone(t.data)).customer,delete s.provider,delete s.service,s.start_datetime=Date.parseExact(s.start_datetime,"yyyy-MM-dd HH:mm:ss").add({days:n.days(),hours:n.hours(),minutes:n.minutes()}).toString("yyyy-MM-dd HH:mm:ss"),s.end_datetime=Date.parseExact(s.end_datetime,"yyyy-MM-dd HH:mm:ss").add({days:n.days(),hours:n.hours(),minutes:n.minutes()}).toString("yyyy-MM-dd HH:mm:ss"),t.data.start_datetime=s.start_datetime,t.data.end_datetime=s.end_datetime,e=function(){Backend.displayNotification(EALang.appointment_updated,[{label:EALang.undo,function:function(){s.start_datetime=Date.parseExact(s.start_datetime,"yyyy-MM-dd HH:mm:ss").add({days:-n.days(),hours:-n.hours(),minutes:-n.minutes()}).toString("yyyy-MM-dd HH:mm:ss"),s.end_datetime=Date.parseExact(s.end_datetime,"yyyy-MM-dd HH:mm:ss").add({days:-n.days(),hours:-n.hours(),minutes:-n.minutes()}).toString("yyyy-MM-dd HH:mm:ss"),t.data.start_datetime=s.start_datetime,t.data.end_datetime=s.end_datetime;var e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_save_appointment",a={csrfToken:GlobalVariables.csrfToken,appointment_data:JSON.stringify(s)};$.post(e,a).done(function(){$("#notification").hide("blind")}),i()}}]),$("#footer").css("position","static")},BackendCalendarApi.saveAppointment(s,null,e)):(r={id:t.data.id,start_datetime:t.start.format("YYYY-MM-DD HH:mm:ss"),end_datetime:t.end.format("YYYY-MM-DD HH:mm:ss"),id_users_provider:t.data.id_users_provider},e=function(){Backend.displayNotification(EALang.unavailable_updated,[{label:EALang.undo,function:function(){r.start_datetime=Date.parseExact(r.start_datetime,"yyyy-MM-dd HH:mm:ss").add({days:-n.days(),minutes:-n.minutes()}).toString("yyyy-MM-dd HH:mm:ss"),r.end_datetime=Date.parseExact(r.end_datetime,"yyyy-MM-dd HH:mm:ss").add({days:-n.days(),minutes:-n.minutes()}).toString("yyyy-MM-dd HH:mm:ss"),t.data.start_datetime=r.start_datetime,t.data.end_datetime=r.end_datetime;var e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_save_unavailable",a={csrfToken:GlobalVariables.csrfToken,unavailable:JSON.stringify(r)};$.post(e,a).done(function(){$("#notification").hide("blind")}),i()}}]),$("#footer").css("position","static")},BackendCalendarApi.saveUnavailable(r,e))}function g(){null!==$("#select-filter-item").val()&&(y($("#calendar"),$("#select-filter-item").val(),$("#select-filter-item option:selected").attr("type"),$("#calendar").fullCalendar("getView").start,$("#calendar").fullCalendar("getView").end),$(window).trigger("resize"),$(".close-popover").each(function(e,a){$(a).parents(".popover").popover("dispose")}),$(".fv-events").each(function(e,a){$(a).popover()}))}function v(){$(".fc-custom").each(function(e,a){var t=$(a).find(".fc-event-title").text();$(a).find(".fc-event-title").html(t);t=$(a).find(".fc-event-time").text();$(a).find(".fc-event-time").html(t)})}function y(e,k,D,a,t){var n=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_get_calendar_appointments",t={csrfToken:GlobalVariables.csrfToken,record_id:k,start_date:a.format("YYYY-MM-DD"),end_date:t.format("YYYY-MM-DD"),filter_type:D};$("#loading").css("visibility","hidden");var A=[];return $.post(n,t).done(function(e){$("#calendar").fullCalendar("removeEvents");e.appointments.forEach(function(e){e={id:e.id,title:e.service.name+" - "+e.customer.first_name+" "+e.customer.last_name,start:moment(e.start_datetime),end:moment(e.end_datetime),allDay:!1,data:e};A.push(e)}),e.unavailables.forEach(function(e){var a=e.notes?" - "+e.notes:"";e.notes&&30<e.notes.length&&(a=e.notes.substring(0,30)+"...");e={title:EALang.unavailable+a,start:moment(e.start_datetime),end:moment(e.end_datetime),allDay:!1,color:"#879DB4",editable:!0,className:"fc-unavailable fc-custom",data:e};A.push(e)});var a=$("#calendar").fullCalendar("getView");if(D===x&&"month"!==a.name){var t=GlobalVariables.availableProviders.find(function(e){return Number(e.id)===Number(k)});if(!t)throw new Error("Provider was not found.");var n,i,s,r,l,o,d,c,m,p,u,b=JSON.parse(t.settings.working_plan),f=JSON.parse(t.settings.working_plan_exceptions),e=GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday),g=GeneralFunctions.sortWeekDictionary(b,e);switch(a.name){case"agendaDay":if(o=parseInt(a.start.format("d")),d=GeneralFunctions.getWeekdayName(o),c=a.start.clone().format("YYYY-MM-DD"),f&&f[c]&&(g[d]=f[c],r=c+" "+g[d].start,l=c+" "+g[d].end,m={title:EALang.working_plan_exception,start:moment(r,"YYYY-MM-DD HH:mm",!0),end:moment(l,"YYYY-MM-DD HH:mm",!0).add(1,"day"),allDay:!0,color:"#879DB4",editable:!1,className:"fc-working-plan-exception fc-custom",data:{date:c,workingPlanException:f[c],provider:t}},A.push(m)),null===g[d])return n={title:EALang.not_working,start:a.intervalStart.clone(),end:a.intervalEnd.clone(),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},void A.push(n);var v,y,_=moment(a.start.format("YYYY-MM-DD")+" 00:00:00"),E=g[d].start.split(":");(y=_.clone()).hour(parseInt(E[0])),y.minute(parseInt(E[1])),_<y&&(v={title:EALang.not_working,start:_,end:y,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},A.push(v)),v=moment(a.end.format("YYYY-MM-DD")+" 00:00:00"),p=g[d].end.split(":"),(u=_.clone()).hour(parseInt(p[0])),u.minute(parseInt(p[1])),u<v&&(v={title:EALang.not_working,start:u,end:v,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},A.push(v)),g[d].breaks.forEach(function(e){var a=e.start.split(":");(i=_.clone()).hour(parseInt(a[0])),i.minute(parseInt(a[1]));e=e.end.split(":");(s=_.clone()).hour(parseInt(e[0])),s.minute(parseInt(e[1]));e={title:EALang.break,start:i,end:s,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable fc-break"};A.push(e)});break;case"agendaWeek":for(var h=a.start.clone();h<a.end;)o=parseInt(h.format("d")),d=GeneralFunctions.getWeekdayName(o),c=h.format("YYYY-MM-DD"),f&&f[c]&&(g[d]=f[c],r=c+" "+g[d].start,l=c+" "+g[d].end,m={title:EALang.working_plan_exception,start:moment(r,"YYYY-MM-DD HH:mm",!0),end:moment(l,"YYYY-MM-DD HH:mm",!0).add(1,"day"),allDay:!0,color:"#879DB4",editable:!1,className:"fc-working-plan-exception fc-custom",data:{date:c,workingPlanException:f[c],provider:t}},A.push(m)),null!==g[d]?(E=g[d].start.split(":"),(y=h.clone()).hour(parseInt(E[0])),y.minute(parseInt(E[1])),h<y&&(n={title:EALang.not_working,start:h.clone(),end:moment(h.format("YYYY-MM-DD")+" "+g[d].start+":00"),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},A.push(n)),p=g[d].end.split(":"),(u=h.clone()).hour(parseInt(p[0])),u.minute(parseInt(p[1])),a.end>u&&(n={title:EALang.not_working,start:moment(h.format("YYYY-MM-DD")+" "+g[d].end+":00"),end:h.clone().add(1,"day"),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},A.push(n)),g[d].breaks.forEach(function(e){var a=e.start.split(":");(i=h.clone()).hour(parseInt(a[0])),i.minute(parseInt(a[1]));a=e.end.split(":");(s=h.clone()).hour(parseInt(a[0])),s.minute(parseInt(a[1]));e={title:EALang.break,start:moment(h.format("YYYY-MM-DD")+" "+e.start),end:moment(h.format("YYYY-MM-DD")+" "+e.end),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable fc-break"};A.push(e)})):(n={title:EALang.not_working,start:h.clone(),end:h.clone().add(1,"day"),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},A.push(n)),h.add(1,"day")}}}).always(function(){$("#loading").css("visibility",""),e.fullCalendar("addEventSource",A)})}e.initialize=function(){var e={};switch(GlobalVariables.dateFormat){case"DMY":e="ddd D/M";break;case"MDY":case"YMD":e="ddd M/D";break;default:throw new Error("Invalid date format setting provided!",GlobalVariables.dateFormat)}var a="",t="";switch(GlobalVariables.timeFormat){case"military":a="H:mm",t="H(:mm)";break;case"regular":a="h:mm a",t="h(:mm) a";break;default:throw new Error("Invalid time format setting provided!",GlobalVariables.timeFormat)}var n=window.innerWidth<468?"agendaDay":"agendaWeek",i=GlobalVariables.firstWeekday,s=GeneralFunctions.getWeekDayId(i);$("#calendar").fullCalendar({defaultView:n,height:c(),editable:!0,firstDay:s,slotDuration:"00:15:00",snapDuration:"00:15:00",slotLabelInterval:"01:00",timeFormat:a,slotLabelFormat:t,allDayText:EALang.all_day,columnFormat:e,header:{left:"prev,next today",center:"title",right:"agendaDay,agendaWeek,month"},selectable:!0,selectHelper:!0,select:function(e,a){var t,n;if(e.hasTime()&&a.hasTime())return $("#insert-appointment").trigger("click"),$("#select-filter-item option:selected").attr("type")===d?(n=GlobalVariables.availableServices.find(function(e){return Number(e.id)===Number($("#select-filter-item").val())}),$("#select-service").val(n.id).trigger("change")):(t=GlobalVariables.availableProviders.find(function(e){return Number(e.id)===Number($("#select-filter-item").val())}),(n=GlobalVariables.availableServices.find(function(e){return-1!==t.services.indexOf(e.id)}))&&$("#select-service").val(n.id),$("#select-service").val()||$("#select-service option:first").prop("selected",!0),$("#select-service").trigger("change"),t&&$("#select-provider").val(t.id),$("#select-provider").val()||$("#select-provider option:first").prop("selected",!0),$("#select-provider").trigger("change")),$("#start-datetime").datepicker("setDate",new Date(e.format("YYYY/MM/DD HH:mm:ss"))),$("#end-datetime").datepicker("setDate",new Date(a.format("YYYY/MM/DD HH:mm:ss"))),!1},monthNames:[EALang.january,EALang.february,EALang.march,EALang.april,EALang.may,EALang.june,EALang.july,EALang.august,EALang.september,EALang.october,EALang.november,EALang.december],monthNamesShort:[EALang.january.substr(0,3),EALang.february.substr(0,3),EALang.march.substr(0,3),EALang.april.substr(0,3),EALang.may.substr(0,3),EALang.june.substr(0,3),EALang.july.substr(0,3),EALang.august.substr(0,3),EALang.september.substr(0,3),EALang.october.substr(0,3),EALang.november.substr(0,3),EALang.december.substr(0,3)],dayNames:[EALang.sunday,EALang.monday,EALang.tuesday,EALang.wednesday,EALang.thursday,EALang.friday,EALang.saturday],dayNamesShort:[EALang.sunday.substr(0,3),EALang.monday.substr(0,3),EALang.tuesday.substr(0,3),EALang.wednesday.substr(0,3),EALang.thursday.substr(0,3),EALang.friday.substr(0,3),EALang.saturday.substr(0,3)],dayNamesMin:[EALang.sunday.substr(0,2),EALang.monday.substr(0,2),EALang.tuesday.substr(0,2),EALang.wednesday.substr(0,2),EALang.thursday.substr(0,2),EALang.friday.substr(0,2),EALang.saturday.substr(0,2)],buttonText:{today:EALang.today,day:EALang.day,week:EALang.week,month:EALang.month},windowResize:u,viewRender:g,dayClick:b,eventClick:m,eventResize:p,eventDrop:f,eventAfterAllRender:v}),u(),0<GlobalVariables.availableProviders.length&&$("<optgroup/>",{label:EALang.providers,type:"providers-group",html:GlobalVariables.availableProviders.map(function(e){var a="1"===e.settings.google_sync?"true":"false";return $("<option/>",{value:e.id,type:x,"google-sync":a,text:e.first_name+" "+e.last_name})})}).appendTo("#select-filter-item"),0<GlobalVariables.availableServices.length&&$("<optgroup/>",{label:EALang.services,type:"services-group",html:GlobalVariables.availableServices.map(function(e){return $("<option/>",{value:e.id,type:d,text:e.name})})}).appendTo("#select-filter-item"),GlobalVariables.user.role_slug===Backend.DB_SLUG_PROVIDER&&($("#select-filter-item optgroup:eq(0)").find('option[value="'+GlobalVariables.user.id+'"]').prop("selected",!0),$("#select-filter-item").prop("disabled",!0)),GlobalVariables.user.role_slug===Backend.DB_SLUG_SECRETARY&&($("#select-filter-item optgroup:eq(1)").remove(),$('#select-filter-item option[type="provider"]').each(function(e,a){GlobalVariables.secretaryProviders.find(function(e){return Number($(a).val())===Number(e)})||$(a).remove()}),$('#select-filter-item option[type="provider"]').length||$('#select-filter-item optgroup[type="providers-group"]').remove()),i=$("#calendar-page"),$("#reload-appointments").on("click",function(){var e=$("#calendar").fullCalendar("getView");y($("#calendar"),$("#select-filter-item").val(),$("#select-filter-item").find("option:selected").attr("type"),e.start,e.end)}),i.on("click",".close-popover",function(){$(this).parents(".popover").popover("dispose")}),i.on("click",".edit-popover",function(){var e,a,t,s,n,i,r;$(this).parents(".popover").popover("dispose"),o.data.workingPlanException?(t=o.data.date,n=o.data.workingPlanException,s=o.data.provider,WorkingPlanExceptionsModal.edit(t,n).done(function(n,i){BackendCalendarApi.saveWorkingPlanException(n,i,s.id,function(){Backend.displayNotification(EALang.working_plan_exception_saved);var e,a=JSON.parse(s.settings.working_plan_exceptions)||{};for(e in a[n]=i,GlobalVariables.availableProviders){var t=GlobalVariables.availableProviders[e];if(Number(t.id)===Number(s.id)){t.settings.working_plan_exceptions=JSON.stringify(a);break}}$("#select-filter-item").trigger("change")},null)})):("0"===o.data.is_unavailable?(n=o.data,i=$("#manage-appointment"),BackendCalendarAppointmentsModal.resetAppointmentDialog(),i.find(".modal-header h3").text(EALang.edit_appointment_title),i.find("#appointment-id").val(n.id),i.find("#select-service").val(n.id_services).trigger("change"),i.find("#select-provider").val(n.id_users_provider),e=Date.parseExact(n.start_datetime,"yyyy-MM-dd HH:mm:ss"),i.find("#start-datetime").datetimepicker("setDate",e),a=Date.parseExact(n.end_datetime,"yyyy-MM-dd HH:mm:ss"),i.find("#end-datetime").datetimepicker("setDate",a),r=n.customer,i.find("#customer-id").val(n.id_users_customer),i.find("#first-name").val(r.first_name),i.find("#last-name").val(r.last_name),i.find("#email").val(r.email),i.find("#phone-number").val(r.phone_number),i.find("#address").val(r.address),i.find("#city").val(r.city),i.find("#zip-code").val(r.zip_code),i.find("#appointment-location").val(n.location),i.find("#appointment-notes").val(n.notes),i.find("#customer-notes").val(r.notes)):((r=o.data).start_datetime=o.start.format("YYYY-MM-DD HH:mm:ss"),e=Date.parseExact(r.start_datetime,"yyyy-MM-dd HH:mm:ss"),r.end_datetime=o.end.format("YYYY-MM-DD HH:mm:ss"),a=Date.parseExact(r.end_datetime,"yyyy-MM-dd HH:mm:ss"),i=$("#manage-unavailable"),BackendCalendarUnavailabilityEventsModal.resetUnavailableDialog(),i.find(".modal-header h3").text("Edit Unavailable Period"),i.find("#unavailable-start").datetimepicker("setDate",e),i.find("#unavailable-id").val(r.id),i.find("#unavailable-provider").val(r.id_users_provider),i.find("#unavailable-end").datetimepicker("setDate",a),i.find("#unavailable-notes").val(r.notes)),i.modal("show"))}),i.on("click",".delete-popover",function(){var e,a,t;if($(this).parents(".popover").popover("dispose"),o.data.workingPlanException){var n=$("#select-filter-item").val(),i=GlobalVariables.availableProviders.find(function(e){return Number(e.id)===Number(n)});if(!i)throw new Error("Provider could not be found: "+n);var s=o.start.format("YYYY-MM-DD");BackendCalendarApi.deleteWorkingPlanException(s,n,function(){Backend.displayNotification(EALang.working_plan_exception_deleted);var e,a=JSON.parse(i.settings.working_plan_exceptions)||{};for(e in delete a[s],GlobalVariables.availableProviders){var t=GlobalVariables.availableProviders[e];if(Number(t.id)===Number(n)){t.settings.working_plan_exceptions=JSON.stringify(a);break}}$("#select-filter-item").trigger("change")})}else"0"===o.data.is_unavailable?(t=[{text:EALang.cancel,click:function(){$("#message-box").dialog("close")}},{text:"OK",click:function(){e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_delete_appointment",a={csrfToken:GlobalVariables.csrfToken,appointment_id:o.data.id,delete_reason:$("#delete-reason").val()},$.post(e,a).done(function(){$("#message-box").dialog("close"),$("#select-filter-item").trigger("change")})}}],GeneralFunctions.displayMessageBox(EALang.delete_appointment_title,EALang.write_appointment_removal_reason,t),$("<textarea/>",{class:"form-control w-100",id:"delete-reason",rows:"3"}).appendTo("#message-box")):(e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_delete_unavailable",a={csrfToken:GlobalVariables.csrfToken,unavailable_id:o.data.id},$.post(e,a).done(function(){$("#message-box").dialog("close"),$("#select-filter-item").trigger("change")}))}),$("#select-filter-item").on("change",function(){var a,e;$("#select-filter-item option:selected").attr("type")===d?($("#google-sync, #enable-sync, #insert-appointment, #insert-dropdown").prop("disabled",!0),$("#calendar").fullCalendar("option",{selectable:!1,editable:!1})):($("#google-sync, #enable-sync, #insert-appointment, #insert-dropdown").prop("disabled",!1),$("#calendar").fullCalendar("option",{selectable:!0,editable:!0}),a=$("#select-filter-item").val(),(e=GlobalVariables.availableProviders.find(function(e){return Number(e.id)===Number(a)}))&&e.timezone&&$(".provider-timezone").text(GlobalVariables.timezones[e.timezone]),"true"===$("#select-filter-item option:selected").attr("google-sync")?($("#enable-sync").removeClass("btn-light").addClass("btn-secondary enabled"),$("#enable-sync span").text(EALang.disable_sync),$("#google-sync").prop("disabled",!1)):($("#enable-sync").removeClass("btn-secondary enabled").addClass("btn-light"),$("#enable-sync span").text(EALang.enable_sync),$("#google-sync").prop("disabled",!0)))}),$("#select-filter-item").trigger("change"),GlobalVariables.editAppointment&&(n=$("#manage-appointment"),s=GlobalVariables.editAppointment,BackendCalendarAppointmentsModal.resetAppointmentDialog(),n.find(".modal-header h3").text(EALang.edit_appointment_title),n.find("#appointment-id").val(s.id),n.find("#select-service").val(s.id_services).trigger("change"),n.find("#select-provider").val(s.id_users_provider),i=Date.parseExact(s.start_datetime,"yyyy-MM-dd HH:mm:ss"),n.find("#start-datetime").datetimepicker("setDate",i),i=Date.parseExact(s.end_datetime,"yyyy-MM-dd HH:mm:ss"),n.find("#end-datetime").datetimepicker("setDate",i),i=s.customer,n.find("#customer-id").val(s.id_users_customer),n.find("#first-name").val(i.first_name),n.find("#last-name").val(i.last_name),n.find("#email").val(i.email),n.find("#phone-number").val(i.phone_number),n.find("#address").val(i.address),n.find("#city").val(i.city),n.find("#zip-code").val(i.zip_code),n.find("#appointment-location").val(s.location),n.find("#appointment-notes").val(s.notes),n.find("#customer-notes").val(i.notes),n.modal("show")),$("#select-filter-item option").length||$("#calendar-actions button").prop("disabled",!0),window.innerHeight<700&&$("#footer").css("position","static");var r=$("#calendar"),l=$("#select-filter-item");setInterval(function(){var e=r.fullCalendar("getView");y(r,l.val(),l.find("option:selected").attr("type"),e.start,e.end)},6e4)}}(window.BackendCalendarDefaultView);