2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import {computed} from '@ember/object';
|
2020-01-10 18:12:39 +03:00
|
|
|
import {run} from '@ember/runloop';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
export default Component.extend({
|
2018-01-11 20:43:23 +03:00
|
|
|
notifications: service(),
|
|
|
|
|
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,
|
|
|
|
|
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 = {
|
|
|
|
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);
|
|
|
|
|
2020-01-10 18:12:39 +03:00
|
|
|
this._animationEndHandler = run.bind(this, function () {
|
2020-01-20 18:30:24 +03:00
|
|
|
if (event.animationName === 'fade-out') {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.notifications.closeNotification(this.message);
|
2014-07-13 18:00:25 +04:00
|
|
|
}
|
2014-03-22 16:08:15 +04:00
|
|
|
});
|
2020-01-10 18:12:39 +03:00
|
|
|
|
|
|
|
this.element.addEventListener('animationend', this._animationEndHandler);
|
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);
|
2020-01-10 18:12:39 +03:00
|
|
|
this.element.removeEventListener('animationend', this._animationEndHandler);
|
2015-06-19 00:56:18 +03:00
|
|
|
},
|
|
|
|
|
2014-03-22 16:08:15 +04:00
|
|
|
actions: {
|
2015-10-28 14:36:45 +03:00
|
|
|
closeNotification() {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.notifications.closeNotification(this.message);
|
2014-03-22 16:08:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|