2014-03-22 16:08:15 +04:00
|
|
|
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') {
|
2014-06-02 00:53:16 +04:00
|
|
|
object.typeClass = object.typeClass + ' notification-passive';
|
2014-03-22 16:08:15 +04:00
|
|
|
}
|
|
|
|
this._super(object);
|
|
|
|
},
|
|
|
|
showError: function (message) {
|
|
|
|
this.pushObject({
|
|
|
|
type: 'error',
|
|
|
|
message: message
|
|
|
|
});
|
|
|
|
},
|
2014-04-20 18:48:34 +04:00
|
|
|
showErrors: function (errors) {
|
|
|
|
for (var i = 0; i < errors.length; i += 1) {
|
|
|
|
this.showError(errors[i].message || errors[i]);
|
|
|
|
}
|
|
|
|
},
|
2014-05-15 03:36:13 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2014-03-22 16:08:15 +04:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-20 18:48:34 +04:00
|
|
|
export default Notifications;
|