983052fe |
1 | /** |
2 | * Created by aditya on 6/12/14. |
3 | */ |
4 | |
5 | |
6 | (function(angular, $, _) { |
7 | |
8 | var partialUrl = function(relPath) { |
9 | return CRM.resourceUrls['civicrm'] + '/partials/abtesting/' + relPath; |
10 | }; |
11 | |
12 | var crmMailingAB = angular.module('crmMailingAB', ['ngRoute', 'ui.utils']); |
13 | |
14 | |
15 | //------------------------------------------------------------------------------------------------------- |
16 | crmMailingAB.config(['$routeProvider', |
17 | function($routeProvider) { |
18 | $routeProvider.when('/mailing', { |
19 | template: '<h1>sdfs</h1>', |
20 | controller: 'mailingListCtrl', |
21 | resolve: { |
22 | mailingList: function($route, crmApi) { |
23 | return crmApi('Mailing', 'get', {}); |
24 | } |
25 | } |
26 | }); |
27 | |
28 | |
29 | $routeProvider.when('/mailing/abtesting', { |
30 | |
31 | templateUrl: partialUrl('helloworld.html'), |
32 | controller: 'TabsDemoCtrl', |
33 | resolve: { |
34 | mailingList: function($route, crmApi) { |
35 | return crmApi('Mailing', 'get', {}); |
36 | } |
37 | } |
38 | |
39 | |
40 | }); |
41 | } |
42 | ]); |
43 | //----------------------------------------- |
44 | // Add a new record by name. |
45 | // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" /> |
46 | |
47 | crmMailingAB.controller('TabsDemoCtrl', function($scope, crmApi, mailingList) { |
48 | |
49 | $scope.adi=0; |
f903f350 |
50 | $scope.campaign_clicked= function(){ |
51 | if($scope.adi >= 0 ){ |
52 | $scope.adi =0; |
53 | } |
54 | }; |
55 | $scope.compose_clicked=function(){ |
56 | if($scope.adi >=1){ |
57 | $scope.adi =1; |
58 | } |
59 | }; |
60 | $scope.rec_clicked=function(){ |
61 | if($scope.adi >=2){ |
62 | $scope.adi =2; |
63 | } |
64 | }; |
65 | $scope.preview_clicked=function(){ |
66 | if($scope.adi>=3){ |
67 | $scope.adi=3; |
68 | } |
69 | }; |
5d8414d9 |
70 | $scope.templates = |
71 | [ { name: 'subjectlines', url: partialUrl('subject_lines.html')}, |
72 | { name: 'fromname', url: partialUrl('from_name.html')}, |
73 | {name:'2emails',url: partialUrl('two_emails.html')} ]; |
74 | $scope.template = $scope.templates[0]; |
983052fe |
75 | |
8d8eb785 |
76 | $scope.slide_value = 0; |
77 | |
08346fd9 |
78 | $scope.$watch("automated", function() { |
983052fe |
79 | |
08346fd9 |
80 | console.log("Smsdd"); |
81 | |
82 | }); |
83 | |
84 | $scope.setifyes= function(val){ |
85 | if(val ==1) { |
86 | $scope.ifyes = true; |
87 | } |
88 | else |
89 | $scope.ifyes=false; |
90 | }; |
91 | |
92 | $scope.closebox="open"; |
983052fe |
93 | |
94 | }); |
95 | |
96 | crmMailingAB.directive('nexttab', function() { |
97 | return { |
98 | // Restrict it to be an attribute in this case |
99 | restrict: 'A', |
100 | // responsible for registering DOM listeners as well as updating the DOM |
101 | link: function(scope, element, attrs) { |
102 | |
103 | $(element).parent().parent().parent().tabs(scope.$eval(attrs.nexttab)); |
82aa3267 |
104 | var myarr = new Array(1,2,3) |
105 | $(element).parent().parent().parent().tabs({disabled:myarr}); |
983052fe |
106 | //$(element).parent().parent().parent().tabs({"enable":1}); |
107 | |
108 | $(element).on("click",function() { |
109 | scope.adi=scope.adi +1; |
82aa3267 |
110 | var myArray1 = new Array( ); |
111 | for ( var i = scope.adi+1; i < 4; i++ ) { |
112 | myArray1.push(i); |
113 | console.log( "try " + i ); |
114 | } |
115 | $(element).parent().parent().parent().tabs( "option", "disabled", myArray1 ); |
983052fe |
116 | $(element).parent().parent().parent().tabs({active:scope.adi}); |
117 | console.log("adiroxxx"); |
118 | }); |
119 | } |
120 | }; |
121 | }); |
122 | |
8d8eb785 |
123 | crmMailingAB.directive('groupselect',function(){ |
124 | return { |
125 | |
126 | restrict : 'AE', |
127 | |
128 | link: function(scope,element, attrs){ |
129 | |
130 | $(document).ready(function() { $(element).select2({width:"400px",placeholder: "Select the groups you wish to include"}); |
131 | |
132 | }); |
133 | |
134 | } |
135 | }; |
136 | |
137 | }); |
138 | |
139 | crmMailingAB.directive('sliderbar',function(){ |
140 | return{ |
141 | |
142 | restrict: 'AE', |
143 | |
144 | link: function(scope,element, attrs){ |
145 | |
146 | $(element).slider(); |
147 | $(element).slider({ |
148 | slide: function( event, ui ) { |
149 | scope.slide_value = ui.value; |
150 | scope.$apply(); |
151 | |
152 | } |
153 | }); |
08346fd9 |
154 | |
8d8eb785 |
155 | } |
156 | |
157 | }; |
158 | |
159 | }); |
160 | |
08346fd9 |
161 | |
162 | |
163 | crmMailingAB.directive('tpmax',function(){ |
8d8eb785 |
164 | return { |
165 | |
08346fd9 |
166 | restrict: 'E', |
8d8eb785 |
167 | |
168 | |
169 | |
170 | link: function(scope,element,attr){ |
171 | |
172 | |
173 | |
08346fd9 |
174 | scope.$watch('automated', function(val) { |
175 | if(val=="yes") { |
176 | console.log("yo"); |
177 | |
178 | $(element).dialog({ |
179 | title: 'Automated A/B Testing', |
180 | width: 800, |
181 | height: 600, |
182 | closed: false, |
183 | cache: false, |
184 | modal: true |
185 | |
186 | }); |
187 | |
188 | |
189 | |
190 | |
191 | |
192 | } |
8d8eb785 |
193 | |
194 | }); |
195 | |
08346fd9 |
196 | $(element).find("#closebutton").on("click",function(){ |
197 | console.log("you can do it"); |
198 | $(element).dialog("close"); |
199 | |
200 | }); |
201 | |
202 | |
203 | |
204 | |
8d8eb785 |
205 | |
206 | } |
207 | |
208 | }; |
209 | |
08346fd9 |
210 | |
211 | |
8d8eb785 |
212 | }); |
213 | |
08346fd9 |
214 | crmMailingAB.directive('numbar',function(){ |
215 | return{ |
8d8eb785 |
216 | |
08346fd9 |
217 | restrict: 'AE', |
8d8eb785 |
218 | |
08346fd9 |
219 | link: function(scope,element, attrs){ |
8d8eb785 |
220 | |
08346fd9 |
221 | $(element).spinner({max:attrs.numbar,min:0}); |
8d8eb785 |
222 | |
223 | |
8d8eb785 |
224 | |
08346fd9 |
225 | } |
226 | |
227 | }; |
8d8eb785 |
228 | |
229 | }); |
230 | |
231 | |
232 | |
233 | |
234 | |
983052fe |
235 | |
236 | |
237 | |
238 | |
239 | |
240 | |
241 | |
242 | })(angular, CRM.$, CRM._); |