2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-05-26 05:10:50 +03:00
|
|
|
export default Ember.Component.extend({
|
2015-05-21 20:03:24 +03:00
|
|
|
tagName: 'article',
|
|
|
|
classNames: ['gh-notification', 'gh-notification-green'],
|
|
|
|
classNameBindings: ['typeClass'],
|
2014-03-22 16:08:15 +04:00
|
|
|
|
2015-05-26 05:10:50 +03:00
|
|
|
message: null,
|
|
|
|
|
|
|
|
notifications: Ember.inject.service(),
|
|
|
|
|
2014-07-30 05:57:19 +04:00
|
|
|
typeClass: Ember.computed(function () {
|
2014-07-09 08:17:30 +04:00
|
|
|
var classes = '',
|
|
|
|
message = this.get('message'),
|
|
|
|
type,
|
|
|
|
dismissible;
|
|
|
|
|
|
|
|
// Check to see if we're working with a DS.Model or a plain JS object
|
|
|
|
if (typeof message.toJSON === 'function') {
|
|
|
|
type = message.get('type');
|
|
|
|
dismissible = message.get('dismissible');
|
2014-10-25 01:09:50 +04:00
|
|
|
} else {
|
2014-07-09 08:17:30 +04:00
|
|
|
type = message.type;
|
|
|
|
dismissible = message.dismissible;
|
|
|
|
}
|
|
|
|
|
|
|
|
classes += 'notification-' + type;
|
|
|
|
|
|
|
|
if (type === 'success' && dismissible !== false) {
|
|
|
|
classes += ' notification-passive';
|
|
|
|
}
|
|
|
|
|
|
|
|
return classes;
|
2014-07-30 05:57:19 +04:00
|
|
|
}),
|
2014-07-09 08:17:30 +04:00
|
|
|
|
2014-03-22 16:08:15 +04:00
|
|
|
didInsertElement: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.$().on('animationend webkitAnimationEnd oanimationend MSAnimationEnd', function (event) {
|
2014-07-13 18:00:25 +04:00
|
|
|
if (event.originalEvent.animationName === 'fade-out') {
|
2015-05-26 05:10:50 +03:00
|
|
|
self.get('notifications').removeObject(self.get('message'));
|
2014-07-13 18:00:25 +04:00
|
|
|
}
|
2014-03-22 16:08:15 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
closeNotification: function () {
|
2015-05-26 05:10:50 +03:00
|
|
|
this.get('notifications').closeNotification(this.get('message'));
|
2014-03-22 16:08:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|