mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-30 07:56:05 +00:00
create related stream
This commit is contained in:
@@ -59,6 +59,24 @@ class Stream extends \Espo\Core\Hooks\Base
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleCreateRelated(Entity $entity)
|
||||
{
|
||||
$relationDefs = $entity->getRelations();
|
||||
|
||||
foreach ($relationDefs as $relation => $defs) {
|
||||
if ($defs['type'] == 'belongsTo') {
|
||||
$field = $relation . 'Id';
|
||||
$scope = $defs['entity'];
|
||||
if ($entity->has($field)) {
|
||||
$entityId = $entity->get($field);
|
||||
if (!empty($entityId) && $this->getMetadata()->get("scopes.{$scope}.stream")) {
|
||||
$this->getStreamService()->noteCreateRelated($entity, $scope, $entityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function afterSave(Entity $entity)
|
||||
{
|
||||
$entityName = $entity->getEntityName();
|
||||
@@ -76,7 +94,8 @@ class Stream extends \Espo\Core\Hooks\Base
|
||||
if (!empty($assignedUserId) && $createdById != $assignedUserId) {
|
||||
$this->getStreamService()->followEntity($entity, $assignedUserId);
|
||||
}
|
||||
$this->getStreamService()->noteCreate($entity);
|
||||
$this->getStreamService()->noteCreate($entity);
|
||||
|
||||
} else {
|
||||
if ($entity->isFieldChanged('assignedUserId')) {
|
||||
$assignedUserId = $entity->get('assignedUserId');
|
||||
@@ -94,9 +113,13 @@ class Stream extends \Espo\Core\Hooks\Base
|
||||
$this->getStreamService()->noteStatus($entity, $field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*if (!$entity->isFetched() && $this->getMetadata()->get("scopes.{$entityName}.tab")) {
|
||||
$this->handleCreateRelated($entity);
|
||||
}*/
|
||||
}
|
||||
|
||||
protected function getStreamService()
|
||||
|
||||
@@ -319,6 +319,24 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$this->getEntityManager()->saveEntity($note);
|
||||
}
|
||||
|
||||
public function noteCreateRelated(Entity $entity, $entityType, $id, $action = 'created')
|
||||
{
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
|
||||
$note->set('type', 'CreateRelated');
|
||||
$note->set('parentId', $id);
|
||||
$note->set('parentType', $entityType);
|
||||
|
||||
$note->set('data', json_encode(array(
|
||||
'action' => $action,
|
||||
'entityType' => $entity->getEntityName(),
|
||||
'entityId' => $entity->id,
|
||||
'entityName' => $entity->get('name')
|
||||
)));
|
||||
|
||||
$this->getEntityManager()->saveEntity($note);
|
||||
}
|
||||
|
||||
public function noteAssign(Entity $entity)
|
||||
{
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
{{#unless onlyContent}}
|
||||
<li data-id="{{model.id}}" class="list-group-item">
|
||||
{{/unless}}
|
||||
|
||||
<div>
|
||||
|
||||
<span class="text-muted">{{{createdBy}}} {{translate action category='relateActions'}} {{relatedTypeString}} <a href="#{{entityType}}/view/{{entityId}}">{{entityName}}</a> {{translate 'on' category='stream'}}
|
||||
{{#if isUserStream}} {{parentTypeString}} {{{parent}}} {{else}} {{translate 'this' category='stream'}} {{parentTypeString}}{{/if}}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="text-muted small">{{{createdAt}}}</span>
|
||||
</div>
|
||||
|
||||
{{#unless onlyContent}}
|
||||
</li>
|
||||
{{/unless}}
|
||||
51
frontend/client/src/views/stream/notes/create-related.js
Normal file
51
frontend/client/src/views/stream/notes/create-related.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://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/.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('Views.Stream.Notes.CreateRelated', 'Views.Stream.Note', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
template: 'stream.notes.create-related',
|
||||
|
||||
data: function () {
|
||||
return _.extend({
|
||||
entityType: this.entityType,
|
||||
entityId: this.entityId,
|
||||
entityName: this.entityName,
|
||||
action: this.action,
|
||||
relatedTypeString: this.translate(this.entityType, 'scopeNames').toLowerCase()
|
||||
}, Dep.prototype.data.call(this));
|
||||
},
|
||||
|
||||
setup: function () {
|
||||
if (this.model.get('data')) {
|
||||
var data = JSON.parse(this.model.get('data'));
|
||||
|
||||
this.entityType = data.entityType || null;
|
||||
this.entityId = data.entityId || null;
|
||||
this.entityName = data.entityName || null;
|
||||
this.action = data.action || null;
|
||||
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user