From 42cdad9d1d8f9e721a3cb552c08c88e98df10c64 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 15 Oct 2013 15:41:15 -0400 Subject: [PATCH] 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. --- .../controllers/edit_category_controller.js | 21 +++++++++--------- .../discourse/controllers/flag_controller.js | 10 ++++----- .../discourse/routes/application_route.js | 22 ++++++++++++++++++- .../discourse/views/modal/modal_body_view.js | 9 -------- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/edit_category_controller.js b/app/assets/javascripts/discourse/controllers/edit_category_controller.js index 5e0ebf52f08..838ac022614 100644 --- a/app/assets/javascripts/discourse/controllers/edit_category_controller.js +++ b/app/assets/javascripts/discourse/controllers/edit_category_controller.js @@ -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); } }); } diff --git a/app/assets/javascripts/discourse/controllers/flag_controller.js b/app/assets/javascripts/discourse/controllers/flag_controller.js index 59c1a66e9de..b88660bf999 100644 --- a/app/assets/javascripts/discourse/controllers/flag_controller.js +++ b/app/assets/javascripts/discourse/controllers/flag_controller.js @@ -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); }); }, diff --git a/app/assets/javascripts/discourse/routes/application_route.js b/app/assets/javascripts/discourse/routes/application_route.js index 80fdd8687c7..973b75a3ed8 100644 --- a/app/assets/javascripts/discourse/routes/application_route.js +++ b/app/assets/javascripts/discourse/routes/application_route.js @@ -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; 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 edde82fb286..77b8b6dfa6c 100644 --- a/app/assets/javascripts/discourse/views/modal/modal_body_view.js +++ b/app/assets/javascripts/discourse/views/modal/modal_body_view.js @@ -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);