X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=ang%2FcrmMailing%2FViewRecipCtrl.js;h=d72793fdb66fe9776320e56cd346d51d46d39123;hb=179cb5e37a971a2666d80918c072852ee00babd5;hp=652b89e3a8881743a31b6351a1d41ed9eaf21d6e;hpb=960327c9fbbb2dc52f8f67a1bf94edc40281c1f0;p=civicrm-core.git diff --git a/ang/crmMailing/ViewRecipCtrl.js b/ang/crmMailing/ViewRecipCtrl.js index 652b89e3a8..d72793fdb6 100644 --- a/ang/crmMailing/ViewRecipCtrl.js +++ b/ang/crmMailing/ViewRecipCtrl.js @@ -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 + ', '; @@ -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 + ', '; @@ -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 + ', '; @@ -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 + ', ';