2 * Created by aditya on 6/12/14.
4 (function (angular
, $, _
) {
6 var partialUrl = function (relPath
) {
7 return CRM
.resourceUrls
['civicrm'] + '/partials/abtesting/' + relPath
;
9 var crmMailingAB
= angular
.module('crmMailingAB', ['ngRoute', 'ui.utils', 'ngSanitize']);
11 crmMailingAB
.run(function ($rootScope
, $templateCache
) {
12 $rootScope
.$on('$viewContentLoaded', function () {
13 $templateCache
.removeAll();
18 function ($routeProvider
) {
19 $routeProvider
.when('/mailing/abtesting', {
20 templateUrl
: partialUrl('list.html'),
21 controller
: 'ABListingCtrl',
23 mailingABList: function ($route
, crmApi
) {
24 return crmApi('MailingAB', 'get', {rowCount
: 0});
28 $routeProvider
.when('/mailing/abtesting/report/:id', {
29 templateUrl
: partialUrl('report.html'),
30 controller
: 'ReportCtrl',
32 selectedABTest: function ($route
, crmApi
) {
33 return crmApi('MailingAB', 'getsingle', {id
: $route
.current
.params
.id
});
37 $routeProvider
.when('/mailing/abtesting/:id', {
38 templateUrl
: partialUrl('main.html'),
39 controller
: 'crmABTestingTabsCtrl',
41 selectedABTest: function ($route
, crmApi
) {
42 if ($route
.current
.params
.id
!== 'new') {
44 return crmApi('MailingAB', 'getsingle', {id
: $route
.current
.params
.id
});
47 //created_id has been set to my id. Does not save without created_id. Needs to made generic based on the user
48 return { just_created
: "1"
57 //-----------------------------------------
58 // Add a new record by name.
59 // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
61 * This controler lists the existing ABtests
62 * used on /partials/abtesting/list.html
63 * @returns mailingABList - object that contains the existing AB mailings
64 * @returns testing_criteria - array that has the name of the different test types
66 crmMailingAB
.controller('ABListingCtrl', function ($scope
, crmApi
, mailingABList
) {
67 $scope
.mailingABList
= mailingABList
.values
;
68 $scope
.testing_criteria
= {
71 '3': "Two different emails"
75 crmMailingAB
.controller('crmABTestingTabsCtrl', function ($scope
, crmApi
, selectedABTest
, $sce
) {
76 $scope
.partialUrl
= partialUrl
;
79 $scope
.currentABTest
= selectedABTest
;
80 $scope
.groups
= CRM
.crmMailing
.groupNames
;
81 $scope
.mailList
= CRM
.crmMailing
.civiMails
;
82 $scope
.eMailing
= CRM
.crmMailing
.emailAdd
;
83 $scope
.tmpList
= CRM
.crmMailing
.mesTemplate
;
84 $scope
.mailingGrp
= CRM
.crmMailing
.mailGrp
;
85 $scope
.headerfooter
= CRM
.crmMailing
.headerfooterList
;
86 $scope
.sparestuff
= {};
87 $scope
.sparestuff
.emailadd
= "";
88 $scope
.sparestuff
.winnercriteria
= "";
89 $scope
.sparestuff
.isnew
= false;
90 $scope
.sparestuff
.allgroups
= "";
92 $scope
.preventsubmit
= false;
94 if ($scope
.currentABTest
.declare_winning_time
!= null) {
95 $scope
.ans
= $scope
.currentABTest
.declare_winning_time
.split(" ");
96 $scope
.currentABTest
.date
= $scope
.ans
[0];
97 $scope
.currentABTest
.time
= $scope
.ans
[1];
101 if ($scope
.currentABTest
.just_created
!= 1) {
102 $scope
.abId
= $scope
.currentABTest
.id
;
103 $scope
.sparestuff
.isnew
= false;
105 var abmailA
= crmApi('Mailing', 'getsingle', {id
: $scope
.currentABTest
.mailing_id_a
});
106 var abmailB
= crmApi('Mailing', 'getsingle', {id
: $scope
.currentABTest
.mailing_id_b
});
107 var abmailC
= crmApi('Mailing', 'getsingle', {id
: $scope
.currentABTest
.mailing_id_c
});
108 abmailA
.success(function (data
) {
109 if (data
.is_error
== 0) {
113 abmailB
.success(function (data
) {
114 if (data
.is_error
== 0) {
118 abmailC
.success(function (data
) {
119 if (data
.is_error
== 0) {
125 $scope
.sparestuff
.isnew
= true;
131 $scope
.sendtest
= false;
132 if (typeof $scope
.mailA
== 'undefined') {
135 if (typeof $scope
.mailB
== 'undefined') {
138 if (typeof $scope
.mailB
== 'undefined') {
144 { name
: 'Subject Lines', url
: partialUrl('subject_lines.html'), val
: 1},
145 { name
: 'From Name', url
: partialUrl('from_name.html'), val
: 2},
146 { name
: 'Two different Emails', url
: partialUrl('two_emails.html'), val
: 3}
149 if ($scope
.currentABTest
.just_created
!= 1) {
150 $scope
.sparestuff
.template
= $scope
.templates
[$scope
.currentABTest
.testing_criteria_id
- 1];
153 $scope
.sparestuff
.template
= $scope
.templates
[0];
157 $scope
.deliberatelyTrustDangerousSnippeta = function () {
158 return $sce
.trustAsHtml($scope
.sparestuff
.previewa
);
161 $scope
.deliberatelyTrustDangerousSnippetb = function () {
162 return $sce
.trustAsHtml($scope
.sparestuff
.previewb
);
166 $scope
.max_tab
= ($scope
.sparestuff
.isnew
== true) ? 0 : 4;
169 * Example: gotoTab('campaign')
171 $scope
.gotoTab = function(name
) {
172 var TABS
= {campaign
: 0, compose
: 1, rec
: 2, preview
: 3}; // FIXME
173 if ($scope
.max_tab
>= TABS
[name
]) {
174 $scope
.tab_val
= TABS
[name
];
178 $scope
.preview
= false;
179 $scope
.slide_value
= 0;
181 $scope
.setifyes = function (val
) {
182 $scope
.ifyes
= val
== 1;
185 /* $scope.reply = function () {
186 if ($scope.trackreplies == 0) {
187 $scope.trackreplies = 1;
190 $scope.trackreplies = 0;
191 $scope.mailA.forward_replies = 0;
192 $scope.mailA.auto_responder = 0;
196 $scope
.isAuto = function (au
) {
197 return au
.component_type
== "Reply";
200 $scope
.trackr = function (trackreplies
) {
201 return trackreplies
== "1";
204 $scope
.sendTestMailing = function () {
205 $scope
.sendtest
= true;
208 $scope
.isHeader = function (hf
) {
209 return hf
.component_type
== "Header";
211 //filter so we only get footers from mailing component
212 $scope
.isFooter = function (f
) {
213 return f
.component_type
== "Footer";
216 $scope
.send_date
= "01/01/2000";
219 $scope
.savea = function (dat
) {
221 var result
= crmApi('Mailing', 'create', dat
, true);
222 result
.success(function (data
) {
223 if (data
.is_error
== 0) {
224 $scope
.mailA
.id
= data
.id
;
225 $scope
.currentABTest
.mailing_id_a
= $scope
.mailA
.id
;
230 $scope
.append_mails = function () {
231 crmApi('MailingAB', 'create', {
233 mailing_id_a
: $scope
.mailA
.id
,
234 mailing_id_b
: $scope
.mailB
.id
,
235 mailing_id_c
: $scope
.mailC
.id
237 $scope
.currentABTest
.id
= $scope
.abId
;
240 $scope
.saveb = function (dat
) {
241 var result
= crmApi('Mailing', 'create', dat
, true);
242 result
.success(function (data
) {
243 if (data
.is_error
== 0) {
244 $scope
.mailB
.id
= data
.id
;
245 $scope
.currentABTest
.mailing_id_b
= $scope
.mailB
.id
;
246 //$scope.append_mails();
251 $scope
.savec = function (dat
) {
252 var result
= crmApi('Mailing', 'create', dat
, true);
254 result
.success(function (data
) {
255 if (data
.is_error
== 0) {
256 $scope
.mailC
.id
= data
.id
;
257 $scope
.currentABTest
.mailing_id_c
= $scope
.mailC
.id
;
258 $scope
.append_mails();
263 $scope
.sparestuff
.previewa
= "";
264 $scope
.pre = function () {
265 $scope
.preview
= true;
268 $scope
.init = function (par
) {
270 $scope
.sparestuff
.template
.url
= partialUrl('from_name.html');
274 $scope
.sparestuff
.template
.url
= partialUrl('subject_lines.html');
277 $scope
.sparestuff
.template
.url
= partialUrl('two_emails.html');
280 $scope
.whatnext
= par
.toString();
283 $scope
.tab_upd = function () {
284 $scope
.tab_val
= $scope
.tab_val
+ 1;
285 $scope
.max_tab
= Math
.max($scope
.tab_val
, $scope
.max_tab
);
288 $scope
.tab_upd_dec = function () {
289 $scope
.tab_val
= $scope
.tab_val
- 1;
292 $scope
.setdate = function (par
) {
293 $scope
.send_date
= par
;
298 $scope
.testmailid
= "";
299 $scope
.incGroup
= [];
300 $scope
.excGroup
= [];
301 $scope
.incGroupids
= [];
302 $scope
.excGroupids
= [];
304 $scope
.create_abtest = function () {
306 $scope
.currentABTest
.testing_criteria_id
= $scope
.sparestuff
.template
.val
;
308 if ($scope
.abId
== "") {
309 result
= crmApi('MailingAB', 'create', {name
: $scope
.currentABTest
.name
, testing_criteria_id
: $scope
.sparestuff
.template
.val
});
312 if (typeof $scope
.currentABTest
.mailing_id_a
== 'undefined') {
313 result
= crmApi('MailingAB', 'create', {name
: $scope
.currentABTest
.name
, id
: $scope
.abId
, testing_criteria_id
: $scope
.sparestuff
.template
.val
});
316 result
= crmApi('MailingAB', 'create', {name
: $scope
.currentABTest
.name
, id
: $scope
.abId
, testing_criteria_id
: $scope
.sparestuff
.template
.val
, mailing_id_a
: $scope
.currentABTest
.mailing_id_a
, mailing_id_b
: $scope
.currentABTest
.mailing_id_b
});
320 result
.success(function (data
) {
321 if (data
.is_error
== 0) {
322 $scope
.abId
= data
.id
;
326 $scope
.tokenfunc = function (elem
, e
, chng
) {
327 var msg
= document
.getElementById(elem
).value
;
328 var cursorlen
= document
.getElementById(elem
).selectionStart
;
329 var textlen
= msg
.length
;
330 document
.getElementById(elem
).value
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
331 chng
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
332 var cursorPos
= (cursorlen
+ e
.val
.length
);
333 document
.getElementById(elem
).selectionStart
= cursorPos
;
334 document
.getElementById(elem
).selectionEnd
= cursorPos
;
335 document
.getElementById(elem
).focus();
338 $scope
.sparestuff
.ingrps
= "";
339 $scope
.sparestuff
.excgrps
= "";
340 $scope
.a_b_update = function () {
341 $scope
.tp1
.include
= $scope
.incGroupids
;
342 $scope
.tp1
.exclude
= $scope
.excGroupids
;
343 console
.log($scope
.tp1
);
344 crmApi('MailingAB', 'recipients_update', {
345 id
: $scope
.currentABTest
.id
,
349 var resulta
= crmApi('Mailing', 'preview', {id
: $scope
.currentABTest
.mailing_id_a
});
351 resulta
.success(function (data
) {
352 if (data
.is_error
== 0) {
353 $scope
.sparestuff
.previewa
= data
.values
.html
;
357 resulta
= crmApi('Mailing', 'preview', {id
: $scope
.currentABTest
.mailing_id_b
});
359 resulta
.success(function (data
) {
360 if (data
.is_error
== 0) {
361 $scope
.sparestuff
.previewb
= data
.values
.html
;
365 $scope
.startabtest = function () {
366 if (typeof $scope
.sparestuff
.date
== 'undefined') {
367 $scope
.sparestuff
.date
= 'now';
369 crmApi('MailingAB', 'send_mail', {id
: $scope
.abId
,
370 scheduled_date
: $scope
.sparestuff
.date
, scheduled_date_time
: $scope
.currentABTest
.latertime
});
373 angular
.forEach($scope
.incGroup
, function (value
) {
374 $scope
.sparestuff
.ingrps
+= value
.toString() + ", ";
376 angular
.forEach($scope
.excGroup
, function (value
) {
377 $scope
.sparestuff
.excgrps
+= value
.toString() + ", ";
379 if ($scope
.sparestuff
.ingrps
.length
!= 0) {
380 $scope
.sparestuff
.ingrps
= $scope
.sparestuff
.ingrps
.substr(0, $scope
.sparestuff
.ingrps
.length
- 2);
382 if ($scope
.sparestuff
.excgrps
.length
!= 0) {
383 $scope
.sparestuff
.excgrps
= $scope
.sparestuff
.excgrps
.substr(0, $scope
.sparestuff
.excgrps
.length
- 2);
387 $scope
.update_abtest = function () {
388 $scope
.currentABTest
.declare_winning_time
= $scope
.currentABTest
.date
+ " " + $scope
.currentABTest
.time
;
389 crmApi('MailingAB', 'create', {
391 testing_criteria_id
: $scope
.sparestuff
.template
.val
,
392 mailing_id_a
: $scope
.currentABTest
.mailing_id_a
,
393 mailing_id_b
: $scope
.currentABTest
.mailing_id_b
,
394 mailing_id_c
: $scope
.currentABTest
.mailing_id_c
,
395 specific_url
: $scope
.currentABTest
.acturl
,
396 winner_criteria_id
: $scope
.currentABTest
.winner_criteria_id
,
397 group_percentage
: $scope
.currentABTest
.group_percentage
,
398 declare_winning_time
: $scope
.currentABTest
.declare_winning_time
401 $scope
.currentABTest
.latertime
= "";
402 $scope
.tmp = function (tst
, aorb
) {
404 $scope
.mailA
.msg_template_id
= tst
;
405 if ($scope
.mailA
.msg_template_id
== null) {
406 $scope
.mailA
.body_html
= "";
407 $scope
.mailA
.subject
= "";
410 for (var a
in $scope
.tmpList
) {
411 if ($scope
.tmpList
[a
].id
== $scope
.mailA
.msg_template_id
) {
412 $scope
.mailA
.body_html
= $scope
.tmpList
[a
].msg_html
;
413 if (typeof $scope
.mailA
.subject
== 'undefined' || $scope
.mailA
.subject
.length
== 0) {
414 $scope
.mailA
.subject
= $scope
.tmpList
[a
].msg_subject
;
422 $scope
.mailB
.msg_template_id
= tst
;
423 if ($scope
.mailB
.msg_template_id
== null) {
424 $scope
.mailB
.body_html
= "";
425 $scope
.mailB
.subject
= "";
428 for (var a
in $scope
.tmpList
) {
429 if ($scope
.tmpList
[a
].id
== $scope
.mailB
.msg_template_id
) {
430 $scope
.mailB
.body_html
= $scope
.tmpList
[a
].msg_html
;
431 if (typeof $scope
.mailB
.subject
== 'undefined' || $scope
.mailB
.subject
.length
== 0) {
432 $scope
.mailB
.subject
= $scope
.tmpList
[a
].msg_subject
;
440 $scope
.mailA
.msg_template_id
= tst
;
441 if ($scope
.mailA
.msg_template_id
== null) {
442 $scope
.mailA
.body_html
= "";
443 $scope
.mailA
.subject
= "";
446 for (var a
in $scope
.tmpList
) {
447 if ($scope
.tmpList
[a
].id
== $scope
.mailA
.msg_template_id
) {
448 $scope
.mailA
.body_html
= $scope
.tmpList
[a
].msg_html
;
449 if (typeof $scope
.mailA
.subject
== 'undefined' || $scope
.mailA
.subject
.length
== 0) {
450 $scope
.mailA
.subject
= $scope
.tmpList
[a
].msg_subject
;
456 $scope
.mailB
.msg_template_id
= tst
;
457 if ($scope
.mailB
.msg_template_id
== null) {
458 $scope
.mailB
.body_html
= "";
459 $scope
.mailB
.subject
= "";
463 for (var a
in $scope
.tmpList
) {
464 if ($scope
.tmpList
[a
].id
== $scope
.mailB
.msg_template_id
) {
465 $scope
.mailB
.body_html
= $scope
.tmpList
[a
].msg_html
;
466 if (typeof $scope
.mailB
.subject
== 'undefined' || $scope
.mailB
.subject
.length
== 0) {
467 $scope
.mailB
.subject
= $scope
.tmpList
[a
].msg_subject
;
477 /*$scope.tmp = function (tst){
478 $scope.currentMailing.msg_template_id=tst;
479 console.log($scope.currentMailing.msg_template_id+ "sasas");
480 if($scope.currentMailing.msg_template_id == null){
481 $scope.currentMailing.body_html="";
482 $scope.currentMailing.subject="";
485 for(var a in $scope.tmpList){
487 if($scope.tmpList[a].id==$scope.currentMailing.msg_template_id){
488 $scope.currentMailing.body_html=$scope.tmpList[a].msg_html;
489 console.log($scope.tmpList[a].msg_subject);
490 $scope.currentMailing.subject=$scope.tmpList[a].msg_subject;
491 console.log($scope.currentMailing.subject);
498 $scope
.$watch('preview', function () {
499 if ($scope
.preview
== true) {
500 $('#prevmail').dialog({
501 title
: 'Preview Mailing',
510 of: $(".crmABTestingAllTabs")
514 $scope
.preview
= false;
519 $("#prevmail").dialog('option', 'position', [300, 50]);
524 $scope
.call = function () {
526 crmApi('Mailing', 'send_test', {
527 mailing_id
: $scope
.currentABTest
.mailing_id_a
,
528 test_email
: $scope
.sparestuff
.emailadd
531 crmApi('Mailing', 'send_test', {
532 mailing_id
: $scope
.currentABTest
.mailing_id_b
,
533 test_email
: $scope
.sparestuff
.emailadd
537 $scope
.$watch('sendtest', function () {
538 if ($scope
.sendtest
== true) {
539 $('#sendtest').dialog({
540 title
: 'Send Test Mails',
547 'Send': function () {
549 $scope
.sendtest
= false;
550 $('#sendtest').dialog("close");
555 $scope
.sendtest
= false;
564 crmMailingAB
.directive('nexttab', function () {
566 // Restrict it to be an attribute in this case
569 // responsible for registering DOM listeners as well as updating the DOM
570 link: function (scope
, element
, attrs
) {
572 var tabselector
= $(".crmABTestingAllTabs");
573 tabselector
.tabs(scope
.$eval(attrs
.nexttab
));
575 // disable remaining tabs
576 if (scope
.sparestuff
.isnew
== true) {
577 tabselector
.tabs({disabled
: [1, 2, 3]});
580 $(element
).on("click", function () {
581 if (scope
.tab_val
== 0) {
582 scope
.create_abtest();
585 if (scope
.tab_val
== 2) {
586 scope
.update_abtest();
587 if (scope
.currentABTest
.winner_criteria_id
== 1) {
588 scope
.sparestuff
.winnercriteria
= "Open";
592 if (scope
.currentABTest
.winner_criteria_id
== 2) {
593 scope
.sparestuff
.winnercriteria
= " Total Unique Clicks";
597 if (scope
.currentABTest
.winner_criteria_id
== 3) {
598 scope
.sparestuff
.winnercriteria
= "Total Clicks on a particular link";
609 for (var i
= scope
.max_tab
+ 1; i
< 4; i
++) {
612 tabselector
.tabs("option", "disabled", myArray1
);
613 tabselector
.tabs("option", "active", scope
.tab_val
);
620 crmMailingAB
.directive('prevtab', function () {
622 // Restrict it to be an attribute in this case
625 // responsible for registering DOM listeners as well as updating the DOM
626 link: function (scope
, element
, attrs
) {
627 $(element
).on("click", function () {
628 var temp
= scope
.tab_val
- 1;
632 $(".crmABTestingAllTabs").tabs("option", "active", temp
);
640 crmMailingAB
.directive('chsgroup', function () {
643 link: function (scope
, element
, attrs
) {
644 function format(item
) {
646 // return `text` for optgroup
649 // return item template
650 var a
= item
.id
.split(" ");
651 if (a
[1] == "civicrm_group" && a
[2] == "include") {
652 return "<img src='../../sites/all/modules/civicrm/i/include.jpeg' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/group.png' height=12 width=12/>" + item
.text
;
654 if (a
[1] == "civicrm_group" && a
[2] == "exclude") {
655 return "<img src='../../sites/all/modules/civicrm/i/Error.gif' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/group.png' height=12 width=12/>" + item
.text
;
657 if (a
[1] == "civicrm_mailing" && a
[2] == "include") {
658 return "<img src='../../sites/all/modules/civicrm/i/include.jpeg' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/EnvelopeIn.gif' height=12 width=12/>" + item
.text
;
660 if (a
[1] == "civicrm_mailing" && a
[2] == "exclude") {
661 return "<img src='../../sites/all/modules/civicrm/i/Error.gif' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/EnvelopeIn.gif' height=12 width=12/>" + item
.text
;
668 placeholder
: "Select the groups you wish to include",
669 formatResult
: format
,
670 formatSelection
: format
,
671 escapeMarkup: function (m
) {
674 }).select2("data", scope
.sparestuff
.allgroups
);
677 $(element
).on('select2-selecting', function (e
) {
678 var a
= e
.val
.split(" ");
680 if (a
[2] == "include") {
682 for (i
= 3; i
< l
; i
++) {
686 scope
.incGroup
.push(str
);
687 scope
.incGroupids
.push(a
[0]);
693 for (i
= 3; i
< l
; i
++) {
698 scope
.excGroup
.push(str
);
699 scope
.excGroupids
.push(a
[0]);
706 $(element
).on("select2-removed", function (e
) {
707 if (e
.val
.split(" ")[2] == "exclude") {
708 var excIndex
= scope
.excGroup
.indexOf(e
.val
.split(" ")[3]);
709 scope
.excGroup
.splice(excIndex
, 1);
710 scope
.excGroupids
.splice(excIndex
, 1);
714 var incIndex
= scope
.incGroup
.indexOf(e
.val
.split(" ")[3]);
715 scope
.incGroup
.splice(incIndex
, 1);
716 scope
.incGroupids
.splice(incIndex
, 1);
726 crmMailingAB
.directive('sliderbar', function () {
729 link: function (scope
, element
, attrs
) {
730 if (typeof scope
.currentABTest
.group_percentage
!= 'undefined') {
731 $(element
).slider({value
: scope
.currentABTest
.group_percentage
});
733 $(element
).slider({min
: 1});
735 slide: function (event
, ui
) {
736 scope
.currentABTest
.group_percentage
= ui
.value
;
744 crmMailingAB
.directive('datepick', function () {
747 link: function (scope
, element
, attrs
) {
748 $(element
).datepicker({
749 dateFormat
: "dd-mm-yy",
750 onSelect: function (date
) {
751 $(".ui-datepicker a").removeAttr("href");
752 scope
.sparestuff
.date
= date
.toString();
760 crmMailingAB
.directive('submitform', function () {
764 link: function (scope
, element
, attrs
) {
765 $(element
).on("click", function () {
768 name
: scope
.currentABTest
.name
+ ' (AB test A)',
769 visibility
: scope
.mailA
.visibility
,
771 subject
: scope
.mailA
.subject
,
772 msg_template_id
: scope
.mailA
.msg_template_id
== null ? "" : scope
.mailA
.msg_template_id
,
773 open_tracking
: scope
.mailA
.open_tracking
,
774 url_tracking
: scope
.mailA
.url_tracking
,
775 forward_replies
: scope
.mailA
.forward_replies
,
776 auto_responder
: scope
.mailA
.auto_responder
,
777 from_name
: scope
.mailA
.from_name
,
778 from_email
: scope
.mailA
.from_email
,
779 replyto_email
: scope
.mailA
.replyto_email
,
780 unsubscribe_id
: scope
.mailA
.unsubscribe_id
,
781 resubscribe_id
: scope
.mailA
.resubscribe_id
,
782 body_html
: scope
.mailA
.body_html
,
783 body_text
: scope
.mailA
.body_text
,
784 scheduled_date
: scope
.mailA
.scheduled_date
,
785 scheduled_id
: scope
.mailA
.scheduled_id
,
786 campaign_id
: scope
.mailA
.campaign_id
== null ? "" : scope
.mailA
.campaign_id
,
787 header_id
: scope
.mailA
.header_id
,
788 footer_id
: scope
.mailA
.footer_id
,
789 is_completed
: scope
.mailA
.is_completed
792 if (scope
.whatnext
== "3") {
793 scope
.mailB
.name
= scope
.mailA
.name
;
794 scope
.mailB
.visibility
= scope
.mailA
.visibility
;
795 scope
.mailB
.created_id
= scope
.mailA
.created_id
;
796 scope
.mailB
.subject
= scope
.mailA
.subject
;
797 scope
.mailB
.msg_template_id
= scope
.mailA
.msg_template_id
== null ? "" : scope
.mailA
.msg_template_id
;
798 scope
.mailB
.open_tracking
= scope
.mailA
.open_tracking
;
799 scope
.mailB
.url_tracking
= scope
.mailA
.url_tracking
;
800 scope
.mailB
.forward_replies
= scope
.mailA
.forward_replies
;
801 scope
.mailB
.auto_responder
= scope
.mailA
.auto_responder
;
802 scope
.mailB
.from_name
= scope
.mailA
.from_name
;
803 scope
.mailB
.replyto_email
= scope
.mailA
.replyto_email
;
804 scope
.mailB
.unsubscribe_id
= scope
.mailA
.unsubscribe_id
;
805 scope
.mailB
.resubscribe_id
= scope
.mailA
.resubscribe_id
;
806 scope
.mailB
.body_html
= scope
.mailA
.body_html
;
807 scope
.mailB
.body_text
= scope
.mailA
.body_text
;
808 scope
.mailB
.scheduled_id
= scope
.mailA
.scheduled_id
;
809 scope
.mailB
.campaign_id
= scope
.mailA
.campaign_id
== null ? "" : scope
.mailA
.campaign_id
;
810 scope
.mailB
.header_id
= scope
.mailA
.header_id
;
811 scope
.mailB
.footer_id
= scope
.mailA
.footer_id
;
812 scope
.mailB
.is_completed
= scope
.mailA
.is_completed
;
815 if (scope
.whatnext
== "2") {
816 scope
.mailB
.fromEmail
= scope
.mailA
.fromEmail
;
817 scope
.mailB
.name
= scope
.mailA
.name
;
818 scope
.mailB
.visibility
= scope
.mailA
.visibility
;
819 scope
.mailB
.created_id
= scope
.mailA
.created_id
;
820 scope
.mailB
.msg_template_id
= scope
.mailA
.msg_template_id
== null ? "" : scope
.mailA
.msg_template_id
;
821 scope
.mailB
.open_tracking
= scope
.mailA
.open_tracking
;
822 scope
.mailB
.url_tracking
= scope
.mailA
.url_tracking
;
823 scope
.mailB
.forward_replies
= scope
.mailA
.forward_replies
;
824 scope
.mailB
.auto_responder
= scope
.mailA
.auto_responder
;
825 scope
.mailB
.from_name
= scope
.mailA
.from_name
;
826 scope
.mailB
.replyto_email
= scope
.mailA
.replyto_email
;
827 scope
.mailB
.unsubscribe_id
= scope
.mailA
.unsubscribe_id
;
828 scope
.mailB
.resubscribe_id
= scope
.mailA
.resubscribe_id
;
829 scope
.mailB
.body_html
= scope
.mailA
.body_html
;
830 scope
.mailB
.body_text
= scope
.mailA
.body_text
;
831 scope
.mailB
.scheduled_id
= scope
.mailA
.scheduled_id
;
832 scope
.mailB
.campaign_id
= scope
.mailA
.campaign_id
== null ? "" : scope
.mailA
.campaign_id
;
833 scope
.mailB
.header_id
= scope
.mailA
.header_id
;
834 scope
.mailB
.footer_id
= scope
.mailA
.footer_id
;
835 scope
.mailB
.is_completed
= scope
.mailA
.is_completed
;
840 name
: scope
.currentABTest
.name
+ ' (AB test B)',
841 visibility
: scope
.mailB
.visibility
,
843 subject
: scope
.mailB
.subject
,
844 msg_template_id
: scope
.mailB
.msg_template_id
== null ? "" : scope
.mailB
.msg_template_id
,
845 open_tracking
: scope
.mailB
.open_tracking
,
846 url_tracking
: scope
.mailB
.url_tracking
,
847 forward_replies
: scope
.mailB
.forward_replies
,
848 auto_responder
: scope
.mailB
.auto_responder
,
849 from_name
: scope
.mailB
.from_name
,
850 from_email
: scope
.mailB
.from_email
,
851 replyto_email
: scope
.mailB
.replyto_email
,
852 unsubscribe_id
: scope
.mailB
.unsubscribe_id
,
853 resubscribe_id
: scope
.mailB
.resubscribe_id
,
854 body_html
: scope
.mailB
.body_html
,
855 body_text
: scope
.mailB
.body_text
,
856 scheduled_id
: scope
.mailB
.scheduled_id
,
857 campaign_id
: scope
.mailB
.campaign_id
== null ? "" : scope
.mailB
.campaign_id
,
858 header_id
: scope
.mailB
.header_id
,
859 footer_id
: scope
.mailB
.footer_id
,
860 is_completed
: scope
.mailA
.is_completed
865 name
: scope
.currentABTest
.name
+ ' (AB test winner)',
866 visibility
: scope
.mailB
.visibility
,
868 subject
: scope
.mailB
.subject
,
869 msg_template_id
: scope
.mailB
.msg_template_id
== null ? "" : scope
.mailB
.msg_template_id
,
870 open_tracking
: scope
.mailB
.open_tracking
,
871 url_tracking
: scope
.mailB
.url_tracking
,
872 forward_replies
: scope
.mailB
.forward_replies
,
873 auto_responder
: scope
.mailB
.auto_responder
,
874 from_name
: scope
.mailB
.from_name
,
875 from_email
: scope
.mailB
.from_email
,
876 replyto_email
: scope
.mailB
.replyto_email
,
877 unsubscribe_id
: scope
.mailB
.unsubscribe_id
,
878 resubscribe_id
: scope
.mailB
.resubscribe_id
,
879 body_html
: scope
.mailB
.body_html
,
880 body_text
: scope
.mailB
.body_text
,
881 campaign_id
: scope
.mailB
.campaign_id
== null ? "" : scope
.mailB
.campaign_id
,
882 header_id
: scope
.mailB
.header_id
,
883 footer_id
: scope
.mailB
.footer_id
,
884 is_completed
: scope
.mailA
.is_completed
,
885 'api.mailing_job.create': 0
892 crmMailingAB
.directive('chsdate', function () {
895 link: function (scope
, element
, attrs
) {
896 $(element
).datepicker({
897 dateFormat
: "yy-mm-dd",
898 onSelect: function (date
) {
899 $(".ui-datepicker a").removeAttr("href");
900 scope
.currentABTest
.date
= date
.toString();
908 crmMailingAB
.directive('prevbutton', function () {
912 template
: '<div class="crm-submit-buttons" >' +
913 '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view" >' +
914 '<input type="submit" value="Previous" id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" prevtab={{tab_val}}>' +
919 crmMailingAB
.directive('groupselect', function () {
922 link: function (scope
, element
, attrs
) {
925 data
: CRM
.crmMailing
.mailTokens
,
926 placeholder
: "Insert Token"
928 $(element
).on('select2-selecting', function (e
) {
930 scope
.$evalAsync('_resetSelection()');
931 var a
= $(element
).attr('id');
932 if (a
== "htgroupcompose") {
933 scope
.tokenfunc("body_html", e
, scope
.mailA
.body_html
);
936 if (a
== "htgroupcomposetwob") {
937 scope
.tokenfunc("twomailbbody_html", e
, scope
.mailB
.body_html
);
940 if (a
== "htgroupcomposetwoa") {
941 scope
.tokenfunc("twomailabody_html", e
, scope
.mailA
.body_html
);
944 if (a
== "textgroupcompose") {
945 scope
.tokenfunc("body_text", e
, scope
.mailA
.body_text
);
948 if (a
== "textgroupcomposetwoa") {
949 scope
.tokenfunc("twomailabody_text", e
, scope
.mailA
.body_text
);
952 if (a
== "textgroupcomposetwob") {
953 scope
.tokenfunc("twomailbbody_text", e
, scope
.mailB
.body_text
);
956 if (a
== "subgroupsuba") {
957 scope
.tokenfunc("suba", e
, scope
.mailA
.subject
);
960 if (a
== "subgroupsubb") {
961 scope
.tokenfunc("subb", e
, scope
.mailB
.subject
);
964 if (a
== "subgroupfrom") {
965 scope
.tokenfunc("subfrom", e
, scope
.mailA
.subject
);
968 if (a
== "subgrouptwoa") {
969 scope
.tokenfunc("twomaila", e
, scope
.mailA
.subject
);
972 if (a
== "subgrouptwob") {
973 scope
.tokenfunc("twomailb", e
, scope
.mailB
.subject
);
993 crmMailingAB
.directive('replytoselect',function(){
996 link: function(scope
, element
, attrs
){
998 function format(item
){
999 return item
.label
.replace(/&/g
, '&')
1000 .replace(/"/g, '"')
1001 .replace(/</g, '<')
1002 .replace(/>/g, '>');
1005 CRM.api3('OptionGroup', 'get', {
1007 "name
": "from_email_address
"
1008 }).done(function(result) {
1009 var emailGroupId = result.id;
1010 CRM.api3('OptionValue', 'get', {
1012 "option_group_id
": result.id
1013 }).done(function(orgEmails) {
1017 $(element).select2({
1018 class: "abtesting
-form
-element
",
1019 data: orgEmails.values,
1020 formatResult: format,
1021 formatSelection: format,
1022 placeholder:"Select reply to address
"});
1033 crmMailingAB.directive('stopa',function(){
1036 link: function (scope, element, attrs) {
1037 scope.$watch('aastop', function () {
1038 if (scope.aastop == true) {
1040 title: 'Confirmation',
1047 'Yes': function () {
1048 scope.aastop = false;
1050 $(element).dialog("close
");
1053 scope.aastop = false;
1054 $(element).dialog("close
");
1057 close: function () {
1058 scope.aastop = false;
1069 crmMailingAB.directive('stopb', function () {
1072 link: function (scope, element, attrs) {
1074 scope.$watch('bbstop', function () {
1075 if (scope.bbstop == true) {
1077 title: 'Confirmation',
1084 'Yes': function () {
1085 scope.bbstop = false;
1087 $(element).dialog("close
");
1090 scope.bbstop = false;
1091 $(element).dialog("close
");
1094 close: function () {
1095 scope.bbstop = false;
1107 crmMailingAB.directive('checktimeentry', function () {
1110 link: function (scope, element, attrs) {
1111 $(element).timeEntry({
1119 crmMailingAB.directive('ckedit', function ($parse) {
1120 CKEDITOR.disableAutoInline = true;
1126 link: function (scope, element, attrs, controller) {
1127 var getter = $parse(attrs.ckedit),
1128 setter = getter.assign;
1130 attrs.$set('contenteditable', true); // inline ckeditor needs this
1132 attrs.$set('id', prefix + (++counter));
1136 // Override the normal CKEditor save plugin
1138 CKEDITOR.plugins.registered['save'] =
1140 init: function (editor) {
1141 editor.addCommand('save',
1143 modes: { wysiwyg: 1, source: 1 },
1144 exec: function (editor) {
1145 if (editor.checkDirty()) {
1146 var ckValue = editor.getData();
1147 scope.$apply(function () {
1148 setter(scope, ckValue);
1151 editor.resetDirty();
1156 editor.ui.addButton('Save', { label: 'Save', command: 'save', toolbar: 'document' });
1161 blur: function (e) {
1162 if (e.editor.checkDirty()) {
1163 var ckValue = e.editor.getData();
1164 scope.$apply(function () {
1165 setter(scope, ckValue);
1168 e.editor.resetDirty();
1172 options.extraPlugins = 'sourcedialog';
1173 options.removePlugins = 'sourcearea';
1174 var editorangular = CKEDITOR.inline(element[0], options); //invoke
1176 scope.$watch(attrs.ckedit, function (value) {
1177 editorangular.setData(value);
1184 })(angular, CRM.$, CRM._);