!function(){var t,e;t=jQuery,e=Garnish.Base.extend({$groups:null,$selectedGroup:null,init:function(){var e=this;this.$groups=t("#groups"),this.$selectedGroup=this.$groups.find("a.sel:first"),this.addListener(t("#newgroupbtn"),"activate","addNewGroup");var r=t("#groupsettingsbtn");r.length&&(r.data("menubtn").settings.onOptionSelect=function(r){switch(t(r).data("action")){case"rename":e.renameSelectedGroup();break;case"delete":e.deleteSelectedGroup()}})},addNewGroup:function(){var t=this,e=this.promptForGroupName("");if(e){var r={name:e};Craft.sendActionRequest("POST","fields/save-group",{data:r}).then((function(t){location.href=Craft.getUrl("settings/fields/"+t.data.group.id)})).catch((function(e){var r=e.response;if(r.data.errors){var a=t.flattenErrors(r.data.errors);Craft.cp.displayError(Craft.t("app","Could not create the group:")+"\n\n"+a.join("\n"))}else Craft.cp.displayError()}))}},renameSelectedGroup:function(){var t=this,e=this.$selectedGroup.text(),r=this.promptForGroupName(e);if(r&&r!==e){var a={id:this.$selectedGroup.data("id"),name:r};Craft.sendActionRequest("POST","fields/save-group",{data:a}).then((function(e){t.$selectedGroup.text(e.data.group.name),Craft.cp.displaySuccess(Craft.t("app","Group renamed."))})).catch((function(e){var r=e.response;if(r.data.errors){var a=t.flattenErrors(r.data.errors);Craft.cp.displayError(Craft.t("app","Could not rename the group:")+"\n\n"+a.join("\n"))}else Craft.cp.displayError()}))}},promptForGroupName:function(t){return prompt(Craft.t("app","What do you want to name the group?"),t)},deleteSelectedGroup:function(){if(confirm(Craft.t("app","Are you sure you want to delete this group and all its fields?"))){var t={id:this.$selectedGroup.data("id")};Craft.sendActionRequest("POST","fields/delete-group",{data:t}).then((function(t){location.href=Craft.getUrl("settings/fields")})).catch((function(t){t.response,Craft.cp.displayError()}))}},flattenErrors:function(t){var e=[];for(var r in t)t.hasOwnProperty(r)&&(e=e.concat(t[r]));return e}}),Garnish.$doc.ready((function(){Craft.FieldsAdmin=new e}))}();
//# sourceMappingURL=fields.js.map