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',
|
2015-06-19 00:56:18 +03:00
|
|
|
classNames: ['gh-notification', 'gh-notification-passive'],
|
2015-05-21 20:03:24 +03:00
|
|
|
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'),
|
2015-06-19 00:56:18 +03:00
|
|
|
type = Ember.get(message, 'type'),
|
|
|
|
typeMapping;
|
2014-07-09 08:17:30 +04:00
|
|
|
|
2015-06-19 00:56:18 +03:00
|
|
|
typeMapping = {
|
|
|
|
success: 'green',
|
|
|
|
error: 'red',
|
|
|
|
warn: 'yellow'
|
|
|
|
};
|
2014-07-09 08:17:30 +04:00
|
|
|
|
2015-06-19 00:56:18 +03:00
|
|
|
if (typeMapping[type] !== undefined) {
|
|
|
|
classes += 'gh-notification-' + typeMapping[type];
|
2014-07-09 08:17:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06-19 00:56:18 +03:00
|
|
|
self.get('notifications').closeNotification(self.get('message'));
|
2014-07-13 18:00:25 +04:00
|
|
|
}
|
2014-03-22 16:08:15 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-19 00:56:18 +03:00
|
|
|
willDestroyElement: function () {
|
|
|
|
this.$().off('animationend webkitAnimationEnd oanimationend MSAnimationEnd');
|
|
|
|
},
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|