Skip to content

EspoCRM – Open Source CRM Application

Confirm dialog Control+Enter

Yurii22458fdf9faf
diff --git a/client/src/ui.ts b/client/src/ui.ts
index c6271eda25..82dfc9f450 100644
--- a/client/src/ui.ts
+++ b/client/src/ui.ts
@@ -33,6 +33,7 @@ import DOMPurify from 'dompurify';
import JQuery from 'jquery';
import Dialog from 'ui/dialog';
import {DialogParams} from 'ui/dialog';
+import Utils from 'utils';
const $ = JQuery;
@@ -130,6 +131,34 @@ const Ui = {
confirmCount ++;
return new Promise(resolve => {
+ const confirm = () => {
+ isResolved = true;
+
+ if (callback) {
+ if (context) {
+ callback.call(context);
+ } else {
+ callback();
+ }
+ }
+
+ resolve();
+
+ dialog.close();
+ };
+
+ const keydownHandler = (e: KeyboardEvent) => {
+ if (!dialog.isTopmost()) {
+ return;
+ }
+
+ if (Utils.getKeyFromKeyEvent(e) === 'Control+Enter') {
+ confirm();
+ }
+ };
+
+ window.addEventListener('keydown', keydownHandler);
+
const dialog = new Dialog({
backdrop: backdrop,
header: null,
@@ -141,21 +170,7 @@ const Ui = {
text: ` ${confirmText} `,
name: 'confirm',
className: 'btn-s-wide',
- onClick: () => {
- isResolved = true;
-
- if (callback) {
- if (context) {
- callback.call(context);
- } else {
- callback();
- }
- }
-
- resolve();
-
- dialog.close();
- },
+ onClick: () => confirm(),
style: confirmStyle,
position: 'right',
},
@@ -181,10 +196,12 @@ const Ui = {
processCancel();
},
+ onRemove: () => {
+ window.removeEventListener('keydown', keydownHandler);
+ },
});
dialog.show();
- $(dialog.getElement()).find('button[data-name="confirm"]').trigger('focus');
});
},
diff --git a/client/src/ui/dialog.ts b/client/src/ui/dialog.ts
index 794341414d..3af795f929 100644
--- a/client/src/ui/dialog.ts
+++ b/client/src/ui/dialog.ts
@@ -523,6 +523,15 @@ class Dialog {
this.footerVNode = patch(this.footerVNode ?? this.footerElement, this.footerComponent.node());
}
+ /**
+ * Is the topmost dialog.
+ *
+ * @since 10.1.0
+ */
+ isTopmost(): boolean {
+ return shownDialogList.at(-1) === this;
+ }
+
/**
* Show.
*/
diff --git a/tsconfig.json b/tsconfig.json
index d4c28a1ba2..6e8d6d7d2f 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -8,7 +8,7 @@
"module": "ES6",
"target": "ES2018",
"lib": [
- "ES2019",
+ "ES2022",
"Decorators",
"DOM.Iterable"
],