FIX: Replace modal with an empty view when closed. Fixes the bug where you'd edit a category, close
and then click edit again.
This commit is contained in:
parent
a53f958c78
commit
bddc9dd4b8
|
@ -96,7 +96,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
|||
}.property(),
|
||||
|
||||
showCategoryTopic: function() {
|
||||
$('#discourse-modal').modal('hide');
|
||||
this.send('closeModal')
|
||||
Discourse.URL.routeTo(this.get('topic_url'));
|
||||
return false;
|
||||
},
|
||||
|
@ -123,7 +123,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
|||
Discourse.SiteSetting.update('uncategorized_name', this.get('name'))
|
||||
).then(function(result) {
|
||||
// success
|
||||
$('#discourse-modal').modal('hide');
|
||||
categoryController.send('closeModal');
|
||||
// We can't redirect to the uncategorized category on save because the slug
|
||||
// might have changed.
|
||||
Discourse.URL.redirectTo("/categories");
|
||||
|
@ -136,7 +136,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
|||
} else {
|
||||
this.get('model').save().then(function(result) {
|
||||
// success
|
||||
$('#discourse-modal').modal('hide');
|
||||
categoryController.send('closeModal');
|
||||
Discourse.URL.redirectTo("/category/" + Discourse.Category.slugFor(result.category));
|
||||
}, function(errors) {
|
||||
// errors
|
||||
|
@ -150,11 +150,13 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
|||
deleteCategory: function() {
|
||||
var categoryController = this;
|
||||
this.set('deleting', true);
|
||||
|
||||
$('#discourse-modal').modal('hide');
|
||||
bootbox.confirm(Em.String.i18n("category.delete_confirm"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) {
|
||||
if (result) {
|
||||
categoryController.get('model').destroy().then(function(){
|
||||
// success
|
||||
categoryController.send('closeModal');
|
||||
Discourse.URL.redirectTo("/categories");
|
||||
}, function(jqXHR){
|
||||
// error
|
||||
|
|
|
@ -55,7 +55,7 @@ Discourse.FlagController = Discourse.ObjectController.extend(Discourse.ModalFunc
|
|||
if (opts) params = $.extend(params, opts);
|
||||
|
||||
postAction.act(params).then(function() {
|
||||
flagController.closeModal();
|
||||
flagController.send('closeModal');
|
||||
}, function(errors) {
|
||||
flagController.displayErrors(errors);
|
||||
});
|
||||
|
|
|
@ -27,8 +27,6 @@ Discourse.MergeTopicController = Discourse.ObjectController.extend(Discourse.Sel
|
|||
movePostsToExistingTopic: function() {
|
||||
this.set('saving', true);
|
||||
|
||||
var moveSelectedView = this;
|
||||
|
||||
var promise = null;
|
||||
if (this.get('allPostsSelected')) {
|
||||
promise = Discourse.Topic.mergeTopic(this.get('id'), this.get('selectedTopicId'));
|
||||
|
@ -40,15 +38,16 @@ Discourse.MergeTopicController = Discourse.ObjectController.extend(Discourse.Sel
|
|||
});
|
||||
}
|
||||
|
||||
var mergeTopicController = this;
|
||||
promise.then(function(result) {
|
||||
// Posts moved
|
||||
$('#discourse-modal').modal('hide');
|
||||
moveSelectedView.get('topicController').toggleMultiSelect();
|
||||
mergeTopicController.send('closeModal');
|
||||
mergeTopicController.get('topicController').toggleMultiSelect();
|
||||
Em.run.next(function() { Discourse.URL.routeTo(result.url); });
|
||||
}, function() {
|
||||
// Error moving posts
|
||||
moveSelectedView.flash(Em.String.i18n('topic.merge_topic.error'));
|
||||
moveSelectedView.set('saving', false);
|
||||
mergeTopicController.flash(Em.String.i18n('topic.merge_topic.error'));
|
||||
mergeTopicController.set('saving', false);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -6,18 +6,6 @@
|
|||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.ModalController = Discourse.Controller.extend({
|
||||
|
||||
/**
|
||||
Close the modal.
|
||||
|
||||
@method closeModal
|
||||
**/
|
||||
closeModal: function() {
|
||||
// Currently uses jQuery to hide it.
|
||||
$('#discourse-modal').modal('hide');
|
||||
}
|
||||
|
||||
});
|
||||
Discourse.ModalController = Discourse.Controller.extend({});
|
||||
|
||||
|
||||
|
|
|
@ -28,20 +28,20 @@ Discourse.SplitTopicController = Discourse.ObjectController.extend(Discourse.Sel
|
|||
this.set('saving', true);
|
||||
|
||||
var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); });
|
||||
var moveSelectedView = this;
|
||||
var splitTopicController = this;
|
||||
|
||||
Discourse.Topic.movePosts(this.get('id'), {
|
||||
title: this.get('topicName'),
|
||||
post_ids: postIds
|
||||
}).then(function(result) {
|
||||
// Posts moved
|
||||
$('#discourse-modal').modal('hide');
|
||||
moveSelectedView.get('topicController').toggleMultiSelect();
|
||||
splitTopicController.send('closeModal');
|
||||
splitTopicController.get('topicController').toggleMultiSelect();
|
||||
Em.run.next(function() { Discourse.URL.routeTo(result.url); });
|
||||
}, function() {
|
||||
// Error moving posts
|
||||
moveSelectedView.flash(Em.String.i18n('topic.split_topic.error'));
|
||||
moveSelectedView.set('saving', false);
|
||||
splitTopicController.flash(Em.String.i18n('topic.split_topic.error'));
|
||||
splitTopicController.set('saving', false);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -21,16 +21,6 @@ Discourse.ModalFunctionality = Em.Mixin.create({
|
|||
message: message,
|
||||
messageClass: messageClass
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
Close the modal.
|
||||
|
||||
@method closeModal
|
||||
**/
|
||||
closeModal: function() {
|
||||
// Currently uses jQuery to hide it.
|
||||
this.get('controllers.modal').closeModal();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -34,6 +34,16 @@ Discourse.ApplicationRoute = Em.Route.extend({
|
|||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
Close the current modal.
|
||||
|
||||
@method closeModal
|
||||
**/
|
||||
closeModal: function() {
|
||||
this.render('hide_modal', {into: 'modal', outlet: 'modalBody'});
|
||||
},
|
||||
|
||||
editCategory: function(category) {
|
||||
var router = this;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{selectedPostsCount}}
|
||||
<p>{{{i18n topic.merge_topic.instructions count="selectedPostsCount"}}}</p>
|
||||
|
||||
{{chooseTopic selectedTopicId=selectedTopicId}}
|
||||
|
|
|
@ -260,7 +260,7 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
// send - this event is triggered when the upload request is about to start
|
||||
$uploadTarget.on('fileuploadsend', function (e, data) {
|
||||
// hide the "image selector" modal
|
||||
$('#discourse-modal').modal('hide');
|
||||
_this.get('controller').send('closeModal');
|
||||
// cf. https://github.com/blueimp/jQuery-File-Upload/wiki/API#how-to-cancel-an-upload
|
||||
var jqXHR = data.xhr();
|
||||
// need to wait for the link to show up in the DOM
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
An empty view for when we want to close a modal.
|
||||
|
||||
@class HideModalView
|
||||
@extends Discourse.ModalBodyView
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.HideModalView = Discourse.ModalBodyView.extend({
|
||||
|
||||
// No rendering!
|
||||
render: function(buffer) { },
|
||||
|
||||
didInsertElement: function() {
|
||||
$('#discourse-modal').modal('hide');
|
||||
}
|
||||
|
||||
});
|
|
@ -17,7 +17,7 @@ Discourse.ImageSelectorView = Discourse.ModalBodyView.extend({
|
|||
|
||||
add: function() {
|
||||
this.get('controller.composerView').addMarkdown("![image](" + $('#fileurl-input').val() + ")");
|
||||
$('#discourse-modal').modal('hide');
|
||||
this.get('controller').send('closeModal');
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -11,6 +11,12 @@ Discourse.ModalBodyView = Discourse.View.extend({
|
|||
// Focus on first element
|
||||
didInsertElement: function() {
|
||||
$('#discourse-modal').modal('show');
|
||||
|
||||
var controller = this.get('controller');
|
||||
$('#discourse-modal').on('hide.discourse', function() {
|
||||
controller.send('closeModal');
|
||||
});
|
||||
|
||||
$('#modal-alert').hide();
|
||||
|
||||
var modalBodyView = this;
|
||||
|
@ -24,6 +30,10 @@ Discourse.ModalBodyView = Discourse.View.extend({
|
|||
}
|
||||
},
|
||||
|
||||
willDestroyElement: function() {
|
||||
$('#discourse-modal').off('hide.discourse');
|
||||
},
|
||||
|
||||
// Pass the errors to our errors view
|
||||
displayErrors: function(errors, callback) {
|
||||
this.set('parentView.parentView.modalErrorsView.errors', errors);
|
||||
|
|
Loading…
Reference in New Issue