2015-08-19 09:24:09 +08:00
|
|
|
import Badge from "discourse/models/badge";
|
|
|
|
import UserBadge from "discourse/models/user-badge";
|
2023-10-11 02:38:59 +08:00
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
2015-08-19 09:24:09 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
export default class AdminUserBadgesRoute extends DiscourseRoute {
|
2015-08-19 09:24:09 +08:00
|
|
|
model() {
|
|
|
|
const username = this.modelFor("adminUser").get("username");
|
|
|
|
return UserBadge.findByUsername(username);
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2015-08-19 09:24:09 +08:00
|
|
|
|
2024-11-05 20:17:32 +08:00
|
|
|
setupController(controller) {
|
|
|
|
super.setupController(...arguments);
|
|
|
|
|
2015-08-19 09:24:09 +08:00
|
|
|
// Find all badges.
|
|
|
|
controller.set("loading", true);
|
|
|
|
Badge.findAll().then(function (badges) {
|
|
|
|
controller.set("badges", badges);
|
|
|
|
if (badges.length > 0) {
|
2023-09-14 10:05:29 +08:00
|
|
|
let grantableBadges = controller.get("availableBadges");
|
2015-08-19 09:24:09 +08:00
|
|
|
if (grantableBadges.length > 0) {
|
|
|
|
controller.set("selectedBadgeId", grantableBadges[0].get("id"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
controller.set("loading", false);
|
|
|
|
});
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
|
|
|
}
|