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

1 line
2.7 KiB

window.BackendCalendarGoogleSync=window.BackendCalendarGoogleSync||{},function(){"use strict";function e(){$("#enable-sync").on("click",function(){var e,n,l,o,a;!1===$("#enable-sync").hasClass("enabled")?(e=GlobalVariables.baseUrl+"/index.php/google/oauth/"+$("#select-filter-item").val(),n=GlobalVariables.baseUrl+"/index.php/google/oauth_callback",l=window.open(e,"Authorize Easy!Appointments","width=800, height=600"),o=window.setInterval(function(){try{var e,a;l.document&&-1!==l.document.URL.indexOf(n)&&(l.close(),window.clearInterval(o),$("#enable-sync").addClass("btn-secondary enabled").removeClass("btn-light"),$("#enable-sync span").text(EALang.disable_sync),$("#google-sync").prop("disabled",!1),$("#select-filter-item option:selected").attr("google-sync","true"),e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_get_google_calendars",a={csrfToken:GlobalVariables.csrfToken,provider_id:$("#select-filter-item").val()},$.post(e,a).done(function(e){$("#google-calendar").empty(),e.forEach(function(e){$("#google-calendar").append(new Option(e.summary,e.id))}),$("#select-google-calendar").modal("show")}))}catch(e){}},100)):(a=[{text:EALang.cancel,click:function(){$("#message-box").dialog("close")}},{text:"OK",click:function(){var e,a,n,l=$("#select-filter-item").val(),o=GlobalVariables.availableProviders.find(function(e){return Number(e.id)===Number(l)});if(!o)throw new Error("Provider not found: "+l);o.settings.google_sync="0",o.settings.google_token=null,e=o.id,a=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_disable_provider_sync",n={csrfToken:GlobalVariables.csrfToken,provider_id:e},$.post(a,n),$("#enable-sync").removeClass("btn-secondary enabled").addClass("btn-light"),$("#enable-sync span").text(EALang.enable_sync),$("#google-sync").prop("disabled",!0),$("#select-filter-item option:selected").attr("google-sync","false"),$("#message-box").dialog("close")}}],GeneralFunctions.displayMessageBox(EALang.disable_sync,EALang.disable_sync_prompt,a))}),$("#select-calendar").on("click",function(){var e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_select_google_calendar",a={csrfToken:GlobalVariables.csrfToken,provider_id:$("#select-filter-item").val(),calendar_id:$("#google-calendar").val()};$.post(e,a).done(function(){Backend.displayNotification(EALang.google_calendar_selected),$("#select-google-calendar").modal("hide")})}),$("#google-sync").on("click",function(){var e=GlobalVariables.baseUrl+"/index.php/google/sync/"+$("#select-filter-item").val();$.ajax({url:e,type:"GET",dataType:"json"}).done(function(e){Backend.displayNotification(EALang.google_sync_completed),$("#reload-appointments").trigger("click")}).fail(function(e,a,n){Backend.displayNotification(EALang.google_sync_failed)})})}window.BackendCalendarGoogleSync.initialize=function(){e()}}();