2013-02-23 04:41:12 +08:00
|
|
|
/**
|
|
|
|
This controller supports the interface for listing users in the admin section.
|
|
|
|
|
2013-05-07 23:15:28 +08:00
|
|
|
@class AdminUsersListController
|
2013-02-23 04:41:12 +08:00
|
|
|
@extends Ember.ArrayController
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-05-07 23:15:28 +08:00
|
|
|
**/
|
2014-07-23 11:20:45 +08:00
|
|
|
export default Ember.ArrayController.extend(Discourse.Presence, {
|
2013-02-23 04:41:12 +08:00
|
|
|
username: null,
|
|
|
|
query: null,
|
|
|
|
selectAll: false,
|
|
|
|
content: null,
|
2013-04-23 22:29:18 +08:00
|
|
|
loading: false,
|
2013-02-21 02:15:50 +08:00
|
|
|
|
2014-09-12 04:30:47 +08:00
|
|
|
mustApproveUsers: Discourse.computed.setting('must_approve_users'),
|
2013-07-15 23:28:41 +08:00
|
|
|
queryNew: Em.computed.equal('query', 'new'),
|
|
|
|
queryPending: Em.computed.equal('query', 'pending'),
|
|
|
|
queryHasApproval: Em.computed.or('queryNew', 'queryPending'),
|
|
|
|
|
2014-10-07 18:05:38 +08:00
|
|
|
searchHint: function() {
|
|
|
|
var searchHintKey = Discourse.User.currentProp("admin") ? "search_hint_admin" : "search_hint";
|
|
|
|
return I18n.t(searchHintKey);
|
|
|
|
}.property(),
|
|
|
|
|
2013-02-22 01:58:21 +08:00
|
|
|
/**
|
2013-02-23 04:41:12 +08:00
|
|
|
Triggered when the selectAll property is changed
|
|
|
|
|
|
|
|
@event selectAll
|
|
|
|
**/
|
2013-05-15 00:03:15 +08:00
|
|
|
selectAllChanged: function() {
|
2013-02-23 04:41:12 +08:00
|
|
|
var _this = this;
|
2013-06-11 04:48:50 +08:00
|
|
|
_.each(this.get('content'),function(user) {
|
2013-02-23 04:41:12 +08:00
|
|
|
user.set('selected', _this.get('selectAll'));
|
|
|
|
});
|
2013-05-15 00:03:15 +08:00
|
|
|
}.observes('selectAll'),
|
2013-02-23 04:41:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Triggered when the username filter is changed
|
|
|
|
|
|
|
|
@event filterUsers
|
|
|
|
**/
|
|
|
|
filterUsers: Discourse.debounce(function() {
|
|
|
|
this.refreshUsers();
|
|
|
|
}, 250).observes('username'),
|
|
|
|
|
|
|
|
/**
|
|
|
|
Triggered when the order of the users list is changed
|
|
|
|
|
|
|
|
@event orderChanged
|
|
|
|
**/
|
2013-05-15 00:03:15 +08:00
|
|
|
orderChanged: function() {
|
2013-02-23 04:41:12 +08:00
|
|
|
this.refreshUsers();
|
2013-05-15 00:03:15 +08:00
|
|
|
}.observes('query'),
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2013-04-23 22:29:18 +08:00
|
|
|
/**
|
|
|
|
The title of the user list, based on which query was performed.
|
|
|
|
|
|
|
|
@property title
|
|
|
|
**/
|
|
|
|
title: function() {
|
2013-07-09 07:32:16 +08:00
|
|
|
return I18n.t('admin.users.titles.' + this.get('query'));
|
2013-04-23 22:29:18 +08:00
|
|
|
}.property('query'),
|
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
/**
|
|
|
|
Do we want to show the approval controls?
|
|
|
|
|
|
|
|
@property showApproval
|
|
|
|
**/
|
2013-05-15 00:03:15 +08:00
|
|
|
showApproval: function() {
|
2013-07-15 23:28:41 +08:00
|
|
|
return Discourse.SiteSettings.must_approve_users && this.get('queryHasApproval');
|
|
|
|
}.property('queryPending'),
|
2013-02-22 01:54:40 +08:00
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
/**
|
|
|
|
How many users are currently selected
|
2013-02-22 03:42:48 +08:00
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
@property selectedCount
|
|
|
|
**/
|
2013-05-15 00:03:15 +08:00
|
|
|
selectedCount: function() {
|
2013-02-23 04:41:12 +08:00
|
|
|
if (this.blank('content')) return 0;
|
|
|
|
return this.get('content').filterProperty('selected').length;
|
2013-05-15 00:03:15 +08:00
|
|
|
}.property('content.@each.selected'),
|
2013-02-23 04:41:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Do we have any selected users?
|
|
|
|
|
|
|
|
@property hasSelection
|
|
|
|
**/
|
2013-07-12 07:35:52 +08:00
|
|
|
hasSelection: Em.computed.gt('selectedCount', 0),
|
2013-02-23 04:41:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Refresh the current list of users.
|
|
|
|
|
|
|
|
@method refreshUsers
|
|
|
|
**/
|
|
|
|
refreshUsers: function() {
|
2013-05-07 23:15:28 +08:00
|
|
|
var adminUsersListController = this;
|
|
|
|
adminUsersListController.set('loading', true);
|
|
|
|
|
2014-07-08 04:18:18 +08:00
|
|
|
Discourse.AdminUser.findAll(this.get('query'), { filter: this.get('username') }).then(function (result) {
|
2013-05-07 23:15:28 +08:00
|
|
|
adminUsersListController.set('content', result);
|
|
|
|
adminUsersListController.set('loading', false);
|
2013-06-22 02:06:20 +08:00
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Show the list of users.
|
|
|
|
|
|
|
|
@method show
|
|
|
|
**/
|
|
|
|
show: function(term) {
|
|
|
|
if (this.get('query') === term) {
|
2013-02-22 01:58:21 +08:00
|
|
|
this.refreshUsers();
|
2013-02-23 04:41:12 +08:00
|
|
|
return;
|
2013-02-21 02:15:50 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
this.set('query', term);
|
|
|
|
},
|
2013-02-21 02:15:50 +08:00
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
/**
|
|
|
|
Approve all the currently selected users.
|
|
|
|
|
|
|
|
@method approveUsers
|
|
|
|
**/
|
|
|
|
approveUsers: function() {
|
|
|
|
Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected'));
|
2013-06-05 23:57:25 +08:00
|
|
|
this.refreshUsers();
|
2013-08-16 23:42:24 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reject all the currently selected users.
|
|
|
|
|
|
|
|
@method rejectUsers
|
|
|
|
**/
|
|
|
|
rejectUsers: function() {
|
|
|
|
var controller = this;
|
|
|
|
Discourse.AdminUser.bulkReject(this.get('content').filterProperty('selected')).then(function(result){
|
|
|
|
var message = I18n.t("admin.users.reject_successful", {count: result.success});
|
|
|
|
if (result.failed > 0) {
|
|
|
|
message += ' ' + I18n.t("admin.users.reject_failures", {count: result.failed});
|
2014-02-21 01:29:40 +08:00
|
|
|
message += ' ' + I18n.t("admin.user.delete_forbidden", {count: Discourse.SiteSettings.delete_user_max_post_age});
|
2013-08-16 23:42:24 +08:00
|
|
|
}
|
|
|
|
bootbox.alert(message);
|
|
|
|
controller.refreshUsers();
|
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
}
|
2013-05-07 23:15:28 +08:00
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|