discourse/app/assets/javascripts/discourse/components/topic_map_component.js
Robin Ward a524194a46 FIX: Bugged up Components vs. Views. My original error was using
`templateName` instead of `layoutName` in an `Em.Component`. This fixes
that and backs out other "fixes"
2014-01-21 13:08:47 -05:00

54 lines
1.4 KiB
JavaScript

/**
The topic map underneath the first post of a topic.
@class TopicMapComponent
@extends Ember.Component
@namespace Discourse
@module Discourse
**/
var LINKS_SHOWN = 5;
Discourse.TopicMapComponent = Ember.Component.extend({
mapCollapsed: true,
layoutName: 'components/topic-map',
details: Em.computed.alias('topic.details'),
allLinksShown: false,
init: function() {
this._super();
// If the topic has a summary, expand the map by default
this.set('mapCollapsed', Discourse.Mobile.mobileView || (!this.get('topic.has_summary')));
},
toggleMapClass: function() {
return this.get('mapCollapsed') ? 'fa fa-chevron-down' : 'fa fa-chevron-up';
}.property('mapCollapsed'),
showAllLinksControls: function() {
if (this.get('allLinksShown')) return false;
if ((this.get('details.links.length') || 0) <= LINKS_SHOWN) return false;
return true;
}.property('allLinksShown', 'topic.details.links'),
infoLinks: function() {
var allLinks = this.get('details.links');
if (Em.isNone(allLinks)) return [];
if (this.get('allLinksShown')) return allLinks;
return allLinks.slice(0, LINKS_SHOWN);
}.property('details.links', 'allLinksShown'),
actions: {
toggleMap: function() {
this.toggleProperty('mapCollapsed');
},
showAllLinks: function() {
this.set('allLinksShown', true);
}
}
});