From 00b60a7a74574213be5a3ebb72480bd1a4333ce7 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 18 Sep 2013 02:45:36 +0100 Subject: [PATCH] Clear notifications before adding new ones closes #783 - I think there's probably a nicer solution than putting clearEverything() everywhere, but that would also probably involve significant refactoring. --- core/client/init.js | 1 + core/client/views/base.js | 10 +--------- core/client/views/editor.js | 22 ++++++++++++---------- core/client/views/settings.js | 3 +++ 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/core/client/init.js b/core/client/init.js index 2e7bab5538..62a444b444 100644 --- a/core/client/init.js +++ b/core/client/init.js @@ -44,6 +44,7 @@ }; Ghost.Validate.handleErrors = function () { + Ghost.notifications.clearEverything(); _.each(Ghost.Validate._errors, function (errorObj) { Ghost.notifications.addItem({ diff --git a/core/client/views/base.js b/core/client/views/base.js index 0cee6744eb..f530000d59 100644 --- a/core/client/views/base.js +++ b/core/client/views/base.js @@ -193,15 +193,7 @@ this.renderItem(item); }, clearEverything: function () { - var height = this.$('.js-notification').outerHeight(true), - self = this; - this.$el.css({height: height}); - this.$el.find('.js-notification.notification-passive').fadeOut(250, function () { - $(this).remove(); - self.$el.slideUp(250, function () { - $(this).show().css({height: "auto"}); - }); - }); + this.$el.find('.js-notification.notification-passive').remove(); }, removeItem: function (e) { e.preventDefault(); diff --git a/core/client/views/editor.js b/core/client/views/editor.js index f66bbe066f..7f3e54b26b 100644 --- a/core/client/views/editor.js +++ b/core/client/views/editor.js @@ -120,11 +120,7 @@ this.savePost({ status: keys[newIndex] }).then(function () { - Ghost.notifications.addItem({ - type: 'success', - message: self.notificationMap[status], - status: 'passive' - }); + self.reportSaveSuccess(status); }, function (xhr) { // Show a notification about the error self.reportSaveError(xhr, model, status); @@ -188,11 +184,7 @@ this.savePost({ status: status }).then(function () { - Ghost.notifications.addItem({ - type: 'success', - message: self.notificationMap[status], - status: 'passive' - }); + self.reportSaveSuccess(status); // Refresh publish button and all relevant controls with updated status. self.render(); }, function (xhr) { @@ -224,6 +216,15 @@ return $.Deferred().reject(); }, + reportSaveSuccess: function (status) { + Ghost.notifications.clearEverything(); + Ghost.notifications.addItem({ + type: 'success', + message: this.notificationMap[status], + status: 'passive' + }); + }, + reportSaveError: function (response, model, status) { var message = this.errorMap[status]; @@ -235,6 +236,7 @@ message += " " + model.validationError; } + Ghost.notifications.clearEverything(); Ghost.notifications.addItem({ type: 'error', message: message, diff --git a/core/client/views/settings.js b/core/client/views/settings.js index bf9495d79d..67fff9df78 100644 --- a/core/client/views/settings.js +++ b/core/client/views/settings.js @@ -116,6 +116,7 @@ }); }, saveSuccess: function (model, response, options) { + Ghost.notifications.clearEverything(); // TODO: better messaging here? Ghost.notifications.addItem({ type: 'success', @@ -124,6 +125,7 @@ }); }, saveError: function (model, xhr) { + Ghost.notifications.clearEverything(); Ghost.notifications.addItem({ type: 'error', message: Ghost.Views.Utils.getRequestErrorMessage(xhr), @@ -131,6 +133,7 @@ }); }, validationError: function (message) { + Ghost.notifications.clearEverything(); Ghost.notifications.addItem({ type: 'error', message: message,