2 * Created by aditya on 6/12/14.
6 (function (angular
, $, _
) {
8 var partialUrl = function (relPath
) {
9 return CRM
.resourceUrls
['civicrm'] + '/partials/abtesting/' + relPath
;
12 var crmMailingAB
= angular
.module('crmMailingAB', ['ngRoute', 'ui.utils','ngSanitize']);
14 crmMailingAB
.run(function ($rootScope
, $templateCache
) {
15 $rootScope
.$on('$viewContentLoaded', function () {
16 $templateCache
.removeAll();
21 function ($routeProvider
) {
22 $routeProvider
.when('/mailing/abtesting', {
23 templateUrl
: partialUrl('list.html'),
24 controller
: 'ABListingCtrl',
26 mailingList: function ($route
, crmApi
) {
27 return crmApi('Mailing', 'get', {});
31 $routeProvider
.when('/mailing/abtesting/report/:id', {
32 templateUrl
: partialUrl('report.html'),
33 controller
: 'ReportCtrl',
35 selectedABTest: function($route
, crmApi
) {
36 return crmApi('MailingAB', 'getsingle', {id
: $route
.current
.params
.id
});
42 $routeProvider
.when('/mailing/abtesting/:id', {
43 templateUrl
: partialUrl('main.html'),
44 controller
: 'TabsDemoCtrl',
46 selectedABTest: function($route
, crmApi
) {
47 if ( $route
.current
.params
.id
!== 'new') {
49 return crmApi('MailingAB', 'getsingle', {id
: $route
.current
.params
.id
});
52 console
.log("created");
53 //created_id has been set to my id. Does not save without created_id. Needs to made generic based on the user
54 return { just_created
:"1"
63 //-----------------------------------------
64 // Add a new record by name.
65 // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
66 crmMailingAB
.controller('ABListingCtrl', function ($scope
, crmApi
) {
67 $scope
.abmailList
= CRM
.crmMailing
.mailingabNames
;
68 console
.log($scope
.abmailList
);
72 crmMailingAB
.controller('ReportCtrl', function ($scope
, crmApi
,selectedABTest
) {
75 $scope
.graph_data
= [{
92 console
.log(selectedABTest
);
93 if(selectedABTest
.winner_criteria_id
==1){
94 $scope
.winner_criteria
= "Open";
96 else if(selectedABTest
.winner_criteria_id
==2){
97 $scope
.winner_criteria
="Total Unique Clicks";
99 else if(selectedABTest
.winner_criteria_id
==3){
100 $scope
.winner_criteria
="Total Clicks on a particular link";
107 crmMailingAB
.controller('TabsDemoCtrl', function ($scope
, crmApi
,selectedABTest
,$sce
) {
110 $scope
.currentABTest
=selectedABTest
111 $scope
.groups
= CRM
.crmMailing
.groupNames
;
112 $scope
.mailList
= CRM
.crmMailing
.civiMails
;
113 $scope
.eMailing
= CRM
.crmMailing
.emailAdd
;
114 $scope
.tmpList
= CRM
.crmMailing
.mesTemplate
;
115 $scope
.headerfooter
= CRM
.crmMailing
.headerfooterList
;
116 if($scope
.currentABTest
.declare_winning_time
!= null){
117 $scope
.ans
= $scope
.currentABTest
.declare_winning_time
.split(" ");
118 $scope
.currentABTest
.date
=$scope
.ans
[0];
119 $scope
.currentABTest
.time
=$scope
.ans
[1];
123 if($scope
.currentABTest
.just_created
!= 1){
124 console
.log("Prithvi");
125 console
.log($scope
.currentABTest
);
126 console
.log($scope
.currentABTest
.mailing_id_a
);
128 $scope
.abId
= $scope
.currentABTest
.id
;
129 var abmailA
= crmApi('Mailing','getsingle',{id
:$scope
.currentABTest
.mailing_id_a
});
130 var abmailB
= crmApi('Mailing','getsingle',{id
:$scope
.currentABTest
.mailing_id_b
});
131 var abmailC
= crmApi('Mailing','getsingle',{id
:$scope
.currentABTest
.mailing_id_c
});
132 abmailA
.success(function (data
) {
133 if (data
.is_error
== 0) {
138 abmailB
.success(function(data
) {
139 if (data
.is_error
== 0) {
144 abmailC
.success(function(data
) {
145 if (data
.is_error
== 0) {
152 console
.log("Prithvila");
153 console
.log($scope
.currentABTest
);
159 $scope
.sendtest
=false;
160 if(typeof $scope
.mailA
== 'undefined')$scope
.mailA
={};
161 if(typeof $scope
.mailB
== 'undefined')$scope
.mailB
={};
162 if(typeof $scope
.mailB
== 'undefined')$scope
.mailC
={};
166 { name
: 'Subject Lines', url
: partialUrl('subject_lines.html'),val
: 1},
167 { name
: 'From Name', url
: partialUrl('from_name.html'),val
:2},
168 {name
: 'Two different Emails', url
: partialUrl('two_emails.html'),val
:3}
170 if($scope
.currentABTest
.just_created
!= 1){
172 console
.log("adit "+$scope
.currentABTest
.testing_criteria_id
);
174 $scope
.template
=$scope
.templates
[$scope
.currentABTest
.testing_criteria_id
-1];
175 console
.log($scope
.template
.val
);
179 $scope
.template
= $scope
.templates
[0];
182 mltokens
= CRM
.crmMailing
.mailTokens
;
183 $scope
.deliberatelyTrustDangerousSnippeta = function() {
184 return $sce
.trustAsHtml($scope
.previewa
);
187 $scope
.deliberatelyTrustDangerousSnippetb = function() {
188 return $sce
.trustAsHtml($scope
.previewb
);
193 $scope
.campaign_clicked = function () {
194 if ($scope
.max_tab
>= 0) {
199 $scope
.winner_criteria
="";
200 $scope
.compose_clicked = function () {
201 if ($scope
.max_tab
>= 1) {
205 $scope
.rec_clicked = function () {
206 if ($scope
.max_tab
>= 2) {
210 $scope
.preview_clicked = function () {
211 if ($scope
.max_tab
>= 3) {
215 $scope
.preview
= false;
216 $scope
.slide_value
= 0;
218 $scope
.setifyes = function (val
) {
223 $scope
.ifyes
= false;
227 $scope
.reply = function(){
228 if($scope
.trackreplies
==0){
229 $scope
.trackreplies
=1;
232 $scope
.trackreplies
=0;
233 $scope
.currentMailing
.forward_replies
=0;
234 $scope
.currentMailing
.auto_responder
=0;
238 $scope
.isAuto= function(au
){
239 return au
.component_type
== "Reply";
242 $scope
.trackr= function(trackreplies
){
243 if(trackreplies
=="1"){
250 $scope
.sen = function(){
251 $scope
.sendtest
=true;
254 $scope
.isHeader= function(hf
){
255 return hf
.component_type
== "Header";
257 //filter so we only get footers from mailing component
258 $scope
.isFooter= function(f
){
259 return f
.component_type
== "Footer";
262 $scope
.send_date
= "01/01/2000";
267 $scope
.savea = function (dat
) {
269 var result
= crmApi('Mailing', 'create', dat
, true);
271 result
.success(function(data
) {
272 if (data
.is_error
== 0) {
273 $scope
.mailA
.id
= data
.id
;
274 $scope
.currentABTest
.mailing_id_a
=$scope
.mailA
.id
;
275 console
.log("Mail a Id "+ $scope
.mailA
.id
);
280 $scope
.append_mails = function(){
281 crmApi('MailingAB','create',{id
:$scope
.abId
,mailing_id_a
:$scope
.mailA
.id
,mailing_id_b
:$scope
.mailB
.id
,mailing_id_c
:$scope
.mailC
.id
});
282 $scope
.currentABTest
.id
= $scope
.abId
;
285 $scope
.saveb = function (dat
) {
287 var result
= crmApi('Mailing', 'create', dat
, true);
289 result
.success(function(data
) {
290 if (data
.is_error
== 0) {
291 $scope
.mailB
.id
= data
.id
;
292 console
.log("Mail b Id "+ $scope
.mailB
.id
);
293 $scope
.currentABTest
.mailing_id_b
=$scope
.mailB
.id
;
295 $scope
.append_mails();
303 $scope
.savec = function (dat
) {
305 console
.log("C is called");
306 var result
= crmApi('Mailing', 'create', dat
, true);
308 result
.success(function(data
) {
309 if (data
.is_error
== 0) {
310 $scope
.mailC
.id
= data
.id
;
311 console
.log("Mail C Id "+ $scope
.mailC
.id
);
312 $scope
.currentABTest
.mailing_id_c
=$scope
.mailC
.id
;
314 $scope
.append_mails();
322 $scope
.pre= function(){
326 $scope
.init = function (par
) {
328 $scope
.whatnext
= par
.toString()
331 $scope
.setdate = function (par
) {
332 console
.log("called")
333 console
.log("av " + par
)
334 $scope
.send_date
= par
;
339 $scope
.testmailid
="";
340 $scope
.incGroup
= [];
341 $scope
.excGroup
= [];
342 $scope
.incGroupids
=[];
343 $scope
.excGroupids
=[];
345 $scope
.create_abtest = function(){
347 $scope
.currentABTest
.testing_criteria_id
=$scope
.template
.val
;
349 if($scope
.abId
=="" )
350 result
= crmApi('MailingAB','create',{name
: $scope
.currentABTest
.name
,testing_criteria_id
: $scope
.template
.val
});
352 if (typeof $scope
.currentABTest
.mailing_id_a
== 'undefined')
353 result
= crmApi('MailingAB','create',{id
:$scope
.abId
,testing_criteria_id
: $scope
.template
.val
});
355 result
= crmApi('MailingAB','create',{id
:$scope
.abId
,testing_criteria_id
: $scope
.template
.val
,mailing_id_a
:$scope
.currentABTest
.mailing_id_a
,mailing_id_b
:$scope
.currentABTest
.mailing_id_b
} );
362 result
.success(function(data
) {
363 if (data
.is_error
== 0) {
364 $scope
.abId
= data
.id
;
365 console
.log("ID "+$scope
.abId
);
372 $scope
.a_b_update = function(){
374 $scope
.tp1
.include
=$scope
.incGroupids
;
375 $scope
.tp1
.exclude
=$scope
.excGroupids
;
377 console
.log($scope
.tp1
);
378 console
.log($scope
.currentABTest
.id
);
380 console
.log("--------");
381 var result
= crmApi('Mailing','a_b_recipients_update',{
382 id
:$scope
.currentABTest
.id
,
386 var resulta
=crmApi('Mailing','preview',{id
:$scope
.currentABTest
.mailing_id_a
});
388 resulta
.success(function(data
) {
389 if (data
.is_error
== 0) {
392 $scope
.previewa
=data
.values
.html
;
399 resulta
=crmApi('Mailing','preview',{id
:$scope
.currentABTest
.mailing_id_b
});
401 resulta
.success(function(data
) {
402 if (data
.is_error
== 0) {
404 console
.log(data
.values
.html
);
405 $scope
.previewb
=data
.values
.html
;
411 $scope
.update_abtest = function(){
413 $scope
.currentABTest
.declare_winning_time
= $scope
.currentABTest
.date
+ " " + $scope
.currentABTest
.time
;
415 result
= crmApi('MailingAB','create',{id
:$scope
.abId
,
416 testing_criteria_id
: $scope
.template
.val
,
417 mailing_id_a
:$scope
.currentABTest
.mailing_id_a
,
418 mailing_id_b
:$scope
.currentABTest
.mailing_id_b
,
419 mailing_id_c
:$scope
.currentABTest
.mailing_id_c
,
420 winner_criteria_id
: $scope
.currentABTest
.winner_criteria_id
,
421 group_percentage
: $scope
.currentABTest
.group_percentage
,
422 declare_winning_time
: $scope
.currentABTest
.declare_winning_time
435 $scope
.tmp = function (tst
,aorb
){
437 $scope
.mailA
.msg_template_id
=tst
;
438 console
.log($scope
.mailA
.msg_template_id
+ "sasas");
439 if($scope
.mailA
.msg_template_id
== null){
440 $scope
.mailA
.body_html
="";
443 for(var a
in $scope
.tmpList
){
445 if($scope
.tmpList
[a
].id
==$scope
.mailA
.msg_template_id
){
446 $scope
.mailA
.body_html
=$scope
.tmpList
[a
].msg_html
;
453 $scope
.mailB
.msg_template_id
=tst
;
454 console
.log($scope
.mailB
.msg_template_id
+ "sasas");
455 if($scope
.mailB
.msg_template_id
== null){
456 $scope
.mailB
.body_html
="";
459 for(var a
in $scope
.tmpList
){
461 if($scope
.tmpList
[a
].id
==$scope
.mailB
.msg_template_id
){
462 $scope
.mailB
.body_html
=$scope
.tmpList
[a
].msg_html
;
470 $scope
.mailA
.msg_template_id
=tst
;
471 console
.log($scope
.mailA
.msg_template_id
+ "sasas");
472 if($scope
.mailA
.msg_template_id
== null){
473 $scope
.mailA
.body_html
="";
476 for(var a
in $scope
.tmpList
){
478 if($scope
.tmpList
[a
].id
==$scope
.mailA
.msg_template_id
){
479 $scope
.mailA
.body_html
=$scope
.tmpList
[a
].msg_html
;
484 $scope
.mailB
.msg_template_id
=tst
;
485 console
.log($scope
.mailB
.msg_template_id
+ "sasas");
486 if($scope
.mailB
.msg_template_id
== null){
487 $scope
.mailB
.body_html
="";
490 for(var a
in $scope
.tmpList
){
492 if($scope
.tmpList
[a
].id
==$scope
.mailB
.msg_template_id
){
493 $scope
.mailB
.body_html
=$scope
.tmpList
[a
].msg_html
;
505 crmMailingAB
.directive('nexttab', function () {
507 // Restrict it to be an attribute in this case
511 // responsible for registering DOM listeners as well as updating the DOM
512 link: function (scope
, element
, attrs
) {
514 $(element
).parent().parent().parent().parent().tabs(scope
.$eval(attrs
.nexttab
));
515 var myarr
= new Array(1, 2, 3)
516 $(element
).parent().parent().parent().parent().tabs({disabled
: myarr
});
518 $(element
).on("click", function () {
519 if(scope
.tab_val
==0){
520 scope
.create_abtest();
522 else if(scope
.tab_val
== 2){
523 scope
.update_abtest();
524 if(scope
.currentABTest
.winner_criteria_id
==1){
525 scope
.winner_criteria
="Open";
527 else if(scope
.currentABTest
.winner_criteria_id
==2){
528 scope
.winner_criteria
=" Total Unique Clicks";
530 else if(scope
.currentABTest
.winner_criteria_id
==3){
531 scope
.winner_criteria
="Total Clicks on a particular link";
539 scope
.tab_val
= scope
.tab_val
+ 1;
541 scope
.max_tab
= Math
.max(scope
.tab_val
, scope
.max_tab
);
542 var myArray1
= new Array();
543 for (var i
= scope
.max_tab
+ 1; i
< 4; i
++) {
546 $(element
).parent().parent().parent().parent().parent().tabs("option", "disabled", myArray1
);
547 $(element
).parent().parent().parent().parent().parent().tabs("option", "active", scope
.tab_val
);
555 crmMailingAB
.directive('prevtab', function () {
557 // Restrict it to be an attribute in this case
560 // responsible for registering DOM listeners as well as updating the DOM
561 link: function (scope
, element
, attrs
) {
564 $(element
).on("click", function () {
565 var temp
= scope
.tab_val
- 1;
566 scope
.tab_val
= scope
.tab_val
- 1;
573 $(element
).parent().parent().parent().parent().parent().tabs("option", "active", temp
);
583 crmMailingAB
.directive('chsgroup', function () {
586 link: function (scope
, element
, attrs
) {
587 function format(item
) {
589 // return `text` for optgroup
592 // return item template
593 var a
= item
.id
.split(" ");
594 if (a
[1] == "group" && a
[2] == "include") {
595 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
;
597 if (a
[1] == "group" && a
[2] == "exclude") {
598 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
;
600 if (a
[1] == "mail" && a
[2] == "include") {
601 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
;
603 if (a
[1] == "mail" && a
[2] == "exclude") {
604 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
;
610 placeholder
: "Select the groups you wish to include",
611 formatResult
: format
,
612 formatSelection
: format
,
613 escapeMarkup: function (m
) {
618 $(element
).on('select2-selecting', function (e
) {
619 var a
= e
.val
.split(" ");
621 if (a
[2] == "include") {
623 for (i
= 3; i
< l
; i
++) {
627 scope
.incGroup
.push(str
);
628 scope
.incGroupids
.push(a
[0]);
634 for (i
= 3; i
< l
; i
++) {
639 scope
.excGroup
.push(str
);
640 scope
.excGroupids
.push(a
[0]);
645 $(element
).on("select2-removed", function (e
) {
646 if (e
.val
.split(" ")[2] == "exclude") {
647 var index
= scope
.excGroup
.indexOf(e
.val
.split(" ")[3]);
648 scope
.excGroup
.splice(index
, 1);
649 scope
.incGroup
.splice(index
,1);
653 var index
= scope
.incGroup
.indexOf(e
.val
.split(" ")[3]);
654 scope
.incGroup
.splice(index
, 1);
655 scope
.incGroupids
.splice(index
,1);
664 crmMailingAB
.directive('groupselect',function(){
667 link: function(scope
,element
, attrs
){
668 $(element
).select2({width
:"200px", data
: mltokens
, placeholder
:"Insert Token"});
671 $(element
).on('select2-selecting', function(e
) {
672 scope
.$evalAsync('_resetSelection()');console
.log(mltokens
);
673 /* if(scope.currentMailing.body_html == null){
674 scope.currentMailing.body_html = e.val;
677 scope.currentMailing.body_html = scope.currentMailing.body_html + e.val;
679 var msg
= document
.getElementById("body_html").value
;
680 var cursorlen
= document
.getElementById("body_html").selectionStart
;
681 console
.log(cursorlen
);
682 var textlen
= msg
.length
;
683 document
.getElementById("body_html").value
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
684 scope
.currentMailing
.body_html
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
685 console
.log(document
.getElementById("body_html").value
);
686 console
.log(scope
.currentMailing
.body_html
);
687 var cursorPos
= (cursorlen
+ e
.val
.length
);
688 document
.getElementById("body_html").selectionStart
= cursorPos
;
689 document
.getElementById("body_html").selectionEnd
= cursorPos
;
690 document
.getElementById("body_html").focus();
700 crmMailingAB
.directive('sliderbar', function () {
703 link: function (scope
, element
, attrs
) {
704 if(typeof scope
.currentABTest
.group_percentage
!= 'undefined'){
706 $(element
).slider({value
:scope
.currentABTest
.group_percentage
});
708 $(element
).slider({min
: 1});
710 slide: function (event
, ui
) {
711 scope
.currentABTest
.group_percentage
= ui
.value
;
719 crmMailingAB
.directive('tpmax', function () {
722 link: function (scope
, element
, attr
) {
723 scope
.$watch('automated', function (val
) {
726 title
: 'Automated A/B Testing',
736 $(element
).find("#closebutton").on("click", function () {
737 $(element
).dialog("close");
743 crmMailingAB
.directive('previewmail', function () {
745 // Restrict it to be an attribute in this case
749 // responsible for registering DOM listeners as well as updating the DOM
750 link: function (scope
, element
, attrs
) {
752 scope
.$watch('preview', function () {
753 if(scope
.preview
== true){
756 title
: 'Preview Mailing',
763 close :function(){console
.log("close");
764 scope
.preview
= false;scope
.$apply()}
772 $(element
).find("#closebutton").on("click", function () {
773 console
.log("close");
774 scope
.preview
= false;
775 $(element
).dialog("close");
781 crmMailingAB
.directive('sendmailtest', function () {
783 // Restrict it to be an attribute in this case
786 link: function (scope
, element
, attrs
) {
788 scope
.$watch('sendtest', function () {
789 if(scope
.sendtest
== true){
792 title
: 'Send Test Mails',
801 $(this).dialog('close');
804 close :function(){console
.log("close");
805 scope
.sendtest
= false;scope
.$apply()}
814 $(element
).find("#closebutton").on("click", function () {
815 console
.log("close");
816 scope
.preview
= false;
817 $(element
).dialog("close");
823 crmMailingAB
.directive('numbar', function () {
826 link: function (scope
, element
, attrs
) {
827 $(element
).spinner({max
: attrs
.numbar
, min
: 0});
832 crmMailingAB
.directive('datepick', function () {
837 link: function (scope
, element
, attrs
) {
838 $(element
).datepicker({
839 dateFormat
: "yy-mm-dd",
840 onSelect: function (date
) {
841 $(".ui-datepicker a").removeAttr("href");
843 scope
.scheddate
.date
= date
.toString();
845 console
.log(scope
.scheddate
.date
);
855 crmMailingAB
.directive('submitform', function () {
859 link: function (scope
, element
, attrs
) {
860 $(element
).on("click", function () {
862 console
.log("clicked");
865 name
: "Aditya Nambiar",
866 visibility
: scope
.mailA
.visibility
,
868 subject
: scope
.mailA
.subject
,
869 msg_template_id
: scope
.mailA
.msg_template_id
==null ? "" : scope
.mailA
.msg_template_id
,
870 open_tracking
: scope
.mailA
.open_tracking
,
871 url_tracking
: scope
.mailA
.url_tracking
,
872 forward_replies
: scope
.mailA
.forward_replies
,
873 auto_responder
: scope
.mailA
.auto_responder
,
874 from_name
: scope
.mailA
.from_name
,
875 from_email
: scope
.mailA
.from_email
,
876 replyto_email
: scope
.mailA
.replyto_email
,
877 unsubscribe_id
: scope
.mailA
.unsubscribe_id
,
878 resubscribe_id
: scope
.mailA
.resubscribe_id
,
879 body_html
: scope
.mailA
.body_html
,
880 body_text
: scope
.mailA
.body_text
,
881 scheduled_date
: scope
.mailA
.scheduled_date
,
882 scheduled_id
: scope
.mailA
.scheduled_id
,
883 campaign_id
: scope
.mailA
.campaign_id
==null ? "" : scope
.mailA
.campaign_id
,
884 header_id
: scope
.mailA
.header_id
,
885 footer_id
: scope
.mailA
.footer_id
,
887 is_completed
: scope
.mailA
.is_completed
890 console
.log("Truth " + scope
.whatnext
)
892 if (scope
.whatnext
== "3") {
895 scope
.mailB
.name
= scope
.mailA
.name
;
896 scope
.mailB
.visibility
= scope
.mailA
.visibility
;
897 scope
.mailB
.created_id
= scope
.mailA
.created_id
;
898 scope
.mailB
.subject
= scope
.mailA
.subject
;
899 scope
.mailB
.msg_template_id
= scope
.mailA
.msg_template_id
==null ? "" : scope
.mailA
.msg_template_id
;
900 scope
.mailB
.open_tracking
= scope
.mailA
.open_tracking
;
901 scope
.mailB
.url_tracking
= scope
.mailA
.url_tracking
;
902 scope
.mailB
.forward_replies
= scope
.mailA
.forward_replies
;
903 scope
.mailB
.auto_responder
= scope
.mailA
.auto_responder
;
904 scope
.mailB
.from_name
= scope
.mailA
.from_name
;
905 scope
.mailB
.replyto_email
= scope
.mailA
.replyto_email
;
906 scope
.mailB
.unsubscribe_id
= scope
.mailA
.unsubscribe_id
;
907 scope
.mailB
.resubscribe_id
= scope
.mailA
.resubscribe_id
;
908 scope
.mailB
.body_html
= scope
.mailA
.body_html
;
909 scope
.mailB
.body_text
= scope
.mailA
.body_text
;
910 scope
.mailB
.scheduled_date
= scope
.mailA
.scheduled_date
;
911 scope
.mailB
.scheduled_id
= scope
.mailA
.scheduled_id
;
912 scope
.mailB
.campaign_id
= scope
.mailA
.campaign_id
==null ? "" : scope
.mailA
.campaign_id
;
913 scope
.mailB
.header_id
= scope
.mailA
.header_id
;
914 scope
.mailB
.footer_id
= scope
.mailA
.footer_id
;
916 scope
.mailB
.is_completed
= scope
.mailA
.is_completed
;
920 if (scope
.whatnext
== "2") {
921 scope
.mailB
.fromEmail
= scope
.mailA
.fromEmail
;
922 scope
.mailB
.name
= scope
.mailA
.name
;
923 scope
.mailB
.visibility
= scope
.mailA
.visibility
;
924 scope
.mailB
.created_id
= scope
.mailA
.created_id
;
925 scope
.mailB
.msg_template_id
= scope
.mailA
.msg_template_id
==null ? "" : scope
.mailA
.msg_template_id
;
926 scope
.mailB
.open_tracking
= scope
.mailA
.open_tracking
;
927 scope
.mailB
.url_tracking
= scope
.mailA
.url_tracking
;
928 scope
.mailB
.forward_replies
= scope
.mailA
.forward_replies
;
929 scope
.mailB
.auto_responder
= scope
.mailA
.auto_responder
;
930 scope
.mailB
.from_name
= scope
.mailA
.from_name
;
931 scope
.mailB
.replyto_email
= scope
.mailA
.replyto_email
;
932 scope
.mailB
.unsubscribe_id
= scope
.mailA
.unsubscribe_id
;
933 scope
.mailB
.resubscribe_id
= scope
.mailA
.resubscribe_id
;
934 scope
.mailB
.body_html
= scope
.mailA
.body_html
;
935 scope
.mailB
.body_text
= scope
.mailA
.body_text
;
936 scope
.mailB
.scheduled_date
= scope
.mailA
.scheduled_date
;
937 scope
.mailB
.scheduled_id
= scope
.mailA
.scheduled_id
;
938 scope
.mailB
.campaign_id
= scope
.mailA
.campaign_id
==null ? "" : scope
.mailA
.campaign_id
;
939 scope
.mailB
.header_id
= scope
.mailA
.header_id
;
940 scope
.mailB
.footer_id
= scope
.mailA
.footer_id
;
942 scope
.mailB
.is_completed
= scope
.mailA
.is_completed
;
946 console
.log("call B");
950 name
: "Aditya Nambiar",
951 visibility
: scope
.mailB
.visibility
,
953 subject
: scope
.mailB
.subject
,
954 msg_template_id
: scope
.mailB
.msg_template_id
==null ? "" : scope
.mailB
.msg_template_id
,
955 open_tracking
: scope
.mailB
.open_tracking
,
956 url_tracking
: scope
.mailB
.url_tracking
,
957 forward_replies
: scope
.mailB
.forward_replies
,
958 auto_responder
: scope
.mailB
.auto_responder
,
959 from_name
: scope
.mailB
.from_name
,
960 from_email
: scope
.mailB
.from_email
,
961 replyto_email
: scope
.mailB
.replyto_email
,
962 unsubscribe_id
: scope
.mailB
.unsubscribe_id
,
963 resubscribe_id
: scope
.mailB
.resubscribe_id
,
964 body_html
: scope
.mailB
.body_html
,
965 body_text
: scope
.mailB
.body_text
,
966 scheduled_date
: scope
.mailB
.scheduled_date
,
967 scheduled_id
: scope
.mailB
.scheduled_id
,
968 campaign_id
: scope
.mailB
.campaign_id
==null ? "" : scope
.mailB
.campaign_id
,
969 header_id
: scope
.mailB
.header_id
,
970 footer_id
: scope
.mailB
.footer_id
,
972 is_completed
: scope
.mailA
.is_completed
975 console
.log("call C");
978 name
: "Aditya Nambiar",
979 visibility
: scope
.mailB
.visibility
,
981 subject
: scope
.mailB
.subject
,
982 msg_template_id
: scope
.mailB
.msg_template_id
==null ? "" : scope
.mailB
.msg_template_id
,
983 open_tracking
: scope
.mailB
.open_tracking
,
984 url_tracking
: scope
.mailB
.url_tracking
,
985 forward_replies
: scope
.mailB
.forward_replies
,
986 auto_responder
: scope
.mailB
.auto_responder
,
987 from_name
: scope
.mailB
.from_name
,
988 from_email
: scope
.mailB
.from_email
,
989 replyto_email
: scope
.mailB
.replyto_email
,
990 unsubscribe_id
: scope
.mailB
.unsubscribe_id
,
991 resubscribe_id
: scope
.mailB
.resubscribe_id
,
992 body_html
: scope
.mailB
.body_html
,
993 body_text
: scope
.mailB
.body_text
,
994 campaign_id
: scope
.mailB
.campaign_id
==null ? "" : scope
.mailB
.campaign_id
,
995 header_id
: scope
.mailB
.header_id
,
996 footer_id
: scope
.mailB
.footer_id
,
998 is_completed
: scope
.mailA
.is_completed
1010 crmMailingAB
.directive('nextbutton', function () {
1014 template
: '<div class="crm-submit-buttons" id="campaignbutton">' +
1015 '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view" >' +
1016 '<input type="submit" value="Next" id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" nexttab={{tab_val}}>' +
1022 crmMailingAB
.directive('cancelbutton', function () {
1026 template
: '<div class="crm-submit-buttons" id="campaignbutton">' +
1027 '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view" >' +
1028 '<input type="submit" value="Cancel" id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" >' +
1034 crmMailingAB
.directive('chsdate',function(){
1037 link: function(scope
,element
,attrs
){
1038 $(element
).datepicker({
1039 dateFormat
: "yy-mm-dd",
1040 onSelect: function(date
) {
1041 $(".ui-datepicker a").removeAttr("href");
1042 scope
.currentABTest
.date
=date
.toString();
1044 console
.log(scope
.currentABTest
.date
);
1051 crmMailingAB
.directive('prevbutton', function () {
1055 template
: '<div class="crm-submit-buttons" >' +
1056 '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view" >' +
1057 '<input type="submit" value="Previous" id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" prevtab={{tab_val}}>' +
1063 crmMailingAB
.directive('linegraph',function(){
1066 link: function(scope
,element
,attrs
){
1068 var data
= scope
.graph_data
;
1070 // see wht it looks like in the console
1071 console
.log("Data");
1074 // set up a colour variable
1075 var color
= d3
.scale
.category10();
1077 // map one colour each to x, y and z
1078 // keys grabs the key value or heading of each key value pair in the json
1082 console
.log(d3
.keys(data
[0]));
1083 color
.domain(d3
.keys(data
[0]).filter(function(key
) {
1084 return key
!== "time";
1087 // create a nested series for passing to the line generator
1088 // it's best understood by console logging the data
1089 var series
= color
.domain().map(function(name
) {
1094 values
: data
.map(function(d
) {
1095 console
.log("------");
1105 console
.log("Series");
1107 console
.log(series
);
1109 // Set the dimensions of the canvas / graph
1116 width
= 375 - margin
.left
- margin
.right
,
1117 height
= 250 - margin
.top
- margin
.bottom
;
1120 //var x = d3.time.scale().range([0, width]).domain([0,10]);
1121 var x
= d3
.scale
.linear().range([0,width
]);
1122 var y
= d3
.scale
.linear().range([height
, 0]);
1125 var xAxis
= d3
.svg
.axis().scale(x
)
1126 .orient("bottom").ticks(10);
1128 var yAxis
= d3
.svg
.axis().scale(y
)
1129 .orient("left").ticks(5);
1132 // Note you plot the time / score pair from each key you created ealier
1133 var valueline
= d3
.svg
.line()
1142 // Adds the svg canvas
1143 var svg
= d3
.select(element
[0])
1145 .attr("width", width
+ margin
.left
+ margin
.right
)
1146 .attr("height", height
+ margin
.top
+ margin
.bottom
)
1148 .attr("transform", "translate(" + margin
.left
+ "," + margin
.top
+ ")");
1150 // Scale the range of the data
1151 x
.domain(d3
.extent(data
, function(d
) {
1155 // note the nested nature of this you need to dig an additional level
1157 d3
.min(series
, function(c
) {
1158 return d3
.min(c
.values
, function(v
) {
1162 d3
.max(series
, function(c
) {
1163 return d3
.max(c
.values
, function(v
) {
1168 svg
.append("text") // text label for the x axis
1169 .attr("x", width
/ 2 )
1170 .attr("y", height
+ margin
.bottom
)
1171 .style("text-anchor", "middle")
1174 svg
.append("text") // text label for the x axis
1176 .style("text-anchor", "middle")
1177 .text(scope
.winner_criteria
).attr("transform", function(d
) {
1178 return "rotate(-90)"
1179 }).attr("x", -height
/2 )
1182 // create a variable called series and bind the date
1183 // for each series append a g element and class it as series for css styling
1184 var series
= svg
.selectAll(".series")
1186 .enter().append("g")
1187 .attr("class", "series");
1189 // create the path for each series in the variable series i.e. x, y and z
1190 // pass each object called x, y nad z to the lne generator
1191 series
.append("path")
1192 .attr("class", "line")
1193 .attr("d", function(d
) {
1194 console
.log(d
); // to see how d3 iterates through series
1195 return valueline(d
.values
);
1197 .style("stroke", function(d
) {
1198 return color(d
.name
);
1202 svg
.append("g") // Add the X Axis
1203 .attr("class", "x axis")
1204 .attr("transform", "translate(0," + height
+ ")")
1208 svg
.append("g") // Add the Y Axis
1209 .attr("class", "y axis")
1219 })(angular
, CRM
.$, CRM
._
);