You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/ui/packages/consul-ui/app/modifiers/notification.js

38 lines
946 B

import Modifier from 'ember-modifier';
import { inject as service } from '@ember/service';
export default class NotificationModifier extends Modifier {
@service('flashMessages') notify;
didInstall() {
this.element.setAttribute('role', 'alert');
this.element.dataset['notification'] = null;
const options = {
timeout: 6000,
extendedTimeout: 300,
...this.args.named,
};
options.dom = this.element.outerHTML;
this.element.remove();
this.notify.clearMessages();
if (typeof options.after === 'function') {
Promise.resolve().then(_ => options.after())
.catch(e => {
if (e.name !== 'TransitionAborted') {
throw e;
}
})
.then(res => {
this.notify.add(options);
});
} else {
this.notify.add(options);
}
}
willDestroy() {
if(this.args.named.sticky) {
this.notify.clearMessages();
}
}
}