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