diff --git a/application/Espo/Modules/Crm/Controllers/TargetList.php b/application/Espo/Modules/Crm/Controllers/TargetList.php index 6f858f1562..c957fc5c7b 100644 --- a/application/Espo/Modules/Crm/Controllers/TargetList.php +++ b/application/Espo/Modules/Crm/Controllers/TargetList.php @@ -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']); + } + } diff --git a/application/Espo/Modules/Crm/Resources/i18n/en_US/TargetList.json b/application/Espo/Modules/Crm/Resources/i18n/en_US/TargetList.json index 6ea27810b6..1a1b76e271 100644 --- a/application/Espo/Modules/Crm/Resources/i18n/en_US/TargetList.json +++ b/application/Espo/Modules/Crm/Resources/i18n/en_US/TargetList.json @@ -25,6 +25,7 @@ }, "labels": { "Create TargetList": "Create Target List", - "Opted Out": "Opted Out" + "Opted Out": "Opted Out", + "Cancel Opt-Out": "Cancel Opt-Out" } } diff --git a/application/Espo/Modules/Crm/Services/TargetList.php b/application/Espo/Modules/Crm/Services/TargetList.php index b6a65c2b03..fa59021120 100644 --- a/application/Espo/Modules/Crm/Services/TargetList.php +++ b/application/Espo/Modules/Crm/Services/TargetList.php @@ -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 + )); + } } diff --git a/frontend/client/modules/crm/src/views/target-list/record/panels/opted-out.js b/frontend/client/modules/crm/src/views/target-list/record/panels/opted-out.js index 44827edfcc..945d01b6c8 100644 --- a/frontend/client/modules/crm/src/views/target-list/record/panels/opted-out.js +++ b/frontend/client/modules/crm/src/views/target-list/record/panels/opted-out.js @@ -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)); + } } + }); }); diff --git a/frontend/client/modules/crm/src/views/target-list/record/row-actions/opted-out.js b/frontend/client/modules/crm/src/views/target-list/record/row-actions/opted-out.js new file mode 100644 index 0000000000..7cf3219b42 --- /dev/null +++ b/frontend/client/modules/crm/src/views/target-list/record/row-actions/opted-out.js @@ -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 + } + } + ]; + } + }); +}); + diff --git a/frontend/client/src/views/record/list.js b/frontend/client/src/views/record/list.js index 8a8ca73f06..8e9d868317 100644 --- a/frontend/client/src/views/record/list.js +++ b/frontend/client/src/views/record/list.js @@ -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') { diff --git a/frontend/client/src/views/record/panels/bottom.js b/frontend/client/src/views/record/panels/bottom.js index f62b6f0a36..868a875de7 100644 --- a/frontend/client/src/views/record/panels/bottom.js +++ b/frontend/client/src/views/record/panels/bottom.js @@ -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') {