Use an `itemController` for topic lists. This will make bulk operations

easier.
This commit is contained in:
Robin Ward 2014-01-28 14:44:26 -05:00
parent 52ff68f74f
commit 4626519cdc
4 changed files with 26 additions and 11 deletions

View File

@ -8,10 +8,6 @@
**/
Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
actions: {
// Star a topic
toggleStar: function(topic) {
topic.toggleStar();
},
// Show newly inserted topics
showInserted: function() {

View File

@ -0,0 +1,21 @@
/**
Handles displaying of a topic as a list item
@class TopicListItemController
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.TopicListItemController = Ember.ObjectController.extend({
needs: ['discoveryTopics'],
canStar: Em.computed.alias('controllers.discoveryTopics.currentUser.id'),
hideCategory: Em.computed.alias('controllers.discoveryTopics.hideCategory'),
actions: {
toggleStar: function() {
this.get('model').toggleStar();
}
}
});

View File

@ -45,7 +45,7 @@
</tbody>
{{/if}}
{{collection contentBinding="topics" tagName="tbody" itemViewClass="Discourse.TopicListItemView"}}
{{each topics itemController="topicListItem" itemViewClass="Discourse.TopicListItemView"}}
</table>
{{/if}}
</div>

View File

@ -1,6 +1,6 @@
{{#if controller.currentUser.id}}
{{#if canStar}}
<td class='star'>
<a {{bind-attr class=":star :fa :fa-star starred:starred"}} {{action toggleStar this}} href='#' {{bind-attr title="starTooltip"}}></a>
<a {{bind-attr class=":star :fa :fa-star starred:starred"}} {{action toggleStar}} href='#' {{bind-attr title="starTooltip"}}></a>
</td>
{{/if}}
@ -30,10 +30,8 @@
{{/if}}
</td>
{{#unless controller.hideCategory}}
<td class='category'>
{{categoryLink category}}
</td>
{{#unless hideCategory}}
<td class='category'>{{categoryLink category}}</td>
{{/unless}}
<td class='posters'>