mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
foreign array fix
This commit is contained in:
@@ -30,6 +30,12 @@
|
||||
|
||||
export default class {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
entityType
|
||||
|
||||
/**
|
||||
* @param {module:views/fields/base} view A field view.
|
||||
*/
|
||||
@@ -48,6 +54,8 @@ export default class {
|
||||
const entityType = metadata.get(['entityDefs', model.entityType, 'links', link, 'entity']) ||
|
||||
model.entityType;
|
||||
|
||||
this.entityType = entityType;
|
||||
|
||||
const fieldDefs = metadata.get(['entityDefs', entityType, 'fields', field]) || {};
|
||||
const type = fieldDefs.type;
|
||||
|
||||
@@ -78,4 +86,11 @@ export default class {
|
||||
getForeignParams() {
|
||||
return Espo.Utils.cloneDeep(this.foreignParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
getEntityType() {
|
||||
return this.entityType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,31 @@
|
||||
|
||||
import ArrayFieldView from 'views/fields/array';
|
||||
import ForeignEnumFieldView from 'views/fields/foreign-enum';
|
||||
import Helper from 'helpers/misc/foreign-field';
|
||||
|
||||
class ForeignArrayFieldView extends ArrayFieldView {
|
||||
|
||||
type = 'foreign'
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
foreignEntityType
|
||||
|
||||
setup() {
|
||||
const helper = new Helper(this);
|
||||
const foreignParams = helper.getForeignParams();
|
||||
|
||||
for (const param in foreignParams) {
|
||||
this.params[param] = foreignParams[param];
|
||||
}
|
||||
|
||||
this.foreignEntityType = helper.getEntityType();
|
||||
|
||||
super.setup();
|
||||
}
|
||||
|
||||
setupOptions() {
|
||||
ForeignEnumFieldView.prototype.setupOptions.call(this);
|
||||
}
|
||||
|
||||
@@ -27,37 +27,34 @@
|
||||
************************************************************************/
|
||||
|
||||
import ChecklistFieldView from 'views/fields/checklist';
|
||||
import Helper from 'helpers/misc/foreign-field';
|
||||
import ForeignArrayFieldView from 'views/fields/foreign-array';
|
||||
|
||||
class ForeignChecklistFieldView extends ChecklistFieldView {
|
||||
|
||||
type = 'foreign'
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
foreignEntityType
|
||||
|
||||
setup() {
|
||||
const helper = new Helper(this);
|
||||
const foreignParams = helper.getForeignParams();
|
||||
|
||||
for (const param in foreignParams) {
|
||||
this.params[param] = foreignParams[param];
|
||||
}
|
||||
|
||||
this.foreignEntityType = helper.getEntityType();
|
||||
|
||||
super.setup();
|
||||
}
|
||||
|
||||
setupOptions() {
|
||||
this.params.options = [];
|
||||
|
||||
if (!this.params.field || !this.params.link) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scope = this.getMetadata()
|
||||
.get(['entityDefs', this.model.entityType, 'links', this.params.link, 'entity']);
|
||||
|
||||
if (!scope) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.params.isSorted = this.getMetadata()
|
||||
.get(['entityDefs', scope, 'fields', this.params.field, 'isSorted']) || false;
|
||||
|
||||
this.params.options = this.getMetadata()
|
||||
.get(['entityDefs', scope, 'fields', this.params.field, 'options']) || [];
|
||||
|
||||
this.translatedOptions = {};
|
||||
|
||||
this.params.options.forEach(item => {
|
||||
this.translatedOptions[item] = this.getLanguage()
|
||||
.translateOption(item, this.params.field, scope);
|
||||
});
|
||||
ForeignArrayFieldView.prototype.setupOptions.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,14 +27,32 @@
|
||||
************************************************************************/
|
||||
|
||||
import EnumFieldView from 'views/fields/enum';
|
||||
import Helper from 'helpers/misc/foreign-field';
|
||||
|
||||
class ForeignEnumFieldView extends EnumFieldView {
|
||||
|
||||
type = 'foreign'
|
||||
|
||||
setupOptions() {
|
||||
this.params.options = [];
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
foreignEntityType
|
||||
|
||||
setup() {
|
||||
const helper = new Helper(this);
|
||||
const foreignParams = helper.getForeignParams();
|
||||
|
||||
for (const param in foreignParams) {
|
||||
this.params[param] = foreignParams[param];
|
||||
}
|
||||
|
||||
this.foreignEntityType = helper.getEntityType();
|
||||
|
||||
super.setup();
|
||||
}
|
||||
|
||||
setupOptions() {
|
||||
const field = this.params.field;
|
||||
const link = this.params.link;
|
||||
|
||||
@@ -42,47 +60,15 @@ class ForeignEnumFieldView extends EnumFieldView {
|
||||
return;
|
||||
}
|
||||
|
||||
const entityType = this.getMetadata().get(`entityDefs.${this.model.entityType}.links.${link}.entity`);
|
||||
|
||||
if (!entityType) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
let {
|
||||
optionsPath,
|
||||
optionsReference,
|
||||
translation,
|
||||
options,
|
||||
isSorted,
|
||||
displayAsLabel,
|
||||
style,
|
||||
labelType,
|
||||
} = fieldDefs;
|
||||
let optionsPath = this.params.optionsPath;
|
||||
const optionsReference = this.params.optionsReference;
|
||||
let options = this.params.options;
|
||||
const style = this.params.style;
|
||||
|
||||
if (!optionsPath && optionsReference) {
|
||||
const [refEntityType, refField] = optionsReference.split('.');
|
||||
|
||||
optionsPath = `entityDefs.${refEntityType}.fields.${refField}.options`;
|
||||
|
||||
style = this.getMetadata().get(`entityDefs.${refEntityType}.fields.${refField}.style`) ?? {};
|
||||
}
|
||||
|
||||
if (optionsPath) {
|
||||
@@ -90,14 +76,10 @@ class ForeignEnumFieldView extends EnumFieldView {
|
||||
}
|
||||
|
||||
this.params.options = Espo.Utils.clone(options) ?? [];
|
||||
this.params.translation = translation;
|
||||
this.params.isSorted = isSorted ?? false;
|
||||
this.params.displayAsLabel = displayAsLabel ?? false;
|
||||
this.params.labelType = labelType;
|
||||
this.styleMap = style ?? {};
|
||||
|
||||
const pairs = this.params.options
|
||||
.map(item => [item, this.getLanguage().translateOption(item, field, entityType)])
|
||||
.map(item => [item, this.getLanguage().translateOption(item, field, this.foreignEntityType)])
|
||||
|
||||
this.translatedOptions = Object.fromEntries(pairs);
|
||||
}
|
||||
|
||||
@@ -28,11 +28,31 @@
|
||||
|
||||
import MultiEnumFieldView from 'views/fields/multi-enum';
|
||||
import ForeignArrayFieldView from 'views/fields/foreign-array';
|
||||
import Helper from 'helpers/misc/foreign-field';
|
||||
|
||||
class ForeignMultiEnumFieldView extends MultiEnumFieldView {
|
||||
|
||||
type = 'foreign'
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
foreignEntityType
|
||||
|
||||
setup() {
|
||||
const helper = new Helper(this);
|
||||
const foreignParams = helper.getForeignParams();
|
||||
|
||||
for (const param in foreignParams) {
|
||||
this.params[param] = foreignParams[param];
|
||||
}
|
||||
|
||||
this.foreignEntityType = helper.getEntityType();
|
||||
|
||||
super.setup();
|
||||
}
|
||||
|
||||
setupOptions() {
|
||||
ForeignArrayFieldView.prototype.setupOptions.call(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user