')+(''+wpforms_builder_providers.error_name+"
")).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(".wpforms-provider-accounts select").trigger("change")):a.errorDisplay(e.data.error,r)})},accountSelect:function(e,n){n.preventDefault();var n=c(e),o=n.closest(".wpforms-provider-connection"),r=n.parent(),e=o.data("provider");a.inputToggle(n,"disable"),r.nextAll(".wpforms-connection-block").remove(),r.nextAll(".wpforms-conditional-block").remove(),n.val()?(o.find(".wpforms-provider-account-add").slideUp(),e={action:"wpforms_provider_ajax_"+e,provider:e,connection_id:o.data("connection_id"),task:"select_account",account_id:n.find(":selected").val()},a.fireAJAX(n,e,function(e){e.success?(r.after(e.data.html),o.find(".wpforms-provider-lists option").first().prop("selected",!0),o.find(".wpforms-provider-lists select").trigger("change")):a.errorDisplay(e.data.error,r)})):(o.find(".wpforms-provider-account-add input").val(""),o.find(".wpforms-provider-account-add").slideDown(),a.inputToggle(n,"enable"))},accountListSelect:function(e,n){n.preventDefault();var n=c(e),e=n.closest(".wpforms-provider-connection"),o=n.parent(),r=e.data("provider"),r=(a.inputToggle(n,"disable"),o.nextAll(".wpforms-connection-block").remove(),o.nextAll(".wpforms-conditional-block").remove(),{action:"wpforms_provider_ajax_"+r,provider:r,connection_id:e.data("connection_id"),task:"select_list",account_id:e.find(".wpforms-provider-accounts option:selected").val(),list_id:n.find(":selected").val(),form_id:s.form.data("id")});a.fireAJAX(n,r,function(e){e.success?(o.after(e.data.html),wpf.initTooltips()):a.errorDisplay(e.data.error,o)})},providerPanelConfirm:function(e){wpforms_panel_switch=!0,"providers"!==e||s.form.data("revision")||wpf.savedState!=wpf.getFormState("#wpforms-builder-form")&&(wpforms_panel_switch=!1,c.confirm({title:!1,content:wpforms_builder_providers.confirm_save,icon:"fa fa-info-circle",type:"blue",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"],action:function(){c("#wpforms-save").trigger("click"),c(document).on("wpformsSaved",function(){window.location.href=wpforms_builder_providers.url})}},cancel:{text:wpforms_builder.cancel}}}))},fireAJAX:function(e,n,o){var r=c(e),e={id:c("#wpforms-builder-form").data("id"),nonce:wpforms_builder.nonce};c.extend(e,n),c.post(wpforms_builder.ajax_url,e,function(e){o(e),a.inputToggle(r,"enable")}).fail(function(e,n,o){console.log(e.responseText)})},inputToggle:function(e,n){e=c(e);"enable"===n?(e.is("select")?e.prop("disabled",!1).next("i"):e.prop("disabled",!1).find("i")).remove():"disable"===n&&(e.is("select")?e.prop("disabled",!0).after(s.spinner):e.prop("disabled",!0).prepend(s.spinnerWhite))},errorDisplay:function(e,n){n.find(".wpforms-error-msg").remove(),n.prepend(''+e+"
")},requiredCheck:function(e,n){var o=!1;return n.find(".wpforms-alert-required").remove(),e.each(function(e,n){c(n).hasClass("wpforms-required")&&0===c(n).val().length?(c(n).addClass("wpforms-error"),o=!0):c(n).removeClass("wpforms-error")}),o&&n.prepend(''+wpforms_builder_providers.required_field+"
"),o},fakeSerialize:function(e){e=e.clone();return e.each(function(e,n){c(n).data("name")&&c(n).attr("name",c(n).data("name"))}),e.serialize()}};a.init()}(jQuery);