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/frontend_book_api.min.js

1 line
4.3 KiB

window.FrontendBookApi=window.FrontendBookApi||{},function(a){"use strict";var i,l,s=!1;function d(t,a,e){e=e||!1,s=!0;var o=Date.parse(a),n=new Date(o.getFullYear(),o.getMonth()+1,0).getDate();if(e&&!GlobalVariables.manageMode)for(var r=1;r<=n;r++){var i=new Date(o.getFullYear(),o.getMonth(),r);if(-1===t.indexOf(i.toString("yyyy-MM-dd"))){$("#select-date").datepicker("setDate",i),FrontendBookApi.getAvailableHours(i.toString("yyyy-MM-dd"));break}}t.length===n&&$("#available-hours").text(EALang.no_available_hours),$("#select-date .ui-datepicker-calendar td:not(.ui-datepicker-other-month)").each(function(a,e){o.set({day:a+1}),-1!==t.indexOf(o.toString("yyyy-MM-dd"))&&$(e).addClass("ui-datepicker-unselectable ui-state-disabled")}),s=!1}a.getAvailableHours=function(i){$("#available-hours").empty();var e=$("#select-service").val(),a=15,t=GlobalVariables.availableServices.find(function(a){return Number(a.id)===Number(e)});t&&(a=t.duration);var o=FrontendBook.manageMode?GlobalVariables.appointmentData.id:null,n=GlobalVariables.baseUrl+"/index.php/appointments/ajax_get_available_hours",r={csrfToken:GlobalVariables.csrfToken,service_id:$("#select-service").val(),provider_id:$("#select-provider").val(),selected_date:i,service_duration:a,manage_mode:FrontendBook.manageMode,appointment_id:o};$.post(n,r).done(function(a){if(0<a.length){var e=$("#select-provider").val();"any-provider"===e&&(e=GlobalVariables.availableProviders[0].id);var t=GlobalVariables.availableProviders.find(function(a){return Number(e)===Number(a.id)});if(!t)throw new Error("Could not find provider.");var o=t.timezone,n=$("#select-timezone").val(),r="regular"===GlobalVariables.timeFormat?"h:mm a":"HH:mm";a.forEach(function(a){var e=moment.tz(i+" "+a+":00",o).tz(n);$("#available-hours").append($("<button/>",{class:"btn btn-outline-secondary btn-block shadow-none available-hour",data:{value:a},text:e.format(r)}))}),FrontendBook.manageMode?$(".available-hour").removeClass("selected-hour").filter(function(){return $(this).text()===Date.parseExact(GlobalVariables.appointmentData.start_datetime,"yyyy-MM-dd HH:mm:ss").toString(r)}).addClass("selected-hour"):$(".available-hour:eq(0)").addClass("selected-hour"),FrontendBook.updateConfirmFrame()}else $("#available-hours").text(EALang.no_available_hours)})},a.registerAppointment=function(){var a,e,t,o,n=$(".captcha-text");0<n.length&&(n.closest(".form-group").removeClass("has-error"),""===n.val())?n.closest(".form-group").addClass("has-error"):(a=JSON.parse($('input[name="post_data"]').val()),e={csrfToken:GlobalVariables.csrfToken,post_data:a},0<n.length&&(e.captcha=n.val()),GlobalVariables.manageMode&&(e.exclude_appointment_id=GlobalVariables.appointmentData.id),t=GlobalVariables.baseUrl+"/index.php/appointments/ajax_register_appointment",o=$("<div/>"),$.ajax({url:t,method:"post",data:e,dataType:"json",beforeSend:function(a,e){o.appendTo("body").css({background:"white",position:"fixed",top:"0",left:"0",height:"100vh",width:"100vw",opacity:"0.5"})}}).done(function(a){if(!1===a.captcha_verification)return $("#captcha-hint").text(EALang.captcha_is_wrong).fadeTo(400,1),setTimeout(function(){$("#captcha-hint").fadeTo(400,0)},3e3),$(".captcha-title button").trigger("click"),n.closest(".form-group").addClass("has-error"),!1;window.location.href=GlobalVariables.baseUrl+"/index.php/appointments/book_success/"+a.appointment_hash}).fail(function(a,e,t){$(".captcha-title button").trigger("click")}).always(function(){o.remove()}))},a.getUnavailableDates=function(a,e,t){var o,n,r;s||a&&e&&(o=FrontendBook.manageMode?GlobalVariables.appointmentData.id:null,n=GlobalVariables.baseUrl+"/index.php/appointments/ajax_get_unavailable_dates",r={provider_id:a,service_id:e,selected_date:encodeURIComponent(t),csrfToken:GlobalVariables.csrfToken,manage_mode:FrontendBook.manageMode,appointment_id:o},$.ajax({url:n,type:"GET",data:r,dataType:"json"}).done(function(a){d(i=a,l=t,!0)}))},a.applyPreviousUnavailableDates=function(){d(i,l)},a.saveConsent=function(a){var e=GlobalVariables.baseUrl+"/index.php/consents/ajax_save_consent",t={csrfToken:GlobalVariables.csrfToken,consent:a};$.post(e,t)},a.deletePersonalInformation=function(a){var e=GlobalVariables.baseUrl+"/index.php/privacy/ajax_delete_personal_information",t={csrfToken:GlobalVariables.csrfToken,customer_token:a};$.post(e,t).done(function(){window.location.href=GlobalVariables.baseUrl})}}(window.FrontendBookApi);