diff --git a/ghost/admin/controllers/forgotten.js b/ghost/admin/controllers/forgotten.js index 4b6a4ea935..fff51d92d2 100644 --- a/ghost/admin/controllers/forgotten.js +++ b/ghost/admin/controllers/forgotten.js @@ -30,12 +30,10 @@ var ForgottenController = Ember.Controller.extend(ValidationEngine, { self.transitionToRoute('signin'); }).catch(function (resp) { self.toggleProperty('submitting'); - self.notifications.closePassive(); - self.notifications.showAPIError(resp, 'There was a problem logging in, please try again.'); + self.notifications.showAPIError(resp, { defaultErrorText: 'There was a problem logging in, please try again.' }); }); }).catch(function (errors) { self.toggleProperty('submitting'); - self.notifications.closePassive(); self.notifications.showErrors(errors); }); } diff --git a/ghost/admin/controllers/modals/delete-post.js b/ghost/admin/controllers/modals/delete-post.js index c7f531aa31..aaaddc5d81 100644 --- a/ghost/admin/controllers/modals/delete-post.js +++ b/ghost/admin/controllers/modals/delete-post.js @@ -10,7 +10,7 @@ var DeletePostController = Ember.Controller.extend({ model.destroyRecord().then(function () { self.get('popover').closePopovers(); self.transitionToRoute('posts.index'); - self.notifications.showSuccess('Your post has been deleted.', true); + self.notifications.showSuccess('Your post has been deleted.', { delayed: true }); }, function () { self.notifications.showError('Your post could not be deleted. Please try again.'); }); diff --git a/ghost/admin/controllers/modals/invite-new-user.js b/ghost/admin/controllers/modals/invite-new-user.js index 2c55f6fdcf..0c72a407aa 100644 --- a/ghost/admin/controllers/modals/invite-new-user.js +++ b/ghost/admin/controllers/modals/invite-new-user.js @@ -38,8 +38,6 @@ var InviteNewUserController = Ember.Controller.extend({ newUser.save().then(function () { var notificationText = 'Invitation sent! (' + email + ')'; - self.notifications.closePassive(); - // If sending the invitation email fails, the API will still return a status of 201 // but the user's status in the response object will be 'invited-pending'. if (newUser.get('status') === 'invited-pending') { @@ -49,7 +47,6 @@ var InviteNewUserController = Ember.Controller.extend({ } }).catch(function (errors) { newUser.deleteRecord(); - self.notifications.closePassive(); self.notifications.showErrors(errors); }); diff --git a/ghost/admin/controllers/modals/transfer-owner.js b/ghost/admin/controllers/modals/transfer-owner.js index a861283dc3..ad503deaca 100644 --- a/ghost/admin/controllers/modals/transfer-owner.js +++ b/ghost/admin/controllers/modals/transfer-owner.js @@ -26,10 +26,8 @@ var TransferOwnerController = Ember.Controller.extend({ }); } - self.notifications.closePassive(); self.notifications.showSuccess('Ownership successfully transferred to ' + user.get('name')); }).catch(function (error) { - self.notifications.closePassive(); self.notifications.showAPIError(error); }); }, diff --git a/ghost/admin/controllers/post-settings-menu.js b/ghost/admin/controllers/post-settings-menu.js index 3829c6e9c4..12645169e5 100644 --- a/ghost/admin/controllers/post-settings-menu.js +++ b/ghost/admin/controllers/post-settings-menu.js @@ -103,11 +103,9 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ showErrors: function (errors) { errors = Ember.isArray(errors) ? errors : [errors]; - this.notifications.closePassive(); this.notifications.showErrors(errors); }, showSuccess: function (message) { - this.notifications.closePassive(); this.notifications.showSuccess(message); }, actions: { diff --git a/ghost/admin/controllers/posts/post.js b/ghost/admin/controllers/posts/post.js index e9bc14aeec..5127cfc312 100644 --- a/ghost/admin/controllers/posts/post.js +++ b/ghost/admin/controllers/posts/post.js @@ -9,7 +9,6 @@ var PostController = Ember.ObjectController.extend({ this.toggleProperty('featured'); this.get('model').save(options).catch(function (errors) { - self.notifications.closePassive(); self.notifications.showErrors(errors); }); } diff --git a/ghost/admin/controllers/settings/general.js b/ghost/admin/controllers/settings/general.js index 2a85bc96fb..fbe87e8416 100644 --- a/ghost/admin/controllers/settings/general.js +++ b/ghost/admin/controllers/settings/general.js @@ -31,12 +31,10 @@ var SettingsGeneralController = Ember.ObjectController.extend({ var self = this; return this.get('model').save().then(function (model) { - self.notifications.closePassive(); self.notifications.showSuccess('Settings successfully saved.'); return model; }).catch(function (errors) { - self.notifications.closePassive(); self.notifications.showErrors(errors); }); }, diff --git a/ghost/admin/controllers/settings/users/user.js b/ghost/admin/controllers/settings/users/user.js index d3a89c5142..dc95bb5c5f 100644 --- a/ghost/admin/controllers/settings/users/user.js +++ b/ghost/admin/controllers/settings/users/user.js @@ -69,7 +69,6 @@ var SettingsUserController = Ember.ObjectController.extend({ var notificationText = 'Invitation revoked. (' + email + ')'; self.notifications.showSuccess(notificationText, false); }).catch(function (error) { - self.notifications.closePassive(); self.notifications.showAPIError(error); }); }, @@ -88,7 +87,6 @@ var SettingsUserController = Ember.ObjectController.extend({ self.notifications.showSuccess(notificationText, false); } }).catch(function (error) { - self.notifications.closePassive(); self.notifications.showAPIError(error); }); }, @@ -98,12 +96,10 @@ var SettingsUserController = Ember.ObjectController.extend({ self = this; user.save({ format: false }).then(function (model) { - self.notifications.closePassive(); self.notifications.showSuccess('Settings successfully saved.'); return model; }).catch(function (errors) { - self.notifications.closePassive(); self.notifications.showErrors(errors); }); }, @@ -122,12 +118,10 @@ var SettingsUserController = Ember.ObjectController.extend({ 'ne2Password': '' }); - self.notifications.closePassive(); self.notifications.showSuccess('Password updated.'); return model; }).catch(function (errors) { - self.notifications.closePassive(); self.notifications.showAPIError(errors); }); } else { diff --git a/ghost/admin/controllers/signin.js b/ghost/admin/controllers/signin.js index d7b6967f0a..7e98e35ec3 100644 --- a/ghost/admin/controllers/signin.js +++ b/ghost/admin/controllers/signin.js @@ -19,7 +19,6 @@ var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControll self.notifications.closePassive(); self.send('authenticate'); }).catch(function (errors) { - self.notifications.closePassive(); self.notifications.showErrors(errors); }); } diff --git a/ghost/admin/mixins/editor-base-controller.js b/ghost/admin/mixins/editor-base-controller.js index ba8b0cdcf8..bdf89ff718 100644 --- a/ghost/admin/mixins/editor-base-controller.js +++ b/ghost/admin/mixins/editor-base-controller.js @@ -166,18 +166,16 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, { showSaveNotification: function (prevStatus, status, delay) { var message = this.messageMap.success.post[prevStatus][status]; - this.notifications.closePassive(); - this.notifications.showSuccess(message, delay); + this.notifications.showSuccess(message, { delayed: delay }); }, showErrorNotification: function (prevStatus, status, errors, delay) { var message = this.messageMap.errors.post[prevStatus][status]; - this.notifications.closePassive(); message += '
' + errors[0].message; - this.notifications.showError(message, delay); + this.notifications.showError(message, { delayed: delay }); }, actions: { diff --git a/ghost/admin/routes/application.js b/ghost/admin/routes/application.js index d84375aed8..8cc426fc1c 100644 --- a/ghost/admin/routes/application.js +++ b/ghost/admin/routes/application.js @@ -19,7 +19,6 @@ var ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shor }, sessionAuthenticationFailed: function (error) { - this.notifications.closePassive(); this.notifications.showError(error.message); }, @@ -38,7 +37,6 @@ var ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shor }, sessionInvalidationFailed: function (error) { - this.notifications.closePassive(); this.notifications.showError(error.message); }, diff --git a/ghost/admin/utils/notifications.js b/ghost/admin/utils/notifications.js index c80ba6b3db..85dae4732b 100644 --- a/ghost/admin/utils/notifications.js +++ b/ghost/admin/utils/notifications.js @@ -36,48 +36,84 @@ var Notifications = Ember.ArrayProxy.extend({ this.delayedNotifications.push(message); } }, - showError: function (message, delayed) { + showError: function (message, options) { + options = options || {}; + + if (!options.doNotClosePassive) { + this.closePassive(); + } + this.handleNotification({ type: 'error', message: message - }, delayed); + }, options.delayed); }, - showErrors: function (errors) { + showErrors: function (errors, options) { + options = options || {}; + + if (!options.doNotClosePassive) { + this.closePassive(); + } + for (var i = 0; i < errors.length; i += 1) { - this.showError(errors[i].message || errors[i]); + this.showError(errors[i].message || errors[i], { doNotClosePassive: true }); } }, - showAPIError: function (resp, defaultErrorText, delayed) { - defaultErrorText = defaultErrorText || 'There was a problem on the server, please try again.'; + showAPIError: function (resp, options) { + options = options || {}; + + if (!options.doNotClosePassive) { + this.closePassive(); + } + + options.defaultErrorText = options.defaultErrorText || 'There was a problem on the server, please try again.'; if (resp && resp.jqXHR && resp.jqXHR.responseJSON && resp.jqXHR.responseJSON.error) { - this.showError(resp.jqXHR.responseJSON.error, delayed); + this.showError(resp.jqXHR.responseJSON.error, options); } else if (resp && resp.jqXHR && resp.jqXHR.responseJSON && resp.jqXHR.responseJSON.errors) { - this.showErrors(resp.jqXHR.responseJSON.errors, delayed); + this.showErrors(resp.jqXHR.responseJSON.errors, options); } else if (resp && resp.jqXHR && resp.jqXHR.responseJSON && resp.jqXHR.responseJSON.message) { - this.showError(resp.jqXHR.responseJSON.message, delayed); + this.showError(resp.jqXHR.responseJSON.message, options); } else { - this.showError(defaultErrorText, delayed); + this.showError(options.defaultErrorText, { doNotClosePassive: true }); } }, - showInfo: function (message, delayed) { + showInfo: function (message, options) { + options = options || {}; + + if (!options.doNotClosePassive) { + this.closePassive(); + } + this.handleNotification({ type: 'info', message: message - }, delayed); + }, options.delayed); }, - showSuccess: function (message, delayed) { + showSuccess: function (message, options) { + options = options || {}; + + if (!options.doNotClosePassive) { + this.closePassive(); + } + this.handleNotification({ type: 'success', message: message - }, delayed); + }, options.delayed); }, // @Todo this function isn't referenced anywhere. Should it be removed? - showWarn: function (message, delayed) { + showWarn: function (message, options) { + options = options || {}; + + if (!options.doNotClosePassive) { + this.closePassive(); + } + this.handleNotification({ type: 'warn', message: message - }, delayed); + }, options.delayed); }, displayDelayed: function () { var self = this;