This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/badges/show.js.es6
2015-05-11 11:18:37 -04:00

52 lines
1.3 KiB
JavaScript

import ObjectController from 'discourse/controllers/object';
export default ObjectController.extend({
noMoreBadges: false,
userBadges: null,
needs: ["application"],
actions: {
loadMore() {
const self = this;
const userBadges = this.get('userBadges');
Discourse.UserBadge.findByBadgeId(this.get('model.id'), {
offset: userBadges.length
}).then(function(result) {
userBadges.pushObjects(result);
if(userBadges.length === 0){
self.set('noMoreBadges', true);
}
});
}
},
layoutClass: function(){
var ub = this.get("userBadges");
if(ub && ub[0] && ub[0].post_id){
return "user-badge-with-posts";
} else {
return "user-badge-no-posts";
}
}.property("userBadges"),
canLoadMore: function() {
if (this.get('noMoreBadges')) { return false; }
if (this.get('userBadges')) {
return this.get('model.grant_count') > this.get('userBadges.length');
} else {
return false;
}
}.property('noMoreBadges', 'model.grant_count', 'userBadges.length'),
_showFooter: function() {
this.set("controllers.application.showFooter", !this.get("canLoadMore"));
}.observes("canLoadMore"),
showLongDescription: function(){
return window.location.search.match("long-description");
}.property('userBadges')
});