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

27 lines
797 B
Plaintext
Raw Normal View History

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