Skip to content

EspoCRM – Open Source CRM Application

TS migration

Yurii055a48ad4323
diff --git a/client/src/views/record/list-base.ts b/client/src/views/record/list-base.ts
index f15efeffb7..e056304db8 100644
--- a/client/src/views/record/list-base.ts
+++ b/client/src/views/record/list-base.ts
@@ -562,11 +562,20 @@ abstract class ListBaseRecordView<
private noRebuild: boolean | null
- private layoutLoadCallbackList: ((layout: TLayout) => void)[]
+ /**
+ * @internal
+ */
+ protected layoutLoadCallbackList: ((layout: TLayout) => void)[]
- private layoutIsBeingLoaded: boolean
+ /**
+ * @internal
+ */
+ protected layoutIsBeingLoaded: boolean
- private _listSettingsHelper: ListSettingsHelper
+ /**
+ * @internal
+ */
+ protected _listSettingsHelper: ListSettingsHelper
private _cachedFilteredListLayout: TLayout
private _cachedScopeForbiddenFieldList: string[]
@@ -2781,85 +2790,7 @@ abstract class ListBaseRecordView<
/**
* @internal
*/
- protected _convertLayout(listLayout: any, model?: Model) {
- model = model || this.collection.prepareModel();
-
- const layout = [];
-
- if (this.checkboxes) {
- layout.push({
- name: 'r-checkboxField',
- columnName: 'r-checkbox',
- template: 'record/list-checkbox',
- });
- }
-
- for (const col of listLayout) {
- const type = col.type || model.getFieldType(col.name) || 'base';
-
- if (!col.name) {
- continue;
- }
-
- const item = {
- columnName: col.name,
- name: col.name + 'Field',
- view: col.view ||
- model.getFieldParam(col.name, 'view') ||
- this.getFieldManager().getViewName(type),
- options: {
- defs: {
- name: col.name,
- params: col.params || {}
- },
- mode: 'list',
- },
- } as any;
-
- if (col.width) {
- item.options.defs.width = col.width;
- }
-
- if (col.widthPx) {
- item.options.defs.widthPx = col.widthPx;
- }
-
- if (col.link) {
- item.options.mode = 'listLink';
- }
- if (col.align) {
- item.options.defs.align = col.align;
- }
-
- if (col.options) {
- for (const optionName in col.options) {
- if (typeof item.options[optionName] !== 'undefined') {
- continue;
- }
-
- item.options[optionName] = col.options[optionName];
- }
- }
-
- if (col.name && this._listSettingsHelper) {
- if (this._listSettingsHelper.isColumnHidden(col.name, col.hidden)) {
- continue;
- }
- }
-
- if (!this._listSettingsHelper && col.hidden) {
- continue;
- }
-
- layout.push(item);
- }
-
- if (this.rowActionsView && !this.rowActionsDisabled) {
- layout.push(this.getRowActionsDefs());
- }
-
- return layout;
- }
+ protected abstract _convertLayout(listLayout: TLayout, model?: Model): any;
/**
* Select a record.
@@ -3061,16 +2992,18 @@ abstract class ListBaseRecordView<
* @param model A model.
* @param item An item.
*/
- protected getCellSelector(model: Model, item: {columnName: string}): string {
+ protected getCellSelector(
+ model: Model,
+ item: Record<string, any> & {columnName: string},
+ ): string {
return `${this.getSelector()} ${this.getRowSelector(model.id!)} .cell[data-name="${item.columnName}"]`;
}
/**
- * @protected
* @internal
*/
- protected prepareInternalLayout(internalLayout: any[], model: Model) {
- internalLayout.forEach(item => {
+ protected prepareInternalLayout(internalLayout: any, model: Model) {
+ (internalLayout as any[]).forEach(item => {
// @todo Revise whether has any effect.
// Has to be in options instead? item.options.fullSelector;
item.fullSelector = this.getCellSelector(model, item);
diff --git a/client/src/views/record/list-expanded.js b/client/src/views/record/list-expanded.ts
similarity index 60%
rename from client/src/views/record/list-expanded.js
rename to client/src/views/record/list-expanded.ts
index 0990ec6632..73cf7dfa05 100644
--- a/client/src/views/record/list-expanded.js
+++ b/client/src/views/record/list-expanded.ts
@@ -26,26 +26,65 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
-/** @module module:views/record/list-expanded */
+import ListBaseRecordView, {ListBaseRecordViewOptions, ListBaseRecordViewSchema} from 'views/record/list-base';
+import type Model from 'model';
+
+type Cell = {
+ name: string,
+ view?: string,
+ soft?: boolean,
+ small?: boolean,
+ link?: boolean;
+ align?: 'left' | 'right',
+ type?: string;
+ params?: Record<string, any>;
+ options?: Record<string, any>;
+}
+
+type Row = Cell[];
+
+export interface ListExpandedLayout {
+ rows: Row[];
+ right: {
+ name?: string,
+ view?: string,
+ options?: Record<string, any>,
+ width?: string,
+ } | null;
+}
-import ListRecordView from 'views/record/list';
+export interface ListExpandedRecordViewOptions extends ListBaseRecordViewOptions<ListExpandedLayout> {}
-class ListExpandedRecordView extends ListRecordView {
+export interface ListExpandedRecordViewSchema extends ListBaseRecordViewSchema<ListExpandedLayout> {
+ options: ListExpandedRecordViewOptions;
+}
+
+class ListExpandedRecordView<
+ S extends ListExpandedRecordViewSchema = ListExpandedRecordViewSchema
+> extends ListBaseRecordView<ListExpandedLayout, S> {
template = 'record/list-expanded'
- checkboxes = false
- selectable = false
- rowActionsView = false
- _internalLayoutType = 'list-row-expanded'
- paginationDisabled = true
- header = false
- _internalLayout = null
- checkedList = null
- listContainerEl = '> .list > ul'
- columnResize = false
-
- init() {
+ protected checkboxes: boolean = false
+
+ protected selectable: boolean = false
+
+ protected rowActionsView: string | null = null
+
+ /**
+ * @internal
+ */
+ protected _internalLayoutType: string = 'list-row-expanded'
+
+ protected paginationDisabled: boolean = true
+
+ protected header: boolean = false
+
+ protected listContainerEl: string = '> .list > ul'
+
+ protected columnResize = false
+
+ protected init() {
if (this.options.forcePagination) {
this.paginationDisabled = false;
}
@@ -53,7 +92,7 @@ class ListExpandedRecordView extends ListRecordView {
super.init();
}
- setup() {
+ protected setup() {
super.setup();
this.on('after:save', model => {
@@ -70,7 +109,10 @@ class ListExpandedRecordView extends ListRecordView {
this.displayTotalCount = false;
}
- _loadListLayout(callback) {
+ /**
+ * @internal
+ */
+ protected _loadListLayout(callback: (layout: ListExpandedLayout) => void) {
const type = this.type + 'Expanded';
this.layoutLoadCallbackList.push(callback);
@@ -81,9 +123,9 @@ class ListExpandedRecordView extends ListRecordView {
this.layoutIsBeingLoaded = true;
- this._helper.layoutManager.get(this.collection.entityType, type, listLayout => {
- this.layoutLoadCallbackList.forEach(c => {
- c(listLayout);
+ this.getHelper().layoutManager.get(this.collection.entityType, type, (listLayout: any) => {
+ this.layoutLoadCallbackList.forEach(callbackItem => {
+ callbackItem(listLayout);
this.layoutLoadCallbackList = [];
this.layoutIsBeingLoaded = false;
@@ -91,13 +133,16 @@ class ListExpandedRecordView extends ListRecordView {
});
}
- _convertLayout(listLayout, model) {
+ /**
+ * @internal
+ */
+ protected _convertLayout(listLayout: ListExpandedLayout, model?: Model) {
model = model || this.collection.prepareModel();
const layout = {
rows: [],
right: false,
- };
+ } as any;
for (const i in listLayout.rows) {
const row = listLayout.rows[i];
@@ -123,7 +168,7 @@ class ListExpandedRecordView extends ListRecordView {
align: rowItem.align,
small: rowItem.small,
soft: rowItem.soft,
- };
+ } as any;
if (rowItem.options) {
for (const optionName in rowItem.options) {
@@ -163,77 +208,86 @@ class ListExpandedRecordView extends ListRecordView {
},
};
}
- }
- else if (this.rowActionsView) {
+ } else if (this.rowActionsView) {
layout.right = this.getRowActionsDefs();
}
return layout;
}
- getRowSelector(id) {
- return 'li[data-id="' + id + '"]';
+ protected getRowSelector(id: string): string {
+ return `li[data-id="${id}"]`;
}
- getCellSelector(model, item) {
+ protected getCellSelector(
+ model: Model,
+ item: Record<string, any> & {columnName: string},
+ ): string {
+
const name = item.field || item.columnName;
- return `${this.getSelector()} ${this.getRowSelector(model.id)} .cell[data-name="${name}"]`;
+ if (!model.id) {
+ console.warn(`No record ID.`);
+ }
+
+ return `${this.getSelector()} ${this.getRowSelector(model.id!)} .cell[data-name="${name}"]`;
}
- getRowContainerHtml(id) {
- return $('<li>')
- .attr('data-id', id)
- .addClass('list-group-item list-row')
- .get(0).outerHTML;
+ protected getRowContainerHtml(id: string): string {
+ const li = document.createElement('li');
+ li.dataset.id = id;
+ li.className = 'list-group-item list-row';
+
+ return li.outerHTML;
}
- prepareInternalLayout(internalLayout, model) {
- const rows = internalLayout.rows || [];
+ /**
+ * @internal
+ */
+ protected prepareInternalLayout(internalLayout: any, model: Model) {
+ const rows = (internalLayout.rows ?? []) as any[][];
rows.forEach(row => {
row.forEach(cell => {
- //cell.fullSelector = this.getCellSelector(model, cell);
-
cell.options ??= {};
cell.options.fullSelector = this.getCellSelector(model, cell)
});
});
if (internalLayout.right) {
- //internalLayout.right.fullSelector = this.getCellSelector(model, internalLayout.right);
-
internalLayout.right.options ??= {};
internalLayout.right.options.fullSelector = this.getCellSelector(model, internalLayout.right);
}
}
- fetchAttributeListFromLayout() {
- const list = [];
+ protected fetchAttributeListFromLayout(): string[] {
+ const entityType = this.entityType;
- if (this.listLayout.rows) {
- this.listLayout.rows.forEach((row) => {
- row.forEach(item => {
- if (!item.name) {
- return;
- }
+ if (!this.listLayout?.rows || !entityType) {
+ return [];
+ }
- const field = item.name;
+ const list: string[] = [];
- const fieldType = this.getMetadata().get(['entityDefs', this.scope, 'fields', field, 'type']);
+ this.listLayout.rows.forEach(row => {
+ row.forEach(item => {
+ if (!item.name) {
+ return;
+ }
- if (!fieldType) {
- return;
- }
+ const field = item.name;
- this.getFieldManager()
- .getEntityTypeFieldAttributeList(this.scope, field)
- .forEach((attribute) => {
- list.push(attribute);
- });
- });
+ const fieldType = this.getMetadata().get(['entityDefs', entityType, 'fields', field, 'type']);
+
+ if (!fieldType) {
+ return;
+ }
+
+ this.getFieldManager()
+ .getEntityTypeFieldAttributeList(entityType, field)
+ .forEach((attribute) => list.push(attribute));
});
- }
+ });
return list;
}
diff --git a/client/src/views/record/list.ts b/client/src/views/record/list.ts
index baea92889c..bbdeeb6564 100644
--- a/client/src/views/record/list.ts
+++ b/client/src/views/record/list.ts
@@ -27,6 +27,7 @@
************************************************************************/
import ListBaseRecordView, {ListBaseRecordViewOptions, ListBaseRecordViewSchema} from 'views/record/list-base';
+import Model from 'model';
/**
* Mass-action definitions.
@@ -250,6 +251,89 @@ class ListRecordView<
protected setup() {
super.setup();
}
+
+ /**
+ * @internal
+ */
+ protected _convertLayout(listLayout: ColumnDefs[], model?: Model): any {
+ model = model || this.collection.prepareModel();
+
+ const layout = [];
+
+ if (this.checkboxes) {
+ layout.push({
+ name: 'r-checkboxField',
+ columnName: 'r-checkbox',
+ template: 'record/list-checkbox',
+ });
+ }
+
+ for (const col of listLayout) {
+ const type = col.type || model.getFieldType(col.name) || 'base';
+
+ if (!col.name) {
+ continue;
+ }
+
+ const item = {
+ columnName: col.name,
+ name: col.name + 'Field',
+ view: col.view ||
+ model.getFieldParam(col.name, 'view') ||
+ this.getFieldManager().getViewName(type),
+ options: {
+ defs: {
+ name: col.name,
+ params: col.params || {}
+ },
+ mode: 'list',
+ },
+ } as any;
+
+ if (col.width) {
+ item.options.defs.width = col.width;
+ }
+
+ if (col.widthPx) {
+ item.options.defs.widthPx = col.widthPx;
+ }
+
+ if (col.link) {
+ item.options.mode = 'listLink';
+ }
+ if (col.align) {
+ item.options.defs.align = col.align;
+ }
+
+ if (col.options) {
+ for (const optionName in col.options) {
+ if (typeof item.options[optionName] !== 'undefined') {
+ continue;
+ }
+
+ item.options[optionName] = col.options[optionName];
+ }
+ }
+
+ if (col.name && this._listSettingsHelper) {
+ if (this._listSettingsHelper.isColumnHidden(col.name, col.hidden)) {
+ continue;
+ }
+ }
+
+ if (!this._listSettingsHelper && col.hidden) {
+ continue;
+ }
+
+ layout.push(item);
+ }
+
+ if (this.rowActionsView && !this.rowActionsDisabled) {
+ layout.push(this.getRowActionsDefs());
+ }
+
+ return layout;
+ }
}
export default ListRecordView;