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:
parent
7dcd3117fe
commit
42cdad9d1d
|
@ -15,6 +15,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
this.changeSize();
|
this.changeSize();
|
||||||
|
this.titleChanged();
|
||||||
},
|
},
|
||||||
|
|
||||||
changeSize: function() {
|
changeSize: function() {
|
||||||
|
@ -44,7 +45,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
||||||
if (!this.get('name')) return true;
|
if (!this.get('name')) return true;
|
||||||
if (!this.get('color')) return true;
|
if (!this.get('color')) return true;
|
||||||
return false;
|
return false;
|
||||||
}.property('name', 'color', 'deleting'),
|
}.property('saving', 'name', 'color', 'deleting'),
|
||||||
|
|
||||||
deleteVisible: function() {
|
deleteVisible: function() {
|
||||||
return (this.get('id') && this.get('topic_count') === 0);
|
return (this.get('id') && this.get('topic_count') === 0);
|
||||||
|
@ -160,25 +161,25 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteCategory: function() {
|
deleteCategory: function() {
|
||||||
var categoryController = this;
|
var self = this;
|
||||||
this.set('deleting', true);
|
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) {
|
bootbox.confirm(I18n.t("category.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
categoryController.get('model').destroy().then(function(){
|
self.get('model').destroy().then(function(){
|
||||||
// success
|
// success
|
||||||
categoryController.send('closeModal');
|
self.send('closeModal');
|
||||||
Discourse.URL.redirectTo("/categories");
|
Discourse.URL.redirectTo("/categories");
|
||||||
}, function(jqXHR){
|
}, function(jqXHR){
|
||||||
// error
|
// error
|
||||||
$('#discourse-modal').modal('show');
|
self.send('showModal');
|
||||||
categoryController.displayErrors([I18n.t("category.delete_error")]);
|
self.displayErrors([I18n.t("category.delete_error")]);
|
||||||
categoryController.set('deleting', false);
|
self.set('deleting', false);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$('#discourse-modal').modal('show');
|
self.send('showModal');
|
||||||
categoryController.set('deleting', false);
|
self.set('deleting', false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,18 +49,18 @@ Discourse.FlagController = Discourse.ObjectController.extend(Discourse.ModalFunc
|
||||||
},
|
},
|
||||||
|
|
||||||
createFlag: function(opts) {
|
createFlag: function(opts) {
|
||||||
var flagController = this;
|
var self = this;
|
||||||
var postAction = this.get('actionByName.' + this.get('selected.name_key'));
|
var postAction = this.get('actionByName.' + this.get('selected.name_key'));
|
||||||
var params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {};
|
var params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {};
|
||||||
|
|
||||||
if (opts) params = $.extend(params, opts);
|
if (opts) params = $.extend(params, opts);
|
||||||
|
|
||||||
$('#discourse-modal').modal('hide');
|
this.send('hideModal');
|
||||||
postAction.act(params).then(function() {
|
postAction.act(params).then(function() {
|
||||||
flagController.send('closeModal');
|
self.send('closeModal');
|
||||||
}, function(errors) {
|
}, function(errors) {
|
||||||
$('#discourse-modal').modal('show');
|
self.send('showModal');
|
||||||
flagController.displayErrors(errors);
|
self.displayErrors(errors);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ Discourse.ApplicationRoute = Em.Route.extend({
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Close the current modal.
|
Close the current modal, and destroy its state.
|
||||||
|
|
||||||
@method closeModal
|
@method closeModal
|
||||||
**/
|
**/
|
||||||
|
@ -41,6 +41,26 @@ Discourse.ApplicationRoute = Em.Route.extend({
|
||||||
this.render('hide_modal', {into: 'modal', outlet: 'modalBody'});
|
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) {
|
editCategory: function(category) {
|
||||||
var router = this;
|
var router = this;
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,6 @@ Discourse.ModalBodyView = Discourse.View.extend({
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
$('#discourse-modal').modal('show');
|
$('#discourse-modal').modal('show');
|
||||||
|
|
||||||
var controller = this.get('controller');
|
|
||||||
$('#discourse-modal').on('hide.discourse', function() {
|
|
||||||
controller.send('closeModal');
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#modal-alert').hide();
|
$('#modal-alert').hide();
|
||||||
|
|
||||||
if (!Discourse.Mobile.mobileView) {
|
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
|
// Pass the errors to our errors view
|
||||||
displayErrors: function(errors, callback) {
|
displayErrors: function(errors, callback) {
|
||||||
this.set('parentView.parentView.modalErrorsView.errors', errors);
|
this.set('parentView.parentView.modalErrorsView.errors', errors);
|
||||||
|
|
Loading…
Reference in New Issue