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