From 4a7f967d4ffc2f4331e1138d7aa3766194b93cd3 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 9 Aug 2024 14:01:53 +0300 Subject: [PATCH] ref --- client/src/views/note/detail.js | 149 +++++++++++++------------- client/src/views/note/fields/users.js | 77 +++++++------ client/src/views/note/modals/edit.js | 44 ++++---- client/src/views/note/record/edit.js | 42 ++++---- 4 files changed, 154 insertions(+), 158 deletions(-) diff --git a/client/src/views/note/detail.js b/client/src/views/note/detail.js index 212f47412b..d96b5a16ea 100644 --- a/client/src/views/note/detail.js +++ b/client/src/views/note/detail.js @@ -26,95 +26,96 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/note/detail', ['views/main'], (Dep) => { +import MainView from 'views/main'; + +class NoteDetailView extends MainView { + + templateContent = ` + +
{{{record}}}
+ ` /** - * @class - * @name Class - * @extends module:views/main - * @memberOf module:views/note/detail + * @private */ - return Dep.extend(/** @lends module:views/note/detail.Class# */{ + isDeleted = false - templateContent: ` - -
{{{record}}}
- `, + setup() { + this.scope = this.model.entityType; - /** - * @private - */ - isDeleted: false, + this.setupHeader(); + this.setupRecord(); - setup: function () { - this.scope = this.model.entityType; + this.listenToOnce(this.model, 'remove', () => { + this.clearView('record'); + this.isDeleted = true; + this.getHeaderView().reRender(); + }); + } - this.setupHeader(); - this.setupRecord(); + /** + * @private + */ + setupHeader() { + this.createView('header', 'views/header', { + selector: '> .header', + scope: this.scope, + fontSizeFlexible: true, + }); + } - this.listenToOnce(this.model, 'remove', () => { - this.clearView('record'); - this.isDeleted = true; - this.getHeaderView().reRender(); - }); - }, + /** + * @private + */ + setupRecord() { + this.wait( + this.getCollectionFactory().create(this.scope) + .then(collection => { + this.collection = collection; + this.collection.add(this.model); - setupHeader: function () { - this.createView('header', 'views/header', { - selector: '> .header', - scope: this.scope, - fontSizeFlexible: true, - }); - }, + this.createView('record', 'views/stream/record/list', { + selector: '> .record', + collection: this.collection, + isUserStream: true, + }); + }) + ); + } - setupRecord: function () { - this.wait( - this.getCollectionFactory().create(this.scope) - .then(collection => { - this.collection = collection; - this.collection.add(this.model); + getHeader() { + const parentType = this.model.get('parentType'); + const parentId = this.model.get('parentId'); + const parentName = this.model.get('parentName'); + const type = this.model.get('type'); - this.createView('record', 'views/stream/record/list', { - selector: '> .record', - collection: this.collection, - isUserStream: true, - }); - }) - ); - }, + const $type = $('') + .text(this.getLanguage().translateOption(type, 'type', 'Note')); - getHeader: function () { - let parentType = this.model.get('parentType'); - let parentId = this.model.get('parentId'); - let parentName = this.model.get('parentName'); - let type = this.model.get('type'); - - let $type = $('') - .text(this.getLanguage().translateOption(type, 'type', 'Note')); - - if (this.model.get('deleted') || this.isDeleted) { - $type.css('text-decoration', 'line-through'); - } - - if (parentType && parentId) { - return this.buildHeaderHtml([ - $('') - .attr('href', '#' + parentType) - .text(this.translate(parentType, 'scopeNamesPlural')), - $('') - .attr('href', '#' + parentType + '/view/' + parentId) - .text(parentName || parentId), - $('') - .text(this.translate('Stream', 'scopeNames')), - $type, - ]); - } + if (this.model.get('deleted') || this.isDeleted) { + $type.css('text-decoration', 'line-through'); + } + if (parentType && parentId) { return this.buildHeaderHtml([ + $('') + .attr('href', `#${parentType}`) + .text(this.translate(parentType, 'scopeNamesPlural')), + $('') + .attr('href', `#${parentType}/view/${parentId}`) + .text(parentName || parentId), $('') .text(this.translate('Stream', 'scopeNames')), $type, ]); - }, - }); -}); + } + + return this.buildHeaderHtml([ + $('') + .text(this.translate('Stream', 'scopeNames')), + $type, + ]); + } +} + +export default NoteDetailView; diff --git a/client/src/views/note/fields/users.js b/client/src/views/note/fields/users.js index 97585bbb0f..0486a1341f 100644 --- a/client/src/views/note/fields/users.js +++ b/client/src/views/note/fields/users.js @@ -26,51 +26,48 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/note/fields/users', ['views/fields/link-multiple'], function (Dep) { +import LinkMultipleFieldView from 'views/fields/link-multiple'; - return Dep.extend({ +export default class extends LinkMultipleFieldView { - init: function () { - this.messagePermission = this.getAcl().getPermissionLevel('message'); - this.portalPermission = this.getAcl().getPermissionLevel('portal'); + init() { + this.messagePermission = this.getAcl().getPermissionLevel('message'); + this.portalPermission = this.getAcl().getPermissionLevel('portal'); - if (this.messagePermission === 'no' && this.portalPermission === 'no') { - this.readOnly = true; - } + if (this.messagePermission === 'no' && this.portalPermission === 'no') { + this.readOnly = true; + } - Dep.prototype.init.call(this); - }, + super.init(); + } - getSelectBoolFilterList: function () { - if (this.messagePermission === 'team') { - return ['onlyMyTeam']; - } - - if (this.portalPermission === 'yes') { - return null; - } - }, - - getSelectPrimaryFilterName: function () { - if (this.portalPermission === 'yes' && this.messagePermission === 'no') { - return 'activePortal'; - } - - return 'active'; - }, - - getSelectFilterList: function () { - - if (this.portalPermission === 'yes') { - if (this.messagePermission === 'no') { - return ['activePortal']; - } - - return ['active', 'activePortal']; - } + getSelectBoolFilterList() { + if (this.messagePermission === 'team') { + return ['onlyMyTeam']; + } + if (this.portalPermission === 'yes') { return null; - }, + } + } - }); -}); + getSelectPrimaryFilterName() { + if (this.portalPermission === 'yes' && this.messagePermission === 'no') { + return 'activePortal'; + } + + return 'active'; + } + + getSelectFilterList() { + if (this.portalPermission === 'yes') { + if (this.messagePermission === 'no') { + return ['activePortal']; + } + + return ['active', 'activePortal']; + } + + return null; + } +} diff --git a/client/src/views/note/modals/edit.js b/client/src/views/note/modals/edit.js index a3e5a37802..f5d31f2834 100644 --- a/client/src/views/note/modals/edit.js +++ b/client/src/views/note/modals/edit.js @@ -26,32 +26,36 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/note/modals/edit', ['views/modals/edit'], function (Dep) { +import EditModalView from 'views/modals/edit'; - return Dep.extend({ +export default class extends EditModalView { - fullFormDisabled: true, + fullFormDisabled = true - setup: function () { - Dep.prototype.setup.call(this); + setup() { + super.setup(); - this.once('ready', () => { - let recordView = this.getView('edit') || this.getView('record'); + this.once('ready', () => { + const recordView = this.getView('edit') || this.getView('record'); - if (recordView) { - var fieldView = recordView.getFieldView('post'); + if (!recordView) { + return; + } - if (fieldView) { - this.listenTo(fieldView, 'add-files', files => { - var attachmentsView = recordView.getFieldView('attachments'); + const fieldView = recordView.getFieldView('post'); - if (attachmentsView) { - recordView.getFieldView('attachments').uploadFiles(files); - } - }); - } + if (!fieldView) { + return; + } + + this.listenTo(fieldView, 'add-files', files => { + /** @type {import('views/fields/attachment-multiple').default} */ + const attachmentsView = recordView.getFieldView('attachments'); + + if (attachmentsView) { + attachmentsView.uploadFiles(files); } }); - }, - }); -}); + }); + } +} diff --git a/client/src/views/note/record/edit.js b/client/src/views/note/record/edit.js index e092bfdb9c..9fc2792d21 100644 --- a/client/src/views/note/record/edit.js +++ b/client/src/views/note/record/edit.js @@ -26,34 +26,28 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/note/record/edit', ['views/record/edit'], function (Dep) { +import EditRecordView from 'views/record/edit'; - return Dep.extend({ +export default class extends EditRecordView { - sideView: null, + sideView = null + isWide = true - isWide: true, + setup() { + super.setup(); - setup: function () { - Dep.prototype.setup.call(this); + this.controlRequiredFields(); + this.listenTo(this.model, 'change:attachmentsIds', () => { this.controlRequiredFields(); + }); + } - this.listenTo(this.model, 'change:attachmentsIds', () => { - this.controlRequiredFields(); - }); - }, - - controlRequiredFields: function () { - if (!(this.model.get('attachmentsIds') || []).length) { - this.setFieldRequired('post'); - } else { - this.setFieldNotRequired('post'); - } - }, - - afterRender: function () { - Dep.prototype.afterRender.call(this); - }, - }); -}); + controlRequiredFields() { + if (!(this.model.get('attachmentsIds') || []).length) { + this.setFieldRequired('post'); + } else { + this.setFieldNotRequired('post'); + } + } +}