note view

This commit is contained in:
Yuri Kuznetsov
2022-08-05 11:17:10 +03:00
parent 01cc896972
commit ec0649f65a
16 changed files with 259 additions and 51 deletions
+46
View File
@@ -211,4 +211,50 @@ class Note extends Entity
return in_array($userId, $userIdList);
}
public function loadAdditionalFields(): void
{
if (
$this->getType() == self::TYPE_POST ||
$this->getType() == self::TYPE_EMAIL_RECEIVED
) {
$this->loadAttachments();
}
if ($this->getParentId() && $this->getParentType()) {
$this->loadParentNameField('parent');
}
if ($this->getRelatedId() && $this->getRelatedType()) {
$this->loadParentNameField('related');
}
if (
$this->getType() == self::TYPE_POST &&
$this->getParentId() === null &&
!$this->get('isGlobal')
) {
$targetType = $this->getTargetType();
if (
!$targetType ||
$targetType === self::TARGET_USERS ||
$targetType === self::TARGET_SELF
) {
$this->loadLinkMultipleField('users');
}
if (
$targetType !== self::TARGET_USERS &&
$targetType !== self::TARGET_SELF
) {
if (!$targetType || $targetType === self::TARGET_TEAMS) {
$this->loadLinkMultipleField('teams');
}
else if ($targetType === self::TARGET_PORTALS) {
$this->loadLinkMultipleField('portals');
}
}
}
}
}
@@ -1,5 +1,6 @@
{
"scopeNames": {
"Note": "Note",
"Email": "Email",
"User": "User",
"Team": "Team",
@@ -57,6 +58,7 @@
"Mass Action": "Mass Action"
},
"scopeNamesPlural": {
"Note": "Notes",
"Email": "Emails",
"User": "Users",
"Team": "Teams",
@@ -1,4 +1,5 @@
{
"controller": "controllers/note",
"collection": "collections/note",
"recordViews": {
"edit": "views/note/record/edit",
+11
View File
@@ -383,6 +383,17 @@ class Note extends Record
parent::unlink($id, $link, $foreignId);
}
/**
* @param NoteEntity $entity
* @return void
*/
public function loadAdditionalFields(Entity $entity)
{
parent::loadAdditionalFields($entity);
$entity->loadAdditionalFields();
}
private function getUserRepository(): UserRepository
{
/** @var UserRepository */
+2 -43
View File
@@ -955,50 +955,9 @@ class Stream
return $whereClause;
}
private function loadNoteAdditionalFields(NoteEntity $e): void
private function loadNoteAdditionalFields(NoteEntity $note): void
{
if (
$e->getType() == NoteEntity::TYPE_POST ||
$e->getType() == NoteEntity::TYPE_EMAIL_RECEIVED
) {
$e->loadAttachments();
}
if ($e->getParentId() && $e->getParentType()) {
$e->loadParentNameField('parent');
}
if ($e->getRelatedId() && $e->getRelatedType()) {
$e->loadParentNameField('related');
}
if (
$e->getType() == NoteEntity::TYPE_POST &&
$e->getParentId() === null &&
!$e->get('isGlobal')
) {
$targetType = $e->getTargetType();
if (
!$targetType ||
$targetType === NoteEntity::TARGET_USERS ||
$targetType === NoteEntity::TARGET_SELF
) {
$e->loadLinkMultipleField('users');
}
if (
$targetType !== NoteEntity::TARGET_USERS &&
$targetType !== NoteEntity::TARGET_SELF
) {
if (!$targetType || $targetType === NoteEntity::TARGET_TEAMS) {
$e->loadLinkMultipleField('teams');
}
else if ($targetType === NoteEntity::TARGET_PORTALS) {
$e->loadLinkMultipleField('portals');
}
}
}
$note->loadAdditionalFields();
}
/**
+1 -1
View File
@@ -13,5 +13,5 @@
</div>
</div>
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
<a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a>
</div>
@@ -15,5 +15,5 @@
</div>
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
<a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a>
</div>
+1 -1
View File
@@ -15,5 +15,5 @@
</div>
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
<a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a>
</div>
@@ -41,6 +41,6 @@
{{/if}}
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
<a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a>
</div>
@@ -41,6 +41,6 @@
{{/if}}
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
<a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a>
</div>
+1 -1
View File
@@ -32,5 +32,5 @@
{{/if}}
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
<a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a>
</div>
+1 -1
View File
@@ -15,5 +15,5 @@
</div>
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
<a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a>
</div>
+1 -1
View File
@@ -46,5 +46,5 @@
</div>
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
<a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a>
</div>
+67
View File
@@ -0,0 +1,67 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii 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('controllers/note', ['controller'], function (Dep) {
/**
* @class
* @name Class
* @extends module:controller.Class
* @memberOf module:controllers/note
*/
return Dep.extend(/** @lends module:controllers/note.Class# */{
actionView: function (options) {
let id = options.id;
if (!id) {
throw new Espo.Espo.Exceptions.NotFound;
}
let viewName = 'views/note/detail' ||
this.getMetadata().get(['clientDefs', this.name, 'views', 'detail']);
let model;
this.showLoadingNotification();
this.modelFactory.create('Note')
.then(m => {
model = m;
model.id = id;
return model.fetch();
})
.then(() => {
this.hideLoadingNotification();
this.main(viewName, {model: model});
});
},
});
});
+120
View File
@@ -0,0 +1,120 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii 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/note/detail', ['views/main'], (Dep) => {
/**
* @class
* @name Class
* @extends module:views/main.Class
* @memberOf module:views/note/detail
*/
return Dep.extend(/** @lends module:views/note/detail.Class# */{
templateContent: `
<div class="header page-header">{{{header}}}</div>
<div class="record list-container-panel block-center">{{{record}}}</div>
`,
/**
* @private
*/
isDeleted: false,
setup: function () {
this.scope = this.model.entityType;
this.setupHeader();
this.setupRecord();
this.listenToOnce(this.model, 'remove', () => {
this.clearView('record');
this.isDeleted = true;
this.getHeaderView().reRender();
});
},
setupHeader: function () {
this.createView('header', 'views/header', {
selector: '> .header',
scope: this.scope,
fontSizeFlexible: true,
});
},
setupRecord: function () {
this.wait(
this.getCollectionFactory().create(this.scope)
.then(collection => {
this.collection = collection;
this.collection.add(this.model);
this.createView('record', 'views/stream/record/list', {
selector: '> .record',
collection: this.collection,
isUserStream: true,
});
})
);
},
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 = $('<span>')
.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([
$('<a>')
.attr('href', '#' + parentType)
.text(this.translate(parentType, 'scopeNamesPlural')),
$('<a>')
.attr('href', '#' + parentType + '/view/' + parentId)
.text(parentName || parentId),
$('<span>')
.text(this.translate('Stream', 'scopeNames')),
$type,
]);
}
return this.buildHeaderHtml([
$('<span>')
.text(this.translate('Stream', 'scopeNames')),
$type,
]);
},
});
});
+2
View File
@@ -153,6 +153,8 @@ define('views/stream/notes/post', ['views/stream/note'], function (Dep) {
if (!this.model.has('usersIds') || !this.model.get('usersIds').length) {
this.createMessage();
return;
}
let userIdList = this.model.get('usersIds');