!function(){var e;e=jQuery,Craft.FieldSettingsToggle=Garnish.Base.extend({$toggle:null,$container:null,namespace:null,currentType:null,_cancelToken:null,_ignoreFailedRequest:!1,init:function(t,n,a,i){this.$toggle=e(t),this.$container=e(n),this.namespace=a,this.currentType=this.$toggle.val(),this.setSettings(i,Craft.FieldSettingsToggle.defaults),this.addListener(this.$toggle,"change","handleToggleChange")},handleToggleChange:function(){var t=this;this._cancelToken&&(this._ignoreFailedRequest=!0,this._cancelToken.cancel(),Garnish.requestAnimationFrame(function(){t._ignoreFailedRequest=!1}));var n=this.currentType,a=e("<form/>").append(this.$container.clone()).serialize();this.currentType=this.$toggle.val(),this.$container.html('<div class="zilch"><div class="spinner"></div></div>'),this._cancelToken=axios.CancelToken.source();var i={type:this.currentType,oldType:n,settings:a};this.namespace&&(i.namespace=this.namespace.replace(/__TYPE__/g,this.currentType),i.oldNamespace=this.namespace.replace(/__TYPE__/g,n)),Craft.sendActionRequest("POST","fields/render-settings",{cancelToken:this._cancelToken.token,data:i}).then(function(n){var a=e(n.data.settingsHtml||"");t.settings.wrapWithTypeClassDiv&&(a=e("<div/>",{id:Craft.formatInputId(t.currentType)}).append(a)),t.$container.html("").append(a),Craft.initUiElements(t.$container),Craft.appendHeadHtml(n.data.headHtml),Craft.appendBodyHtml(n.data.bodyHtml)}).catch(function(e){var n;t._ignoreFailedRequest||(Craft.cp.displayError(null==e||null===(n=e.response)||void 0===n||null===(n=n.data)||void 0===n?void 0:n.message),t.$container.html(""))})}},{defaults:{wrapWithTypeClassDiv:!1}})}();
//# sourceMappingURL=fieldsettings.js.map