|
|
|
@ -5,20 +5,28 @@
|
|
|
|
|
|
|
|
|
|
import Modifier from 'ember-modifier';
|
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
import { registerDestructor } from '@ember/destroyable';
|
|
|
|
|
|
|
|
|
|
function cleanup(instance) {
|
|
|
|
|
if (instance && instance?.named?.sticky) {
|
|
|
|
|
instance.notify?.clearMessages();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export default class NotificationModifier extends Modifier {
|
|
|
|
|
@service('flashMessages') notify;
|
|
|
|
|
|
|
|
|
|
didInstall() {
|
|
|
|
|
this.element.setAttribute('role', 'alert');
|
|
|
|
|
this.element.dataset['notification'] = null;
|
|
|
|
|
modify(element, _, named) {
|
|
|
|
|
this.named = named;
|
|
|
|
|
element.setAttribute('role', 'alert');
|
|
|
|
|
element.dataset['notification'] = null;
|
|
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
|
timeout: 6000,
|
|
|
|
|
extendedTimeout: 300,
|
|
|
|
|
...this.args.named,
|
|
|
|
|
...named,
|
|
|
|
|
};
|
|
|
|
|
options.dom = this.element.outerHTML;
|
|
|
|
|
this.element.remove();
|
|
|
|
|
options.dom = element.outerHTML;
|
|
|
|
|
element.remove();
|
|
|
|
|
this.notify.clearMessages();
|
|
|
|
|
if (typeof options.after === 'function') {
|
|
|
|
|
Promise.resolve()
|
|
|
|
@ -28,16 +36,13 @@ export default class NotificationModifier extends Modifier {
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
.then((_) => {
|
|
|
|
|
this.notify.add(options);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.notify.add(options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
willDestroy() {
|
|
|
|
|
if (this.args.named.sticky) {
|
|
|
|
|
this.notify.clearMessages();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registerDestructor(this, cleanup);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|