notifications

This commit is contained in:
yuri
2015-04-08 17:38:32 +03:00
parent d4f4fcb10e
commit 01af1677cf
43 changed files with 741 additions and 98 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ namespace Espo\Core\Hooks;
use \Espo\Core\Interfaces\Injectable;
class Base implements Injectable
abstract class Base implements Injectable
{
protected $dependencies = array(
'entityManager',
@@ -0,0 +1,98 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 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/.
************************************************************************/
namespace Espo\Core\Notificators;
use \Espo\Core\Interfaces\Injectable;
use \Espo\ORM\Entity;
class Base implements Injectable
{
protected $dependencies = array(
'user',
'entityManager',
);
protected $injections = array();
public static $order = 9;
public function __construct()
{
$this->init();
}
protected function init()
{
}
public function getDependencyList()
{
return $this->dependencies;
}
protected function getInjection($name)
{
return $this->injections[$name];
}
public function inject($name, $object)
{
$this->injections[$name] = $object;
}
protected function getEntityManager()
{
return $this->injections['entityManager'];
}
protected function getUser()
{
return $this->injections['user'];
}
public function process(Entity $entity)
{
if ($entity->has('assignedUserId') && $entity->get('assignedUserId')) {
$assignedUserId = $entity->get('assignedUserId');
if ($assignedUserId != $this->getUser()->id && $entity->isFieldChanged('assignedUserId')) {
$notification = $this->getEntityManager()->getEntity('Notification');
$notification->set(array(
'type' => 'Assign',
'userId' => $assignedUserId,
'data' => array(
'entityType' => $entity->getEntityType(),
'entityId' => $entity->id,
'entityName' => $entity->get('name'),
'isNew' => $entity->isNew(),
'userId' => $this->getUser()->id,
'userName' => $this->getUser()->get('name')
)
));
$this->getEntityManager()->saveEntity($notification);
}
}
}
}
@@ -136,7 +136,8 @@ class EntityManager
'customizable' => true,
'importable' => true,
'type' => $type,
'stream' => $stream
'stream' => $stream,
'notifications' => true
);
$this->getMetadata()->set('scopes', $name, $scopeData);
@@ -93,6 +93,7 @@ return array (
'disableExport' => false,
'assignmentEmailNotifications' => false,
'assignmentEmailNotificationsEntityList' => array('Lead', 'Opportunity', 'Task', 'Case'),
'assignmentNotificationsEntityList' => array('Meeting', 'Call', 'Task', 'Email'),
'emailMessageMaxSize' => 10,
'notificationsCheckInterval' => 10,
'disabledCountQueryEntityList' => array('Email'),
@@ -26,12 +26,13 @@ use Espo\ORM\Entity;
class AssignmentEmailNotification extends \Espo\Core\Hooks\Base
{
public function afterSave(Entity $entity)
{
if (
$this->getConfig()->get('assignmentEmailNotifications')
&&
$entity->has('assignedUserId')
&&
in_array($entity->getEntityName(), $this->getConfig()->get('assignmentEmailNotificationsEntityList', array()))
) {
@@ -0,0 +1,106 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 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/.
************************************************************************/
namespace Espo\Hooks\Common;
use Espo\ORM\Entity;
use Espo\Core\Utils\Util;
class Notifications extends \Espo\Core\Hooks\Base
{
public static $order = 10;
protected $noticatorsHash = array();
protected function init()
{
$this->dependencies[] = 'container';
$this->dependencies[] = 'metadata';
}
private $hasStreamCache = array();
protected function getContainer()
{
return $this->getInjection('container');
}
protected function getMetadata()
{
return $this->getInjection('metadata');
}
protected function checkHasStream($entityType)
{
if (!array_key_exists($entityType, $this->hasStreamCache)) {
$this->hasStreamCache[$entityType] = $this->getMetadata()->get("scopes.{$entityType}.stream");
}
return $this->hasStreamCache[$entityType];
}
protected function getNotificator($entityType)
{
if (empty($this->noticatorsHash[$entityType])) {
$normalizedName = Util::normilizeClassName($entityType);
$className = '\\Espo\\Custom\\Notificators\\' . $normalizedName;
if (!class_exists($className)) {
$moduleName = $this->getMetadata()->getScopeModuleName($entityName);
if ($moduleName) {
$className = '\\Espo\\Modules\\' . $moduleName . '\\Notificators\\' . $normalizedName;
} else {
$className = '\\Espo\\Notificators\\' . $normalizedName;
}
if (!class_exists($className)) {
$className = '\\Espo\\Core\\Notificators\\Base';
}
}
$notificator = new $className();
$dependencies = $notificator->getDependencyList();
foreach ($dependencies as $name) {
$notificator->inject($name, $this->getContainer()->get($name));
}
$this->noticatorsHash[$entityType] = $notificator;
}
return $this->noticatorsHash[$entityType];
}
public function afterSave(Entity $entity, array $options = array())
{
$entityType = $entity->getEntityType();
if (!empty($options['silent']) && !empty($options['noNotifications'])) {
return;
}
if (!$this->checkHasStream($entity)) {
if (in_array($entityType, $this->getConfig()->get('assignmentNotificationsEntityList', []))) {
$notificator = $this->getNotificator();
$notificator->process($entity);
}
}
}
}
+2
View File
@@ -36,6 +36,8 @@ class Stream extends \Espo\Core\Hooks\Base
protected $statusFields = null;
public static $order = 9;
protected function init()
{
$this->dependencies[] = 'serviceFactory';
@@ -6,5 +6,6 @@
"module": "Crm",
"customizable": true,
"stream": true,
"importable": true
"importable": true,
"notifications": true
}
@@ -5,5 +5,6 @@
"acl": true,
"module": "Crm",
"customizable": true,
"importable": true
"importable": true,
"notifications": true
}
@@ -6,5 +6,6 @@
"module": "Crm",
"customizable": true,
"stream": true,
"importable": true
"importable": true,
"notifications": true
}
@@ -1,5 +1,11 @@
{"entity":true,"layouts":true,"tab":true,"acl":true,"module":"Crm",
{
"entity":true,
"layouts":true,
"tab":true,
"acl":true,
"module":"Crm",
"customizable": true,
"stream": true,
"importable": true
"importable": true,
"notifications": true
}
@@ -5,5 +5,6 @@
"acl": true,
"module": "Crm",
"customizable": true,
"importable": false
"importable": false,
"notifications": true
}
@@ -6,5 +6,6 @@
"module": "Crm",
"customizable": true,
"stream": true,
"importable": true
"importable": true,
"notifications": true
}
@@ -5,5 +5,6 @@
"acl": true,
"module": "Crm",
"customizable": true,
"importable": true
"importable": true,
"notifications": true
}
@@ -6,5 +6,6 @@
"module": "Crm",
"customizable": true,
"stream": true,
"importable": true
"importable": true,
"notifications": true
}
@@ -5,5 +5,6 @@
"acl": false,
"module": "Crm",
"customizable": false,
"importable": false
"importable": false,
"notifications": false
}
@@ -6,5 +6,6 @@
"module": "Crm",
"customizable": false,
"stream": false,
"importable": false
"importable": false,
"notifications": true
}
@@ -5,5 +5,6 @@
"acl": true,
"module": "Crm",
"customizable": true,
"importable": true
"importable": true,
"notifications": true
}
+83
View File
@@ -0,0 +1,83 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 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/.
************************************************************************/
namespace Espo\Notificators;
use \Espo\ORM\Entity;
class Email extends \Espo\Core\Notificators\Base
{
public function process(Entity $entity)
{
if (!$entity->isNew()) {
return;
}
$userIdList = [];
if ($entity->has('assignedUserId') && $entity->get('assignedUserId')) {
$assignedUserId = $entity->get('assignedUserId');
if ($assignedUserId != $this->getUser()->id && $entity->isFieldChanged('assignedUserId')) {
$userIdList[] = $assignedUserId;
}
}
$emailUserIdList = $email->get('usersIds');
if (is_null($emailUserIdList)) {
$email->loadLinkMultipleField('from');
$emailUserIdList = $email->get('usersIds');
}
if (!is_array($emailUserIdList)) {
$emailUserIdList = [];
}
foreach ($emailUserIdList as $userId) {
if (!in_array($userId, $userIdList)) {
$userIdList[] = $userId;
}
}
$data = array(
'emailId' => $entity->id,
'emailName' => $entity->get('name'),
);
$from = $entity->get('from');
if ($from) {
$person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddress($from);
if ($person) {
$data['personEntityType'] = $person->getEntityName();
$data['personEntityName'] = $person->get('name');
$data['personEntityId'] = $person->id;
}
}
foreach ($userIdList as $userId) {
$notification = $this->getEntityManager()->getEntity('Notification');
$notification->set(array(
'type' => 'EmailReceived',
'userId' => $userId,
'data' => $data
));
$this->getEntityManager()->saveEntity($notification);
}
}
}
@@ -44,7 +44,8 @@
"Create Entity": "Create Entity",
"Edit Entity": "Edit Entity",
"Create Link": "Create Link",
"Edit Link": "Edit Link"
"Edit Link": "Edit Link",
"Notifications": "Notifications"
},
"layouts": {
"list": "List",
@@ -138,7 +139,8 @@
"authentication": "Authentication settings.",
"currency": "Currency settings and rates.",
"extensions": "Install or uninstall extensions.",
"integrations": "Integration with third-party services."
"integrations": "Integration with third-party services.",
"notifications": "In-app and email notification settings."
},
"options": {
"previewSize": {
@@ -225,6 +225,10 @@
"dashlets": {
"Stream": "Stream"
},
"notificationMessages": {
"assign": "{entityType} {entity} has been assigned to you",
"emailReceived": "Email received from {from}"
},
"streamMessages": {
"create": "{user} created {entityType} {entity}",
"createAssigned": "{user} created {entityType} {entity} assigned to {assignee}",
@@ -53,8 +53,9 @@
"ldapAccountDomainNameShort": "Account Domain Name Short",
"ldapOptReferrals": "Opt Referrals",
"disableExport": "Disable Export (only admin is allowed)",
"assignmentNotificationsEntityList": "Entities to Notify about upon Assignment",
"assignmentEmailNotifications": "Send Email Notifications upon Assignment",
"assignmentEmailNotificationsEntityList": "Entities to Notify About",
"assignmentEmailNotificationsEntityList": "Entities to Notify about with Email upon Assignment",
"b2cMode": "B2C Mode",
"disableAvatars": "Disable Avatars"
},
@@ -72,7 +73,8 @@
"Locale": "Locale",
"SMTP": "SMTP",
"Configuration": "Configuration",
"Notifications": "Notifications",
"In-app Notifications": "In-app Notifications",
"Email Notifications": "Email Notifications",
"Currency Settings": "Currency Settings",
"Currency Rtes": "Currency Rates"
}
@@ -0,0 +1,15 @@
[
{
"label": "In-app Notifications",
"rows": [
[{"name": "assignmentNotificationsEntityList"}]
]
},
{
"label": "Email Notifications",
"rows": [
[{"name": "assignmentEmailNotifications"}],
[{"name": "assignmentEmailNotificationsEntityList"}]
]
}
]
@@ -14,11 +14,5 @@
[{"name": "outboundEmailFromName"}, {"name": "outboundEmailFromAddress"}],
[{"name": "outboundEmailIsShared"}]
]
},
{
"label": "Notifications",
"rows": [
[{"name": "assignmentEmailNotifications"}, {"name": "assignmentEmailNotificationsEntityList"}]
]
}
]
@@ -22,6 +22,11 @@
"label":"Currency",
"description":"currency"
},
{
"url":"#Admin/notifications",
"label":"Notifications",
"description":"notifications"
},
{
"url":"#Admin/integrations",
"label":"Integrations",
@@ -214,6 +214,11 @@
"translation": "Global.scopeNamesPlural",
"view": "Settings.Fields.AssignmentEmailNotificationsEntityList"
},
"assignmentNotificationsEntityList": {
"type": "multiEnum",
"translation": "Global.scopeNamesPlural",
"view": "Settings.Fields.AssignmentNotificationsEntityList"
},
"b2cMode": {
"type": "bool",
"default": false
@@ -2,5 +2,6 @@
"entity": true,
"layouts": false,
"tab": true,
"acl": true
"acl": true,
"notifications": true
}
+1 -1
View File
@@ -470,7 +470,7 @@ class Import extends \Espo\Services\Record
try {
$isDuplicate = $recordService->checkEntityForDuplicate($entity);
if ($this->getEntityManager()->saveEntity($entity, array('noStream' => true))) {
if ($this->getEntityManager()->saveEntity($entity, array('noStream' => true, 'noNotifications' => true))) {
$result['id'] = $entity->id;
if (empty($id)) {
$result['isImported'] = true;
@@ -0,0 +1 @@
<h3><a href="#Admin">{{translate 'Administration'}}</a> &raquo {{translate 'Notifications' scope='Admin'}}</h3>
@@ -0,0 +1,11 @@
<div class="stream-head-container">
<div class="pull-left">
{{{avatar}}}
</div>
<div class="stream-head-text-container text-muted">
{{{message}}}
</div>
</div>
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
</div>
@@ -0,0 +1,44 @@
{{#unless onlyContent}}
<li data-id="{{model.id}}" class="list-group-item">
{{/unless}}
{{#unless noEdit}}
<div class="pull-right right-container">
{{{right}}}
</div>
{{/unless}}
<div class="stream-head-container">
<div class="pull-left">
{{{avatar}}}
</div>
<div class="stream-head-text-container">
<span class="text-muted"><span class="glyphicon glyphicon-envelope action" style="cursor: pointer;" title="{{translate 'View'}}" data-action="viewRecord" data-id="{{emailId}}" data-scope="Email"></span>
{{{message}}}
</span>
</div>
</div>
<div class="stream-subject-container">
<span class="cell cell-name"><a href="#Email/view/{{emailId}}">{{emailName}}</a></span>
</div>
{{#if post}}
<div class="stream-post-container">
<span class="cell cell-post">{{{post}}}</span>
</div>
{{/if}}
{{#if attachments}}
<div class="stream-attachments-container">
<span class="cell cell-attachments">{{{attachments}}}</span>
</div>
{{/if}}
<div class="stream-date-container">
<span class="text-muted small">{{{createdAt}}}</span>
</div>
{{#unless onlyContent}}
</li>
{{/unless}}
+16
View File
@@ -86,6 +86,22 @@ Espo.define('Controllers.Admin', 'Controller', function (Dep) {
model.fetch();
},
notifications: function () {
var model = this.getSettingsModel();
model.once('sync', function () {
model.id = '1';
this.main('Edit', {
model: model,
views: {
header: {template: 'admin.settings.header-notifications'},
body: {view: 'Admin.Notifications'}
},
});
}, this);
model.fetch();
},
outboundEmail: function () {
var model = this.getSettingsModel();
@@ -0,0 +1,54 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 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.Admin.Notifications', 'Views.Settings.Record.Edit', function (Dep) {
return Dep.extend({
layoutName: 'notifications',
dependencyDefs: {
'assignmentEmailNotifications': {
map: {
true: [
{
action: 'show',
fields: ['assignmentEmailNotificationsEntityList']
}
]
},
default: [
{
action: 'hide',
fields: ['assignmentEmailNotificationsEntityList']
}
]
}
},
setup: function () {
Dep.prototype.setup.call(this);
}
});
});
@@ -17,31 +17,15 @@
*
* 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.Admin.OutboundEmail', 'Views.Settings.Record.Edit', function (Dep) {
************************************************************************/
Espo.define('Views.Admin.OutboundEmail', 'Views.Settings.Record.Edit', function (Dep) {
return Dep.extend({
layoutName: 'outboundEmail',
dependencyDefs: {
'assignmentEmailNotifications': {
map: {
true: [
{
action: 'show',
fields: ['assignmentEmailNotificationsEntityList']
}
]
},
default: [
{
action: 'hide',
fields: ['assignmentEmailNotificationsEntityList']
}
]
},
'smtpAuth': {
map: {
true: [
@@ -58,16 +42,15 @@ Espo.define('Views.Admin.OutboundEmail', 'Views.Settings.Record.Edit', function
}
]
}
},
setup: function () {
Dep.prototype.setup.call(this);
},
setup: function () {
Dep.prototype.setup.call(this);
},
afterRender: function () {
Dep.prototype.afterRender.call(this);
Dep.prototype.afterRender.call(this);
var smtpSecurityField = this.getFieldView('smtpSecurity');
this.listenTo(smtpSecurityField, 'change', function () {
var smtpSecurity = smtpSecurityField.fetch()['smtpSecurity'];
@@ -77,11 +60,11 @@ Espo.define('Views.Admin.OutboundEmail', 'Views.Settings.Record.Edit', function
this.model.set('smtpPort', '587');
} else {
this.model.set('smtpPort', '25');
}
}.bind(this));
}
}.bind(this));
},
});
});
});
@@ -17,19 +17,18 @@
*
* 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.Notifications.Field', 'Views.Fields.Base', function (Dep) {
return Dep.extend({
type: 'notification',
type: 'notification',
listTemplate: 'notifications.field',
detailTemplate: 'notifications.field',
setup: function () {
switch (this.model.get('type')) {
case 'Note':
@@ -37,41 +36,54 @@ Espo.define('Views.Notifications.Field', 'Views.Fields.Base', function (Dep) {
break;
case 'MentionInPost':
this.processMentionInPost(this.model.get('noteData'));
break;
break;
default:
this.process();
}
},
processNote: function (data) {
process: function () {
var type = this.model.get('type');
if (!type) return;
var viewName = 'Notifications.Items.' + type.replace(/ /g, '');
this.createView('notification', viewName, {
model: this.model,
el: this.params.containerEl + ' li[data-id="' + this.model.id + '"]',
});
},
processNote: function (data) {
this.wait(true);
this.getModelFactory().create('Note', function (model) {
model.set(data);
model.set(data);
var viewName = 'Stream.Notes.' + data.type;
this.createView('notification', viewName, {
model: model,
isUserStream: true,
el: this.params.containerEl + ' li[data-id="' + this.model.id + '"]',
onlyContent: true,
onlyContent: true,
});
this.wait(false);
}, this);
}, this);
},
processMentionInPost: function (data) {
processMentionInPost: function (data) {
this.wait(true);
this.getModelFactory().create('Note', function (model) {
model.set(data);
model.set(data);
var viewName = 'Stream.Notes.MentionInPost';
this.createView('notification', viewName, {
model: model,
userId: this.model.get('userId'),
isUserStream: true,
el: this.params.containerEl + ' li[data-id="' + this.model.id + '"]',
onlyContent: true,
onlyContent: true,
});
this.wait(false);
}, this);
},
});
});
@@ -0,0 +1,44 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 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.Notifications.Items.Assign', 'Views.Notifications.Notification', function (Dep) {
return Dep.extend({
messageName: 'assign',
template: 'notifications.items.assign',
setup: function () {
var data = this.model.get('data') || {};
this.userId = data.userId;
this.messageData['entityType'] = Espo.Utils.upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase());
this.messageData['entity'] = '<a href="#' + data.entityType + '/view/' + data.entityId + '">' + data.entityName + '</a>';
this.messageData['user'] = '<a href="#User/view/' + data.userId + '">' + data.userName + '</a>';
this.createMessage();
},
});
});
@@ -0,0 +1,95 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 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.Notifications.Notification', 'View', function (Dep) {
return Dep.extend({
messageName: null,
messageTemplate: null,
messageData: null,
isSystemAvatar: true,
data: function () {
return {
avatar: this.getAvatarHtml()
};
},
init: function () {
this.createField('createdAt', null, null, 'Fields.DatetimeShort');
this.messageData = {};
},
createField: function (name, type, params, view) {
type = type || this.model.getFieldType(name) || 'base';
this.createView(name, view || this.getFieldManager().getViewName(type), {
model: this.model,
defs: {
name: name,
params: params || {}
},
el: this.options.el + ' .cell-' + name,
mode: 'list'
});
},
createMessage: function () {
if (!this.messageTemplate) {
this.messageTemplate = this.translate(this.messageName, 'notificationMessages') || '';
}
this.createView('message', 'Stream.Message', {
messageTemplate: this.messageTemplate,
el: this.options.el + ' .message',
model: this.model,
messageData: this.messageData
});
},
getAvatarHtml: function () {
if (this.getConfig().get('disableAvatars')) {
return '';
}
var t;
var cache = this.getCache();
if (cache) {
t = cache.get('app', 'timestamp');
} else {
t = Date.now();
}
var id = this.userId;
if (this.isSystemAvatar) {
id = 'system';
}
if (!id) {
return '';
}
return '<img class="avatar" width="20" src="?entryPoint=avatar&size=small&id=' + id + '&t='+t+'">';
}
});
});
@@ -21,18 +21,18 @@
Espo.define('Views.Settings.Fields.AssignmentEmailNotificationsEntityList', 'Views.Fields.MultiEnum', function (Dep) {
return Dep.extend({
setup: function () {
this.params.options = Object.keys(this.getMetadata().get('scopes')).filter(function (scope) {
return this.getMetadata().get('scopes.' + scope + '.tab') && this.getMetadata().get('scopes.' + scope + '.entity');
return this.getMetadata().get('scopes.' + scope + '.notifications') && this.getMetadata().get('scopes.' + scope + '.entity');
}, this).sort(function (v1, v2) {
return this.translate(v1, 'scopeNamesPlural').localeCompare(this.translate(v2, 'scopeNamesPlural'));
}.bind(this));
Dep.prototype.setup.call(this);
},
});
});
@@ -0,0 +1,40 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 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.Settings.Fields.AssignmentNotificationsEntityList', 'Views.Fields.MultiEnum', function (Dep) {
return Dep.extend({
setup: function () {
this.params.options = Object.keys(this.getMetadata().get('scopes')).filter(function (scope) {
return this.getMetadata().get('scopes.' + scope + '.notifications') &&
!this.getMetadata().get('scopes.' + scope + '.stream') &&
this.getMetadata().get('scopes.' + scope + '.entity');
}, this).sort(function (v1, v2) {
return this.translate(v1, 'scopeNamesPlural').localeCompare(this.translate(v2, 'scopeNamesPlural'));
}.bind(this));
Dep.prototype.setup.call(this);
},
});
});
+13 -14
View File
@@ -17,34 +17,34 @@
*
* 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.Message', 'View', function (Dep) {
return Dep.extend({
setup: function () {
var template = this.options.messageTemplate;
var template = this.options.messageTemplate;
var data = this.options.messageData;
for (var key in data) {
var value = data[key] || '';
if (value.indexOf('field:') === 0) {
var field = value.substr(6);
this.createField(key, field);
template = template.replace('{' + key +'}', '{{{' + key +'}}}');
template = template.replace('{' + key +'}', '{{{' + key +'}}}');
} else {
template = template.replace('{' + key +'}', value);
}
}
this._template = template;
this._template = template;
},
createField: function (key, name, type, params) {
type = type || this.model.getFieldType(name) || 'base';
createField: function (key, name, type, params) {
type = type || this.model.getFieldType(name) || 'base';
this.createView(key, this.getFieldManager().getViewName(type), {
model: this.model,
defs: {
@@ -53,8 +53,7 @@ Espo.define('Views.Stream.Message', 'View', function (Dep) {
},
mode: 'list'
});
},
}
});
});
+7 -1
View File
@@ -33,6 +33,8 @@ Espo.define('Views.Stream.Note', 'View', function (Dep) {
isRemovable: false,
isSystemAvatar: false,
data: function () {
return {
isUserStream: this.isUserStream,
@@ -125,7 +127,11 @@ Espo.define('Views.Stream.Note', 'View', function (Dep) {
} else {
t = Date.now();
}
return '<img class="avatar" width="20" src="?entryPoint=avatar&size=small&id=' + this.model.get('createdById') + '&t='+t+'">';
var id = this.model.get('createdById');
if (this.isSystemAvatar) {
id = 'system';
}
return '<img class="avatar" width="20" src="?entryPoint=avatar&size=small&id=' + id + '&t='+t+'">';
}
});
@@ -27,6 +27,8 @@ Espo.define('Views.Stream.Notes.EmailReceived', 'Views.Stream.Note', function (D
isRemovable: true,
isSystemAvatar: true,
data: function () {
return _.extend({
emailId: this.emailId,
@@ -23,7 +23,7 @@ Espo.define('Views.Stream.Notes.EmailSent', 'Views.Stream.Note', function (Dep)
return Dep.extend({
template: 'stream.notes.email-received',
template: 'stream.notes.email-sent',
isRemovable: true,