Front end code is complete for changing categories of topics in bulk

This commit is contained in:
Robin Ward 2014-01-29 15:48:52 -05:00
parent 6ee266c7ee
commit 0c73eb8ce1
14 changed files with 85 additions and 14 deletions

View file

@ -10,5 +10,40 @@
Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.ModalFunctionality, { Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.ModalFunctionality, {
onShow: function() { onShow: function() {
this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal'); this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal');
},
perform: function(operation) {
this.set('loading', true);
var self = this,
topics = this.get('model');
return Discourse.Topic.bulkOperation(this.get('model'), operation).then(function(result) {
self.set('loading', false);
if (result && result.topic_ids) {
return result.topic_ids.map(function (t) {
return topics.findBy('id', t);
});
}
return result;
}).catch(function() {
self.set('loading', false);
});
},
actions: {
showChangeCategory: function() {
this.send('changeBulkTemplate', 'modal/bulk_change_category');
},
changeCategory: function() {
var category = Discourse.Category.findById(parseInt(this.get('newCategoryId'), 10)),
self = this;
this.perform({type: 'change_category', category_id: this.get('newCategoryId')}).then(function(topics) {
topics.forEach(function(t) {
t.set('category', category);
});
self.send('closeModal');
});
}
} }
}); });

View file

@ -382,6 +382,16 @@ Discourse.Topic.reopenClass({
promise.reject(new Error("error moving posts topic")); promise.reject(new Error("error moving posts topic"));
}); });
return promise; return promise;
},
bulkOperation: function(topics, operation) {
return Discourse.ajax("/topics/bulk", {
type: 'PUT',
data: {
topic_ids: topics.map(function(t) { return t.get('id'); }),
operation: operation
}
});
} }
}); });

View file

@ -37,9 +37,14 @@ Discourse.DiscoveryRoute = Discourse.Route.extend({
}); });
}, },
changeBulkTemplate: function(w) {
this.render(w, {into: 'topicBulkActions', outlet: 'bulkOutlet', controller: 'topicBulkActions'});
},
showBulkActions: function() { showBulkActions: function() {
var selected = this.controllerFor('discoveryTopics').get('selected'); var selected = this.controllerFor('discoveryTopics').get('selected');
Discourse.Route.showModal(this, 'topicBulkActions', selected); Discourse.Route.showModal(this, 'topicBulkActions', selected);
this.send('changeBulkTemplate', 'modal/bulk_actions_buttons');
} }
} }
}); });

View file

@ -11,7 +11,7 @@
<tr> <tr>
<th> <th>
{{#if canBulkSelect}} {{#if canBulkSelect}}
<button class='btn bulk-select' {{action toggleBulkSelect}} title="{{i18n topics.toggle_bulk_select}}"><i class='fa fa-list'></i></button> <button class='btn bulk-select' {{action toggleBulkSelect}} title="{{i18n topics.bulk.toggle}}"><i class='fa fa-list'></i></button>
{{/if}} {{/if}}
</th> </th>
{{#sortable-heading sortBy="default" sortOrder=sortOrder}} {{#sortable-heading sortBy="default" sortOrder=sortOrder}}

View file

@ -37,7 +37,7 @@
</td> </td>
{{#unless hideCategory}} {{#unless hideCategory}}
<td class='category'>{{categoryLink category}}</td> <td class='category'>{{boundCategoryLink category}}</td>
{{/unless}} {{/unless}}
<td class='posters'> <td class='posters'>

View file

@ -0,0 +1 @@
<button class='btn' {{action showChangeCategory}}>{{i18n topics.bulk.change_category}}</button>

View file

@ -0,0 +1,10 @@
<p>Choose the new category for the topics:</p>
<p>{{categoryChooser value=newCategoryId}}</p>
{{#if loading}}
<div class='loading'>{{i18n loading}}</div>
{{else}}
<button class='btn' {{action changeCategory}}>Change Category</button>
{{/if}}

View file

@ -1,7 +1,7 @@
<div class='modal-body'> <div class='modal-body'>
<p>{{{i18n topics.selected count=length}}}</p> <p>{{{i18n topics.bulk.selected count=length}}}</p>
<button class='btn'>Change Category</button> {{outlet bulkOutlet}}
</div> </div>

View file

@ -8,5 +8,5 @@
**/ **/
Discourse.TopicBulkActionsView = Discourse.ModalBodyView.extend({ Discourse.TopicBulkActionsView = Discourse.ModalBodyView.extend({
templateName: 'modal/topic_bulk_actions', templateName: 'modal/topic_bulk_actions',
title: I18n.t('topics.bulk_actions') title: I18n.t('topics.bulk.actions')
}); });

View file

@ -251,6 +251,10 @@
p { p {
margin-top: 0; margin-top: 0;
} }
.modal-body {
height: 420px;
max-height: 420px;
}
} }
.tabbed-modal { .tabbed-modal {
.modal-body { .modal-body {

View file

@ -69,9 +69,6 @@
&:nth-child(even) { &:nth-child(even) {
background-color: #f8f8f8; background-color: #f8f8f8;
} }
&.checked {
background-color: $highlight;
}
&.archived a { &.archived a {
opacity: 0.6; opacity: 0.6;
} }

View file

@ -19,7 +19,8 @@ class TopicsController < ApplicationController
:move_posts, :move_posts,
:merge_topic, :merge_topic,
:clear_pin, :clear_pin,
:autoclose] :autoclose,
:bulk]
before_filter :consider_user_for_promotion, only: :show before_filter :consider_user_for_promotion, only: :show
@ -266,6 +267,11 @@ class TopicsController < ApplicationController
render 'topics/show', formats: [:rss] render 'topics/show', formats: [:rss]
end end
def bulk
topic_ids = params.require(:topic_ids).map {|t| t.to_i}
render_json_dump topic_ids: topic_ids
end
private private
def toggle_mute def toggle_mute

View file

@ -600,11 +600,13 @@ en:
unstar: 'remove this topic from your starred list' unstar: 'remove this topic from your starred list'
topics: topics:
toggle_bulk_select: "toggle bulk selection of topics" bulk:
bulk_actions: "Bulk Actions" toggle: "toggle bulk selection of topics"
selected: actions: "Bulk Actions"
one: "You have selected <b>1</b> topic." change_category: "Change Category"
other: "You have selected <b>{{count}}</b> topics." selected:
one: "You have selected <b>1</b> topic."
other: "You have selected <b>{{count}}</b> topics."
none: none:
starred: "You haven't starred any topics yet. To star a topic, click or tap the star next to the title." starred: "You haven't starred any topics yet. To star a topic, click or tap the star next to the title."

View file

@ -242,6 +242,7 @@ Discourse::Application.routes.draw do
post "t" => "topics#create" post "t" => "topics#create"
put "t/:id" => "topics#update" put "t/:id" => "topics#update"
delete "t/:id" => "topics#destroy" delete "t/:id" => "topics#destroy"
put "topics/bulk"
post "topics/timings" post "topics/timings"
get "topics/similar_to" get "topics/similar_to"
get "topics/created-by/:username" => "list#topics_by", as: "topics_by", constraints: {username: USERNAME_ROUTE_FORMAT} get "topics/created-by/:username" => "list#topics_by", as: "topics_by", constraints: {username: USERNAME_ROUTE_FORMAT}