FIX: edit category modal with no title, empty modals that can't be closed. Added a better way to hide a modal without really closing it.

This commit is contained in:
Neil Lalonde 2013-10-15 15:41:15 -04:00
parent 7dcd3117fe
commit 42cdad9d1d
4 changed files with 37 additions and 25 deletions

View File

@ -15,6 +15,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
onShow: function() {
this.changeSize();
this.titleChanged();
},
changeSize: function() {
@ -44,7 +45,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
if (!this.get('name')) return true;
if (!this.get('color')) return true;
return false;
}.property('name', 'color', 'deleting'),
}.property('saving', 'name', 'color', 'deleting'),
deleteVisible: function() {
return (this.get('id') && this.get('topic_count') === 0);
@ -160,25 +161,25 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
},
deleteCategory: function() {
var categoryController = this;
var self = this;
this.set('deleting', true);
$('#discourse-modal').modal('hide');
this.send('hideModal');
bootbox.confirm(I18n.t("category.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
if (result) {
categoryController.get('model').destroy().then(function(){
self.get('model').destroy().then(function(){
// success
categoryController.send('closeModal');
self.send('closeModal');
Discourse.URL.redirectTo("/categories");
}, function(jqXHR){
// error
$('#discourse-modal').modal('show');
categoryController.displayErrors([I18n.t("category.delete_error")]);
categoryController.set('deleting', false);
self.send('showModal');
self.displayErrors([I18n.t("category.delete_error")]);
self.set('deleting', false);
});
} else {
$('#discourse-modal').modal('show');
categoryController.set('deleting', false);
self.send('showModal');
self.set('deleting', false);
}
});
}

View File

@ -49,18 +49,18 @@ Discourse.FlagController = Discourse.ObjectController.extend(Discourse.ModalFunc
},
createFlag: function(opts) {
var flagController = this;
var self = this;
var postAction = this.get('actionByName.' + this.get('selected.name_key'));
var params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {};
if (opts) params = $.extend(params, opts);
$('#discourse-modal').modal('hide');
this.send('hideModal');
postAction.act(params).then(function() {
flagController.send('closeModal');
self.send('closeModal');
}, function(errors) {
$('#discourse-modal').modal('show');
flagController.displayErrors(errors);
self.send('showModal');
self.displayErrors(errors);
});
},

View File

@ -33,7 +33,7 @@ Discourse.ApplicationRoute = Em.Route.extend({
/**
Close the current modal.
Close the current modal, and destroy its state.
@method closeModal
**/
@ -41,6 +41,26 @@ Discourse.ApplicationRoute = Em.Route.extend({
this.render('hide_modal', {into: 'modal', outlet: 'modalBody'});
},
/**
Hide the modal, but keep it with all its state so that it can be shown again later.
This is useful if you want to prompt for confirmation. hideModal, ask "Are you sure?",
user clicks "No", showModal. If user clicks "Yes", be sure to call closeModal.
@method hideModal
**/
hideModal: function() {
$('#discourse-modal').modal('hide');
},
/**
Show the modal. Useful after calling hideModal.
@method showModal
**/
showModal: function() {
$('#discourse-modal').modal('show');
},
editCategory: function(category) {
var router = this;

View File

@ -12,11 +12,6 @@ Discourse.ModalBodyView = Discourse.View.extend({
didInsertElement: function() {
$('#discourse-modal').modal('show');
var controller = this.get('controller');
$('#discourse-modal').on('hide.discourse', function() {
controller.send('closeModal');
});
$('#modal-alert').hide();
if (!Discourse.Mobile.mobileView) {
@ -32,10 +27,6 @@ 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);