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

1 line
10 KiB

window.BackendCalendarAppointmentsModal=window.BackendCalendarAppointmentsModal||{},function(e){"use strict";function a(){$("#manage-appointment #save-appointment").on("click",function(){var a,e,t,n,i;!function(){var a=$("#manage-appointment");a.find(".has-error").removeClass("has-error"),a.find(".modal-message").addClass("d-none");try{var t=!1;if(a.find(".required").each(function(e,a){""!==$(a).val()&&null!==$(a).val()||($(a).closest(".form-group").addClass("has-error"),t=!0)}),t)throw new Error(EALang.fields_are_required);if(!GeneralFunctions.validateEmail(a.find("#email").val()))throw a.find("#email").closest(".form-group").addClass("has-error"),new Error(EALang.invalid_email);var e=$("#start-datetime").datetimepicker("getDate");if($("#end-datetime").datetimepicker("getDate")<e)throw a.find("#start-datetime, #end-datetime").closest(".form-group").addClass("has-error"),new Error(EALang.start_date_before_end_error);return 1}catch(e){return void a.find(".modal-message").addClass("alert-danger").text(e.message).removeClass("d-none")}}()||(e=(a=$("#manage-appointment")).find("#start-datetime").datetimepicker("getDate").toString("yyyy-MM-dd HH:mm:ss"),t=a.find("#end-datetime").datetimepicker("getDate").toString("yyyy-MM-dd HH:mm:ss"),n={id_services:a.find("#select-service").val(),id_users_provider:a.find("#select-provider").val(),start_datetime:e,end_datetime:t,location:a.find("#appointment-location").val(),notes:a.find("#appointment-notes").val(),is_unavailable:!1},""!==a.find("#appointment-id").val()&&(n.id=a.find("#appointment-id").val()),i={first_name:a.find("#first-name").val(),last_name:a.find("#last-name").val(),email:a.find("#email").val(),phone_number:a.find("#phone-number").val(),address:a.find("#address").val(),city:a.find("#city").val(),zip_code:a.find("#zip-code").val(),notes:a.find("#customer-notes").val()},""!==a.find("#customer-id").val()&&(i.id=a.find("#customer-id").val(),n.id_users_customer=i.id),BackendCalendarApi.saveAppointment(n,i,function(e){Backend.displayNotification(EALang.appointment_saved),a.find(".alert").addClass("d-none"),a.modal("hide"),$("#select-filter-item").trigger("change")},function(){a.find(".modal-message").text(EALang.service_communication_error),a.find(".modal-message").addClass("alert-danger").removeClass("d-none"),a.find(".modal-body").scrollTop(0)}))}),$("#insert-appointment").on("click",function(){$(".popover").remove(),BackendCalendarAppointmentsModal.resetAppointmentDialog();var a,e,t=$("#manage-appointment");"provider"===$("#select-filter-item option:selected").attr("type")?(a=$("#select-filter-item").val(),(e=GlobalVariables.availableProviders.filter(function(e){return Number(e.id)===Number(a)})).length&&(t.find("#select-service").val(e[0].services[0]).trigger("change"),t.find("#select-provider").val(a))):"service"===$("#select-filter-item option:selected").attr("type")?t.find('#select-service option[value="'+$("#select-filter-item").val()+'"]').prop("selected",!0):t.find("#select-service option:first").prop("selected",!0).trigger("change");var n=t.find("#select-service").val(),i=GlobalVariables.availableServices.find(function(e){return Number(e.id)===Number(n)}),r=i?i.duration:60,s=new Date,d=parseInt(s.toString("mm"));0<d&&d<15?s.set({minute:15}):15<d&&d<30?s.set({minute:30}):30<d&&d<45?s.set({minute:45}):s.addHours(1).set({minute:0}),t.find("#start-datetime").val(GeneralFunctions.formatDate(s,GlobalVariables.dateFormat,!0)),t.find("#end-datetime").val(GeneralFunctions.formatDate(s.addMinutes(r),GlobalVariables.dateFormat,!0)),t.find(".modal-header h3").text(EALang.new_appointment_title),t.modal("show")}),$("#select-customer").on("click",function(){var a=$("#existing-customers-list");a.is(":visible")?(a.slideUp("slow"),$("#filter-existing-customers").fadeOut("slow"),$(this).find("span").text(EALang.select)):($(this).find("span").text(EALang.hide),a.empty(),a.slideDown("slow"),$("#filter-existing-customers").fadeIn("slow"),$("#filter-existing-customers").val(""),GlobalVariables.customers.forEach(function(e){$("<div/>",{"data-id":e.id,text:e.first_name+" "+e.last_name}).appendTo(a)}))}),$("#manage-appointment").on("click","#existing-customers-list div",function(){var a=$(this).attr("data-id"),e=GlobalVariables.customers.find(function(e){return Number(e.id)===Number(a)});e&&($("#customer-id").val(e.id),$("#first-name").val(e.first_name),$("#last-name").val(e.last_name),$("#email").val(e.email),$("#phone-number").val(e.phone_number),$("#address").val(e.address),$("#city").val(e.city),$("#zip-code").val(e.zip_code),$("#customer-notes").val(e.notes)),$("#select-customer").trigger("click")});var e=null;$("#filter-existing-customers").on("keyup",function(){e&&clearTimeout(e);var i=$(this).val().toLowerCase();e=setTimeout(function(){var n=$("#existing-customers-list"),e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_filter_customers",a={csrfToken:GlobalVariables.csrfToken,key:i};$("#loading").css("visibility","hidden"),$.post(e,a).done(function(e){n.empty(),e.forEach(function(a){$("<div/>",{"data-id":a.id,text:a.first_name+" "+a.last_name}).appendTo(n),GlobalVariables.customers.filter(function(e){return Number(e.id)===Number(a.id)}).length||GlobalVariables.customers.push(a)})}).fail(function(e,a,t){n.empty(),GlobalVariables.customers.forEach(function(e,a){-1===e.first_name.toLowerCase().indexOf(i)&&-1===e.last_name.toLowerCase().indexOf(i)&&-1===e.email.toLowerCase().indexOf(i)&&-1===e.phone_number.toLowerCase().indexOf(i)&&-1===e.address.toLowerCase().indexOf(i)&&-1===e.city.toLowerCase().indexOf(i)&&-1===e.zip_code.toLowerCase().indexOf(i)&&-1===e.notes.toLowerCase().indexOf(i)||$("<div/>",{"data-id":e.id,text:e.first_name+" "+e.last_name}).appendTo(n)})}).always(function(){$("#loading").css("visibility","")})},1e3)}),$("#select-service").on("change",function(){var t=$("#select-service").val();$("#select-provider").empty();var e=GlobalVariables.availableServices.find(function(e){return Number(e.id)===Number(t)}),a=e?e.duration:60,n=$("#start-datetime").datetimepicker("getDate");$("#end-datetime").datetimepicker("setDate",new Date(n.getTime()+6e4*a)),GlobalVariables.availableProviders.forEach(function(a){a.services.forEach(function(e){GlobalVariables.user.role_slug===Backend.DB_SLUG_PROVIDER&&Number(a.id)!==GlobalVariables.user.id||GlobalVariables.user.role_slug===Backend.DB_SLUG_SECRETARY&&-1===GlobalVariables.secretaryProviders.indexOf(a.id)||Number(e)===Number(t)&&$("#select-provider").append(new Option(a.first_name+" "+a.last_name,a.id))})})}),$("#select-provider").on("change",function(){var a,e;a=$("#select-provider").val(),(e=GlobalVariables.availableProviders.find(function(e){return Number(e.id)===Number(a)}))&&e.timezone&&$(".provider-timezone").text(GlobalVariables.timezones[e.timezone])}),$("#new-customer").on("click",function(){$("#manage-appointment").find("#customer-id, #first-name, #last-name, #email, #phone-number, #address, #city, #zip-code, #customer-notes").val("")})}e.resetAppointmentDialog=function(){var n=$("#manage-appointment");n.find("input, textarea").val(""),n.find(".modal-message").fadeOut(),n.find("#select-service").val(n.find("#select-service").eq(0).attr("value")),n.find("#select-provider").empty(),GlobalVariables.availableProviders.forEach(function(e,a){var t=n.find("#select-service").val();0<e.services.filter(function(e){return Number(e)===Number(t)}).length&&n.find("#select-provider").append(new Option(e.first_name+" "+e.last_name,e.id))}),$("#existing-customers-list").slideUp("slow"),$("#filter-existing-customers").fadeOut("slow"),$("#select-customer span").text(EALang.select);var e,a=n.find("#select-service").val(),t=GlobalVariables.availableServices.forEach(function(e){return Number(e.id)===Number(a)}),i=t?t.duration:0,r=new Date,s=(new Date).addMinutes(i);switch(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 GlobalVariables.dateFormat value.")}var d=GlobalVariables.firstWeekday,o=GeneralFunctions.getWeekDayId(d);n.find("#start-datetime").datetimepicker({dateFormat:e,timeFormat:"regular"===GlobalVariables.timeFormat?"h:mm TT":"HH:mm",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)],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],prevText:EALang.previous,nextText:EALang.next,currentText:EALang.now,closeText:EALang.close,timeOnlyTitle:EALang.select_time,timeText:EALang.time,hourText:EALang.hour,minuteText:EALang.minutes,firstDay:o,onClose:function(){var a=$("#select-service").val(),e=GlobalVariables.availableServices.find(function(e){return Number(e.id)===Number(a)}),t=$("#start-datetime").datetimepicker("getDate");$("#end-datetime").datetimepicker("setDate",new Date(t.getTime()+6e4*e.duration))}}),n.find("#start-datetime").datetimepicker("setDate",r),n.find("#end-datetime").datetimepicker({dateFormat:e,timeFormat:"regular"===GlobalVariables.timeFormat?"h:mm TT":"HH:mm",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)],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],prevText:EALang.previous,nextText:EALang.next,currentText:EALang.now,closeText:EALang.close,timeOnlyTitle:EALang.select_time,timeText:EALang.time,hourText:EALang.hour,minuteText:EALang.minutes,firstDay:o}),n.find("#end-datetime").datetimepicker("setDate",s)},e.initialize=function(){a()}}(window.BackendCalendarAppointmentsModal);