Ghost/core/client/utils/notifications.js
Jacob Gable 42a1d55858 Improve signin
Ref #2413

- Remove fixture and use actual API
- Store and send down actual logged in user data
- Refactor isLoggedIn to use computed property on application
- After signin, update user data in dependency container
- Add CSRF to all routes and controllers via initializer
- Update authenticated route to check for user.isLoggedIn
- Add notifications for signin error
- Add notifications.showAPIError helper
- Add plumbing for refreshless signup to doSignUp in admin controller
2014-05-15 09:18:43 -05:00

53 lines
1.5 KiB
JavaScript

var Notifications = Ember.ArrayProxy.extend({
content: Ember.A(),
timeout: 3000,
pushObject: function (object) {
object.typeClass = 'notification-' + object.type;
// This should be somewhere else.
if (object.type === 'success') {
object.typeClass = object.typeClass + " notification-passive";
}
this._super(object);
},
showError: function (message) {
this.pushObject({
type: 'error',
message: message
});
},
showErrors: function (errors) {
for (var i = 0; i < errors.length; i += 1) {
this.showError(errors[i].message || errors[i]);
}
},
showAPIError: function (resp, defaultErrorText) {
defaultErrorText = 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);
} else {
this.showError(defaultErrorText);
}
},
showInfo: function (message) {
this.pushObject({
type: 'info',
message: message
});
},
showSuccess: function (message) {
this.pushObject({
type: 'success',
message: message
});
},
showWarn: function (message) {
this.pushObject({
type: 'warn',
message: message
});
}
});
export default Notifications;