2015-02-13 05:22:32 +01:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2016-01-19 14:03:27 +01:00
|
|
|
const {
|
|
|
|
Component,
|
|
|
|
computed,
|
|
|
|
inject: {service}
|
|
|
|
} = Ember;
|
2015-10-28 12:36:45 +01:00
|
|
|
|
|
|
|
export default Component.extend({
|
2015-05-21 19:03:24 +02:00
|
|
|
tagName: 'article',
|
2015-06-18 23:56:18 +02:00
|
|
|
classNames: ['gh-notification', 'gh-notification-passive'],
|
2015-05-21 19:03:24 +02:00
|
|
|
classNameBindings: ['typeClass'],
|
2014-03-22 13:08:15 +01:00
|
|
|
|
2015-05-26 04:10:50 +02:00
|
|
|
message: null,
|
|
|
|
|
2016-01-19 14:03:27 +01:00
|
|
|
notifications: service(),
|
2015-05-26 04:10:50 +02:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
typeClass: computed('message.type', function () {
|
|
|
|
let type = this.get('message.type');
|
|
|
|
let classes = '';
|
|
|
|
let typeMapping;
|
2014-07-09 06:17:30 +02:00
|
|
|
|
2015-06-18 23:56:18 +02:00
|
|
|
typeMapping = {
|
|
|
|
success: 'green',
|
|
|
|
error: 'red',
|
|
|
|
warn: 'yellow'
|
|
|
|
};
|
2014-07-09 06:17:30 +02:00
|
|
|
|
2015-06-18 23:56:18 +02:00
|
|
|
if (typeMapping[type] !== undefined) {
|
2015-10-28 12:36:45 +01:00
|
|
|
classes += `gh-notification-${typeMapping[type]}`;
|
2014-07-09 06:17:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return classes;
|
2014-07-30 03:57:19 +02:00
|
|
|
}),
|
2014-07-09 06:17:30 +02:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
didInsertElement() {
|
2015-11-15 12:06:49 +01:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
this.$().on('animationend webkitAnimationEnd oanimationend MSAnimationEnd', (event) => {
|
2014-07-13 16:00:25 +02:00
|
|
|
if (event.originalEvent.animationName === 'fade-out') {
|
2015-10-28 12:36:45 +01:00
|
|
|
this.get('notifications').closeNotification(this.get('message'));
|
2014-07-13 16:00:25 +02:00
|
|
|
}
|
2014-03-22 13:08:15 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
willDestroyElement() {
|
2015-11-15 12:06:49 +01:00
|
|
|
this._super(...arguments);
|
2015-06-18 23:56:18 +02:00
|
|
|
this.$().off('animationend webkitAnimationEnd oanimationend MSAnimationEnd');
|
|
|
|
},
|
|
|
|
|
2014-03-22 13:08:15 +01:00
|
|
|
actions: {
|
2015-10-28 12:36:45 +01:00
|
|
|
closeNotification() {
|
2015-05-26 04:10:50 +02:00
|
|
|
this.get('notifications').closeNotification(this.get('message'));
|
2014-03-22 13:08:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|