!function(){var e;e=jQuery,Craft.FieldSettingsToggle=Garnish.Base.extend({$toggle:null,$container:null,namespace:null,currentType:null,typeSettings:null,_cancelToken:null,_ignoreFailedRequest:!1,init:function(t,n,i,a){this.$toggle=e(t),this.$container=e(n),this.namespace=i,this.currentType=this.$toggle.val(),this.typeSettings={},this.setSettings(a,Craft.FieldSettingsToggle.defaults),this.addListener(this.$toggle,"change","handleToggleChange")},handleToggleChange:function(){var t=this;if(this._cancelToken&&(this._ignoreFailedRequest=!0,this._cancelToken.cancel(),Garnish.requestAnimationFrame((function(){t._ignoreFailedRequest=!1}))),this.typeSettings[this.currentType]=this.$container.children().detach(),this.currentType=this.$toggle.val(),void 0===this.typeSettings[this.currentType]){this.$container.html('<div class="zilch"><div class="spinner"></div></div>'),this._cancelToken=axios.CancelToken.source();var n={type:this.currentType};this.namespace&&(n.namespace=this.namespace.replace(/__TYPE__/g,this.currentType)),Craft.sendActionRequest("POST","fields/render-settings",{cancelToken:this._cancelToken.token,data:n}).then((function(n){var i=e(n.data.settingsHtml||"");t.settings.wrapWithTypeClassDiv&&(i=e("<div/>",{id:Craft.formatInputId(t.currentType)}).append(i)),t.$container.html("").append(i),Craft.initUiElements(t.$container),Craft.appendHeadHtml(n.data.headHtml),Craft.appendFootHtml(n.data.footHtml)})).catch((function(){t._ignoreFailedRequest||(Craft.cp.displayError(Craft.t("app","A server error occurred.")),t.$container.html(""))}))}else this.typeSettings[this.currentType].appendTo(this.$container)}},{defaults:{wrapWithTypeClassDiv:!1}})}();
//# sourceMappingURL=fieldsettings.js.map