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_table_view...

1 line
26 KiB

window.BackendCalendarTableView=window.BackendCalendarTableView||{},function(){"use strict";var d,o,l;function r(t,n){$("#calendar .calendar-header .btn").addClass("disabled").prop("disabled",!0);var r={};$(".provider-column").each(function(e,a){var t=$(a),n=t.data("provider").id;r[n]=t.find(".calendar-wrapper").fullCalendar("getView").name}),$("#calendar .calendar-view").remove(),Backend.placeFooterToBottom();var e=$("<div/>",{class:"calendar-view"}).appendTo("#calendar");e.data({startDate:t.toString("yyyy-MM-dd"),endDate:n.toString("yyyy-MM-dd")});var i=$("<div/>").appendTo(e);E(t,n).done(function(e){for(var a=t;a<=n;)s(i,a,e),a.add({days:1});_(),Backend.placeFooterToBottom(),$("#calendar .calendar-header .btn").removeClass("disabled").prop("disabled",!1),$(".provider-column").each(function(e,a){var t=$(a),n=t.data("provider").id;t.find(".calendar-wrapper").fullCalendar("changeView",r[n]||"agendaDay")})})}function s(e,a,t){var n=$("<div/>",{class:"date-column"}).appendTo(e);n.data("date",a.getTime()),$("<h5/>",{class:"date-column-title",text:GeneralFunctions.formatDate(a,GlobalVariables.dateFormat)}).appendTo(n);var r=d.val(),i=o.val(),s=GlobalVariables.availableProviders.filter(function(e){var a=e.services.filter(function(a){return i.filter(function(e){return Number(a)===Number(e)}).length});return!r.length&&!i.length||r.length&&!i.length&&-1!==r.indexOf(e.id)||!r.length&&i.length&&a.length||r.length&&i.length&&a.length&&-1!==r.indexOf(e.id)});"provider"===GlobalVariables.user.role_slug&&GlobalVariables.availableProviders.forEach(function(e){Number(e.id)===Number(GlobalVariables.user.id)&&(s=[e])}),"secretary"===GlobalVariables.user.role_slug&&(s=[],GlobalVariables.availableProviders.forEach(function(e){-1<GlobalVariables.secretaryProviders.indexOf(e.id)&&s.push(e)})),s.forEach(function(e){!function(e,a,t,n){if(0===t.services.length)return;var r=$("<div/>",{class:"provider-column"}).appendTo(e);r.data("provider",t),function(e,a,t){var n=$("<div/>",{class:"calendar-wrapper"}).appendTo(e),r="";switch(GlobalVariables.dateFormat){case"DMY":r="ddd D/M";break;case"MDY":case"YMD":r="ddd M/D";break;default:throw new Error("Invalid date format setting provided!",GlobalVariables.dateFormat)}var i="",s="";switch(GlobalVariables.timeFormat){case"military":i="H:mm",s="H(:mm)";break;case"regular":i="h:mm a",s="h(:mm) a";break;default:throw new Error("Invalid time format setting provided!"+GlobalVariables.timeFormat)}var d=GlobalVariables.firstWeekday,o=GeneralFunctions.getWeekDayId(d);n.fullCalendar({defaultView:"agendaDay",height:c(),editable:!0,timeFormat:i,slotLabelFormat:s,allDaySlot:!0,columnFormat:r,firstDay:o,snapDuration:"00:15:00",header:{left:"listDay,agendaDay",center:"",right:""},selectable:!0,selectHelper:!0,select:function(e,a,t){if(e.hasTime()&&a.hasTime()){$("#insert-appointment").trigger("click");var n=$(t.target).parents(".provider-column").data("provider").id,r=GlobalVariables.availableProviders.find(function(e){return Number(e.id)===Number(n)}),i=GlobalVariables.availableServices.find(function(e){return-1!==r.services.indexOf(e.id)});return i&&$("#select-service").val(i.id),$("#select-service").val()||$("#select-service option:first").prop("selected",!0),$("#select-service").trigger("change"),r&&$("#select-provider").val(r.id),$("#select-provider").val()||$("#select-provider option:first").prop("selected",!0),$("#select-provider").trigger("change"),$("#start-datetime").datepicker("setDate",new Date(e.format("YYY/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,agendaDay:EALang.calendar,listDay:EALang.list},eventClick:g,eventResize:y,eventDrop:h,viewRender:m}),n.fullCalendar("gotoDate",moment(a)),$("<h6/>",{text:t.first_name+" "+t.last_name}).prependTo(e)}(r,a,t),p(r.find(".calendar-wrapper"),t),u(r,n.appointments),b(r,n.unavailability_events),Backend.placeFooterToBottom()}(n,a,e,t)})}function c(){var e=window.innerHeight-$("#footer").outerHeight()-$("#header").outerHeight()-60;return 500<e?e:500}function m(e,a){$(a).fullCalendar("option","height",c())}function p(t,e){var a,n,r,i,s,d,o,l,c,m=JSON.parse(e.settings.working_plan),p=JSON.parse(e.settings.working_plan_exceptions)||{},u=t.fullCalendar("getView"),b=u.start.clone(),f=u.end.clone(),v=b.toDate().toString("dddd").toLowerCase(),g=b.format("YYYY-MM-DD");p[g]&&(m[v]=p[g],a=g+" "+m[v].start,n=g+" "+m[v].end,r={title:EALang.working_plan_exception,start:moment(a,"YYYY-MM-DD HH:mm",!0),end:moment(n,"YYYY-MM-DD HH:mm",!0).add(1,"day"),allDay:!0,color:"#879DB4",editable:!1,className:"fc-working-plan-exception fc-custom",data:{date:g,workingPlanException:p[g],provider:e}},t.fullCalendar("renderEvent",r,!1)),null!==m[v]?(i=moment(b.toDate().toString("yyyy-MM-dd")+" "+m[v].start),b<i&&(d={title:EALang.not_working,start:b,end:i,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},t.fullCalendar("renderEvent",d,!1)),(s=moment(b.toDate().toString("yyyy-MM-dd")+" "+m[v].end))<f&&(d={title:EALang.not_working,start:s,end:f,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},t.fullCalendar("renderEvent",d,!1)),m[v].breaks.forEach(function(e){o=moment(b.toDate().toString("yyyy-MM-dd")+" "+e.start),l=moment(b.toDate().toString("yyyy-MM-dd")+" "+e.end);var a={title:EALang.break,start:o,end:l,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable fc-break"};t.fullCalendar("renderEvent",a,!1)})):(c={title:EALang.not_working,start:b,end:f,allDay:!1,color:"#BEBEBE",editable:!1,className:"fc-unavailable"},t.fullCalendar("renderEvent",c,!0))}function u(e,a){if(0!==a.length){var t=o.val();a=a.filter(function(e){return!t.length||-1!==t.indexOf(e.id_services)});var n=[];for(var r in a){var i=a[r];i.id_users_provider===e.data("provider").id&&n.push({id:i.id,title:i.service.name+" - "+i.customer.first_name+" "+i.customer.last_name,start:moment(i.start_datetime),end:moment(i.end_datetime),allDay:!1,data:i})}e.find(".calendar-wrapper").fullCalendar("addEventSource",n)}}function b(e,a){if(0!==a.length)for(var t in a){var n,r=a[t];r.id_users_provider===e.data("provider").id&&(n={title:EALang.unavailable,start:moment(r.start_datetime),end:moment(r.end_datetime),allDay:!1,color:"#879DB4",editable:!0,className:"fc-unavailable fc-custom",data:r},e.find(".calendar-wrapper").fullCalendar("renderEvent",n,!1))}}function f(e,a){if(0!==a.length){var r=new Date(e.parents(".date-column").data("date")),t=e.find("table tbody");for(var n in a){var i=a[n],s=i.start.split(":"),d=new Date(r.getFullYear(),r.getMonth(),r.getDate(),s[0],s[1]),o=i.end.split(":"),l=new Date(r.getFullYear(),r.getMonth(),r.getDate(),o[0],o[1]),c=Math.round((l-d)/6e4),m=$("<div/>",{class:"event unavailability break"});m.html(EALang.break+' <span class="hour">'+d.toString("HH:mm")+"</span> ("+c+"')"),m.data(i),t.find("tr").each(function(e,a){var t=$(a).find("td:first"),n=new Date(r.getTime()).set({hour:parseInt(t.text().split(":")[0]),minute:parseInt(t.text().split(":")[1])});if(d<n)return d.toString("HH:mm")===$(a).prev().find("td").eq(0).text()&&m.find(".hour").remove(),$(a).prev().find("td:gt(0)").each(function(e,a){m.clone().appendTo($(a))}),!1})}}}function v(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 r=$(a.target.offsetParent),i=$(a.target).parents().eq(1),s=$(this).hasClass("fc-unavailable")||r.hasClass("fc-unavailable")||i.hasClass("fc-unavailable")?(t=(r.hasClass("fc-custom")||i.hasClass("fc-custom"))&&!0===GlobalVariables.user.privileges.appointments.edit?"":"d-none",n=(r.hasClass("fc-custom")||i.hasClass("fc-custom"))&&!0===GlobalVariables.user.privileges.appointments.delete?"":"d-none",$("<div/>",{html:[$("<strong/>",{text:EALang.start}),$("<span/>",{text:GeneralFunctions.formatDate(e.start.format("YYYY-MM-DD HH:mm:ss"),GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{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:v(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 mr-2 "+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")||r.hasClass("fc-working-plan-exception")||i.hasClass("fc-working-plan-exception")?(t=(r.hasClass("fc-custom")||i.hasClass("fc-custom"))&&!0===GlobalVariables.user.privileges.appointments.edit?"":"d-none",n=(r.hasClass("fc-custom")||i.hasClass("fc-custom"))&&!0===GlobalVariables.user.privileges.appointments.delete?"":"d-none",$("<div/>",{html:[$("<strong/>",{text:EALang.provider}),$("<span/>",{text:e.data?e.data.provider.first_name+" "+e.data.provider.last_name:"-"}),$("<br/>"),$("<strong/>",{text:EALang.start}),$("<span/>",{text:GeneralFunctions.formatDate(e.start.format("YYYY-MM-DD HH:mm:ss"),GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{text:EALang.end}),$("<span/>",{text:GeneralFunctions.formatDate(e.end.format("YYYY-MM-DD HH:mm:ss"),GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{text:EALang.timezone}),$("<span/>",{text:GlobalVariables.timezones[e.data.provider.timezone]}),$("<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 mr-2 "+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?"":"d-none",n=!0===GlobalVariables.user.privileges.appointments.delete?"":"d-none",$("<div/>",{html:[$("<strong/>",{text:EALang.start}),$("<span/>",{text:GeneralFunctions.formatDate(e.start.format("YYYY-MM-DD HH:mm:ss"),GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{text:EALang.end}),$("<span/>",{text:GeneralFunctions.formatDate(e.end.format("YYYY-MM-DD HH:mm:ss"),GlobalVariables.dateFormat,!0)}),$("<br/>"),$("<strong/>",{text:EALang.timezone}),$("<span/>",{text:GlobalVariables.timezones[e.data.provider.timezone]}),$("<br/>"),$("<strong/>",{text:EALang.service}),$("<span/>",{text:e.data.service.name}),$("<br/>"),$("<strong/>",{text:EALang.provider}),GeneralFunctions.renderMapIcon(e.data.provider),$("<span/>",{text:e.data.provider.first_name+" "+e.data.provider.last_name}),$("<br/>"),$("<strong/>",{text:EALang.customer}),GeneralFunctions.renderMapIcon(e.data.customer),$("<span/>",{text:e.data.customer.first_name+" "+e.data.customer.last_name}),$("<br/>"),$("<strong/>",{text:EALang.email}),GeneralFunctions.renderMailIcon(e.data.customer.email),$("<span/>",{text:e.data.customer.email}),$("<br/>"),$("<strong/>",{text:EALang.phone}),GeneralFunctions.renderPhoneIcon(e.data.customer.phone_number),$("<span/>",{text:e.data.customer.phone_number}),$("<br/>"),$("<strong/>",{text:EALang.notes}),$("<span/>",{text:v(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 mr-2"+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"}),l=e,$(a.target).popover("toggle"),0<$(".popover").length&&$(".popover").position().top<200&&$(".popover").css("top","200px")}function y(t,n,r){if(!1===GlobalVariables.user.privileges.appointments.edit)return r(),void Backend.displayNotification(EALang.no_privileges_edit_appointments);var e,i,s,a=$("#calendar");$("#notification").is(":visible")&&$("#notification").hide("bind"),"0"===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(i=GeneralFunctions.clone(t.data)).customer,delete i.provider,delete i.service,e=function(){Backend.displayNotification(EALang.appointment_updated,[{label:EALang.undo,function:function(){i.end_datetime=t.data.end_datetime=Date.parseExact(i.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(i)};$.post(e,a).done(function(){$("#notification").hide("blind")}),r()}}]),$("#footer").css("position","static"),a.fullCalendar("updateEvent",t)},BackendCalendarApi.saveAppointment(i,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")}),r()}}]),$("#footer").css("position","static"),a.fullCalendar("updateEvent",t)},BackendCalendarApi.saveUnavailable(s,e))}function h(t,n,r){if(!1===GlobalVariables.user.privileges.appointments.edit)return r(),void Backend.displayNotification(EALang.no_privileges_edit_appointments);var i,s,e;$("#notification").is(":visible")&&$("#notification").hide("bind"),"0"===t.data.is_unavailable?(delete(i=GeneralFunctions.clone(t.data)).customer,delete i.provider,delete i.service,i.start_datetime=Date.parseExact(i.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"),i.end_datetime=Date.parseExact(i.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=i.start_datetime,t.data.end_datetime=i.end_datetime,e=function(){Backend.displayNotification(EALang.appointment_updated,[{label:EALang.undo,function:function(){i.start_datetime=Date.parseExact(i.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"),i.end_datetime=Date.parseExact(i.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=i.start_datetime,t.data.end_datetime=i.end_datetime;var e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_save_appointment",a={csrfToken:GlobalVariables.csrfToken,appointment_data:JSON.stringify(i)};$.post(e,a).done(function(){$("#notification").hide("blind")}),r()}}]),$("#footer").css("position","static")},BackendCalendarApi.saveAppointment(i,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")}),r()}}]),$("#footer").css("position","static")},BackendCalendarApi.saveUnavailable(s,e))}function _(){var e=window.innerHeight-$("#header").outerHeight()-$("#footer").outerHeight()-$("#calendar-toolbar").outerHeight()-$(".calendar-header").outerHeight()-50;e<500&&(e=500);var a=$(".date-column"),t=$(".calendar-view > div");t.css("min-width","1000%");var n=0;a.each(function(e,a){n+=$(a).outerWidth()}),t.css("min-width",n+200);var r=a.outerHeight();$(".calendar-view .not-working").outerHeight((e<r?r:e)-70)}function E(e,a){var t=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_get_calendar_events",n={csrfToken:GlobalVariables.csrfToken,startDate:e.toString("yyyy-MM-dd"),endDate:a.toString("yyyy-MM-dd")};return $.ajax({url:t,data:n,method:"POST",beforeSend:function(){},complete:function(){}})}window.BackendCalendarTableView.initialize=function(){var e,a;!function(){$("#calendar-filter").find("select").empty().append(new Option("1 "+EALang.day,1)).append(new Option("3 "+EALang.days,3));var e,a=$("<div/>",{class:"calendar-header"}).appendTo("#calendar");switch($("<button/>",{class:"btn btn-xs btn-outline-secondary previous mr-2",html:[$("<span/>",{class:"fas fa-chevron-left"})]}).appendTo(a),$("<input/>",{type:"text",class:"form-control d-inline-block select-date mr-2",value:GeneralFunctions.formatDate(new Date,GlobalVariables.dateFormat,!1)}).appendTo(a),$("<button/>",{class:"btn btn-xs btn-outline-secondary next",html:[$("<span/>",{class:"fas fa-chevron-right"})]}).appendTo(a),GlobalVariables.dateFormat){case"DMY":e="dd/mm/yy";break;case"MDY":e="mm/dd/yy";break;case"YMD":e="yy/mm/dd";break;default:throw new Error("Invalid date format setting provided: "+GlobalVariables.dateFormat)}a.find(".select-date").datepicker({defaultDate:new Date,dateFormat:e,onSelect:function(e,a){var t=new Date(a.currentYear,a.currentMonth,a.currentDay),n=new Date(t.getTime()).add({days:parseInt($("#select-filter-item").val())-1});r(t,n)}});var t=GlobalVariables.availableProviders.filter(function(e){return GlobalVariables.user.role_slug===Backend.DB_SLUG_ADMIN||GlobalVariables.user.role_slug===Backend.DB_SLUG_SECRETARY&&-1!==GlobalVariables.secretaryProviders.indexOf(e.id)||GlobalVariables.user.role_slug===Backend.DB_SLUG_PROVIDER&&Number(e.id)===Number(GlobalVariables.user.id)});$("<label/>",{text:EALang.provider}).appendTo(a),d=$("<select/>",{id:"filter-provider",multiple:"multiple",on:{change:function(){var e=new Date($(".calendar-view .date-column:first").data("date")),a=new Date(e.getTime()).add({days:parseInt($("#select-date").val())-1});r(e,a)}}}).appendTo(a),GlobalVariables.user.role_slug!==Backend.DB_SLUG_PROVIDER?t.forEach(function(e){d.append(new Option(e.first_name+" "+e.last_name,e.id))}):t.forEach(function(e){Number(e.id)===Number(GlobalVariables.user.id)&&d.append(new Option(e.first_name+" "+e.last_name,e.id))}),d.select2();var n=GlobalVariables.availableServices.filter(function(a){var e=t.find(function(e){return-1!==e.services.indexOf(a.id)});return GlobalVariables.user.role_slug===Backend.DB_SLUG_ADMIN||e});$("<label/>",{text:EALang.service}).appendTo(a),o=$("<select/>",{id:"filter-service",multiple:"multiple",on:{change:function(){var e=new Date($(".calendar-view .date-column:first").data("date")),a=new Date(e.getTime()).add({days:parseInt($("#select-date").val())-1});r(e,a)}}}).appendTo(a),n.forEach(function(e){o.append(new Option(e.name,e.id))}),o.select2()}(),r(moment().toDate(),moment().add(Number($("#select-filter-item").val())-1,"days").toDate()),$("#insert-working-plan-exception").hide(),e=$("#calendar-toolbar"),(a=$("#calendar")).on("click",".calendar-header .btn.previous",function(){var e=$("#select-filter-item").val(),a=$(".select-date").datepicker("getDate"),t=moment(a).subtract(1,"days"),n=t.clone().add(e-1,"days");$(".select-date").datepicker("setDate",t.toDate()),r(t.toDate(),n.toDate())}),a.on("click",".calendar-header .btn.next",function(){var e=$("#select-filter-item").val(),a=$(".select-date").datepicker("getDate"),t=moment(a).add(1,"days"),n=t.clone().add(e-1,"days");$(".select-date").datepicker("setDate",t.toDate()),r(t.toDate(),n.toDate())}),e.on("change","#select-filter-item",function(){var e=$("#select-filter-item").val(),a=$(".select-date").datepicker("getDate"),t=moment(a),n=t.clone().add(e-1,"days");r(t.toDate(),n.toDate())}),e.on("click","#reload-appointments",function(){$(".calendar-view .event").remove();var e=$("#select-filter-item").val(),a=$(".select-date").datepicker("getDate"),t=moment(a),r=t.toDate(),i=t.clone().add(e-1,"days").toDate();E(r,i).done(function(d){for(var n=r;n<=i;)$(".calendar-view .date-column").each(function(e,a){var t=$(a),s=new Date(t.data("date"));if(n.getTime()!==s.getTime())return!0;t.find(".date-column-title").text(GeneralFunctions.formatDate(s,GlobalVariables.dateFormat)),t.find(".provider-column").each(function(e,a){var t=$(a),n=t.data("provider");t.find(".calendar-wrapper").fullCalendar("removeEvents"),p(t.find(".calendar-wrapper"),t.data("provider")),u(t,d.appointments),b(t,d.unavailability_events);var r=JSON.parse(n.settings.working_plan),i=s.toString("dddd").toLowerCase();r[i]&&f(t,r[i].breaks)})}),n.add({days:1});Backend.placeFooterToBottom()})}),$(window).on("resize",function(){_()}),a.on("click",".close-popover",function(){$(this).parents(".popover").popover("dispose")}),a.on("click",".edit-popover",function(){var e,a,i,t,n,r,s,d,o;$(this).parents(".popover").popover("dispose"),l.data.workingPlanException?(e=l.data.date,a=l.data.workingPlanException,i=l.data.provider,WorkingPlanExceptionsModal.edit(e,a).done(function(n,r){BackendCalendarApi.saveWorkingPlanException(n,r,i.id,function(){Backend.displayNotification(EALang.working_plan_exception_saved);var e=JSON.parse(i.settings.working_plan_exceptions)||{};for(var a in e[n]=r,GlobalVariables.availableProviders){var t=GlobalVariables.availableProviders[a];if(Number(t.id)===Number(i.id)){t.settings.working_plan_exceptions=JSON.stringify(e);break}}$("#select-filter-item").trigger("change")},null)})):("0"===l.data.is_unavailable?(t=l.data,n=$("#manage-appointment"),BackendCalendarAppointmentsModal.resetAppointmentDialog(),n.find(".modal-header h3").text(EALang.edit_appointment_title),n.find("#appointment-id").val(t.id),n.find("#select-service").val(t.id_services).trigger("change"),n.find("#select-provider").val(t.id_users_provider),d=Date.parseExact(t.start_datetime,"yyyy-MM-dd HH:mm:ss"),n.find("#start-datetime").datetimepicker("setDate",d),o=Date.parseExact(t.end_datetime,"yyyy-MM-dd HH:mm:ss"),n.find("#end-datetime").datetimepicker("setDate",o),r=t.customer,n.find("#customer-id").val(t.id_users_customer),n.find("#first-name").val(r.first_name),n.find("#last-name").val(r.last_name),n.find("#email").val(r.email),n.find("#phone-number").val(r.phone_number),n.find("#address").val(r.address),n.find("#city").val(r.city),n.find("#zip-code").val(r.zip_code),n.find("#appointment-location").val(t.location),n.find("#appointment-notes").val(t.notes),n.find("#customer-notes").val(r.notes)):((s=l.data).start_datetime=l.start.format("YYYY-MM-DD HH:mm:ss"),d=Date.parseExact(s.start_datetime,"yyyy-MM-dd HH:mm:ss"),s.end_datetime=l.end.format("YYYY-MM-DD HH:mm:ss"),o=Date.parseExact(s.end_datetime,"yyyy-MM-dd HH:mm:ss"),n=$("#manage-unavailable"),BackendCalendarUnavailabilityEventsModal.resetUnavailableDialog(),n.find(".modal-header h3").text("Edit Unavailable Period"),n.find("#unavailable-start").datetimepicker("setDate",d),n.find("#unavailable-id").val(s.id),n.find("#unavailable-provider").val(s.id_users_provider),n.find("#unavailable-end").datetimepicker("setDate",o),n.find("#unavailable-notes").val(s.notes)),n.modal("show"))}),a.on("click",".delete-popover",function(){var e,a,t;$(this).parents(".popover").popover("dispose"),l.data.hasOwnProperty("id_roles")?(e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_delete_working_plan_exception",a={csrfToken:GlobalVariables.csrfToken,working_plan_exception:l.start.format("YYYY-MM-DD"),provider_id:l.data.id},$.post(e,a).done(function(){$("#message-box").dialog("close");var e=JSON.parse(l.data.settings.working_plan_exceptions);delete e[l.start.format("YYYY-MM-DD")],l.data.settings.working_plan_exceptions=JSON.stringify(e),$("#select-filter-item").trigger("change")})):"0"===l.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:l.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:l.data.id},$.post(e,a).done(function(){$("#message-box").dialog("close"),$("#select-filter-item").trigger("change")}))}),$("#enable-sync, #google-sync").hide()}}();