From e93860101cc0b4730cf331b0d50bd4e9d0c769f0 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 11 Mar 2020 14:38:15 +0200 Subject: [PATCH] comples created modified fields --- .../templates/record/panels/default-side.tpl | 44 ---------- client/res/templates/record/panels/side.tpl | 2 +- client/src/views/fields/complex-created.js | 84 +++++++++++++++++++ client/src/views/record/panels/bottom.js | 3 +- .../src/views/record/panels/default-side.js | 45 +++++++--- client/src/views/record/panels/side.js | 18 ++-- 6 files changed, 135 insertions(+), 61 deletions(-) delete mode 100644 client/res/templates/record/panels/default-side.tpl create mode 100644 client/src/views/fields/complex-created.js diff --git a/client/res/templates/record/panels/default-side.tpl b/client/res/templates/record/panels/default-side.tpl deleted file mode 100644 index 6c8dbc5fbd..0000000000 --- a/client/res/templates/record/panels/default-side.tpl +++ /dev/null @@ -1,44 +0,0 @@ -{{#if fieldList.length}} -
-{{#each fieldList}} -
- -
- {{{var viewKey ../this}}} -
-
-{{/each}} -
-{{/if}} - -{{#unless complexDateFieldsDisabled}} -
- {{#if hasComplexCreated}} -
- -
- {{{createdAtField}}} » {{{createdByField}}} -
-
- {{/if}} - {{#if hasComplexModified}} -
- -
- {{{modifiedAtField}}} » {{{modifiedByField}}} -
-
- {{/if}} -
-{{/unless}} - -{{#if followersField}} -
-
- -
- {{{followersField}}} -
-
-
-{{/if}} diff --git a/client/res/templates/record/panels/side.tpl b/client/res/templates/record/panels/side.tpl index 30809576c4..ee8c2e0c12 100644 --- a/client/res/templates/record/panels/side.tpl +++ b/client/res/templates/record/panels/side.tpl @@ -2,7 +2,7 @@
{{#each fieldList}}
- +
{{{var viewKey ../this}}}
diff --git a/client/src/views/fields/complex-created.js b/client/src/views/fields/complex-created.js new file mode 100644 index 0000000000..95da9ed21f --- /dev/null +++ b/client/src/views/fields/complex-created.js @@ -0,0 +1,84 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko + * Website: https://www.espocrm.com + * + * EspoCRM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EspoCRM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EspoCRM. If not, see http://www.gnu.org/licenses/. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +define('views/fields/complex-created', 'views/fields/base', function (Dep) { + + return Dep.extend({ + + detailTemplateContent: + `{{{atField}}} `+ + `» `+ + `{{{byField}}}`, + + baseName: 'created', + + getAttributeList: function () { + return [this.fieldAt, this.fieldBy]; + }, + + setup: function () { + Dep.prototype.setup.call(this); + + this.baseName = this.options.baseName || this.baseName; + + this.fieldAt = this.baseName + 'At'; + this.fieldBy = this.baseName + 'By'; + + this.createField('at'); + this.createField('by'); + }, + + data: function () { + return _.extend({ + baseName: this.baseName, + }, Dep.prototype.data.call(this)); + }, + + createField: function (part) { + var field = this.baseName + Espo.Utils.upperCaseFirst(part); + + var type = this.model.getFieldType(field) || 'base'; + + var viewName = this.model.getFieldParam(field, 'view') || this.getFieldManager().getViewName(type); + + this.createView(part + 'Field', viewName, { + name: field, + model: this.model, + mode: 'detail', + readOnly: true, + readOnlyLocked: true, + el: this.getSelector() + ' [data-name="'+field+'"]', + }); + }, + + fetch: function () { + return {}; + }, + + }); +}); diff --git a/client/src/views/record/panels/bottom.js b/client/src/views/record/panels/bottom.js index a4e7b8b821..a6860c7030 100644 --- a/client/src/views/record/panels/bottom.js +++ b/client/src/views/record/panels/bottom.js @@ -102,6 +102,7 @@ Espo.define('views/record/panels/bottom', 'view', function (Dep) { } item = Espo.Utils.clone(item); item.viewKey = item.name + 'Field'; + item.label = item.label || item.name; if (this.recordHelper.getFieldStateParam(item.name, 'hidden') !== null) { item.hidden = this.recordHelper.getFieldStateParam(item.name, 'hidden'); @@ -143,7 +144,7 @@ Espo.define('views/record/panels/bottom', 'view', function (Dep) { }, getFields: function () { - return this.getFields(); + return this.getFieldViews(); }, getFieldList: function () { diff --git a/client/src/views/record/panels/default-side.js b/client/src/views/record/panels/default-side.js index 685e35b235..55478c4dab 100644 --- a/client/src/views/record/panels/default-side.js +++ b/client/src/views/record/panels/default-side.js @@ -26,12 +26,10 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('views/record/panels/default-side', 'views/record/panels/side', function (Dep) { +define('views/record/panels/default-side', 'views/record/panels/side', function (Dep) { return Dep.extend({ - template: 'record/panels/default-side', - data: function () { var data = Dep.prototype.data.call(this); if (this.complexCreatedDisabled && this.complexModifiedDisabled || (!this.hasComplexCreated && !this.hasComplexModified)) { @@ -43,7 +41,7 @@ Espo.define('views/record/panels/default-side', 'views/record/panels/side', func }, setup: function () { - Dep.prototype.setup.call(this); + this.fieldList = Espo.Utils.cloneDeep(this.fieldList); this.hasComplexCreated = !!this.getMetadata().get(['entityDefs', this.model.name, 'fields', 'createdAt']) @@ -55,10 +53,22 @@ Espo.define('views/record/panels/default-side', 'views/record/panels/side', func && !!this.getMetadata().get(['entityDefs', this.model.name, 'fields', 'modifiedBy']); + Dep.prototype.setup.call(this); + }, + + setupFields: function () { + Dep.prototype.setupFields.call(this); + if (!this.complexCreatedDisabled) { if (this.hasComplexCreated) { - this.createField('createdBy', null, null, null, true); - this.createField('createdAt', null, null, null, true); + this.fieldList.push({ + name: 'complexCreated', + labelText: this.translate('Created'), + isAdditional: true, + view: 'views/fields/complex-created', + readOnly: true, + }); + if (!this.model.get('createdById')) { this.recordViewObject.hideField('complexCreated'); } @@ -69,8 +79,16 @@ Espo.define('views/record/panels/default-side', 'views/record/panels/side', func if (!this.complexModifiedDisabled) { if (this.hasComplexModified) { - this.createField('modifiedBy', null, null, null, true); - this.createField('modifiedAt', null, null, null, true); + this.fieldList.push({ + name: 'complexModified', + labelText: this.translate('Modified'), + isAdditional: true, + view: 'views/fields/complex-created', + readOnly: true, + options: { + baseName: 'modified', + }, + }); } if (!this.model.get('modifiedById')) { this.recordViewObject.hideField('complexModified'); @@ -93,7 +111,13 @@ Espo.define('views/record/panels/default-side', 'views/record/panels/side', func } if (this.getMetadata().get(['scopes', this.model.name ,'stream']) && !this.getUser().isPortal()) { - this.createField('followers', 'views/fields/followers', null, null, true); + this.fieldList.push({ + name: 'followers', + labelText: this.translate('Followers'), + isAdditional: true, + view: 'views/fields/followers', + readOnly: true, + }); this.controlFollowersField(); this.listenTo(this.model, 'change:followersIds', this.controlFollowersField, this); } @@ -105,6 +129,7 @@ Espo.define('views/record/panels/default-side', 'views/record/panels/side', func } else { this.recordViewObject.hideField('followers'); } - } + }, + }); }); diff --git a/client/src/views/record/panels/side.js b/client/src/views/record/panels/side.js index 32252b8224..18d7cd95c9 100644 --- a/client/src/views/record/panels/side.js +++ b/client/src/views/record/panels/side.js @@ -102,6 +102,7 @@ Espo.define('views/record/panels/side', 'view', function (Dep) { } item = Espo.Utils.clone(item); item.viewKey = item.name + 'Field'; + item.label = item.label || item.name; if (this.recordHelper.getFieldStateParam(item.name, 'hidden') !== null) { item.hidden = this.recordHelper.getFieldStateParam(item.name, 'hidden'); @@ -113,7 +114,10 @@ Espo.define('views/record/panels/side', 'view', function (Dep) { this.fieldList = this.fieldList.filter(function (item) { if (!item.name) return; - if (!(item.name in (((this.model.defs || {}).fields) || {}))) return; + + if (!item.isAdditional) { + if (!(item.name in (((this.model.defs || {}).fields) || {}))) return; + } return true; }, this); @@ -208,16 +212,20 @@ Espo.define('views/record/panels/side', 'view', function (Dep) { } else { field = item; } - if (!(field in this.model.defs.fields)) { - return; + + if (!item.isAdditional) { + if (!(field in this.model.defs.fields)) { + return; + } } - this.createField(field, view, null, null, readOnly); + + this.createField(field, view, null, null, readOnly, item.options); }, this); }, getFields: function () { - return this.getFields(); + return this.getFieldViews(); }, getFieldViews: function () {