foreign enum option reference
This commit is contained in:
@@ -175,7 +175,7 @@ class EnumFieldView extends BaseFieldView {
|
||||
this.styleMap = this.params.style || this.model.getFieldParam(this.name, 'style') || {};
|
||||
|
||||
let optionsPath = this.params.optionsPath;
|
||||
/** @type {?string} */
|
||||
/** @type {string|null} */
|
||||
const optionsReference = this.params.optionsReference;
|
||||
|
||||
if (!optionsPath && optionsReference) {
|
||||
|
||||
@@ -27,49 +27,14 @@
|
||||
************************************************************************/
|
||||
|
||||
import ArrayFieldView from 'views/fields/array';
|
||||
import ForeignEnumFieldView from 'views/fields/foreign-enum';
|
||||
|
||||
class ForeignArrayFieldView extends ArrayFieldView {
|
||||
|
||||
type = 'foreign'
|
||||
|
||||
setupOptions() {
|
||||
this.params.options = [];
|
||||
|
||||
const field = this.params.field;
|
||||
const link = this.params.link;
|
||||
|
||||
if (!field || !link) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scope = this.getMetadata().get(['entityDefs', this.model.entityType, 'links', link, 'entity']);
|
||||
|
||||
if (!scope) {
|
||||
return;
|
||||
}
|
||||
|
||||
let {
|
||||
optionsPath,
|
||||
translation,
|
||||
options,
|
||||
isSorted,
|
||||
displayAsLabel,
|
||||
style,
|
||||
} = this.getMetadata()
|
||||
.get(['entityDefs', scope, 'fields', field]);
|
||||
|
||||
options = optionsPath ? this.getMetadata().get(optionsPath) : options;
|
||||
|
||||
this.params.options = Espo.Utils.clone(options) || [];
|
||||
this.params.translation = translation;
|
||||
this.params.isSorted = isSorted || false;
|
||||
this.params.displayAsLabel = displayAsLabel || false;
|
||||
this.styleMap = style || {};
|
||||
|
||||
this.translatedOptions = Object.fromEntries(
|
||||
this.params.options
|
||||
.map(item => [item, this.getLanguage().translateOption(item, field, scope)])
|
||||
);
|
||||
ForeignEnumFieldView.prototype.setupOptions.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,13 +42,25 @@ class ForeignEnumFieldView extends EnumFieldView {
|
||||
return;
|
||||
}
|
||||
|
||||
const scope = this.getMetadata().get(['entityDefs', this.model.entityType, 'links', link, 'entity']);
|
||||
const entityType = this.getMetadata().get(`entityDefs.${this.model.entityType}.links.${link}.entity`);
|
||||
|
||||
if (!scope) {
|
||||
if (!entityType) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fieldDefs = this.getMetadata().get(['entityDefs', scope, 'fields', field]);
|
||||
/**
|
||||
* @type {{
|
||||
* optionsPath?: string|null,
|
||||
* optionsReference?: string|null,
|
||||
* translation?: string|null,
|
||||
* options?: string[],
|
||||
* isSorted?: boolean,
|
||||
* displayAsLabel?: boolean,
|
||||
* style?: Record,
|
||||
* labelType?: string,
|
||||
* }}
|
||||
*/
|
||||
const fieldDefs = this.getMetadata().get(`entityDefs.${entityType}.fields.${field}`);
|
||||
|
||||
if (!fieldDefs) {
|
||||
return;
|
||||
@@ -56,6 +68,7 @@ class ForeignEnumFieldView extends EnumFieldView {
|
||||
|
||||
let {
|
||||
optionsPath,
|
||||
optionsReference,
|
||||
translation,
|
||||
options,
|
||||
isSorted,
|
||||
@@ -64,19 +77,29 @@ class ForeignEnumFieldView extends EnumFieldView {
|
||||
labelType,
|
||||
} = fieldDefs;
|
||||
|
||||
options = optionsPath ? this.getMetadata().get(optionsPath) : options;
|
||||
if (!optionsPath && optionsReference) {
|
||||
const [refEntityType, refField] = optionsReference.split('.');
|
||||
|
||||
this.params.options = Espo.Utils.clone(options) || [];
|
||||
optionsPath = `entityDefs.${refEntityType}.fields.${refField}.options`;
|
||||
|
||||
style = this.getMetadata().get(`entityDefs.${refEntityType}.fields.${refField}.style`) ?? {};
|
||||
}
|
||||
|
||||
if (optionsPath) {
|
||||
options = this.getMetadata().get(optionsPath);
|
||||
}
|
||||
|
||||
this.params.options = Espo.Utils.clone(options) ?? [];
|
||||
this.params.translation = translation;
|
||||
this.params.isSorted = isSorted || false;
|
||||
this.params.displayAsLabel = displayAsLabel || false;
|
||||
this.params.isSorted = isSorted ?? false;
|
||||
this.params.displayAsLabel = displayAsLabel ?? false;
|
||||
this.params.labelType = labelType;
|
||||
this.styleMap = style || {};
|
||||
this.styleMap = style ?? {};
|
||||
|
||||
this.translatedOptions = Object.fromEntries(
|
||||
this.params.options
|
||||
.map(item => [item, this.getLanguage().translateOption(item, field, scope)])
|
||||
);
|
||||
const pairs = this.params.options
|
||||
.map(item => [item, this.getLanguage().translateOption(item, field, entityType)])
|
||||
|
||||
this.translatedOptions = Object.fromEntries(pairs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user