From ccc2ed09b87e0a0343ee95d2b914497b3dfa5a32 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 6 Aug 2022 11:22:32 +0300 Subject: [PATCH] select record ctrl enter --- client/src/views/modal.js | 17 ++++++ client/src/views/modals/select-records.js | 71 ++++++++++++++++------- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/client/src/views/modal.js b/client/src/views/modal.js index ff74a38f3c..082397bf45 100644 --- a/client/src/views/modal.js +++ b/client/src/views/modal.js @@ -843,6 +843,23 @@ define('views/modal', ['view'], function (Dep) { } }, + /** + * Whether an action item is visible and not disabled. + * + * @param {string} name An action item name. + */ + hasAvailableActionItem: function (name) { + let hasButton = this.buttonList + .findIndex(item => item.name === name && !item.disabled && !item.hidden) !== -1; + + if (hasButton) { + return true; + } + + return this.dropdownItemList + .findIndex(item => item.name === name && !item.disabled && !item.hidden) !== -1; + }, + /** * @private * @return {boolean} diff --git a/client/src/views/modals/select-records.js b/client/src/views/modals/select-records.js index d92d76416c..5272a48ede 100644 --- a/client/src/views/modals/select-records.js +++ b/client/src/views/modals/select-records.js @@ -60,6 +60,9 @@ define('views/modals/select-records', ['views/modal', 'search-manager'], functio * @inheritDoc */ shortcutKeys: { + 'Control+Enter': function (e) { + this.handleShortcutKeyCtrlEnter(e); + }, 'Control+Space': function (e) { this.handleShortcutKeyCtrlSpace(e); }, @@ -119,26 +122,7 @@ define('views/modals/select-records', ['views/modal', 'search-manager'], functio style: 'danger', label: 'Select', disabled: true, - onClick: (dialog) => { - var listView = this.getView('list'); - - if (listView.allResultIsChecked) { - this.trigger('select', { - massRelate: true, - where: this.collection.getWhere(), - searchParams: this.collection.data, - }); - } - else { - var list = listView.getSelected(); - - if (list.length) { - this.trigger('select', list); - } - } - - dialog.close(); - } + title: 'Ctrl+Enter', }); } @@ -351,6 +335,34 @@ define('views/modals/select-records', ['views/modal', 'search-manager'], functio }); }, + actionSelect: function () { + if (!this.multiple) { + return; + } + + let listView = this.getView('list'); + + if (listView.allResultIsChecked) { + this.trigger('select', { + massRelate: true, + where: this.collection.getWhere(), + searchParams: this.collection.data, + }); + + this.close(); + + return; + } + + let list = listView.getSelected(); + + if (list.length) { + this.trigger('select', list); + } + + this.close(); + }, + /** * @protected * @return {?module:views/record/search.Class} @@ -380,6 +392,25 @@ define('views/modals/select-records', ['views/modal', 'search-manager'], functio $search.focus(); }, + /** + * @protected + * @param {JQueryKeyEventObject} e + */ + handleShortcutKeyCtrlEnter: function (e) { + if (!this.multiple) { + return; + } + + if (!this.hasAvailableActionItem('select')) { + return; + } + + e.stopPropagation(); + e.preventDefault(); + + this.actionSelect(); + }, + /** * @protected * @param {JQueryKeyEventObject} e