/** This controller supports the interface for listing users in the admin section. @class AdminUsersListController @extends Ember.ArrayController @namespace Discourse @module Discourse **/ export default Ember.ArrayController.extend(Discourse.Presence, { username: null, query: null, selectAll: false, loading: false, mustApproveUsers: Discourse.computed.setting('must_approve_users'), queryNew: Em.computed.equal('query', 'new'), queryPending: Em.computed.equal('query', 'pending'), queryHasApproval: Em.computed.or('queryNew', 'queryPending'), searchHint: function() { return I18n.t("search_hint"); }.property(), /** Triggered when the selectAll property is changed @event selectAll **/ selectAllChanged: function() { var _this = this; _.each(this.get('model'),function(user) { user.set('selected', _this.get('selectAll')); }); }.observes('selectAll'), /** 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 **/ orderChanged: function() { this.refreshUsers(); }.observes('query'), /** The title of the user list, based on which query was performed. @property title **/ title: function() { return I18n.t('admin.users.titles.' + this.get('query')); }.property('query'), /** Do we want to show the approval controls? @property showApproval **/ showApproval: function() { return Discourse.SiteSettings.must_approve_users && this.get('queryHasApproval'); }.property('queryPending'), /** How many users are currently selected @property selectedCount **/ selectedCount: function() { if (this.blank('model')) return 0; return this.get('model').filterProperty('selected').length; }.property('model.@each.selected'), /** Do we have any selected users? @property hasSelection **/ hasSelection: Em.computed.gt('selectedCount', 0), /** Refresh the current list of users. @method refreshUsers **/ refreshUsers: function(showEmails) { var adminUsersListController = this; adminUsersListController.set('loading', true); Discourse.AdminUser.findAll(this.get('query'), { filter: this.get('username'), show_emails: showEmails }).then(function (result) { adminUsersListController.set('model', result); adminUsersListController.set('loading', false); }); }, /** Show the list of users. @method show **/ show: function(term) { if (this.get('query') === term) { this.refreshUsers(); return; } this.set('query', term); }, actions: { approveUsers: function() { Discourse.AdminUser.bulkApprove(this.get('model').filterProperty('selected')); this.refreshUsers(); }, rejectUsers: function() { var controller = this; Discourse.AdminUser.bulkReject(this.get('model').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}); message += ' ' + I18n.t("admin.user.delete_forbidden", {count: Discourse.SiteSettings.delete_user_max_post_age}); } bootbox.alert(message); controller.refreshUsers(); }); }, showEmails: function() { this.refreshUsers(true); } } });