Toggle button for bulk selection of topics

This commit is contained in:
Robin Ward 2014-01-28 17:13:13 -05:00
parent dc24226893
commit 1696cde2ff
8 changed files with 52 additions and 11 deletions

View File

@ -7,8 +7,10 @@
@module Discourse
**/
Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
actions: {
bulkSelectEnabled: false,
selected: [],
actions: {
// Show newly inserted topics
showInserted: function() {
var tracker = Discourse.TopicTrackingState.current();
@ -28,6 +30,11 @@ Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
self.set('model', list);
self.send('loadingComplete');
});
},
toggleBulkSelect: function() {
this.toggleProperty('bulkSelectEnabled');
this.get('selected').clear();
}
},
@ -35,6 +42,7 @@ Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
return Discourse.TopicTrackingState.current();
}.property(),
canBulkSelect: Em.computed.alias('currentUser.staff'),
hasTopics: Em.computed.gt('topics.length', 0),
showTable: Em.computed.or('hasTopics', 'topicTrackingState.hasIncoming'),
allLoaded: Em.computed.empty('more_topics_url'),

View File

@ -11,6 +11,21 @@ Discourse.TopicListItemController = Ember.ObjectController.extend({
canStar: Em.computed.alias('controllers.discoveryTopics.currentUser.id'),
hideCategory: Em.computed.alias('controllers.discoveryTopics.hideCategory'),
bulkSelectEnabled: Em.computed.alias('controllers.discoveryTopics.bulkSelectEnabled'),
checked: function(key, value) {
var selected = this.get('controllers.discoveryTopics.selected'),
topic = this.get('model');
if (arguments.length > 1) {
if (value) {
selected.addObject(topic);
} else {
selected.removeObject(topic);
}
}
return selected.contains(topic);
}.property('controllers.discoveryTopics.selected.length'),
actions: {
toggleStar: function() {

View File

@ -3,9 +3,11 @@
<table id='topic-list'>
<thead>
<tr>
{{#if currentUser}}
<th>&nbsp;</th>
{{/if}}
<th>
{{#if canBulkSelect}}
<button class='btn bulk-select' {{action toggleBulkSelect}} title="{{i18n topics.toggle_bulk_select}}"><i class='fa fa-list'></i></button>
{{/if}}
</th>
{{#sortable-heading sortBy="default" sortOrder=sortOrder}}
{{i18n topic.title}}
{{/sortable-heading}}

View File

@ -1,7 +1,13 @@
{{#if canStar}}
{{#if bulkSelectEnabled}}
<td class='star'>
<a {{bind-attr class=":star :fa :fa-star starred:starred"}} {{action toggleStar}} href='#' {{bind-attr title="starTooltip"}}></a>
{{input type="checkbox" checked=checked}}
</td>
{{else}}
{{#if canStar}}
<td class='star'>
<a {{bind-attr class=":star :fa :fa-star starred:starred"}} {{action toggleStar}} href='#' {{bind-attr title="starTooltip"}}></a>
</td>
{{/if}}
{{/if}}
<td class='main-link clearfix'>

View File

@ -2,16 +2,15 @@
This view handles the rendering of a topic in a list
@class TopicListItemView
@extends Discourse.GroupedView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
Discourse.TopicListItemView = Discourse.GroupedView.extend({
tagName: 'tr',
templateName: 'list/topic_list_item',
classNameBindings: ['content.archived', ':topic-list-item', 'content.hasExcerpt:has-excerpt'],
classNameBindings: ['controller.checked', 'content.archived', ':topic-list-item', 'content.hasExcerpt:has-excerpt'],
attributeBindings: ['data-topic-id'],
'data-topic-id': Em.computed.alias('content.id'),
highlight: function() {

View File

@ -21,8 +21,6 @@ Discourse.GroupedView = Ember.View.extend(Discourse.Presence, {
}
});
Discourse.View.reopenClass({
/**

View File

@ -69,6 +69,9 @@
&:nth-child(even) {
background-color: #f8f8f8;
}
&.checked {
background-color: $highlight;
}
&.archived a {
opacity: 0.6;
}
@ -112,6 +115,14 @@
font-size: 14px;
}
button.bulk-select {
padding: 0;
background: transparent;
&:hover {
color: #999;
}
}
.star {
width: 20px;
padding-right: 0;

View File

@ -600,6 +600,8 @@ en:
unstar: 'remove this topic from your starred list'
topics:
toggle_bulk_select: "toggle bulk selection of topics"
none:
starred: "You haven't starred any topics yet. To star a topic, click or tap the star next to the title."
unread: "You have no unread topics."