From 90f8eb20fcbaa8a0285e7e30c32f1eb6d69b9686 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 4 Aug 2023 11:28:12 +0300 Subject: [PATCH] fix select with categories --- .../modals/select-records-with-categories.js | 84 ++++++++++--------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/client/src/views/modals/select-records-with-categories.js b/client/src/views/modals/select-records-with-categories.js index 80e68dc616..71c2a50842 100644 --- a/client/src/views/modals/select-records-with-categories.js +++ b/client/src/views/modals/select-records-with-categories.js @@ -33,9 +33,9 @@ class SelectRecordsWithCategoriesModalView extends SelectRecordsModal { template = 'modals/select-records-with-categories' + //categoryField = 'category' + //categoryFilterType = 'inCategory' categoryScope = '' - categoryField = 'category' - categoryFilterType = 'inCategory' isExpanded = true data() { @@ -56,60 +56,62 @@ class SelectRecordsWithCategoriesModalView extends SelectRecordsModal { super.setup(); } - loadList() { + setupList() { if (!this.categoriesDisabled) { - this.loadCategories(); + this.setupCategories(); } - super.loadList(); + super.setupList(); } - loadCategories() { - this.getCollectionFactory().create(this.categoryScope, collection => { + setupCategories() { + const promise = this.getCollectionFactory().create(this.categoryScope, collection => { + this.treeCollection = collection; + collection.url = collection.entityType + '/action/listTree'; collection.data.onlyNotEmpty = true; - this.listenToOnce(collection, 'sync', () => { - this.createView('categories', 'views/record/list-tree', { - collection: collection, - selector: '.categories-container', - selectable: true, - readOnly: true, - showRoot: true, - rootName: this.translate(this.scope, 'scopeNamesPlural'), - buttonsDisabled: true, - checkboxes: false, - isExpanded: this.isExpanded, - }, view => { - if (this.isRendered()) { - view.render(); - } else { - this.listenToOnce(this, 'after:render', () => view.render()); - } + collection.fetch() + .then(() => this.createCategoriesView()); + }); - this.listenTo(view, 'select', model => { - this.currentCategoryId = null; - this.currentCategoryName = ''; + this.wait(promise); + } - if (model && model.id) { - this.currentCategoryId = model.id; - this.currentCategoryName = model.get('name'); - } + createCategoriesView() { + this.createView('categories', 'views/record/list-tree', { + collection: this.treeCollection, + selector: '.categories-container', + selectable: true, + readOnly: true, + showRoot: true, + rootName: this.translate(this.scope, 'scopeNamesPlural'), + buttonsDisabled: true, + checkboxes: false, + isExpanded: this.isExpanded, + }, view => { + if (this.isRendered()) { + view.render(); + } else { + this.listenToOnce(this, 'after:render', () => view.render()); + } - this.applyCategoryToCollection(); + this.listenTo(view, 'select', model => { + this.currentCategoryId = null; + this.currentCategoryName = ''; - Espo.Ui.notify(' ... '); + if (model && model.id) { + this.currentCategoryId = model.id; + this.currentCategoryName = model.get('name'); + } - this.listenToOnce(this.collection, 'sync', () => { - Espo.Ui.notify(false); - }); + this.applyCategoryToCollection(); - this.collection.fetch(); - }); - }); + Espo.Ui.notify(' ... '); + + this.collection.fetch() + .then(() => Espo.Ui.notify(false)); }); - - collection.fetch(); }); }