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/poster_expansion_controller.js
Robin Ward cf6cbb955b REFACTOR: Introduce Discourse.computed.setting to create a computed
property that links to a `Discourse.SiteSetting`
2014-04-24 18:36:02 -04:00

87 lines
2.3 KiB
JavaScript

/**
A controller for expanding information about a poster.
@class PosterExpansion
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.PosterExpansionController = Discourse.ObjectController.extend({
needs: ['topic'],
visible: false,
user: null,
participant: null,
postStream: Em.computed.alias('controllers.topic.postStream'),
enoughPostsForFiltering: Em.computed.gte('participant.post_count', 2),
showFilter: Em.computed.and('postStream.hasNoFilters', 'enoughPostsForFiltering'),
showName: Discourse.computed.propertyNotEqual('user.name', 'user.username'),
hasUserFilters: Em.computed.gt('postStream.userFilters.length', 0),
showBadges: Discourse.computed.setting('enable_badges'),
moreBadgesCount: function() {
return this.get('user.badge_count') - this.get('user.featured_user_badges.length');
}.property('user.badge_count', 'user.featured_user_badges.@each'),
showMoreBadges: Em.computed.gt('moreBadgesCount', 0),
show: function(post) {
// Don't show on mobile
if (Discourse.Mobile.mobileView) {
Discourse.URL.routeTo(post.get('usernameUrl'));
return;
}
var currentPostId = this.get('id'),
wasVisible = this.get('visible');
this.setProperties({model: post, visible: true});
// If we click the avatar again, close it.
if (post.get('id') === currentPostId && wasVisible) {
this.setProperties({ visible: false, model: null });
return;
}
this.set('participant', null);
// Retrieve their participants info
var participants = this.get('topic.details.participants');
if (participants) {
this.set('participant', participants.findBy('username', post.get('username')));
}
var self = this;
self.set('user', null);
Discourse.User.findByUsername(post.get('username')).then(function (user) {
self.set('user', user);
});
},
close: function() {
this.set('visible', false);
},
actions: {
togglePosts: function(user) {
var postStream = this.get('controllers.topic.postStream');
postStream.toggleParticipant(user.get('username'));
this.close();
},
cancelFilter: function() {
var postStream = this.get('postStream');
postStream.cancelFilter();
postStream.refresh();
this.close();
}
}
});