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 b,w="provider",f="service";function v(){var e=window.innerHeight-$("#footer").outerHeight()-$("#header").outerHeight()-$("#calendar-toolbar").outerHeight()-60;return 500<e?e:500}function l(e){if(!e.data||!e.data.notes)return"-";var a=e.data.notes;return 100<a.length?a.substring(0,100)+"...":a}function g(e,a){var t,n;$(".popover").popover("dispose");var i=$(a.target.offsetParent),r=$(a.target).parents().eq(1),s=$(this).hasClass("fc-unavailable")||i.hasClass("fc-unavailable")||r.hasClass("fc-unavailable")?(t=(i.hasClass("fc-custom")||r.hasClass("fc-custom"))&&!0===GlobalVariables.user.privileges.appointments.edit?"mr-2":"d-none",n=(i.hasClass("fc-custom")||r.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:l(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 "+n,html:[$("<i/>",{class:"fas fa-trash-alt mr-2"}),$("<span/>",{text:EALang.delete})]}),$("<button/>",{class:"edit-popover btn btn-primary "+t,html:[$("<i/>",{class:"fas fa-edit mr-2"}),$("<span/>",{text:EALang.edit})]})]})]})):$(this).hasClass("fc-working-plan-exception")||i.hasClass("fc-working-plan-exception")||r.hasClass("fc-working-plan-exception")?(n=(i.hasClass("fc-custom")||r.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.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/>"),$("<hr/>"),$("<div/>",{class:"d-flex justify-content-between",html:[$("<button/>",{class:"close-popover btn btn-outline-secondary",html:[$("<i/>",{class:"fas fa-ban mr-2"}),$("<span/>",{text:EALang.close})]}),$("<button/>",{class:"delete-popover btn btn-outline-secondary "+n,html:[$("<i/>",{class:"fas fa-trash-alt mr-2"}),$("<span/>",{text:EALang.delete})]}),$("<button/>",{class:"edit-popover btn btn-primary "+t,html:[$("<i/>",{class:"fas fa-edit mr-2"}),$("<span/>",{text:EALang.edit})]})]})]})):(t=!0===GlobalVariables.user.privileges.appointments.edit?"mr-2":"d-none",n=!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:l(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 "+n,html:[$("<i/>",{class:"fas fa-trash-alt mr-2"}),$("<span/>",{text:EALang.delete})]}),$("<button/>",{class:"edit-popover btn btn-primary "+t,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"}),b=e,$(a.target).popover("toggle"),0<$(".popover").length&&$(".popover").position().top<200&&$(".popover").css("top","200px")}function y(t,n,i){if(!1===GlobalVariables.user.privileges.appointments.edit)return i(),void Backend.displayNotification(EALang.no_privileges_edit_appointments);var e,r,s,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(r=GeneralFunctions.clone(t.data)).customer,delete r.provider,delete r.service,e=function(){Backend.displayNotification(EALang.appointment_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({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(r)};$.post(e,a).done(function(){$("#notification").hide("blind")}),i()}}]),$("#footer").css("position","static"),a.fullCalendar("updateEvent",t)},BackendCalendarApi.saveAppointment(r,null,e)):(s={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=s.end_datetime,e=function(){Backend.displayNotification(EALang.unavailable_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({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(s)};$.post(e,a).done(function(){$("#notification").hide("blind")}),i()}}]),$("#footer").css("position","static"),a.fullCalendar("updateEvent",t)},BackendCalendarApi.saveUnavailable(s,e,null))}function E(){$("#calendar").fullCalendar("option","height",v())}function _(e){e.hasTime()||($("#calendar").fullCalendar("changeView","agendaDay"),$("#calendar").fullCalendar("gotoDate",e))}function h(t,n,i){if(!1===GlobalVariables.user.privileges.appointments.edit)return i(),void Backend.displayNotification(EALang.no_privileges_edit_appointments);var r,s,e;$("#notification").is(":visible")&&$("#notification").hide("bind"),"0"===t.data.is_unavailable?(delete(r=GeneralFunctions.clone(t.data)).customer,delete r.provider,delete r.service,r.start_datetime=Date.parseExact(r.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"),r.end_datetime=Date.parseExact(r.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=r.start_datetime,t.data.end_datetime=r.end_datetime,e=function(){Backend.displayNotification(EALang.appointment_updated,[{label:EALang.undo,function:function(){r.start_datetime=Date.parseExact(r.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"),r.end_datetime=Date.parseExact(r.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=r.start_datetime,t.data.end_datetime=r.end_datetime;var e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_save_appointment",a={csrfToken:GlobalVariables.csrfToken,appointment_data:JSON.stringify(r)};$.post(e,a).done(function(){$("#notification").hide("blind")}),i()}}]),$("#footer").css("position","static")},BackendCalendarApi.saveAppointment(r,null,e)):(s={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(){s.start_datetime=Date.parseExact(s.start_datetime,"yyyy-MM-dd HH:mm:ss").add({days:-n.days(),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(),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_unavailable",a={csrfToken:GlobalVariables.csrfToken,unavailable:JSON.stringify(s)};$.post(e,a).done(function(){$("#notification").hide("blind")}),i()}}]),$("#footer").css("position","static")},BackendCalendarApi.saveUnavailable(s,e))}function k(){null!==$("#select-filter-item").val()&&(A($("#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 D(){$(".fc-custom").each(function(e,a){var t=$(a).find(".fc-event-title").text();$(a).find(".fc-event-title").html(t);var n=$(a).find(".fc-event-time").text();$(a).find(".fc-event-time").html(n)})}function A(e,L,H,a,t){var n=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_get_calendar_appointments",i={csrfToken:GlobalVariables.csrfToken,record_id:L,start_date:a.format("YYYY-MM-DD"),end_date:t.format("YYYY-MM-DD"),filter_type:H};return $("#loading").css("visibility","hidden"),$.post(n,i).done(function(e){var i=$("#calendar");i.fullCalendar("removeEvents");var t=[];e.appointments.forEach(function(e){var a={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};t.push(a)}),i.fullCalendar("addEventSource",t);var n=[];e.unavailables.forEach(function(e){var a=e.notes?" - "+e.notes:"";e.notes&&30<e.notes.length&&(a=e.notes.substring(0,30)+"...");var t={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};n.push(t)}),i.fullCalendar("addEventSource",n);var a=$("#calendar").fullCalendar("getView");if(H===w&&"month"!==a.name){var r=GlobalVariables.availableProviders.find(function(e){return Number(e.id)===Number(L)});if(!r)throw new Error("Provider was not found.");var s,l,o,d,c,m,p,u,b,f,v,g,y=JSON.parse(r.settings.working_plan),E=JSON.parse(r.settings.working_plan_exceptions),_=GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday),h=GeneralFunctions.sortWeekDictionary(y,_);switch(a.name){case"agendaDay":if(p=parseInt(a.start.format("d")),u=GeneralFunctions.getWeekdayName(p),b=a.start.clone().format("YYYY-MM-DD"),E&&E[b]&&(h[u]=E[b],c=b+" "+h[u].start,m=b+" "+h[u].end,f={title:EALang.working_plan_exception,start:moment(c,"YYYY-MM-DD HH:mm",!0),end:moment(m,"YYYY-MM-DD HH:mm",!0).add(1,"day"),allDay:!0,color:"#879DB4",editable:!1,className:"fc-working-plan-exception fc-custom",data:{date:b,workingPlanException:E[b],provider:r}},i.fullCalendar("renderEvent",f,!1)),null===h[u])return s={title:EALang.not_working,start:a.intervalStart.clone(),end:a.intervalEnd.clone(),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},void i.fullCalendar("renderEvent",s,!1);var k,D,A,M=moment(a.start.format("YYYY-MM-DD")+" 00:00:00"),Y=h[u].start.split(":");(A=M.clone()).hour(parseInt(Y[0])),A.minute(parseInt(Y[1])),M<A&&(k={title:EALang.not_working,start:M,end:A,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},i.fullCalendar("renderEvent",k,!1)),l=moment(a.end.format("YYYY-MM-DD")+" 00:00:00"),v=h[u].end.split(":"),(g=M.clone()).hour(parseInt(v[0])),g.minute(parseInt(v[1])),g<l&&(D={title:EALang.not_working,start:g,end:l,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},i.fullCalendar("renderEvent",D,!1)),h[u].breaks.forEach(function(e){var a=e.start.split(":");(o=M.clone()).hour(parseInt(a[0])),o.minute(parseInt(a[1]));var t=e.end.split(":");(d=M.clone()).hour(parseInt(t[0])),d.minute(parseInt(t[1]));var n={title:EALang.break,start:o,end:d,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable fc-break"};i.fullCalendar("renderEvent",n,!1)});break;case"agendaWeek":for(var x=a.start.clone();x<a.end;)p=parseInt(x.format("d")),u=GeneralFunctions.getWeekdayName(p),b=x.format("YYYY-MM-DD"),E&&E[b]&&(h[u]=E[b],c=b+" "+h[u].start,m=b+" "+h[u].end,f={title:EALang.working_plan_exception,start:moment(c,"YYYY-MM-DD HH:mm",!0),end:moment(m,"YYYY-MM-DD HH:mm",!0).add(1,"day"),allDay:!0,color:"#879DB4",editable:!1,className:"fc-working-plan-exception fc-custom",data:{date:b,workingPlanException:E[b],provider:r}},i.fullCalendar("renderEvent",f,!1)),null!==h[u]?(Y=h[u].start.split(":"),(A=x.clone()).hour(parseInt(Y[0])),A.minute(parseInt(Y[1])),x<A&&(s={title:EALang.not_working,start:x.clone(),end:moment(x.format("YYYY-MM-DD")+" "+h[u].start+":00"),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},i.fullCalendar("renderEvent",s,!0)),v=h[u].end.split(":"),(g=x.clone()).hour(parseInt(v[0])),g.minute(parseInt(v[1])),a.end>g&&(s={title:EALang.not_working,start:moment(x.format("YYYY-MM-DD")+" "+h[u].end+":00"),end:x.clone().add(1,"day"),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},i.fullCalendar("renderEvent",s,!1)),h[u].breaks.forEach(function(e){var a=e.start.split(":");(o=x.clone()).hour(parseInt(a[0])),o.minute(parseInt(a[1]));var t=e.end.split(":");(d=x.clone()).hour(parseInt(t[0])),d.minute(parseInt(t[1]));var n={title:EALang.break,start:moment(x.format("YYYY-MM-DD")+" "+e.start),end:moment(x.format("YYYY-MM-DD")+" "+e.end),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable fc-break"};i.fullCalendar("renderEvent",n,!1)})):(s={title:EALang.not_working,start:x.clone(),end:x.clone().add(1,"day"),allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},i.fullCalendar("renderEvent",s,!0)),x.add(1,"day")}}}).always(function(){$("#loading").css("visibility","")})}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,i,r,s,l,o,d=window.innerWidth<468?"agendaDay":"agendaWeek",c=GlobalVariables.firstWeekday,m=GeneralFunctions.getWeekDayId(c);$("#calendar").fullCalendar({defaultView:d,height:v(),editable:!0,firstDay:m,snapDuration:"00:15: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")===f?(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:E,viewRender:k,dayClick:_,eventClick:g,eventResize:y,eventDrop:h,eventAfterAllRender:D}),E(),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:w,"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:f,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()),n=$("#calendar-page"),$("#reload-appointments").on("click",function(){var e=$("#calendar").fullCalendar("getView");A($("#calendar"),$("#select-filter-item").val(),$("#select-filter-item").find("option:selected").attr("type"),e.start,e.end)}),n.on("click",".close-popover",function(){$(this).parents(".popover").popover("dispose")}),n.on("click",".edit-popover",function(){var e,a,t,n,r,i,s,l,o;$(this).parents(".popover").popover("dispose"),b.data.workingPlanException?(t=b.data.date,n=b.data.workingPlanException,r=b.data.provider,WorkingPlanExceptionsModal.edit(t,n).done(function(n,i){BackendCalendarApi.saveWorkingPlanException(n,i,r.id,function(){Backend.displayNotification(EALang.working_plan_exception_saved);var e=JSON.parse(r.settings.working_plan_exceptions)||{};for(var a in e[n]=i,GlobalVariables.availableProviders){var t=GlobalVariables.availableProviders[a];if(Number(t.id)===Number(r.id)){t.settings.working_plan_exceptions=JSON.stringify(e);break}}$("#select-filter-item").trigger("change")},null)})):("0"===b.data.is_unavailable?(i=b.data,s=$("#manage-appointment"),BackendCalendarAppointmentsModal.resetAppointmentDialog(),s.find(".modal-header h3").text(EALang.edit_appointment_title),s.find("#appointment-id").val(i.id),s.find("#select-service").val(i.id_services).trigger("change"),s.find("#select-provider").val(i.id_users_provider),e=Date.parseExact(i.start_datetime,"yyyy-MM-dd HH:mm:ss"),s.find("#start-datetime").datetimepicker("setDate",e),a=Date.parseExact(i.end_datetime,"yyyy-MM-dd HH:mm:ss"),s.find("#end-datetime").datetimepicker("setDate",a),l=i.customer,s.find("#customer-id").val(i.id_users_customer),s.find("#first-name").val(l.first_name),s.find("#last-name").val(l.last_name),s.find("#email").val(l.email),s.find("#phone-number").val(l.phone_number),s.find("#address").val(l.address),s.find("#city").val(l.city),s.find("#zip-code").val(l.zip_code),s.find("#appointment-location").val(i.location),s.find("#appointment-notes").val(i.notes),s.find("#customer-notes").val(l.notes)):((o=b.data).start_datetime=b.start.format("YYYY-MM-DD HH:mm:ss"),e=Date.parseExact(o.start_datetime,"yyyy-MM-dd HH:mm:ss"),o.end_datetime=b.end.format("YYYY-MM-DD HH:mm:ss"),a=Date.parseExact(o.end_datetime,"yyyy-MM-dd HH:mm:ss"),s=$("#manage-unavailable"),BackendCalendarUnavailabilityEventsModal.resetUnavailableDialog(),s.find(".modal-header h3").text("Edit Unavailable Period"),s.find("#unavailable-start").datetimepicker("setDate",e),s.find("#unavailable-id").val(o.id),s.find("#unavailable-provider").val(o.id_users_provider),s.find("#unavailable-end").datetimepicker("setDate",a),s.find("#unavailable-notes").val(o.notes)),s.modal("show"))}),n.on("click",".delete-popover",function(){var e,a,t;if($(this).parents(".popover").popover("dispose"),b.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 r=b.start.format("YYYY-MM-DD");BackendCalendarApi.deleteWorkingPlanException(r,n,function(){Backend.displayNotification(EALang.working_plan_exception_deleted);var e=JSON.parse(i.settings.working_plan_exceptions)||{};for(var a in delete e[r],GlobalVariables.availableProviders){var t=GlobalVariables.availableProviders[a];if(Number(t.id)===Number(n)){t.settings.working_plan_exceptions=JSON.stringify(e);break}}$("#select-filter-item").trigger("change")})}else{"0"===b.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:b.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:b.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")===f?($("#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&&(i=$("#manage-appointment"),r=GlobalVariables.editAppointment,BackendCalendarAppointmentsModal.resetAppointmentDialog(),i.find(".modal-header h3").text(EALang.edit_appointment_title),i.find("#appointment-id").val(r.id),i.find("#select-service").val(r.id_services).trigger("change"),i.find("#select-provider").val(r.id_users_provider),s=Date.parseExact(r.start_datetime,"yyyy-MM-dd HH:mm:ss"),i.find("#start-datetime").datetimepicker("setDate",s),l=Date.parseExact(r.end_datetime,"yyyy-MM-dd HH:mm:ss"),i.find("#end-datetime").datetimepicker("setDate",l),o=r.customer,i.find("#customer-id").val(r.id_users_customer),i.find("#first-name").val(o.first_name),i.find("#last-name").val(o.last_name),i.find("#email").val(o.email),i.find("#phone-number").val(o.phone_number),i.find("#address").val(o.address),i.find("#city").val(o.city),i.find("#zip-code").val(o.zip_code),i.find("#appointment-location").val(r.location),i.find("#appointment-notes").val(r.notes),i.find("#customer-notes").val(o.notes),i.modal("show")),$("#select-filter-item option").length||$("#calendar-actions button").prop("disabled",!0),window.innerHeight<700&&$("#footer").css("position","static");var p=$("#calendar"),u=$("#select-filter-item");setInterval(function(){var e=p.fullCalendar("getView");A(0,u.val(),u.find("option:selected").attr("type"),e.start,e.end)},6e4)}}(window.BackendCalendarDefaultView);