diff --git a/app/assets/javascripts/admin/controllers/admin-group.js.es6 b/app/assets/javascripts/admin/controllers/admin-group.js.es6 index 6bd8eda6b..89b448b52 100644 --- a/app/assets/javascripts/admin/controllers/admin-group.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-group.js.es6 @@ -1,7 +1,6 @@ export default Em.ObjectController.extend({ - needs: ['adminGroups'], + needs: ['adminGroupsType'], disableSave: false, - usernames: null, currentPage: function() { if (this.get("user_count") == 0) { return 0; } @@ -59,28 +58,29 @@ export default Em.ObjectController.extend({ }, addMembers: function() { - // TODO: should clear the input if (Em.isEmpty(this.get("usernames"))) { return; } this.get("model").addMembers(this.get("usernames")); + // clear the user selector + this.set("usernames", null); }, save: function() { var self = this, - group = this.get('model'); + group = this.get('model'), + groupsController = this.get("controllers.adminGroupsType"); - self.set('disableSave', true); + this.set('disableSave', true); var promise; - if (group.get('id')) { + if (group.get("id")) { promise = group.save(); } else { promise = group.create().then(function() { - var groupsController = self.get('controllers.adminGroups'); groupsController.addObject(group); }); } promise.then(function() { - self.send('showGroup', group); + self.transitionToRoute("adminGroup", group); }, function(e) { var message = $.parseJSON(e.responseText).errors; bootbox.alert(message); @@ -91,12 +91,13 @@ export default Em.ObjectController.extend({ destroy: function() { var group = this.get('model'), - groupsController = this.get('controllers.adminGroups'), + groupsController = this.get('controllers.adminGroupsType'), self = this; - bootbox.confirm(I18n.t("admin.groups.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) { - if (result) { - self.set('disableSave', true); + this.set('disableSave', true); + + bootbox.confirm(I18n.t("admin.groups.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(confirmed) { + if (confirmed) { group.destroy().then(function() { groupsController.get('model').removeObject(group); self.transitionToRoute('adminGroups.index'); diff --git a/app/assets/javascripts/admin/controllers/admin-groups-type.js.es6 b/app/assets/javascripts/admin/controllers/admin-groups-type.js.es6 new file mode 100644 index 000000000..2d75d1911 --- /dev/null +++ b/app/assets/javascripts/admin/controllers/admin-groups-type.js.es6 @@ -0,0 +1,16 @@ +export default Ember.ArrayController.extend({ + sortProperties: ['name'], + refreshingAutoGroups: false, + + actions: { + refreshAutoGroups: function(){ + var self = this; + this.set('refreshingAutoGroups', true); + Discourse.ajax('/admin/groups/refresh_automatic_groups', {type: 'POST'}).then(function() { + self.transitionToRoute("adminGroupsType", "automatic").then(function() { + self.set('refreshingAutoGroups', false); + }); + }); + } + } +}); diff --git a/app/assets/javascripts/admin/controllers/admin-groups.js.es6 b/app/assets/javascripts/admin/controllers/admin-groups.js.es6 deleted file mode 100644 index 03de7cfe9..000000000 --- a/app/assets/javascripts/admin/controllers/admin-groups.js.es6 +++ /dev/null @@ -1,24 +0,0 @@ -export default Ember.ArrayController.extend({ - sortProperties: ['name'], - - refreshingAutoGroups: false, - - actions: { - refreshAutoGroups: function(){ - var self = this, - groups = this.get('model'); - - self.set('refreshingAutoGroups', true); - this.transitionToRoute('adminGroups.index').then(function() { - Discourse.ajax('/admin/groups/refresh_automatic_groups', {type: 'POST'}).then(function() { - return Discourse.Group.findAll().then(function(newGroups) { - groups.clear(); - groups.addObjects(newGroups); - }).finally(function() { - self.set('refreshingAutoGroups', false); - }); - }); - }); - } - } -}); diff --git a/app/assets/javascripts/admin/routes/admin-group-new.js.es6 b/app/assets/javascripts/admin/routes/admin-group-new.js.es6 new file mode 100644 index 000000000..5e1cff95a --- /dev/null +++ b/app/assets/javascripts/admin/routes/admin-group-new.js.es6 @@ -0,0 +1,6 @@ +export default Discourse.Route.extend({ + renderTemplate: function() { + debugger; + this.render("admin/templates/group"); + } +}); diff --git a/app/assets/javascripts/admin/routes/admin_group_route.js b/app/assets/javascripts/admin/routes/admin-group.js.es6 similarity index 60% rename from app/assets/javascripts/admin/routes/admin_group_route.js rename to app/assets/javascripts/admin/routes/admin-group.js.es6 index 89388e1c3..f39729776 100644 --- a/app/assets/javascripts/admin/routes/admin_group_route.js +++ b/app/assets/javascripts/admin/routes/admin-group.js.es6 @@ -1,17 +1,20 @@ -Discourse.AdminGroupRoute = Discourse.Route.extend({ +export default Discourse.Route.extend({ model: function(params) { - var groups = this.modelFor('adminGroups'), + var groups = this.modelFor('adminGroupsType'), group = groups.findProperty('name', params.name); if (!group) { return this.transitionTo('adminGroups.index'); } + return group; }, setupController: function(controller, model) { controller.set("model", model); + // clear the user selector + controller.set("usernames", null); + // load the members of the group model.findMembers(); } }); - diff --git a/app/assets/javascripts/admin/routes/admin-groups-index.js.es6 b/app/assets/javascripts/admin/routes/admin-groups-index.js.es6 new file mode 100644 index 000000000..33c42cbb0 --- /dev/null +++ b/app/assets/javascripts/admin/routes/admin-groups-index.js.es6 @@ -0,0 +1,5 @@ +export default Discourse.Route.extend({ + redirect: function() { + this.transitionTo("adminGroupsType", "custom"); + } +}) diff --git a/app/assets/javascripts/admin/routes/admin-groups-type.js.es6 b/app/assets/javascripts/admin/routes/admin-groups-type.js.es6 new file mode 100644 index 000000000..5c04e2506 --- /dev/null +++ b/app/assets/javascripts/admin/routes/admin-groups-type.js.es6 @@ -0,0 +1,17 @@ +export default Discourse.Route.extend({ + model: function(params) { + return Discourse.Group.findAll().then(function(groups) { + return groups.filterBy("type", params.type); + }); + }, + + actions: { + newGroup: function() { + var 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/routes/admin-route-map.js.es6 b/app/assets/javascripts/admin/routes/admin-route-map.js.es6 index 8d868d711..c5ce804ef 100644 --- a/app/assets/javascripts/admin/routes/admin-route-map.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-route-map.js.es6 @@ -40,8 +40,10 @@ export default function() { this.route('screenedUrls', { path: '/screened_urls' }); }); - this.resource('adminGroups', { path: '/groups'}, function() { - this.resource('adminGroup', { path: '/:name' }); + this.resource('adminGroups', { path: '/groups' }, function() { + this.resource('adminGroupsType', { path: '/:type' }, function() { + this.resource('adminGroup', { path: '/:name' }); + }); }); this.resource('adminUsers', { path: '/users' }, function() { @@ -51,7 +53,7 @@ export default function() { }); this.resource('adminUsersList', { path: '/list' }, function() { - this.route('show', {path: '/:filter'}); + this.route('show', { path: '/:filter' }); }); }); diff --git a/app/assets/javascripts/admin/routes/admin_groups_route.js b/app/assets/javascripts/admin/routes/admin_groups_route.js deleted file mode 100644 index e66299a50..000000000 --- a/app/assets/javascripts/admin/routes/admin_groups_route.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - Handles routes for admin groups - - @class AdminGroupsRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminGroupsRoute = Discourse.Route.extend({ - model: function() { - return Discourse.Group.findAll(); - }, - - actions: { - showGroup: function(g) { - // This hack is needed because the autocomplete plugin does not - // refresh properly when the underlying data changes. TODO should - // be to update the plugin so it works properly and remove this hack. - var self = this; - this.transitionTo('adminGroups.index').then(function() { - self.transitionTo('adminGroup', g); - }); - }, - - newGroup: function(){ - var group = Discourse.Group.create({ visible: true }); - this.send('showGroup', group); - } - } -}); - diff --git a/app/assets/javascripts/admin/templates/admin.hbs b/app/assets/javascripts/admin/templates/admin.hbs index 209a6dc29..0958fe0d4 100644 --- a/app/assets/javascripts/admin/templates/admin.hbs +++ b/app/assets/javascripts/admin/templates/admin.hbs @@ -13,7 +13,7 @@
  • {{#link-to 'adminBadges.index'}}{{i18n 'admin.badges.title'}}{{/link-to}}
  • {{/if}} {{#if currentUser.admin}} -
  • {{#link-to 'adminGroups.index'}}{{i18n 'admin.groups.title'}}{{/link-to}}
  • +
  • {{#link-to 'adminGroups'}}{{i18n 'admin.groups.title'}}{{/link-to}}
  • {{/if}}
  • {{#link-to 'adminEmail'}}{{i18n 'admin.email.title'}}{{/link-to}}
  • {{#link-to 'adminFlags'}}{{i18n 'admin.flags.title'}}{{/link-to}}
  • diff --git a/app/assets/javascripts/admin/templates/groups.hbs b/app/assets/javascripts/admin/templates/groups.hbs index 061bf715d..751e46323 100644 --- a/app/assets/javascripts/admin/templates/groups.hbs +++ b/app/assets/javascripts/admin/templates/groups.hbs @@ -1,20 +1,11 @@ -
    -
    -

    {{i18n 'admin.groups.edit'}}

    -