| 1 | (function(angular, $, _) { |
| 2 | |
| 3 | angular.module('crmMailingAB').controller('CrmMailingABReportCtrl', function($scope, crmApi, crmMailingStats) { |
| 4 | var ts = $scope.ts = CRM.ts(null); |
| 5 | |
| 6 | var CrmMailingABReportCnt = 1, activeMailings = null; |
| 7 | $scope.getActiveMailings = function() { |
| 8 | if ($scope.abtest.$CrmMailingABReportCnt != CrmMailingABReportCnt) { |
| 9 | $scope.abtest.$CrmMailingABReportCnt = ++CrmMailingABReportCnt; |
| 10 | activeMailings = [ |
| 11 | { |
| 12 | name: 'a', |
| 13 | title: ts('Mailing A'), |
| 14 | mailing: $scope.abtest.mailings.a, |
| 15 | attachments: $scope.abtest.attachments.a |
| 16 | }, |
| 17 | { |
| 18 | name: 'b', |
| 19 | title: ts('Mailing B'), |
| 20 | mailing: $scope.abtest.mailings.b, |
| 21 | attachments: $scope.abtest.attachments.b |
| 22 | } |
| 23 | ]; |
| 24 | if ($scope.abtest.ab.status == 'Final') { |
| 25 | activeMailings.push({ |
| 26 | name: 'c', |
| 27 | title: ts('Final'), |
| 28 | mailing: $scope.abtest.mailings.c, |
| 29 | attachments: $scope.abtest.attachments.c |
| 30 | }); |
| 31 | } |
| 32 | } |
| 33 | return activeMailings; |
| 34 | }; |
| 35 | |
| 36 | crmMailingStats.getStats({ |
| 37 | a: $scope.abtest.ab.mailing_id_a, |
| 38 | b: $scope.abtest.ab.mailing_id_b, |
| 39 | c: $scope.abtest.ab.mailing_id_c |
| 40 | }).then(function(stats) { |
| 41 | $scope.stats = stats; |
| 42 | }); |
| 43 | |
| 44 | $scope.statTypes = crmMailingStats.getStatTypes(); |
| 45 | $scope.statUrl = function statUrl(mailing, statType, view) { |
| 46 | return crmMailingStats.getUrl(mailing, statType, view, 'abtest/' + $scope.abtest.ab.id); |
| 47 | }; |
| 48 | |
| 49 | $scope.checkPerm = CRM.checkPerm; |
| 50 | }); |
| 51 | |
| 52 | })(angular, CRM.$, CRM._); |