2 * Created by aditya on 6/12/14.
6 (function(angular
, $, _
) {
8 var partialUrl = function(relPath
) {
9 //console.log(CRM.resourceUrls['civicrm']);
10 return CRM
.resourceUrls
['civicrm'] + '/partials/abtesting/' + relPath
;
11 //return '/drupal-7.28/sites/all/modules/civicrm/partials/abtesting/' + relPath;
16 var crmMailingAB
= angular
.module('crmMailingAB', ['ngRoute', 'ui.utils']);
18 crmMailingAB
.run(function($rootScope
, $templateCache
) {
19 $rootScope
.$on('$viewContentLoaded', function() {
20 $templateCache
.removeAll();
24 crmMailingAB
.config(['$routeProvider',
25 function($routeProvider
) {
26 $routeProvider
.when('/mailing', {
27 template
: '<h1>sdfs</h1>',
28 controller
: 'mailingListCtrl',
30 mailingList: function($route
, crmApi
) {
31 return crmApi('Mailing', 'get', {});
36 $routeProvider
.when('/mailing/abtesting', {
37 templateUrl
: partialUrl('main.html'),
38 controller
: 'TabsDemoCtrl',
41 mailingList: function($route
, crmApi
) {
42 return crmApi('Mailing', 'get', {});
48 //-----------------------------------------
49 // Add a new record by name.
50 // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
52 crmMailingAB
.controller('TabsDemoCtrl', function($scope
, crmApi
) {
54 $scope
.groups
= CRM
.crmMailing
.groupNames
;
55 $scope
.mailList
= CRM
.crmMailing
.civiMails
;
59 $scope
.campaign_clicked= function(){
60 if($scope
.max_tab
>= 0 ){
64 $scope
.compose_clicked=function(){
65 if($scope
.max_tab
>=1){
69 $scope
.rec_clicked=function(){
70 if($scope
.max_tab
>=2){
74 $scope
.preview_clicked=function(){
75 if($scope
.max_tab
>=3){
80 [ { name
: 'Subject Lines', url
: partialUrl('subject_lines.html')},
81 { name
: 'From Name', url
: partialUrl('from_name.html')},
82 {name
:'Two different Emails',url
: partialUrl('two_emails.html')} ];
83 $scope
.template
= $scope
.templates
[0];
85 $scope
.slide_value
= 0;
87 $scope
.setifyes= function(val
){
95 $scope
.send_date
="01/01/2000";
102 $scope
.save=function(dat
){
104 var result
= crmApi('Mailing', 'create',dat
, true);
105 console
.log("Ac "+result
);
108 $scope
.init=function(par
){
110 $scope
.whatnext
=par
.toString()
113 $scope
.setdate= function(par
){
114 console
.log("called")
115 console
.log("av "+par
)
116 $scope
.send_date
=par
;
122 $scope
.scheddate
.date
= "6";
123 $scope
.scheddate
.time
= "";
130 crmMailingAB
.directive('nexttab', function() {
132 // Restrict it to be an attribute in this case
136 // responsible for registering DOM listeners as well as updating the DOM
137 link: function(scope
, element
, attrs
) {
139 $(element
).parent().parent().parent().parent().tabs(scope
.$eval(attrs
.nexttab
));
140 var myarr
= new Array(1,2,3)
141 $(element
).parent().parent().parent().parent().tabs({disabled
:myarr
});
143 $(element
).on("click",function() {
144 scope
.tab_val
=scope
.tab_val
+1;
146 scope
.max_tab
= Math
.max(scope
.tab_val
,scope
.max_tab
);
147 var myArray1
= new Array( );
148 for ( var i
= scope
.max_tab
+1; i
< 4; i
++ ) {
151 $(element
).parent().parent().parent().parent().parent().tabs( "option", "disabled", myArray1
);
152 $(element
).parent().parent().parent().parent().parent().tabs("option", "active", scope
.tab_val
);
160 crmMailingAB
.directive('prevtab', function() {
162 // Restrict it to be an attribute in this case
165 // responsible for registering DOM listeners as well as updating the DOM
166 link: function(scope
, element
, attrs
) {
170 $(element
).on("click",function() {
171 var temp
= scope
.tab_val
-1 ;
172 scope
.tab_val
=scope
.tab_val
-1;
179 $(element
).parent().parent().parent().parent().parent().tabs("option", "active", temp
);
189 crmMailingAB
.directive('groupselect',function(){
192 link: function(scope
,element
, attrs
){
193 function format(item
) {
195 // return `text` for optgroup
198 // return item template
199 var a
= item
.id
.split(" ");
200 if(a
[1]=="group" && a
[2]=="include")
201 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
;
202 if(a
[1]=="group" && a
[2]=="exclude")
203 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
;
204 if(a
[1]=="mail" && a
[2]=="include")
205 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
;
206 if(a
[1]=="mail" && a
[2]=="exclude")
207 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
;
212 placeholder
: "Select the groups you wish to include",
213 formatResult
: format
,
214 formatSelection
: format
,
215 escapeMarkup: function(m
) { return m
; }
218 $(element
).on('select2-selecting', function(e
) {
219 var a
= e
.val
.split(" ");
227 scope
.incGroup
.push(str
);scope
.$apply();}
236 scope
.excGroup
.push(str
);scope
.$apply();}
239 $(element
).on("select2-removed", function(e
) {
240 if(e
.val
.split(" ")[2]=="exclude") {
241 var index
= scope
.excGroup
.indexOf(e
.val
.split(" ")[3]);
242 scope
.excGroup
.splice(index
, 1);
246 var index
= scope
.incGroup
.indexOf(e
.val
.split(" ")[3]);
247 scope
.incGroup
.splice(index
, 1);scope
.$apply();
255 crmMailingAB
.directive('sliderbar',function(){
258 link: function(scope
,element
, attrs
){
259 $(element
).slider({min
:1});
261 slide: function( event
, ui
) {
262 scope
.slide_value
= ui
.value
;
270 crmMailingAB
.directive('tpmax',function(){
273 link: function(scope
,element
,attr
){
274 scope
.$watch('automated', function(val
) {
277 title
: 'Automated A/B Testing',
287 $(element
).find("#closebutton").on("click",function(){
288 $(element
).dialog("close");
294 crmMailingAB
.directive('numbar',function(){
297 link: function(scope
,element
, attrs
){
298 $(element
).spinner({max
:attrs
.numbar
,min
:0});
303 crmMailingAB
.directive('datepick',function(){
308 link: function(scope
,element
,attrs
){
309 $(element
).datepicker({
310 dateFormat
: "yy-mm-dd",
311 onSelect: function(date
) {
312 $(".ui-datepicker a").removeAttr("href");
314 scope
.scheddate
.date
=date
.toString();
316 console
.log(scope
.scheddate
.date
);
326 crmMailingAB
.directive('submitform',function(){
330 link: function(scope
,element
,attrs
){
331 $(element
).on("click",function() {
333 console
.log("clicked");
336 "name": "Aditya Nambiar",
337 "subject": scope
.mailA
.subj
,
339 "from_email": scope
.mailA
.fromEmail
,
340 "body_text": scope
.mailA
.body
343 console
.log("Truth "+ scope
.whatnext
)
345 if(scope
.whatnext
=="3"){
347 scope
.mailB
.subj
=scope
.mailA
.subj
;
348 scope
.mailB
.body
=scope
.mailA
.body
;
351 else if(scope
.whatnext
=="2"){
352 scope
.mailB
.fromEmail
=scope
.mailA
.fromEmail
;
353 scope
.mailB
.body
=scope
.mailA
.body
;
360 "name": "Aditya Nambiar",
361 "subject": scope
.mailB
.subj
,
363 "from_email": scope
.mailB
.fromEmail
,
364 "body_text": scope
.mailB
.body
374 crmMailingAB
.directive('nextbutton',function(){
378 template
:'<div class="crm-submit-buttons" id="campaignbutton">'+
379 '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view" >' +
380 '<input type="submit" value="Next" id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" nexttab={{tab_val}}>'+
386 crmMailingAB
.directive('cancelbutton',function(){
390 template
:'<div class="crm-submit-buttons" id="campaignbutton">'+
391 '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view" >' +
392 '<input type="submit" value="Cancel" id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" >'+
398 crmMailingAB
.directive('prevbutton',function(){
402 template
:'<div class="crm-submit-buttons" >'+
403 '<div class = "crm-button crm-button-type-upload crm-button_qf_Contact_upload_view" >' +
404 '<input type="submit" value="Previous" id="campaignbutton _qf_Contact_upload_view-top" class="btn btn-primary" prevtab={{tab_val}}>'+
413 })(angular
, CRM
.$, CRM
._
);