From e7bea7e7feef551f80b3abd96f3a8e4871cff0ca Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 22 Feb 2025 09:28:03 +0200 Subject: [PATCH] ref, types --- client/src/search-manager.js | 11 +++++- .../modals/select-category-tree-records.js | 39 ++++++++++++------- client/src/views/modals/select-records.js | 17 ++++---- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/client/src/search-manager.js b/client/src/search-manager.js index e80e9f6643..48d338a45e 100644 --- a/client/src/search-manager.js +++ b/client/src/search-manager.js @@ -38,7 +38,7 @@ * @property {string} [primary] A primary filter. * @property {Object.} [bool] Bool filters. * @property {Record} [advanced] Advanced filters (field filters). - * Contains data needed for both the backend and frontend. Keys are field names. + * Contains data needed for both the backend and frontend. Keys are field names. */ /** @@ -353,9 +353,16 @@ class SearchManager { /** * Set bool filters. * - * @param {Object.} bool Bool filters. + * @param {Record.|string[]} bool Bool filters. */ setBool(bool) { + if (Array.isArray(bool)) { + const data = {}; + bool.forEach(it => data[it] = true); + + bool = data; + } + this.data = Espo.Utils.clone(this.data); this.data.bool = bool; diff --git a/client/src/views/modals/select-category-tree-records.js b/client/src/views/modals/select-category-tree-records.js index 741935c219..3ca8726694 100644 --- a/client/src/views/modals/select-category-tree-records.js +++ b/client/src/views/modals/select-category-tree-records.js @@ -31,9 +31,7 @@ import SelectRecordsModalView from 'views/modals/select-records'; class SelectCategoryTreeRecordsModalView extends SelectRecordsModalView { setup() { - /** @type {Object.} */ this.filters = this.options.filters || {}; - /** @type {Object.} */ this.boolFilterList = this.options.boolFilterList || {}; this.primaryFilterName = this.options.primaryFilterName || null; @@ -47,7 +45,7 @@ class SelectCategoryTreeRecordsModalView extends SelectRecordsModalView { this.buttonList = [ { name: 'cancel', - label: 'Cancel' + label: 'Cancel', } ]; @@ -60,17 +58,26 @@ class SelectCategoryTreeRecordsModalView extends SelectRecordsModalView { const listView = this.getRecordView(); if (listView.allResultIsChecked) { - this.trigger('select', { + const data = { massRelate: true, where: this.collection.getWhere(), searchParams: this.collection.data, - }); - } - else { + }; + + this.trigger('select', data); + + if (this.options.onMassSelect) { + this.options.onMassSelect(data); + } + } else { const list = listView.getSelected(); if (list.length) { this.trigger('select', list); + + if (this.options.onSelect) { + this.options.onSelect(list); + } } } @@ -79,25 +86,26 @@ class SelectCategoryTreeRecordsModalView extends SelectRecordsModalView { }); } - this.scope = this.options.scope; + // noinspection JSUnresolvedReference + this.scope = this.entityType = this.options.entityType || this.options.scope; this.$header = $(''); this.$header.append( $('').text( - this.translate('Select') + ': ' + - this.getLanguage().translate(this.scope, 'scopeNamesPlural') + this.translate('Select') + ' ยท ' + + this.getLanguage().translate(this.entityType, 'scopeNamesPlural') ) ); this.$header.prepend( - this.getHelper().getScopeColorIconHtml(this.scope) + this.getHelper().getScopeColorIconHtml(this.entityType) ); this.waitForView('list'); Espo.loader.require('search-manager', SearchManager => { - this.getCollectionFactory().create(this.scope, collection => { + this.getCollectionFactory().create(this.entityType, collection => { collection.maxSize = this.getConfig().get('recordsPerPageSelect') || 5; this.collection = collection; @@ -122,7 +130,7 @@ class SelectCategoryTreeRecordsModalView extends SelectRecordsModalView { collection.url = collection.entityType + '/action/listTree'; const viewName = - this.getMetadata().get('clientDefs.' + this.scope + '.recordViews.listSelectCategoryTree') || + this.getMetadata().get(`clientDefs.${this.entityType}.recordViews.listSelectCategoryTree`) || 'views/record/list-tree'; this.listenToOnce(collection, 'sync', () => { @@ -139,6 +147,11 @@ class SelectCategoryTreeRecordsModalView extends SelectRecordsModalView { }, listView => { listView.once('select', model => { this.trigger('select', model); + + if (this.options.onSelect) { + this.options.onSelect([model]); + } + this.close(); }); }); diff --git a/client/src/views/modals/select-records.js b/client/src/views/modals/select-records.js index ce2c4221a3..8af5e73257 100644 --- a/client/src/views/modals/select-records.js +++ b/client/src/views/modals/select-records.js @@ -130,6 +130,8 @@ class SelectRecordsModalView extends ModalView { /** @private */ this.createAttributesProvider = options.createAttributesProvider; + + this.options = options; } data() { @@ -140,7 +142,6 @@ class SelectRecordsModalView extends ModalView { } setup() { - /** @type {Object.} */ this.filters = this.options.filters || {}; this.boolFilterList = this.options.boolFilterList; this.primaryFilterName = this.options.primaryFilterName || null; @@ -174,6 +175,7 @@ class SelectRecordsModalView extends ModalView { }); } + // noinspection JSUnresolvedReference this.scope = this.entityType = this.options.scope || this.scope || this.options.entityType; const orderBy = this.options.orderBy || @@ -278,20 +280,14 @@ class SelectRecordsModalView extends ModalView { } const boolFilterList = this.boolFilterList || - this.getMetadata().get('clientDefs.' + this.scope + '.selectDefaultFilters.boolFilterList'); + this.getMetadata().get(`clientDefs.${this.scope}.selectDefaultFilters.boolFilterList`); if (boolFilterList) { - const d = {}; - - boolFilterList.forEach(item => { - d[item] = true; - }); - - searchManager.setBool(d); + searchManager.setBool(boolFilterList); } const primaryFilterName = this.primaryFilterName || - this.getMetadata().get('clientDefs.' + this.scope + '.selectDefaultFilters.filter'); + this.getMetadata().get(`clientDefs.${this.scope}.selectDefaultFilters.filter`); if (primaryFilterName) { searchManager.setPrimary(primaryFilterName); @@ -416,6 +412,7 @@ class SelectRecordsModalView extends ModalView { } // @todo Remove in v9.1.0. Kept bc. + // noinspection JSUnresolvedReference if (this.options.triggerCreateEvent) { this.trigger('create');