From 87725206cd15ec33b63fd6bf316b744c8b0f7fac Mon Sep 17 00:00:00 2001 From: getabetterpic Date: Thu, 17 Sep 2015 10:20:21 -0400 Subject: [PATCH] Fix bug when adding new custom group When adding a new group, if Delete was clicked before saving the group, the modal would come up, but the Yes confirmation would do nothing. This fixes that by taking an approach similar to the Badges and checks to see if the Group is new, and if it is, just returns to the index instead of invoking the confirm modal. This also fixes the redirect after saving a new Group. --- .../admin/controllers/admin-group.js.es6 | 10 ++++++++-- .../javascripts/admin/routes/admin-group.js.es6 | 13 +++++++++++-- .../admin/routes/admin-groups-type.js.es6 | 10 ---------- .../javascripts/admin/templates/groups_type.hbs | 4 +++- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin-group.js.es6 b/app/assets/javascripts/admin/controllers/admin-group.js.es6 index 2ee95299a18..dbe31af85ea 100644 --- a/app/assets/javascripts/admin/controllers/admin-group.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-group.js.es6 @@ -75,13 +75,14 @@ export default Ember.Controller.extend({ save() { const group = this.get('model'), - groupsController = this.get("controllers.adminGroupsType"); + groupsController = this.get("controllers.adminGroupsType"), + groupType = groupsController.get("type"); this.set('disableSave', true); let promise = group.get("id") ? group.save() : group.create().then(() => groupsController.addObject(group)); - promise.then(() => this.transitionToRoute("adminGroup", group)) + promise.then(() => this.transitionToRoute("adminGroup", groupType, group.get('name'))) .catch(popupAjaxError) .finally(() => this.set('disableSave', false)); }, @@ -91,6 +92,11 @@ export default Ember.Controller.extend({ groupsController = this.get('controllers.adminGroupsType'), self = this; + if (!group.get('id')) { + self.transitionToRoute('adminGroupsType.index', 'custom'); + return; + } + this.set('disableSave', true); bootbox.confirm( diff --git a/app/assets/javascripts/admin/routes/admin-group.js.es6 b/app/assets/javascripts/admin/routes/admin-group.js.es6 index fd56aeca52d..b46022a6460 100644 --- a/app/assets/javascripts/admin/routes/admin-group.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-group.js.es6 @@ -1,8 +1,17 @@ +import Group from 'discourse/models/group'; + export default Discourse.Route.extend({ model: function(params) { - var groups = this.modelFor('adminGroupsType'), - group = groups.findProperty('name', params.name); + var groups = this.modelFor('adminGroupsType'); + if (params.name === 'new') { + return Group.create({ + automatic: false, + visible: true + }); + } + + var group = groups.findProperty('name', params.name); if (!group) { return this.transitionTo('adminGroups.index'); } diff --git a/app/assets/javascripts/admin/routes/admin-groups-type.js.es6 b/app/assets/javascripts/admin/routes/admin-groups-type.js.es6 index c8226f04dc4..def99aa7c15 100644 --- a/app/assets/javascripts/admin/routes/admin-groups-type.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-groups-type.js.es6 @@ -9,15 +9,5 @@ export default Discourse.Route.extend({ setupController(controller, model){ controller.set("type", this.get("type")); controller.set("model", model); - }, - - actions: { - newGroup() { - const self = this; - this.transitionTo("adminGroupsType", "custom").then(function() { - var group = Discourse.Group.create({ automatic: false, visible: true }); - self.transitionTo("adminGroup", group); - }); - } } }); diff --git a/app/assets/javascripts/admin/templates/groups_type.hbs b/app/assets/javascripts/admin/templates/groups_type.hbs index 8188752a9ad..980ca08c8f6 100644 --- a/app/assets/javascripts/admin/templates/groups_type.hbs +++ b/app/assets/javascripts/admin/templates/groups_type.hbs @@ -9,7 +9,9 @@ {{/each}}
- {{d-button action="newGroup" icon="plus" label="admin.groups.new"}} + {{#link-to 'adminGroup' 'new' class="btn"}} + {{fa-icon "plus"}} {{i18n 'admin.groups.new'}} + {{/link-to}} {{#if controller.isAuto}} {{d-button action="refreshAutoGroups" icon="refresh" label="admin.groups.refresh" disabled=refreshingAutoGroups}} {{/if}}