discourse/app/assets/javascripts/admin/controllers/admin-users-list-show.js.es6

101 lines
2.8 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import debounce from "discourse/lib/debounce";
import { i18n } from "discourse/lib/computed";
import AdminUser from "admin/models/admin-user";
import { observes } from "ember-addons/ember-computed-decorators";
2015-08-08 03:08:27 +08:00
export default Ember.Controller.extend({
query: null,
2018-06-15 23:03:24 +08:00
queryParams: ["order", "ascending"],
order: null,
ascending: null,
showEmails: false,
refreshing: false,
listFilter: null,
selectAll: false,
2018-06-15 23:03:24 +08:00
queryNew: Em.computed.equal("query", "new"),
queryPending: Em.computed.equal("query", "pending"),
queryHasApproval: Em.computed.or("queryNew", "queryPending"),
showApproval: Em.computed.and(
"siteSettings.must_approve_users",
"queryHasApproval"
),
searchHint: i18n("search_hint"),
hasSelection: Em.computed.gt("selectedCount", 0),
selectedCount: function() {
2018-06-15 23:03:24 +08:00
var model = this.get("model");
if (!model || !model.length) return 0;
2018-06-15 23:03:24 +08:00
return model.filterBy("selected").length;
}.property("model.@each.selected"),
selectAllChanged: function() {
2018-06-15 23:03:24 +08:00
var val = this.get("selectAll");
this.get("model").forEach(function(user) {
if (user.get("can_approve")) {
user.set("selected", val);
}
});
2018-06-15 23:03:24 +08:00
}.observes("selectAll"),
title: function() {
2018-06-15 23:03:24 +08:00
return I18n.t("admin.users.titles." + this.get("query"));
}.property("query"),
2015-08-11 05:11:27 +08:00
_filterUsers: debounce(function() {
this._refreshUsers();
2018-06-15 23:03:24 +08:00
}, 250).observes("listFilter"),
2018-06-15 23:03:24 +08:00
@observes("order", "ascending")
_refreshUsers: function() {
2018-06-15 23:03:24 +08:00
this.set("refreshing", true);
2018-06-15 23:03:24 +08:00
AdminUser.findAll(this.get("query"), {
filter: this.get("listFilter"),
show_emails: this.get("showEmails"),
order: this.get("order"),
ascending: this.get("ascending")
})
.then(result => {
this.set("model", result);
})
.finally(() => {
this.set("refreshing", false);
});
},
actions: {
approveUsers: function() {
2018-06-15 23:03:24 +08:00
AdminUser.bulkApprove(this.get("model").filterBy("selected"));
this._refreshUsers();
},
rejectUsers: function() {
var maxPostAge = this.siteSettings.delete_user_max_post_age;
var controller = this;
2018-06-15 23:03:24 +08:00
AdminUser.bulkReject(this.get("model").filterBy("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: maxPostAge });
}
bootbox.alert(message);
controller._refreshUsers();
}
2018-06-15 23:03:24 +08:00
);
},
showEmails: function() {
2018-06-15 23:03:24 +08:00
this.set("showEmails", true);
this._refreshUsers(true);
}
}
});