diff --git a/app/assets/javascripts/discourse/controllers/modal_controller.js b/app/assets/javascripts/discourse/controllers/modal_controller.js index 987b8c5545a..50648c2137b 100644 --- a/app/assets/javascripts/discourse/controllers/modal_controller.js +++ b/app/assets/javascripts/discourse/controllers/modal_controller.js @@ -1,7 +1,7 @@ /** This controller supports actions related to showing modals - @class ModalController + @class ModalController @extends Discourse.Controller @namespace Discourse @module Discourse diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 1cc55eeb123..2b5875c3f91 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -83,20 +83,20 @@ Discourse.TopicController = Discourse.ObjectController.extend({ if (!modalController) return; modalController.show(Discourse.MoveSelectedView.create({ + topicController: this, topic: this.get('content'), - selectedPosts: this.get('selectedPosts') + selectedPosts: this.get('selectedPosts'), })); }, deleteSelected: function() { var topicController = this; - return bootbox.confirm(Em.String.i18n("post.delete.confirm", { - count: this.get('selectedCount') - }), function(result) { + return bootbox.confirm(Em.String.i18n("post.delete.confirm", { count: this.get('selectedCount')}), function(result) { if (result) { var selectedPosts = topicController.get('selectedPosts'); Discourse.Post.deleteMany(selectedPosts); topicController.get('content.posts').removeObjects(selectedPosts); + topicController.toggleMultiSelect(); } }); }, diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index 79fab6f6dd4..460398dc4e8 100755 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -451,10 +451,15 @@ Discourse.Topic.reopenClass({ // Create a topic from posts movePosts: function(topicId, title, postIds) { - return Discourse.ajax("/t/" + topicId + "/move-posts", { + + var promise = Discourse.ajax("/t/" + topicId + "/move-posts", { type: 'POST', data: { title: title, post_ids: postIds } + }).then(function (result) { + if (result.success) return result; + promise.reject(); }); + return promise; }, create: function(obj, topicView) { diff --git a/app/assets/javascripts/discourse/views/modal/modal_body_view.js b/app/assets/javascripts/discourse/views/modal/modal_body_view.js index 50b723bcc94..0e4fc66f56f 100644 --- a/app/assets/javascripts/discourse/views/modal/modal_body_view.js +++ b/app/assets/javascripts/discourse/views/modal/modal_body_view.js @@ -10,10 +10,8 @@ Discourse.ModalBodyView = Discourse.View.extend({ // Focus on first element didInsertElement: function() { - var _this = this; - Em.run.next(function() { - _this.$('form input:first').focus(); - }); + var modalBodyView = this; + Em.run.next(function() { modalBodyView.$('form input:first').focus(); }); }, // Pass the errors to our errors view @@ -25,9 +23,8 @@ Discourse.ModalBodyView = Discourse.View.extend({ // Just use jQuery to show an alert. We don't need anythign fancier for now // like an actual ember view flash: function(msg, flashClass) { - var $alert; if (!flashClass) flashClass = "success"; - $alert = $('#modal-alert').hide().removeClass('alert-error', 'alert-success'); + var $alert = $('#modal-alert').hide().removeClass('alert-error', 'alert-success'); $alert.addClass("alert alert-" + flashClass).html(msg); $alert.fadeIn(); } diff --git a/app/assets/javascripts/discourse/views/modal/modal_view.js b/app/assets/javascripts/discourse/views/modal/modal_view.js index 6d1f1219a75..7b0b9295f97 100644 --- a/app/assets/javascripts/discourse/views/modal/modal_view.js +++ b/app/assets/javascripts/discourse/views/modal/modal_view.js @@ -16,26 +16,19 @@ Discourse.ModalView = Ember.ContainerView.extend({ templateName: 'modal/modal_header', titleBinding: 'controller.currentView.title' }), + modalBodyView: Ember.ContainerView.create({ currentViewBinding: 'controller.currentView' }), + modalErrorsView: Ember.View.create({ templateName: 'modal/modal_errors' }), - modalBodyView: Ember.ContainerView.create({ - currentViewBinding: 'controller.currentView' - }), - - modalErrorsView: Ember.View.create({ - templateName: 'modal/modal_errors' - }), - - viewChanged: (function() { - var view, - _this = this; + viewChanged: function() { this.set('modalErrorsView.errors', null); - if (view = this.get('controller.currentView')) { + + var view = this.get('controller.currentView'); + var modalView = this; + if (view) { $('#modal-alert').hide(); - return Em.run.next(function() { - return _this.$().modal('show'); - }); + Em.run.next(function() { modalView.$().modal('show'); }); } - }).observes('controller.currentView') + }.observes('controller.currentView') }); diff --git a/app/assets/javascripts/discourse/views/modal/move_selected_view.js b/app/assets/javascripts/discourse/views/modal/move_selected_view.js index 132ac94d0d8..6186c0d4909 100644 --- a/app/assets/javascripts/discourse/views/modal/move_selected_view.js +++ b/app/assets/javascripts/discourse/views/modal/move_selected_view.js @@ -11,41 +11,36 @@ Discourse.MoveSelectedView = Discourse.ModalBodyView.extend({ title: Em.String.i18n('topic.move_selected.title'), saving: false, - selectedCount: (function() { + selectedCount: function() { if (!this.get('selectedPosts')) return 0; return this.get('selectedPosts').length; - }).property('selectedPosts'), + }.property('selectedPosts'), - buttonDisabled: (function() { + buttonDisabled: function() { if (this.get('saving')) return true; return this.blank('topicName'); - }).property('saving', 'topicName'), + }.property('saving', 'topicName'), - buttonTitle: (function() { + buttonTitle: function() { if (this.get('saving')) return Em.String.i18n('saving'); return Em.String.i18n('topic.move_selected.title'); - }).property('saving'), + }.property('saving'), movePosts: function() { - var postIds, - _this = this; this.set('saving', true); - postIds = this.get('selectedPosts').map(function(p) { - return p.get('id'); - }); + + var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); }); + var moveSelectedView = this; + Discourse.Topic.movePosts(this.get('topic.id'), this.get('topicName'), postIds).then(function(result) { - if (result.success) { - $('#discourse-modal').modal('hide'); - Em.run.next(function() { - Discourse.URL.routeTo(result.url); - }); - } else { - _this.flash(Em.String.i18n('topic.move_selected.error')); - return _this.set('saving', false); - } + // Posts moved + $('#discourse-modal').modal('hide'); + moveSelectedView.get('topicController').toggleMultiSelect(); + Em.run.next(function() { Discourse.URL.routeTo(result.url); }); }, function() { - _this.flash(Em.String.i18n('topic.move_selected.error')); - return _this.set('saving', false); + // Error moving posts + moveSelectedView.flash(Em.String.i18n('topic.move_selected.error')); + moveSelectedView.set('saving', false); }); return false; }