opted out remove
This commit is contained in:
@@ -45,4 +45,18 @@ class TargetList extends \Espo\Core\Controllers\Record
|
||||
return $this->getRecordService()->unlinkAll($data['id'], $data['link']);
|
||||
}
|
||||
|
||||
public function postActionCancelOptOut($params, $data)
|
||||
{
|
||||
if (empty($data['id'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
if (empty($data['targetType'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
if (empty($data['targetId'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
return $this->getRecordService()->cancelOptOut($data['id'], $data['targetType'], $data['targetId']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
},
|
||||
"labels": {
|
||||
"Create TargetList": "Create Target List",
|
||||
"Opted Out": "Opted Out"
|
||||
"Opted Out": "Opted Out",
|
||||
"Cancel Opt-Out": "Cancel Opt-Out"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Espo\Modules\Crm\Services;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
use \Espo\Core\Exceptions\NotFound;
|
||||
|
||||
class TargetList extends \Espo\Services\Record
|
||||
{
|
||||
public function loadAdditionalFields(Entity $entity)
|
||||
@@ -158,5 +160,32 @@ class TargetList extends \Espo\Services\Record
|
||||
'list' => $arr
|
||||
);
|
||||
}
|
||||
|
||||
public function cancelOptOut($id, $targetType, $targetId)
|
||||
{
|
||||
$targetList = $this->getEntityManager()->getEntity('TargetList', $id);
|
||||
if (!$targetList) {
|
||||
throw new NotFound();
|
||||
}
|
||||
$target = $this->getEntityManager()->getEntity($targetType, $targetId);
|
||||
if (!$target) {
|
||||
throw new NotFound();
|
||||
}
|
||||
$map = array(
|
||||
'Account' => 'accounts',
|
||||
'Contact' => 'contacts',
|
||||
'Lead' => 'leads',
|
||||
'User' => 'users'
|
||||
);
|
||||
|
||||
if (empty($map[$targetType])) {
|
||||
throw new Error();
|
||||
}
|
||||
$link = $map[$targetType];
|
||||
|
||||
return $this->getEntityManager()->getRepository('TargetList')->updateRelation($targetList, $link, $targetId, array(
|
||||
'optedOut' => false
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('Crm:Views.TargetList.Record.Panels.OptedOut', ['Views.Record.Panels.Relationship', 'MultiCollection'], function (Dep, MultiCollection) {
|
||||
Espo.define('crm:views/target-list/record/panels/opted-out', ['views/record/panels/relationship', 'multi-collection'], function (Dep, MultiCollection) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
name: 'optedOut',
|
||||
|
||||
template: 'crm:target-list.record.panels.opted-out',
|
||||
template: 'crm:target-list/record/panels/opted-out',
|
||||
|
||||
scopeList: ['Contact', 'Lead', 'User', 'Account'],
|
||||
|
||||
@@ -109,11 +109,11 @@ Espo.define('Crm:Views.TargetList.Record.Panels.OptedOut', ['Views.Record.Panels
|
||||
this.collection.maxSize = this.getConfig().get('recordsPerPageSmall') || 5;
|
||||
|
||||
this.listenToOnce(this.collection, 'sync', function () {
|
||||
this.createView('list', 'Record.ListExpanded', {
|
||||
this.createView('list', 'views/record/list-expanded', {
|
||||
el: this.$el.selector + ' > .list-container',
|
||||
pagination: false,
|
||||
type: 'listRelationship',
|
||||
rowActionsView: null,
|
||||
rowActionsView: 'crm:views/target-list/record/row-actions/opted-out',
|
||||
checkboxes: false,
|
||||
collection: this.collection,
|
||||
listLayout: this.listLayout,
|
||||
@@ -126,7 +126,24 @@ Espo.define('Crm:Views.TargetList.Record.Panels.OptedOut', ['Views.Record.Panels
|
||||
|
||||
actionRefresh: function () {
|
||||
this.collection.fetch();
|
||||
},
|
||||
|
||||
actionCancelOptOut: function (data) {
|
||||
if (confirm(this.translate('confirmation', 'messages'))) {
|
||||
$.ajax({
|
||||
url: 'TargetList/action/cancelOptOut',
|
||||
type: 'POST',
|
||||
data: JSON.stringify({
|
||||
id: this.model.id,
|
||||
targetId: data.id,
|
||||
targetType: data.type
|
||||
})
|
||||
}).done(function () {
|
||||
this.collection.fetch();
|
||||
}.bind(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('crm:views/target-list/record/row-actions/opted-out', 'views/record/row-actions/default', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
getActionList: function () {
|
||||
return [
|
||||
{
|
||||
action: 'cancelOptOut',
|
||||
label: 'Cancel Opt-Out',
|
||||
data: {
|
||||
id: this.model.id,
|
||||
type: this.model.name
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -137,7 +137,7 @@ Espo.define('Views.Record.List', 'View', function (Dep) {
|
||||
}
|
||||
},
|
||||
'click .action': function (e) {
|
||||
$el = $(e.currentTarget);
|
||||
var $el = $(e.currentTarget);
|
||||
var action = $el.data('action');
|
||||
var method = 'action' + Espo.Utils.upperCaseFirst(action);
|
||||
if (typeof this[method] == 'function') {
|
||||
|
||||
@@ -33,7 +33,7 @@ Espo.define('views/record/panels/bottom', 'view', function (Dep) {
|
||||
|
||||
events: {
|
||||
'click .action': function (e) {
|
||||
$el = $(e.currentTarget);
|
||||
var $el = $(e.currentTarget);
|
||||
var action = $el.data('action');
|
||||
var method = 'action' + Espo.Utils.upperCaseFirst(action);
|
||||
if (typeof this[method] == 'function') {
|
||||
|
||||
Reference in New Issue
Block a user