2016-06-30 21:14:25 +03:00
|
|
|
import Component from 'ember-component';
|
|
|
|
import computed from 'ember-computed';
|
2017-05-29 21:50:03 +03:00
|
|
|
import injectService from 'ember-service/inject';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
export default 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,
|
|
|
|
|
2016-06-30 21:14:25 +03:00
|
|
|
notifications: injectService(),
|
2015-05-26 05:10:50 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
typeClass: computed('message.type', function () {
|
|
|
|
let type = this.get('message.type');
|
|
|
|
let classes = '';
|
|
|
|
let 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) {
|
2015-10-28 14:36:45 +03:00
|
|
|
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
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
didInsertElement() {
|
2015-11-15 14:06:49 +03:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
this.$().on('animationend webkitAnimationEnd oanimationend MSAnimationEnd', (event) => {
|
2014-07-13 18:00:25 +04:00
|
|
|
if (event.originalEvent.animationName === 'fade-out') {
|
2015-10-28 14:36:45 +03:00
|
|
|
this.get('notifications').closeNotification(this.get('message'));
|
2014-07-13 18:00:25 +04:00
|
|
|
}
|
2014-03-22 16:08:15 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
willDestroyElement() {
|
2015-11-15 14:06:49 +03:00
|
|
|
this._super(...arguments);
|
2015-06-19 00:56:18 +03:00
|
|
|
this.$().off('animationend webkitAnimationEnd oanimationend MSAnimationEnd');
|
|
|
|
},
|
|
|
|
|
2014-03-22 16:08:15 +04:00
|
|
|
actions: {
|
2015-10-28 14:36:45 +03:00
|
|
|
closeNotification() {
|
2015-05-26 05:10:50 +03:00
|
|
|
this.get('notifications').closeNotification(this.get('message'));
|
2014-03-22 16:08:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|