1 (function (angular
, $, _
) {
2 var partialUrl = function (relPath
) {
3 return CRM
.resourceUrls
['civicrm'] + '/partials/crmMailingAB2/' + relPath
;
7 // scope.myAbtest = new CrmMailingAB();
8 // <crm-mailing-ab-block-mailing="{fromAddressA: 1, fromAddressB: 1}" crm-abtest="myAbtest" />
9 var simpleDirectives
= {
10 crmMailingAbBlockMailing
: partialUrl('joint-mailing.html'),
11 crmMailingAbBlockSetup
: partialUrl('setup.html')
13 _
.each(simpleDirectives
, function (templateUrl
, directiveName
) {
14 angular
.module('crmMailingAB2').directive(directiveName
, function ($parse
, crmMailingABCriteria
) {
15 var scopeDesc
= {crmAbtest
: '@'};
16 scopeDesc
[directiveName
] = '@';
20 templateUrl
: templateUrl
,
21 link: function (scope
, elm
, attr
) {
22 var model
= $parse(attr
.crmAbtest
);
23 scope
.abtest
= model(scope
.$parent
);
24 scope
.crmMailingConst
= CRM
.crmMailing
;
25 scope
.crmMailingABCriteria
= crmMailingABCriteria
;
26 scope
.ts
= CRM
.ts('CiviMail');
28 var fieldsModel
= $parse(attr
[directiveName
]);
29 scope
.fields
= fieldsModel(scope
.$parent
);
35 // example: <div crm-mailing-ab-slider ng-model="abtest.ab.group_percentage"></div>
36 angular
.module('crmMailingAB2').directive('crmMailingAbSlider', function () {
40 templateUrl
: partialUrl('slider.html'),
41 link: function (scope
, element
, attrs
, ngModel
) {
42 var TEST_MIN
= 1, TEST_MAX
= 50;
43 var sliders
= $('.slider-test,.slider-win', element
);
44 var sliderTests
= $('.slider-test', element
);
45 var sliderWin
= $('.slider-win', element
);
47 scope
.ts
= CRM
.ts('CiviMail');
51 // set the base value (following a GUI event)
52 function setValue(value
) {
53 value
= Math
.min(TEST_MAX
, Math
.max(TEST_MIN
, value
));
54 scope
.$apply(function () {
55 ngModel
.$setViewValue(value
);
56 scope
.testValue
= value
;
57 scope
.winValue
= 100 - (2 * scope
.testValue
);
58 sliderTests
.slider('value', scope
.testValue
);
59 sliderWin
.slider('value', scope
.winValue
);
70 slide
: function slideTest(event
, ui
) {
71 event
.preventDefault();
76 slide
: function slideWinner(event
, ui
) {
77 event
.preventDefault();
78 setValue(Math
.round((100 - ui
.value
) / 2));
82 ngModel
.$render = function () {
83 scope
.testValue
= ngModel
.$viewValue
;
84 scope
.winValue
= 100 - (2 * scope
.testValue
);
85 sliderTests
.slider('value', scope
.testValue
);
86 sliderWin
.slider('value', scope
.winValue
);
91 })(angular
, CRM
.$, CRM
._
);