mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
Fix: Multi-Select should close when an operation succeeds. A little refactoring, too.
This commit is contained in:
parent
2ba08d23cb
commit
0d8c962fdf
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
This controller supports actions related to showing modals
|
This controller supports actions related to showing modals
|
||||||
|
|
||||||
@class ModalController
|
@class ModalController
|
||||||
@extends Discourse.Controller
|
@extends Discourse.Controller
|
||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module Discourse
|
@module Discourse
|
||||||
|
@ -83,20 +83,20 @@ Discourse.TopicController = Discourse.ObjectController.extend({
|
|||||||
if (!modalController) return;
|
if (!modalController) return;
|
||||||
|
|
||||||
modalController.show(Discourse.MoveSelectedView.create({
|
modalController.show(Discourse.MoveSelectedView.create({
|
||||||
|
topicController: this,
|
||||||
topic: this.get('content'),
|
topic: this.get('content'),
|
||||||
selectedPosts: this.get('selectedPosts')
|
selectedPosts: this.get('selectedPosts'),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteSelected: function() {
|
deleteSelected: function() {
|
||||||
var topicController = this;
|
var topicController = this;
|
||||||
return bootbox.confirm(Em.String.i18n("post.delete.confirm", {
|
return bootbox.confirm(Em.String.i18n("post.delete.confirm", { count: this.get('selectedCount')}), function(result) {
|
||||||
count: this.get('selectedCount')
|
|
||||||
}), function(result) {
|
|
||||||
if (result) {
|
if (result) {
|
||||||
var selectedPosts = topicController.get('selectedPosts');
|
var selectedPosts = topicController.get('selectedPosts');
|
||||||
Discourse.Post.deleteMany(selectedPosts);
|
Discourse.Post.deleteMany(selectedPosts);
|
||||||
topicController.get('content.posts').removeObjects(selectedPosts);
|
topicController.get('content.posts').removeObjects(selectedPosts);
|
||||||
|
topicController.toggleMultiSelect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -451,10 +451,15 @@ Discourse.Topic.reopenClass({
|
|||||||
|
|
||||||
// Create a topic from posts
|
// Create a topic from posts
|
||||||
movePosts: function(topicId, title, postIds) {
|
movePosts: function(topicId, title, postIds) {
|
||||||
return Discourse.ajax("/t/" + topicId + "/move-posts", {
|
|
||||||
|
var promise = Discourse.ajax("/t/" + topicId + "/move-posts", {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: { title: title, post_ids: postIds }
|
data: { title: title, post_ids: postIds }
|
||||||
|
}).then(function (result) {
|
||||||
|
if (result.success) return result;
|
||||||
|
promise.reject();
|
||||||
});
|
});
|
||||||
|
return promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
create: function(obj, topicView) {
|
create: function(obj, topicView) {
|
||||||
|
@ -10,10 +10,8 @@ Discourse.ModalBodyView = Discourse.View.extend({
|
|||||||
|
|
||||||
// Focus on first element
|
// Focus on first element
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
var _this = this;
|
var modalBodyView = this;
|
||||||
Em.run.next(function() {
|
Em.run.next(function() { modalBodyView.$('form input:first').focus(); });
|
||||||
_this.$('form input:first').focus();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Pass the errors to our errors view
|
// 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
|
// Just use jQuery to show an alert. We don't need anythign fancier for now
|
||||||
// like an actual ember view
|
// like an actual ember view
|
||||||
flash: function(msg, flashClass) {
|
flash: function(msg, flashClass) {
|
||||||
var $alert;
|
|
||||||
if (!flashClass) flashClass = "success";
|
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.addClass("alert alert-" + flashClass).html(msg);
|
||||||
$alert.fadeIn();
|
$alert.fadeIn();
|
||||||
}
|
}
|
||||||
|
@ -16,26 +16,19 @@ Discourse.ModalView = Ember.ContainerView.extend({
|
|||||||
templateName: 'modal/modal_header',
|
templateName: 'modal/modal_header',
|
||||||
titleBinding: 'controller.currentView.title'
|
titleBinding: 'controller.currentView.title'
|
||||||
}),
|
}),
|
||||||
|
modalBodyView: Ember.ContainerView.create({ currentViewBinding: 'controller.currentView' }),
|
||||||
|
modalErrorsView: Ember.View.create({ templateName: 'modal/modal_errors' }),
|
||||||
|
|
||||||
modalBodyView: Ember.ContainerView.create({
|
viewChanged: function() {
|
||||||
currentViewBinding: 'controller.currentView'
|
|
||||||
}),
|
|
||||||
|
|
||||||
modalErrorsView: Ember.View.create({
|
|
||||||
templateName: 'modal/modal_errors'
|
|
||||||
}),
|
|
||||||
|
|
||||||
viewChanged: (function() {
|
|
||||||
var view,
|
|
||||||
_this = this;
|
|
||||||
this.set('modalErrorsView.errors', null);
|
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();
|
$('#modal-alert').hide();
|
||||||
return Em.run.next(function() {
|
Em.run.next(function() { modalView.$().modal('show'); });
|
||||||
return _this.$().modal('show');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}).observes('controller.currentView')
|
}.observes('controller.currentView')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,41 +11,36 @@ Discourse.MoveSelectedView = Discourse.ModalBodyView.extend({
|
|||||||
title: Em.String.i18n('topic.move_selected.title'),
|
title: Em.String.i18n('topic.move_selected.title'),
|
||||||
saving: false,
|
saving: false,
|
||||||
|
|
||||||
selectedCount: (function() {
|
selectedCount: function() {
|
||||||
if (!this.get('selectedPosts')) return 0;
|
if (!this.get('selectedPosts')) return 0;
|
||||||
return this.get('selectedPosts').length;
|
return this.get('selectedPosts').length;
|
||||||
}).property('selectedPosts'),
|
}.property('selectedPosts'),
|
||||||
|
|
||||||
buttonDisabled: (function() {
|
buttonDisabled: function() {
|
||||||
if (this.get('saving')) return true;
|
if (this.get('saving')) return true;
|
||||||
return this.blank('topicName');
|
return this.blank('topicName');
|
||||||
}).property('saving', 'topicName'),
|
}.property('saving', 'topicName'),
|
||||||
|
|
||||||
buttonTitle: (function() {
|
buttonTitle: function() {
|
||||||
if (this.get('saving')) return Em.String.i18n('saving');
|
if (this.get('saving')) return Em.String.i18n('saving');
|
||||||
return Em.String.i18n('topic.move_selected.title');
|
return Em.String.i18n('topic.move_selected.title');
|
||||||
}).property('saving'),
|
}.property('saving'),
|
||||||
|
|
||||||
movePosts: function() {
|
movePosts: function() {
|
||||||
var postIds,
|
|
||||||
_this = this;
|
|
||||||
this.set('saving', true);
|
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) {
|
Discourse.Topic.movePosts(this.get('topic.id'), this.get('topicName'), postIds).then(function(result) {
|
||||||
if (result.success) {
|
// Posts moved
|
||||||
$('#discourse-modal').modal('hide');
|
$('#discourse-modal').modal('hide');
|
||||||
Em.run.next(function() {
|
moveSelectedView.get('topicController').toggleMultiSelect();
|
||||||
Discourse.URL.routeTo(result.url);
|
Em.run.next(function() { Discourse.URL.routeTo(result.url); });
|
||||||
});
|
|
||||||
} else {
|
|
||||||
_this.flash(Em.String.i18n('topic.move_selected.error'));
|
|
||||||
return _this.set('saving', false);
|
|
||||||
}
|
|
||||||
}, function() {
|
}, function() {
|
||||||
_this.flash(Em.String.i18n('topic.move_selected.error'));
|
// Error moving posts
|
||||||
return _this.set('saving', false);
|
moveSelectedView.flash(Em.String.i18n('topic.move_selected.error'));
|
||||||
|
moveSelectedView.set('saving', false);
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user