'+wpforms_builder_providers.error_name+"
")).replace(/%type%/g,o);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(),o=this.$content.find(".error");if(""===e)return o.show(),!1;a.inputToggle(n,"disable");e={action:"wpforms_provider_ajax_"+t,provider:t,task:"new_connection",name:e,id:s.form.data("id"),nonce:wpforms_builder.nonce};a.fireAJAX(n,e,function(e){var o;e.success?(r.find(".wpforms-builder-provider-connections-default").addClass("wpforms-hidden"),r.find(".wpforms-provider-connections").prepend(e.data.html),(o=r.find(".wpforms-provider-connection:first")).find(".wpforms-provider-accounts option:selected")&&(o.find(".wpforms-provider-accounts option:first").prop("selected",!0),o.find(".wpforms-provider-accounts select").trigger("change"))):a.errorDisplay(e.data.error,i)})}},cancel:{text:wpforms_builder.cancel}}})},accountAdd:function(e,o){o.preventDefault();var n=c(e),r=n.data("provider"),i=n.closest(".wpforms-provider-connection"),t=n.parent(),o=t.find(":input"),e=a.requiredCheck(o,t);if(a.inputToggle(n,"disable"),e)return n.prop("disabled",!1).find("i").remove(),!1;o={action:"wpforms_provider_ajax_"+r,provider:r,connection_id:i.data("connection_id"),task:"new_account",data:a.fakeSerialize(o)};a.fireAJAX(n,o,function(e){e.success?(t.nextAll(".wpforms-connection-block").remove(),t.nextAll(".wpforms-conditional-block").remove(),t.after(e.data.html),t.slideUp(),i.find(".wpforms-provider-accounts select").trigger("change")):a.errorDisplay(e.data.error,t)})},accountSelect:function(e,o){o.preventDefault();var o=c(e),n=o.closest(".wpforms-provider-connection"),r=o.parent(),e=n.data("provider");a.inputToggle(o,"disable"),r.nextAll(".wpforms-connection-block").remove(),r.nextAll(".wpforms-conditional-block").remove(),o.val()?(n.find(".wpforms-provider-account-add").slideUp(),e={action:"wpforms_provider_ajax_"+e,provider:e,connection_id:n.data("connection_id"),task:"select_account",account_id:o.find(":selected").val()},a.fireAJAX(o,e,function(e){e.success?(r.after(e.data.html),n.find(".wpforms-provider-lists option:first").prop("selected",!0),n.find(".wpforms-provider-lists select").trigger("change")):a.errorDisplay(e.data.error,r)})):(n.find(".wpforms-provider-account-add input").val(""),n.find(".wpforms-provider-account-add").slideDown(),a.inputToggle(o,"enable"))},accountListSelect:function(e,o){o.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();o={action:"wpforms_provider_ajax_"+e,provider:e,connection_id:o.data("connection_id"),task:"select_list",account_id:o.find(".wpforms-provider-accounts option:selected").val(),list_id:n.find(":selected").val(),form_id:s.formID};a.fireAJAX(n,o,function(e){e.success?(r.after(e.data.html),wpf.initTooltips()):a.errorDisplay(e.data.error,r)})},providerPanelConfirm:function(e){wpforms_panel_switch=!0,"providers"===e&&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,o,n){var r=c(e),e={id:c("#wpforms-builder-form").data("id"),nonce:wpforms_builder.nonce};c.extend(e,o),c.post(wpforms_builder.ajax_url,e,function(e){n(e),a.inputToggle(r,"enable")}).fail(function(e,o,n){console.log(e.responseText)})},inputToggle:function(e,o){e=c(e);"enable"===o?(e.is("select")?e.prop("disabled",!1).next("i"):e.prop("disabled",!1).find("i")).remove():"disable"===o&&(e.is("select")?e.prop("disabled",!0).after(s.spinner):e.prop("disabled",!0).prepend(s.spinnerWhite))},errorDisplay:function(e,o){o.find(".wpforms-error-msg").remove(),o.prepend(''+e+"
")},requiredCheck:function(e,o){var n=!1;return o.find(".wpforms-alert-required").remove(),e.each(function(e,o){c(o).hasClass("wpforms-required")&&0===c(o).val().length?(c(o).addClass("wpforms-error"),n=!0):c(o).removeClass("wpforms-error")}),n&&o.prepend(''+wpforms_builder_providers.required_field+"
"),n},fakeSerialize:function(e){e=e.clone();return e.each(function(e,o){c(o).data("name")&&c(o).attr("name",c(o).data("name"))}),e.serialize()}};a.init()}(jQuery);