Skip to content

EspoCRM – Open Source CRM Application

TS migration

Yuriibc491463552b
diff --git a/client/src/views/detail.ts b/client/src/views/detail.ts
index d8afab824e..343f7412f6 100644
--- a/client/src/views/detail.ts
+++ b/client/src/views/detail.ts
@@ -45,7 +45,7 @@ export interface DetailViewOptions extends MainViewOptions {
rootUrl?: string;
isReturn?: boolean;
isAfterCreate?: boolean;
- rootData?: Record<string, unknown>
+ rootData?: Record<string, unknown>;
};
recordView?: string;
}
@@ -62,7 +62,7 @@ class DetailView<S extends DetailViewSchema = DetailViewSchema> extends MainView
protected template = 'detail'
- name: string = 'Detail'
+ readonly name: string = 'Detail'
protected optionsToPass: string[] = [
'attributes',
@@ -135,8 +135,6 @@ class DetailView<S extends DetailViewSchema = DetailViewSchema> extends MainView
protected viewModeList: string[]
protected setup() {
- super.setup();
-
if (!this.model.entityType) {
throw new Error('No entity type.');
}
diff --git a/client/src/views/edit.js b/client/src/views/edit.ts
similarity index 73%
rename from client/src/views/edit.js
rename to client/src/views/edit.ts
index b4a3ee787a..b222bd694f 100644
--- a/client/src/views/edit.js
+++ b/client/src/views/edit.ts
@@ -26,23 +26,40 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
-/** @module module:views/edit */
+import MainView, {MainViewOptions} from 'views/main';
+import Model from 'model';
+import type View from 'view';
-import MainView from 'views/main';
+export interface EditViewSchema {
+ model: Model;
+ options: EditViewOptions;
+}
+
+export interface EditViewOptions extends MainViewOptions {
+ rootUrl?: string;
+ params?: {
+ rootUrl?: string;
+ rootData?: Record<string, unknown>;
+ focusForCreate?: boolean;
+ };
+ recordView?: string;
+}
+
+type RecordView = View & {
+ setupReuse?: () => void;
+ getMode: () => 'detail' | 'edit';
+}
/**
* An edit view.
*/
-class EditView extends MainView {
+class EditView<S extends EditViewSchema = EditViewSchema> extends MainView<S> {
- /** @inheritDoc */
- template = 'edit'
+ protected template: string = 'edit'
- /** @inheritDoc */
- name = 'Edit'
+ readonly name = 'Edit'
- /** @inheritDoc */
- optionsToPass = [
+ protected optionsToPass: string[] = [
'returnUrl',
'returnDispatchParams',
'attributes',
@@ -54,53 +71,50 @@ class EditView extends MainView {
/**
* A header view name.
- *
- * @type {string}
*/
- headerView = 'views/header'
+ protected headerView = 'views/header'
/**
* A record view name.
- *
- * @type {string}
*/
- recordView = 'views/record/edit'
+ protected recordView = 'views/record/edit'
/**
* A root breadcrumb item not to be a link.
- *
- * @type {boolean}
*/
- rootLinkDisabled = false
+ protected readonly rootLinkDisabled: boolean = false
/**
* A root URL.
- *
- * @type {string}
*/
- rootUrl
+ protected rootUrl: string
- /**
- * @private
- * @type {string}
- */
- nameAttribute
+ private nameAttribute: string = 'name'
+
+ protected entityType: string | null
+
+ protected setup() {
+ if (!this.model.entityType) {
+ throw new Error('No entity type.');
+ }
+
+ this.entityType = this.model.entityType;
- /** @inheritDoc */
- setup() {
this.headerView = this.options.headerView || this.headerView;
this.recordView = this.options.recordView || this.recordView;
- this.rootUrl = this.options.rootUrl ?? this.options.params.rootUrl ?? this.rootUrl ?? '#' + this.scope;
+ this.rootUrl = this.options.rootUrl ?? this.options.params?.rootUrl ?? this.rootUrl ?? `#${this.scope}`;
- this.nameAttribute = this.getMetadata().get(`clientDefs.${this.entityType}.nameAttribute`) || 'name';
+ if (this.entityType) {
+ this.nameAttribute = this.getMetadata().get(`clientDefs.${this.entityType}.nameAttribute`) ??
+ this.nameAttribute;
+ }
this.setupHeader();
this.setupRecord();
}
- /** @inheritDoc */
- setupFinal() {
+ protected setupFinal() {
super.setupFinal();
this.wait(
@@ -111,7 +125,7 @@ class EditView extends MainView {
/**
* Set up a header.
*/
- setupHeader() {
+ protected setupHeader() {
this.createView('header', this.headerView, {
model: this.model,
fullSelector: '#main > .header',
@@ -122,19 +136,19 @@ class EditView extends MainView {
/**
* Set up a record.
*/
- setupRecord() {
+ protected setupRecord() {
const o = {
model: this.model,
fullSelector: '#main > .record',
scope: this.scope,
shortcutKeysEnabled: true,
- };
+ } as Record<string, unknown>;
this.optionsToPass.forEach(option => {
o[option] = this.options[option];
});
- const params = this.options.params || {};
+ const params = this.options.params ?? {};
o.rootUrl = this.rootUrl;
@@ -149,28 +163,22 @@ class EditView extends MainView {
return this.createView('record', this.getRecordViewName(), o);
}
- /**
- * @return {module:views/record/edit}
- */
- getRecordView() {
- return this.getView('record');
+ protected getRecordView(): RecordView {
+ return this.getView<RecordView>('record') as RecordView;
}
/**
* Get a record view name.
- *
- * @returns {string}
*/
- getRecordViewName() {
- return this.getMetadata().get('clientDefs.' + this.scope + '.recordViews.edit') || this.recordView;
+ private getRecordViewName(): string {
+ return this.getMetadata().get('clientDefs.' + this.scope + '.recordViews.edit') ?? this.recordView;
}
- /** @inheritDoc */
- getHeader() {
+ getHeader(): string {
const scopeLabel = this.getLanguage().translate(this.scope, 'scopeNamesPlural');
let root = document.createElement('span');
- root.text = scopeLabel;
+ root.textContent = scopeLabel;
root.style.userSelect = 'none';
if (!this.options.noHeaderLinks && !this.rootLinkDisabled) {
@@ -219,7 +227,6 @@ class EditView extends MainView {
return this.buildHeaderHtml([root, title]);
}
- /** @inheritDoc */
updatePageTitle() {
if (this.model.isNew()) {
const title = this.getLanguage().translate('Create') + ' ' +
@@ -237,7 +244,10 @@ class EditView extends MainView {
this.setPageTitle(title);
}
- setupReuse(params) {
+ setupReuse(params: Record<string, unknown>) {
+ // noinspection BadExpressionStatementJS
+ params;
+
const recordView = this.getRecordView();
if (!recordView) {
diff --git a/client/src/views/list.ts b/client/src/views/list.ts
index b5a002479c..1f5eb320ae 100644
--- a/client/src/views/list.ts
+++ b/client/src/views/list.ts
@@ -60,7 +60,7 @@ class ListView<S extends ListViewSchema = ListViewSchema> extends MainView<S> {
protected template = 'list'
- name: string = 'List'
+ readonly name: string = 'List'
protected optionsToPass: string[] = []
diff --git a/client/src/views/main.ts b/client/src/views/main.ts
index 0f2c422ba9..c852237851 100644
--- a/client/src/views/main.ts
+++ b/client/src/views/main.ts
@@ -26,8 +26,6 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
-/** @module views/main */
-
import View from 'view';
import {inject} from 'di';
import ShortcutManager from 'helpers/site/shortcut-manager';
@@ -180,7 +178,7 @@ class MainView<S extends MainViewSchema = MainViewSchema> extends View<S> {
/**
* A name.
*/
- name: string = ''
+ readonly name: string = ''
/**
* Top-right menu definitions.