Groups API used
[civicrm-core.git] / js / angular-crmMailingAB.js
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 metaData: function($route, crmApi) {
35 return crmApi('Group', 'get', {});
36 },
37 mailingList: function($route, crmApi) {
38 return crmApi('Mailing', 'get', {});
39 }
40
41 }
42
43
44 });
45
46
47 }
48 ]);
49 //-----------------------------------------
50 // Add a new record by name.
51 // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
52
53 crmMailingAB.controller('TabsDemoCtrl', function($scope, crmApi, metaData, mailingList) {
54
55 $scope.groups = metaData.values;
56 $scope.mailings = mailingList.values;
57 $scope.adi=0;
58 $scope.campaign_clicked= function(){
59 if($scope.adi >= 0 ){
60 $scope.adi =0;
61 }
62 };
63 $scope.compose_clicked=function(){
64 if($scope.adi >=1){
65 $scope.adi =1;
66 }
67 };
68 $scope.rec_clicked=function(){
69 if($scope.adi >=2){
70 $scope.adi =2;
71 }
72 };
73 $scope.preview_clicked=function(){
74 if($scope.adi>=3){
75 $scope.adi=3;
76 }
77 };
78 $scope.templates =
79 [ { name: 'Subject Lines', url: partialUrl('subject_lines.html')},
80 { name: 'From Name', url: partialUrl('from_name.html')},
81 {name:'Two different Emails',url: partialUrl('two_emails.html')} ];
82 $scope.template = $scope.templates[0];
83
84 $scope.slide_value = 0;
85
86 $scope.$watch("automated", function() {
87
88 console.log("Smsdd");
89
90 });
91
92 $scope.setifyes= function(val){
93 if(val ==1) {
94 $scope.ifyes = true;
95 }
96 else
97 $scope.ifyes=false;
98 };
99
100 $scope.send_date ="10/4/2004";
101
102
103
104 });
105
106 crmMailingAB.directive('nexttab', function() {
107 return {
108 // Restrict it to be an attribute in this case
109 restrict: 'A',
110 // responsible for registering DOM listeners as well as updating the DOM
111 link: function(scope, element, attrs) {
112
113 $(element).parent().parent().parent().tabs(scope.$eval(attrs.nexttab));
114 var myarr = new Array(1,2,3)
115 $(element).parent().parent().parent().tabs({disabled:myarr});
116 //$(element).parent().parent().parent().tabs({"enable":1});
117
118 $(element).on("click",function() {
119 scope.adi=scope.adi +1;
120 var myArray1 = new Array( );
121 for ( var i = scope.adi+1; i < 4; i++ ) {
122 myArray1.push(i);
123 console.log( "try " + i );
124 }
125 $(element).parent().parent().parent().tabs( "option", "disabled", myArray1 );
126 $(element).parent().parent().parent().tabs({active:scope.adi});
127 console.log("adiroxxx");
128 });
129 }
130 };
131 });
132
133 crmMailingAB.directive('groupselect',function(){
134 return {
135
136 restrict : 'AE',
137
138 link: function(scope,element, attrs){
139
140 $(element).select2({width:"400px",placeholder: "Select the groups you wish to include"});
141 $(element).select2("data",groups)
142
143
144
145
146 }
147 };
148
149 });
150
151 crmMailingAB.directive('sliderbar',function(){
152 return{
153
154 restrict: 'AE',
155
156 link: function(scope,element, attrs){
157
158 $(element).slider({min:1});
159 $(element).slider({
160 slide: function( event, ui ) {
161 scope.slide_value = ui.value;
162 scope.$apply();
163
164 }
165 });
166
167 }
168
169 };
170
171 });
172
173
174
175 crmMailingAB.directive('tpmax',function(){
176 return {
177
178 restrict: 'E',
179
180
181
182 link: function(scope,element,attr){
183
184
185
186 scope.$watch('automated', function(val) {
187 if(val=="Yes") {
188 console.log("yo");
189
190 $(element).dialog({
191 title: 'Automated A/B Testing',
192 width: 800,
193 height: 600,
194 closed: false,
195 cache: false,
196 modal: true
197
198 });
199
200
201
202
203
204 }
205
206 });
207
208 $(element).find("#closebutton").on("click",function(){
209 console.log("you can do it");
210 $(element).dialog("close");
211
212 });
213
214
215
216
217
218 }
219
220 };
221
222
223
224 });
225
226 crmMailingAB.directive('numbar',function(){
227 return{
228
229 restrict: 'AE',
230
231 link: function(scope,element, attrs){
232
233 $(element).spinner({max:attrs.numbar,min:0});
234
235
236
237 }
238
239 };
240
241 });
242
243 crmMailingAB.directive('datepick',function(){
244
245 return {
246 scope :{
247 foo : '=send_date'
248 },
249
250
251 restrict: 'AE',
252
253
254 link: function(scope,element,attrs){
255
256 $(element).datepicker({
257 onSelect: function(date) {
258 $(".ui-datepicker a").removeAttr("href");
259 scope.foo =date;
260 console.log(date);
261 }
262 });
263 }
264 };
265
266
267 });
268
269
270
271
272
273
274
275
276
277
278
279
280
281 })(angular, CRM.$, CRM._);