Skip to content

Commit

Permalink
Merge pull request #11010 from seamuslee001/CRM-21206
Browse files Browse the repository at this point in the history
CRM-21206 Ensure that the recipients field of AB Test results is fill…
  • Loading branch information
eileenmcnaughton authored Dec 2, 2017
2 parents 8f10777 + 5800883 commit c4ef9a8
Showing 1 changed file with 76 additions and 4 deletions.
80 changes: 76 additions & 4 deletions ang/crmMailing/ViewRecipCtrl.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,83 @@
(function(angular, $, _) {

angular.module('crmMailing').controller('ViewRecipCtrl', function ViewRecipCtrl($scope) {
var mids = [];
var gids = [];
var groupNames = [];
var mailings = [];
var civimailings = [];
var civimails = [];

function getGroupNames(mailing) {
if (-1 == mailings.indexOf(mailing.id)) {
mailings.push(mailing.id);
_.each(mailing.recipients.groups.include, function(id) {
if (-1 == gids.indexOf(id)) {
gids.push(id);
}
});
_.each(mailing.recipients.groups.exclude, function(id) {
if (-1 == gids.indexOf(id)) {
gids.push(id);
}
});
_.each(mailing.recipients.groups.base, function(id) {
if (-1 == gids.indexOf(id)) {
gids.push(id);
}
});
if (!_.isEmpty(gids)) {
CRM.api3('Group', 'get', {'id': {"IN": gids}}).then(function(result) {
_.each(result.values, function(grp) {
if (_.isEmpty(_.where(groupNames, {id: parseInt(grp.id)}))) {
groupNames.push({id: parseInt(grp.id), title: grp.title, is_hidden: grp.is_hidden});
}
});
CRM.crmMailing.groupNames = groupNames;
$scope.$parent.crmMailingConst.groupNames = groupNames;
});
}
}
}

function getCiviMails(mailing) {
if (-1 == civimailings.indexOf(mailing.id)) {
civimailings.push(mailing.id);
_.each(mailing.recipients.mailings.include, function(id) {
if (-1 == mids.indexOf(id)) {
mids.push(id);
}
});
_.each(mailing.recipients.mailings.exclude, function(id) {
if (-1 == mids.indexOf(id)) {
mids.push(id);
}
});
if (!_.isEmpty(mids)) {
CRM.api3('Mailing', 'get', {'id': {"IN": mids}}).then(function(result) {
_.each(result.values, function(mail) {
if (_.isEmpty(_.where(civimails, {id: parseInt(mail.id)}))) {
civimails.push({id: parseInt(mail.id), name: mail.label});
}
});
CRM.crmMailing.civiMails = civimails;
$scope.$parent.crmMailingConst.civiMails = civimails;
});
}
}
}

$scope.getIncludesAsString = function(mailing) {
var first = true;
var names = '';
if (_.isEmpty(CRM.crmMailing.groupNames)) {
getGroupNames(mailing);
}
if (_.isEmpty(CRM.crmMailing.civiMails)) {
getCiviMails(mailing);
}
_.each(mailing.recipients.groups.include, function(id) {
var group = _.where(CRM.crmMailing.groupNames, {id: '' + id});
var group = _.where(CRM.crmMailing.groupNames, {id: parseInt(id)});
if (group.length) {
if (!first) {
names = names + ', ';
Expand All @@ -15,7 +87,7 @@
}
});
_.each(mailing.recipients.mailings.include, function(id) {
var oldMailing = _.where(CRM.crmMailing.civiMails, {id: '' + id});
var oldMailing = _.where(CRM.crmMailing.civiMails, {id: parseInt(id)});
if (oldMailing.length) {
if (!first) {
names = names + ', ';
Expand All @@ -30,7 +102,7 @@
var first = true;
var names = '';
_.each(mailing.recipients.groups.exclude, function(id) {
var group = _.where(CRM.crmMailing.groupNames, {id: '' + id});
var group = _.where(CRM.crmMailing.groupNames, {id: parseInt(id)});
if (group.length) {
if (!first) {
names = names + ', ';
Expand All @@ -40,7 +112,7 @@
}
});
_.each(mailing.recipients.mailings.exclude, function(id) {
var oldMailing = _.where(CRM.crmMailing.civiMails, {id: '' + id});
var oldMailing = _.where(CRM.crmMailing.civiMails, {id: parseInt(id)});
if (oldMailing.length) {
if (!first) {
names = names + ', ';
Expand Down

0 comments on commit c4ef9a8

Please sign in to comment.