You cannot 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
7.2 KiB
JavaScript

!function(c){var s,a={settings:{spinner:'<i class="wpforms-loading-spinner wpforms-loading-inline"></i>',spinnerWhite:'<i class="wpforms-loading-spinner wpforms-loading-inline wpforms-loading-white"></i>'},init:function(){s=this.settings,c(a.ready),a.bindUIActions()},ready:function(){s.form=c("#wpforms-builder-form")},bindUIActions:function(){c(document).on("click",".wpforms-provider-connection-delete",function(e){a.connectionDelete(this,e)}),c(document).on("click",".wpforms-provider-connections-add",function(e){a.connectionAdd(this,e)}),c(document).on("click",".wpforms-provider-account-add button",function(e){a.accountAdd(this,e)}),c(document).on("change",".wpforms-provider-accounts select",function(e){a.accountSelect(this,e)}),c(document).on("change",".wpforms-provider-lists select",function(e){a.accountListSelect(this,e)}),c(document).on("wpformsPanelSwitch",function(e,n){a.providerPanelConfirm(n)}),c(document).on("wpformsSaved",function(){var r=[],e=c("#wpforms-panel-providers").find(".wpforms-connection-block");e.length&&e.each(function(){var e,n,o=!1;c(this).find("table span.required").each(function(){""===c(this).parent().parent().find("select").val()&&(o=!0)}),o&&((e=c(this).closest(".wpforms-panel-content-section").find(".wpforms-panel-content-section-title").clone()).find("button").remove(),e=e.text().trim(),n=wpforms_builder.provider_required_flds,-1<r.indexOf(e)||(c.alert({title:wpforms_builder.heads_up,content:n.replace("{provider}",e),icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}}),r.push(e)))})})},connectionDelete:function(e,n){n.preventDefault();var o=c(e);c.confirm({title:!1,content:wpforms_builder_providers.confirm_connection,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"],action:function(){var e=o.closest(".wpforms-panel-content-section");o.closest(".wpforms-provider-connection").remove(),e.find(".wpforms-provider-connection").length||e.find(".wpforms-builder-provider-connections-default").removeClass("wpforms-hidden")}},cancel:{text:wpforms_builder.cancel}}})},connectionAdd:function(e,n){n.preventDefault();var o=c(e),r=o.parent().parent(),i=o.parent(),t=o.data("provider"),n=o.data("type"),e=(e=wpforms_builder_providers.prompt_connection+('<input autofocus="" type="text" id="provider-connection-name" placeholder="'+wpforms_builder_providers.prompt_placeholder+'">')+('<p class="error">'+wpforms_builder_providers.error_name+"</p>")).replace(/%type%/g,n);c.confirm({title:!1,content:e,icon:"fa fa-info-circle",type:"blue",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"],action:function(){var e=this.$content.find("input#provider-connection-name").val().trim(),n=this.$content.find(".error");if(""===e)return n.show(),!1;a.inputToggle(o,"disable");n={action:"wpforms_provider_ajax_"+t,provider:t,task:"new_connection",name:e,id:s.form.data("id"),nonce:wpforms_builder.nonce};a.fireAJAX(o,n,function(e){var n;e.success?(r.find(".wpforms-builder-provider-connections-default").addClass("wpforms-hidden"),r.find(".wpforms-provider-connections").prepend(e.data.html),(n=r.find(".wpforms-provider-connection").first()).find(".wpforms-provider-accounts option:selected")&&(n.find(".wpforms-provider-accounts option").first().prop("selected",!0),n.find(".wpforms-provider-accounts select").trigger("change"))):a.errorDisplay(e.data.error,i)})}},cancel:{text:wpforms_builder.cancel}}})},accountAdd:function(e,n){n.preventDefault();var n=c(e),e=n.data("provider"),o=n.closest(".wpforms-provider-connection"),r=n.parent(),i=r.find(":input"),t=a.requiredCheck(i,r);if(a.inputToggle(n,"disable"),t)return n.prop("disabled",!1).find("i").remove(),!1;t={action:"wpforms_provider_ajax_"+e,provider:e,connection_id:o.data("connection_id"),task:"new_account",data:a.fakeSerialize(i)};a.fireAJAX(n,t,function(e){e.success?(r.nextAll(".wpforms-connection-block").remove(),r.nextAll(".wpforms-conditional-block").remove(),r.after(e.data.html),r.slideUp(),o.find(".wp