diff --git a/app/assets/javascripts/discourse/controllers/merge_topic_controller.js b/app/assets/javascripts/discourse/controllers/merge_topic_controller.js index 8483b19745c..481b66a601c 100644 --- a/app/assets/javascripts/discourse/controllers/merge_topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/merge_topic_controller.js @@ -25,6 +25,10 @@ Discourse.MergeTopicController = Discourse.ObjectController.extend(Discourse.Sel return I18n.t('topic.merge_topic.title'); }.property('saving'), + onShow: function() { + this.set('controllers.modal.modalClass', 'split-modal'); + }, + movePostsToExistingTopic: function() { this.set('saving', true); diff --git a/app/assets/javascripts/discourse/controllers/split_topic_controller.js b/app/assets/javascripts/discourse/controllers/split_topic_controller.js index 01ad6094d5d..d8fae96d7f2 100644 --- a/app/assets/javascripts/discourse/controllers/split_topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/split_topic_controller.js @@ -25,31 +25,43 @@ Discourse.SplitTopicController = Discourse.ObjectController.extend(Discourse.Sel }.property('saving'), onShow: function() { - this.set('saving', false); + this.setProperties({ + 'controllers.modal.modalClass': 'split-modal', + saving: false, + categoryId: null, + topicName: '' + }); }, - movePostsToNewTopic: function() { - this.set('saving', true); + actions: { + movePostsToNewTopic: function() { + this.set('saving', true); - var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); }), - replyPostIds = this.get('selectedReplies').map(function(p) { return p.get('id'); }), - self = this; + var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); }), + replyPostIds = this.get('selectedReplies').map(function(p) { return p.get('id'); }), + self = this, + categoryId = this.get('categoryId'), + saveOpts = { + title: this.get('topicName'), + post_ids: postIds, + reply_post_ids: replyPostIds + }; - Discourse.Topic.movePosts(this.get('id'), { - title: this.get('topicName'), - post_ids: postIds, - reply_post_ids: replyPostIds - }).then(function(result) { - // Posts moved - self.send('closeModal'); - self.get('topicController').send('toggleMultiSelect'); - Em.run.next(function() { Discourse.URL.routeTo(result.url); }); - }, function() { - // Error moving posts - self.flash(I18n.t('topic.split_topic.error')); - self.set('saving', false); - }); - return false; + if (!Ember.isNone(categoryId)) { saveOpts.category_id = categoryId; } + + Discourse.Topic.movePosts(this.get('id'), saveOpts).then(function(result) { + // Posts moved + self.send('closeModal'); + self.get('topicController').send('toggleMultiSelect'); + Em.run.next(function() { Discourse.URL.routeTo(result.url); }); + }, function() { + // Error moving posts + self.flash(I18n.t('topic.split_topic.error')); + self.set('saving', false); + }); + return false; + } } + }); diff --git a/app/assets/javascripts/discourse/templates/modal/merge_topic.js.handlebars b/app/assets/javascripts/discourse/templates/modal/merge_topic.js.handlebars index 137f6fa665a..5526bf993cb 100644 --- a/app/assets/javascripts/discourse/templates/modal/merge_topic.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/merge_topic.js.handlebars @@ -7,7 +7,9 @@

{{{i18n topic.merge_topic.instructions count="selectedPostsCount"}}}

- {{chooseTopic selectedTopicId=selectedTopicId}} +
+ {{chooseTopic selectedTopicId=selectedTopicId}} +
diff --git a/app/assets/stylesheets/desktop/modal.scss b/app/assets/stylesheets/desktop/modal.scss index 03faf9ca6f8..4d124dce19e 100644 --- a/app/assets/stylesheets/desktop/modal.scss +++ b/app/assets/stylesheets/desktop/modal.scss @@ -175,6 +175,10 @@ .chzn-search input { width: 378px; } + + .chzn-search-icon { + margin-top: 8px; + } } &.hidden { @@ -208,28 +212,6 @@ } } -#move-selected { - p { - margin-top: 0; - } - - input[type=radio] { - margin-right: 10px; - } - - button { - margin-top: 10px; - display: block; - width: 300px; - } - - form { - margin-top: 20px; - input[type=text] { - width: 500px; - } - } -} .flag-modal { max-height: 450px; @@ -282,6 +264,37 @@ position: absolute; } +.split-modal { + .modal-body { + position: relative; + height: 350px; + } + + + #move-selected { + p { + margin-top: 0; + } + + input[type=radio] { + margin-right: 10px; + } + + button { + margin-top: 10px; + display: block; + width: 300px; + } + + form { + margin-top: 20px; + #split-topic-name, #choose-topic-title { + width: 520px; + } + } + } +} + .invite-modal { overflow: visible; .ember-text-field { diff --git a/app/assets/stylesheets/vendor/chosen.css.erb b/app/assets/stylesheets/vendor/chosen.css.erb index 0fcabcb662c..d66e8b44d57 100644 --- a/app/assets/stylesheets/vendor/chosen.css.erb +++ b/app/assets/stylesheets/vendor/chosen.css.erb @@ -20,6 +20,7 @@ box-shadow : 0 4px 5px rgba(0,0,0,.15); z-index: 1010; } + /* @end */ /* @group Single Chosen */ diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index acff18a4365..c2b2daff49c 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -227,6 +227,8 @@ class TopicsController < ApplicationController def move_posts params.require(:post_ids) + params.require(:topic_id) + params.permit(:category_id) topic = Topic.where(id: params[:topic_id]).first guardian.ensure_can_move_posts!(topic) @@ -325,6 +327,7 @@ class TopicsController < ApplicationController args = {} args[:title] = params[:title] if params[:title].present? args[:destination_topic_id] = params[:destination_topic_id].to_i if params[:destination_topic_id].present? + args[:category_id] = params[:category_id].to_i if params[:category_id].present? topic.move_posts(current_user, post_ids_including_replies, args) end diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index aa657a617d8..2fe745087d7 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -19,14 +19,14 @@ class PostMover end end - def to_new_topic(title) + def to_new_topic(title, category_id=nil) @move_type = PostMover.move_types[:new_topic] Topic.transaction do move_posts_to Topic.create!( user: user, title: title, - category: original_topic.category + category_id: category_id ) end end diff --git a/app/models/topic.rb b/app/models/topic.rb index a3e3a2aac3f..eec938f5b0d 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -486,7 +486,7 @@ class Topic < ActiveRecord::Base if opts[:destination_topic_id] post_mover.to_topic opts[:destination_topic_id] elsif opts[:title] - post_mover.to_new_topic opts[:title] + post_mover.to_new_topic(opts[:title], opts[:category_id]) end end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0be59d5f860..b4e5b2f0973 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -763,7 +763,7 @@ en: split_topic: title: "Move to New Topic" action: "move to new topic" - topic_name: "New Topic Name:" + topic_name: "New Topic Name" error: "There was an error moving posts to the new topic." instructions: one: "You are about to create a new topic and populate it with the post you've selected." diff --git a/config/locales/client.id.yml b/config/locales/client.id.yml index d1f93b0aa0a..d11b936eb97 100644 --- a/config/locales/client.id.yml +++ b/config/locales/client.id.yml @@ -469,7 +469,7 @@ id: move_selected: title: "Move Selected Posts" - topic_name: "New Topic Name:" + topic_name: "New Topic Name" error: "Sorry, there was an error moving those posts." instructions: one: "You are about to create a new topic and populate it with the post you've selected." diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index fcd9b23301b..9c54976c905 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -62,8 +62,8 @@ describe TopicsController do let(:p2) { Fabricate(:post, user: user) } before do - Topic.any_instance.expects(:move_posts).with(user, [p2.id], title: 'blah').returns(topic) - xhr :post, :move_posts, topic_id: topic.id, title: 'blah', post_ids: [p2.id] + Topic.any_instance.expects(:move_posts).with(user, [p2.id], title: 'blah', category_id: 123).returns(topic) + xhr :post, :move_posts, topic_id: topic.id, title: 'blah', post_ids: [p2.id], category_id: 123 end it "returns success" do diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index 5ae21949d8a..5be7b08cb30 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -6,7 +6,7 @@ describe PostMover do let(:user) { Fabricate(:user) } let(:another_user) { Fabricate(:evil_trout) } let(:category) { Fabricate(:category, user: user) } - let!(:topic) { Fabricate(:topic, user: user, category: category) } + let!(:topic) { Fabricate(:topic, user: user) } let!(:p1) { Fabricate(:post, topic: topic, user: user) } let!(:p2) { Fabricate(:post, topic: topic, user: another_user, raw: "Has a link to [evil trout](http://eviltrout.com) which is a cool site.")} let!(:p3) { Fabricate(:post, topic: topic, user: user)} @@ -58,7 +58,7 @@ describe PostMover do end context "to a new topic" do - let!(:new_topic) { topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name") } + let!(:new_topic) { topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id) } it "works correctly" do TopicUser.where(user_id: user.id, topic_id: topic.id).first.last_read_post_number.should == p3.post_number @@ -102,7 +102,7 @@ describe PostMover do let!(:destination_topic) { Fabricate(:topic, user: user ) } let!(:destination_op) { Fabricate(:post, topic: destination_topic, user: user) } - let!(:moved_to) { topic.move_posts(user, [p2.id, p4.id], destination_topic_id: destination_topic.id )} + let!(:moved_to) { topic.move_posts(user, [p2.id, p4.id], destination_topic_id: destination_topic.id)} it "works correctly" do moved_to.should == destination_topic