Skip to content

EspoCRM – Open Source CRM Application

ref

Yuri Kuznetsovd7460a9e0a4d
diff --git a/client/src/views/fields/link-multiple.js b/client/src/views/fields/link-multiple.js
index 8ff91511f1..c9a1e609ad 100644
--- a/client/src/views/fields/link-multiple.js
+++ b/client/src/views/fields/link-multiple.js
@@ -1067,59 +1067,59 @@ class LinkMultipleFieldView extends BaseFieldView {
/**
* @protected
*/
- actionSelect() {
+ async actionSelect() {
Espo.Ui.notifyWait();
- const panelDefs = this.panelDefs;
-
- const viewName = panelDefs.selectModalView ||
+ const viewName = this.panelDefs.selectModalView ||
this.getMetadata().get(`clientDefs.${this.foreignScope}.modalViews.select`) ||
this.selectRecordsView;
const mandatorySelectAttributeList = this.mandatorySelectAttributeList ||
- panelDefs.selectMandatoryAttributeList;
+ this.panelDefs.selectMandatoryAttributeList;
const createButton = this.isEditMode() &&
- (!this.createDisabled && !panelDefs.createDisabled || this.forceCreateButton);
+ (!this.createDisabled && !this.panelDefs.createDisabled || this.forceCreateButton);
const createAttributesProvider = createButton ?
this.getCreateAttributesProvider() :
null;
- this._getSelectFilters().then(filters => {
- const orderBy = filters.orderBy || this.panelDefs.selectOrderBy;
- const orderDirection = filters.orderBy ? filters.order : this.panelDefs.selectOrderDirection;
-
- this.createView('dialog', viewName, {
- scope: this.foreignScope,
- createButton: createButton,
- filters: filters.advanced,
- boolFilterList: filters.bool,
- primaryFilterName: filters.primary,
- filterList: this.getSelectFilterList(),
- multiple: true,
- mandatorySelectAttributeList: mandatorySelectAttributeList,
- forceSelectAllAttributes: this.forceSelectAllAttributes,
- createAttributesProvider: createAttributesProvider,
- layoutName: this.panelDefs.selectLayout,
- orderBy: orderBy,
- orderDirection: orderDirection,
- }, dialog => {
- dialog.render();
-
- Espo.Ui.notify(false);
-
- this.listenToOnce(dialog, 'select', models => {
- this.clearView('dialog');
-
- if (Object.prototype.toString.call(models) !== '[object Array]') {
- models = [models];
- }
+ const filters = await this._getSelectFilters();
- this.select(models);
- });
- });
- });
+ const orderBy = filters.orderBy || this.panelDefs.selectOrderBy;
+ const orderDirection = filters.orderBy ? filters.order : this.panelDefs.selectOrderDirection;
+
+ /** @type {import('views/modal').default} */
+ let view;
+
+ /** @type {module:views/modals/select-records~Options} */
+ const options = {
+ entityType: this.foreignScope,
+ createButton: createButton,
+ filters: filters.advanced,
+ boolFilterList: filters.bool,
+ primaryFilterName: filters.primary,
+ filterList: this.getSelectFilterList(),
+ multiple: true,
+ mandatorySelectAttributeList: mandatorySelectAttributeList,
+ forceSelectAllAttributes: this.forceSelectAllAttributes,
+ createAttributesProvider: createAttributesProvider,
+ layoutName: this.panelDefs.selectLayout,
+ orderBy: orderBy,
+ orderDirection: orderDirection,
+ onSelect: (models) => {
+ view.close();
+
+ this.select(models);
+ },
+ };
+
+ view = /** @type {import('views/modal').default} */
+ await this.createView('modal', viewName, options);
+
+ await view.render();
+
+ Espo.Ui.notify();
}
/**
diff --git a/client/src/views/fields/link-parent.js b/client/src/views/fields/link-parent.js
index 74d63ec140..5cb7bc18b1 100644
--- a/client/src/views/fields/link-parent.js
+++ b/client/src/views/fields/link-parent.js
@@ -333,7 +333,7 @@ class LinkParentFieldView extends BaseFieldView {
this.foreignScopeList.unshift(this.foreignScope);
}
- this.listenTo(this.model, 'change:' + this.typeName, () => {
+ this.listenTo(this.model, `change:${this.typeName}`, () => {
this.foreignScope = this.model.get(this.typeName) || this.foreignScopeList[0];
});
@@ -344,53 +344,71 @@ class LinkParentFieldView extends BaseFieldView {
}
if (!this.isListMode()) {
- this.addActionHandler('selectLink', () => {
- Espo.Ui.notifyWait();
-
- const viewName = this.getMetadata().get(`clientDefs.${this.foreignScope}.modalViews.select`) ||
- this.selectRecordsView;
-
- const createButton = !this.createDisabled && this.isEditMode();
-
- this.createView('dialog', viewName, {
- scope: this.foreignScope,
- createButton: createButton,
- filters: this.getSelectFilters(),
- boolFilterList: this.getSelectBoolFilterList(),
- primaryFilterName: this.getSelectPrimaryFilterName(),
- createAttributes: createButton ? this.getCreateAttributes() : null,
- mandatorySelectAttributeList: this.getMandatorySelectAttributeList(),
- forceSelectAllAttributes: this.isForceSelectAllAttributes(),
- }, dialog => {
- dialog.render();
-
- Espo.Ui.notify(false);
-
- this.listenToOnce(dialog, 'select', (model) => {
- this.clearView('dialog');
- this.select(model);
- });
- });
- });
+ this.addActionHandler('selectLink', () => this.actionSelect());
+ this.addActionHandler('clearLink', () => this.actionClearLink());
- this.addActionHandler('clearLink', () => {
- if (this.foreignScopeList.length) {
- this.foreignScope = this.foreignScopeList[0];
- Select.setValue(this.$elementType, this.foreignScope);
- }
+ this.events[`change select[data-name="${this.typeName}"]`] = e => {
+ this.foreignScope = e.currentTarget.value;
this.$elementName.val('');
this.$elementId.val('');
+ };
+ }
+ }
- this.trigger('change');
- });
+ /**
+ * @protected
+ */
+ actionClearLink() {
+ if (this.foreignScopeList.length) {
+ this.foreignScope = this.foreignScopeList[0];
- this.events['change select[data-name="'+this.typeName+'"]'] = (e) => {
- this.foreignScope = e.currentTarget.value;
- this.$elementName.val('');
- this.$elementId.val('');
- };
+ Select.setValue(this.$elementType, this.foreignScope);
}
+
+ this.$elementName.val('');
+ this.$elementId.val('');
+
+ this.trigger('change');
+ }
+
+ /**
+ * @protected
+ */
+ async actionSelect() {
+ const viewName = this.getMetadata().get(`clientDefs.${this.foreignScope}.modalViews.select`) ||
+ this.selectRecordsView;
+
+ const createButton = !this.createDisabled && this.isEditMode();
+
+ /** @type {import('views/modal').default} */
+ let view;
+
+ /** @type {module:views/modals/select-records~Options} */
+ const options = {
+ scope: this.foreignScope,
+ createButton: createButton,
+ filters: this.getSelectFilters(),
+ boolFilterList: this.getSelectBoolFilterList(),
+ primaryFilterName: this.getSelectPrimaryFilterName(),
+ createAttributes: createButton ? this.getCreateAttributes() : null,
+ mandatorySelectAttributeList: this.getMandatorySelectAttributeList(),
+ forceSelectAllAttributes: this.isForceSelectAllAttributes(),
+ onSelect: models => {
+ view.close();
+
+ this.select(models[0]);
+ },
+ };
+
+ Espo.Ui.notifyWait();
+
+ view = view = /** @type {import('views/modal').default} */
+ await this.createView('modal', viewName, options);
+
+ await view.render();
+
+ Espo.Ui.notify();
}
/** @inheritDoc */
diff --git a/client/src/views/fields/link.js b/client/src/views/fields/link.js
index 35ac7e35b0..0d128ffdd0 100644
--- a/client/src/views/fields/link.js
+++ b/client/src/views/fields/link.js
@@ -1169,14 +1169,14 @@ class LinkFieldView extends BaseFieldView {
layoutName: this.panelDefs.selectLayout,
orderBy: orderBy,
orderDirection: orderDirection,
- onSelect: (models) => {
+ onSelect: models => {
view.close();
this.select(models[0]);
},
};
- view = /** @type {import('views/modal').default} */
+ view = /** @type {import('views/modal').default} */
await this.createView('modal', viewName, options);
await view.render();
diff --git a/client/src/views/modals/select-records.js b/client/src/views/modals/select-records.js
index 70338f36cd..b3d54de6dd 100644
--- a/client/src/views/modals/select-records.js
+++ b/client/src/views/modals/select-records.js
@@ -325,11 +325,15 @@ class SelectRecordsModalView extends ModalView {
pagination: this.getMetadata().get(['clientDefs', this.scope, 'listPagination']) || null,
}, view => {
- this.listenToOnce(view, 'select', model => {
- this.trigger('select', model);
+ this.listenToOnce(view, 'select', models => {
+ this.trigger('select', models);
if (this.onSelect) {
- this.onSelect([model]);
+ if (!Array.isArray(models)) {
+ models = [models];
+ }
+
+ this.onSelect(models);
}
this.close();
diff --git a/client/src/views/record/list.js b/client/src/views/record/list.js
index 08a3ac499a..6ee691e5a8 100644
--- a/client/src/views/record/list.js
+++ b/client/src/views/record/list.js
@@ -96,6 +96,8 @@ class ListRecordView extends View {
* @property {boolean} [displayTotalCount] Display total count.
* @property {Record} [rootData] Root data.
* @property {boolean} [columnResize] Column resize. Actual only if the settings is enabled.
+ * @property {function(import('model').default[])} [onSelect] An on-select callback. Actual if selectable.
+ * As of v9.1.0.
*/
/**
@@ -2225,6 +2227,10 @@ class ListRecordView extends View {
}
this.trigger('select', model);
+
+ if (this.options.onSelect) {
+ this.options.onSelect([model]);
+ }
}
onRemove() {