Commit | Line | Data |
---|---|---|
70980d8e TO |
1 | (function (angular, $, _) { |
2 | ||
3 | var partialUrl = function (relPath, module) { | |
4 | if (!module) { | |
5 | module = 'crmMailingAB2'; | |
6 | } | |
7 | return CRM.resourceUrls['civicrm'] + '/partials/' + module + '/' + relPath; | |
8 | }; | |
9 | ||
10 | angular.module('crmMailingAB2', ['ngRoute', 'ui.utils', 'ngSanitize', 'crmUi', 'crmMailing2']); | |
11 | angular.module('crmMailingAB2').config([ | |
12 | '$routeProvider', | |
13 | function ($routeProvider) { | |
14 | $routeProvider.when('/abtest2', { | |
15 | templateUrl: partialUrl('list.html'), | |
16 | controller: 'CrmMailingAB2ListCtrl', | |
17 | resolve: { | |
18 | mailingABList: function ($route, crmApi) { | |
19 | return crmApi('MailingAB', 'get', {rowCount: 0}); | |
20 | } | |
21 | } | |
22 | }); | |
23 | $routeProvider.when('/abtest2/:id', { | |
24 | templateUrl: partialUrl('edit.html'), | |
25 | controller: 'CrmMailingAB2EditCtrl', | |
26 | resolve: { | |
27 | abtest: function ($route, CrmMailingAB) { | |
28 | var abtest = new CrmMailingAB($route.current.params.id == 'new' ? null : $route.current.params.id); | |
29 | return abtest.load(); | |
30 | } | |
31 | } | |
32 | }); | |
33 | } | |
34 | ]); | |
35 | ||
36 | angular.module('crmMailingAB2').controller('CrmMailingAB2ListCtrl', function ($scope, mailingABList, crmMailingABCriteria) { | |
37 | $scope.mailingABList = mailingABList.values; | |
38 | $scope.testing_criteria = crmMailingABCriteria.getAll(); | |
39 | }) | |
40 | ||
41 | ||
42 | angular.module('crmMailingAB2').controller('CrmMailingAB2EditCtrl', function ($scope, abtest, crmMailingABCriteria, crmMailingMgr) { | |
43 | $scope.abtest = abtest; | |
44 | $scope.ts = CRM.ts('CiviMail'); | |
45 | $scope.sync = function sync() { | |
46 | abtest.mailings.a.name = ts('Test A (%1)', {1: abtest.ab.name}); | |
47 | abtest.mailings.b.name = ts('Test B (%1)', {1: abtest.ab.name}); | |
48 | abtest.mailings.c.name = ts('Winner (%1)', {1: abtest.ab.name}); | |
49 | ||
50 | var criteria = crmMailingABCriteria.get(abtest.ab.testing_criteria_id); | |
51 | if (criteria) { | |
52 | switch (criteria.name) { | |
53 | case 'Subject lines': | |
54 | crmMailingMgr.mergeInto(abtest.mailings.b, abtest.mailings.a, ['name', 'subject']); | |
55 | break; | |
56 | case 'From names': | |
57 | crmMailingMgr.mergeInto(abtest.mailings.b, abtest.mailings.a, ['name', 'from_name', 'from_email']); | |
58 | break; | |
59 | case 'Two different emails': | |
60 | crmMailingMgr.mergeInto(abtest.mailings.b, abtest.mailings.a, [ | |
61 | 'name', | |
62 | 'subject', | |
63 | 'from_name', | |
64 | 'from_email', | |
65 | 'body_html', | |
66 | 'body_text' | |
67 | ]); | |
68 | break; | |
69 | default: | |
70 | throw "Unrecognized testing_criteria"; | |
71 | } | |
72 | } | |
73 | crmMailingMgr.mergeInto(abtest.mailings.c, abtest.mailings.a, ['name']); | |
74 | }; | |
75 | $scope.save = function save() { | |
76 | $scope.sync(); | |
77 | return abtest.save(); | |
78 | }; | |
79 | $scope.delete = function () { | |
80 | throw "Not implemented: EditCtrl.delete" | |
81 | }; | |
82 | ||
83 | $scope.sync(); | |
84 | }); | |
85 | ||
86 | })(angular, CRM.$, CRM._); |