1 (function (angular
, $, _
) {
3 var partialUrl = function (relPath
, module
) {
5 module
= 'crmMailingAB2';
7 return CRM
.resourceUrls
['civicrm'] + '/partials/' + module
+ '/' + relPath
;
10 angular
.module('crmMailingAB2', ['ngRoute', 'ui.utils', 'ngSanitize', 'crmUi', 'crmAttachment', 'crmMailing']);
11 angular
.module('crmMailingAB2').config([
13 function ($routeProvider
) {
14 $routeProvider
.when('/abtest2', {
15 templateUrl
: partialUrl('list.html'),
16 controller
: 'CrmMailingAB2ListCtrl',
18 mailingABList: function ($route
, crmApi
) {
19 return crmApi('MailingAB', 'get', {rowCount
: 0});
23 $routeProvider
.when('/abtest2/:id', {
24 templateUrl
: partialUrl('edit.html'),
25 controller
: 'CrmMailingAB2EditCtrl',
27 abtest: function ($route
, CrmMailingAB
) {
28 var abtest
= new CrmMailingAB($route
.current
.params
.id
== 'new' ? null : $route
.current
.params
.id
);
36 angular
.module('crmMailingAB2').controller('CrmMailingAB2ListCtrl', function ($scope
, mailingABList
, crmMailingABCriteria
) {
37 $scope
.mailingABList
= mailingABList
.values
;
38 $scope
.testing_criteria
= crmMailingABCriteria
.getAll();
41 angular
.module('crmMailingAB2').controller('CrmMailingAB2EditCtrl', function ($scope
, abtest
, crmMailingABCriteria
, crmMailingMgr
) {
43 $scope
.abtest
= abtest
;
44 $scope
.ts
= CRM
.ts('CiviMail');
45 $scope
.crmMailingABCriteria
= crmMailingABCriteria
;
46 $scope
.crmMailingConst
= CRM
.crmMailing
;
47 $scope
.partialUrl
= partialUrl
;
49 $scope
.sync
= function sync() {
50 abtest
.mailings
.a
.name
= ts('Test A (%1)', {1: abtest
.ab
.name
});
51 abtest
.mailings
.b
.name
= ts('Test B (%1)', {1: abtest
.ab
.name
});
52 abtest
.mailings
.c
.name
= ts('Winner (%1)', {1: abtest
.ab
.name
});
54 var criteria
= crmMailingABCriteria
.get(abtest
.ab
.testing_criteria_id
);
56 // TODO review fields exposed in UI and make sure the sync rules match
57 switch (criteria
.name
) {
59 crmMailingMgr
.mergeInto(abtest
.mailings
.b
, abtest
.mailings
.a
, ['name', 'subject']);
62 crmMailingMgr
.mergeInto(abtest
.mailings
.b
, abtest
.mailings
.a
, ['name', 'from_name', 'from_email']);
64 case 'Two different emails':
65 crmMailingMgr
.mergeInto(abtest
.mailings
.b
, abtest
.mailings
.a
, [
75 throw "Unrecognized testing_criteria";
78 crmMailingMgr
.mergeInto(abtest
.mailings
.c
, abtest
.mailings
.a
, ['name']);
80 $scope
.save
= function save() {
84 $scope
.delete = function () {
85 throw "Not implemented: EditCtrl.delete"
87 $scope
.submit = function () {
88 throw "Not implemented: EditCtrl.submit"
91 function updateCriteriaName() {
92 var criteria
= crmMailingABCriteria
.get($scope
.abtest
.ab
.testing_criteria_id
)
93 $scope
.criteriaName
= criteria
? criteria
.name
: null;
99 $scope
.$watch('abtest.ab.testing_criteria_id', updateCriteriaName
);
102 })(angular
, CRM
.$, CRM
._
);