diff --git a/addon/decorators/confirm-task.js b/addon/decorators/confirm-task.js
index 59204b3e..4b4fd711 100644
--- a/addon/decorators/confirm-task.js
+++ b/addon/decorators/confirm-task.js
@@ -1,6 +1,8 @@
import { assert } from "@ember/debug";
import UIkit from "uikit";
+import ENV from "ember-emeis/config/environment";
+
/**
* This decorator makes heavy use of the UIKit modal. If anything breaks in future releases, it could be
* caused by the use of non-public API in this decorator.
@@ -19,15 +21,15 @@ async function confirm(text, options) {
}
}
-function validate(args) {
+function initOptions(args) {
if (args.length === 1) {
assert(
"You should pass the confirm-task options as an object looking like this: { message: 'emeis.form.deleteMessage', cancel: 'emeis.form.back' } ",
typeof args[0] === "object"
);
- return true;
+ return args[0];
}
- return false;
+ return {};
}
function validateIntl(context) {
@@ -40,7 +42,7 @@ function validateIntl(context) {
function translateOptions(context, options) {
const translated = {};
for (const key in options) {
- if (LABELS.includes(key)) {
+ if (LABELS.includes(key) && context.intl.exists(options[key])) {
translated[key] = context.intl.t(options[key]);
}
}
@@ -56,6 +58,17 @@ function translateOptions(context, options) {
};
}
+function filterOptions(options) {
+ const filteredOptions = Object.fromEntries(
+ Object.entries(options).filter(([key]) => !LABELS.includes(key))
+ );
+
+ if (ENV.environment === "test") {
+ filteredOptions.container = "#ember-testing";
+ }
+ return filteredOptions;
+}
+
// make sure that decorator can be called with or without arguments
const makeFlexibleDecorator = (decorateFn, args) => {
if (args.length === 3 && !args[0].message) {
@@ -67,19 +80,23 @@ const makeFlexibleDecorator = (decorateFn, args) => {
};
export function confirmTask(...decoratorArgs) {
- const options = validate(decoratorArgs) ? decoratorArgs[0] : {};
+ const options = initOptions(decoratorArgs);
function decorate(target, property, desc) {
const gen = desc.value;
desc.value = function* (...args) {
+ const event = args.find((arg) => arg instanceof Event);
+
+ if (event) {
+ event.preventDefault();
+ }
+
validateIntl(this);
const translatedOptions = translateOptions(this, options);
// append other options which are not confirm-labels to the modal object
// that way you can modify the modal with further options like "container"
- const filteredOptions = Object.fromEntries(
- Object.entries(options).filter(([key]) => !LABELS.includes(key))
- );
+ const filteredOptions = filterOptions(options);
if (
!(yield confirm(translatedOptions.labels.message, {
...translatedOptions,
diff --git a/addon/templates/users/index.hbs b/addon/templates/users/index.hbs
index c14c3a85..b3649a58 100644
--- a/addon/templates/users/index.hbs
+++ b/addon/templates/users/index.hbs
@@ -31,7 +31,6 @@
{{t "emeis.scopes.title"}}