0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Refactor notifications to prevent stacking.

Closes #3511, Closes #3512, Closes #3526
- show* methods now close existing passive notifications by
  default.  They also now take an optional options object where
  existing parameters such as "delayed" and "defaultErrorText"
  can be passed in as well as the new "doNotClosePassive" flag.
- Removed all explicit calls to notifications.closePassive except
  for the few places where it makes sense to call it separately.
This commit is contained in:
Jason Williams 2014-08-01 05:40:49 +00:00
parent 063bd3536b
commit dd50cca97a
12 changed files with 56 additions and 43 deletions

View file

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

View file

@ -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.');
});

View file

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

View file

@ -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);
});
},

View file

@ -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: {

View file

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

View file

@ -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);
});
},

View file

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

View file

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

View file

@ -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 += '<br />' + errors[0].message;
this.notifications.showError(message, delay);
this.notifications.showError(message, { delayed: delay });
},
actions: {

View file

@ -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);
},

View file

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