FEATURE: split group admin in 2 tabs (custom & automatic)

FIX: clear the user-selector when adding new members
This commit is contained in:
Régis Hanol
2015-01-21 20:52:48 +01:00
parent 03eb4752d1
commit e300945879
20 changed files with 139 additions and 113 deletions

View File

@@ -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');

View File

@@ -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);
});
});
}
}
});

View File

@@ -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);
});
});
});
}
}
});

View File

@@ -0,0 +1,6 @@
export default Discourse.Route.extend({
renderTemplate: function() {
debugger;
this.render("admin/templates/group");
}
});

View File

@@ -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();
}
});

View File

@@ -0,0 +1,5 @@
export default Discourse.Route.extend({
redirect: function() {
this.transitionTo("adminGroupsType", "custom");
}
})

View File

@@ -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);
})
}
}
});

View File

@@ -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' });
});
});

View File

@@ -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);
}
}
});

View File

@@ -13,7 +13,7 @@
<li>{{#link-to 'adminBadges.index'}}{{i18n 'admin.badges.title'}}{{/link-to}}</li>
{{/if}}
{{#if currentUser.admin}}
<li>{{#link-to 'adminGroups.index'}}{{i18n 'admin.groups.title'}}{{/link-to}}</li>
<li>{{#link-to 'adminGroups'}}{{i18n 'admin.groups.title'}}{{/link-to}}</li>
{{/if}}
<li>{{#link-to 'adminEmail'}}{{i18n 'admin.email.title'}}{{/link-to}}</li>
<li>{{#link-to 'adminFlags'}}{{i18n 'admin.flags.title'}}{{/link-to}}</li>

View File

@@ -1,20 +1,11 @@
<div class='row groups'>
<div class='content-list span6'>
<h3>{{i18n 'admin.groups.edit'}}</h3>
<ul>
{{#each group in arrangedContent}}
<li>
<a href='#' {{action "showGroup" group}}>{{group.name}} <span class="count">{{group.userCountDisplay}}</span></a>
</li>
{{/each}}
<div class="admin-controls">
<div class="span15">
<ul class="nav nav-pills">
<li>{{#link-to "adminGroupsType" "custom"}}{{i18n 'admin.groups.custom'}}{{/link-to}}</li>
<li>{{#link-to "adminGroupsType" "automatic"}}{{i18n 'admin.groups.automatic'}}{{/link-to}}</li>
</ul>
<div class='controls'>
<button class='btn' {{bind-attr disabled="refreshingAutoGroups"}} {{action "refreshAutoGroups"}}><i class="fa fa-refresh"></i>{{i18n 'admin.groups.refresh'}}</button>
<button class='btn' {{action "newGroup"}}><i class="fa fa-plus"></i>{{i18n 'admin.groups.new'}}</button>
</div>
</div>
<div class='content-editor'>
{{outlet}}
</div>
</div>
<div class="admin-container">
{{outlet}}
</div>

View File

@@ -1 +0,0 @@
{{i18n 'admin.groups.about'}}

View File

@@ -0,0 +1,20 @@
<div class='row groups'>
<div class='content-list span6'>
<h3>{{i18n 'admin.groups.edit'}}</h3>
<ul>
{{#each group in controller}}
<li>
{{#link-to "adminGroup" group.type group.name}}{{group.name}} <span class="count">{{group.userCountDisplay}}</span>{{/link-to}}
</li>
{{/each}}
</ul>
<div class='controls'>
{{d-button action="newGroup" icon="plus" label="admin.groups.new"}}
{{d-button action="refreshAutoGroups" icon="refresh" label="admin.groups.refresh" disabled=refreshingAutoGroups}}
</div>
</div>
<div class='content-editor'>
{{outlet}}
</div>
</div>