1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00

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.
This commit is contained in:
Hannah Wolfe 2013-09-18 02:45:36 +01:00
parent cf842b01ec
commit 9ebfebf31c
4 changed files with 17 additions and 19 deletions

View file

@ -44,6 +44,7 @@
};
Ghost.Validate.handleErrors = function () {
Ghost.notifications.clearEverything();
_.each(Ghost.Validate._errors, function (errorObj) {
Ghost.notifications.addItem({

View file

@ -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();

View file

@ -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,

View file

@ -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,