discourse/app/assets/javascripts/admin/routes/admin-user-badges.js

Failed to ignore revisions in .git-blame-ignore-revs.

28 lines
853 B
JavaScript
Raw Normal View History

import DiscourseRoute from "discourse/routes/discourse";
2018-06-15 23:03:24 +08:00
import UserBadge from "discourse/models/user-badge";
import Badge from "discourse/models/badge";
2015-08-19 09:24:09 +08:00
export default DiscourseRoute.extend({
2015-08-19 09:24:09 +08:00
model() {
2018-06-15 23:03:24 +08:00
const username = this.modelFor("adminUser").get("username");
2015-08-19 09:24:09 +08:00
return UserBadge.findByUsername(username);
},
setupController(controller, model) {
// Find all badges.
2018-06-15 23:03:24 +08:00
controller.set("loading", true);
2015-08-19 09:24:09 +08:00
Badge.findAll().then(function(badges) {
2018-06-15 23:03:24 +08:00
controller.set("badges", badges);
2015-08-19 09:24:09 +08:00
if (badges.length > 0) {
2018-06-15 23:03:24 +08:00
var grantableBadges = controller.get("grantableBadges");
2015-08-19 09:24:09 +08:00
if (grantableBadges.length > 0) {
2018-06-15 23:03:24 +08:00
controller.set("selectedBadgeId", grantableBadges[0].get("id"));
2015-08-19 09:24:09 +08:00
}
}
2018-06-15 23:03:24 +08:00
controller.set("loading", false);
2015-08-19 09:24:09 +08:00
});
// Set the model.
2018-06-15 23:03:24 +08:00
controller.set("model", model);
2015-08-19 09:24:09 +08:00
}
});