Commit | Line | Data |
---|---|---|
ab953923 SR |
1 | (function(angular, $, _) { |
2 | //partials for the html pages | |
3 | var partialUrl = function(relPath) { | |
4 | return CRM.resourceUrls['civicrm'] + '/partials/crmMailing/' + relPath; | |
5 | }; | |
6 | ||
7 | var crmMailing = angular.module('crmMailing', ['ngRoute', 'ui.utils','ngSanitize']); | |
8 | var chck = []; //to fill the group variable $scope.incGroup | |
9 | var chck2= []; // to get id and text in the required format | |
10 | var mltokens = []; | |
11 | var global = 0; | |
12 | //------------------------------------------------------------------------------------------------------- | |
13 | crmMailing.config(['$routeProvider', | |
14 | function($routeProvider) { | |
15 | $routeProvider.when('/mailing', { | |
16 | templateUrl: partialUrl('mailingList.html'), | |
17 | controller: 'mailingListCtrl', | |
18 | resolve: { | |
19 | mailingList: function($route, crmApi) { | |
20 | return crmApi('Mailing', 'get', {}); | |
21 | } | |
22 | ||
23 | } | |
24 | }); //This route is used for generating the list of mails created. | |
25 | ||
26 | ||
27 | ||
28 | $routeProvider.when('/mailing/:id', { | |
29 | templateUrl: partialUrl('main.html'), | |
30 | controller: 'mailingCtrl', | |
31 | resolve: { | |
32 | selectedMail: function($route, crmApi) { | |
33 | if ( $route.current.params.id !== 'new') { | |
34 | return crmApi('Mailing', 'getsingle', {id: $route.current.params.id}); | |
35 | } | |
36 | else { | |
37 | //created_id has been set to my id. Does not save without created_id. Needs to made generic based on the user | |
38 | return {visibility: "Public Pages", url_tracking:"1",dedupe_email:"1", forward_replies:"0", auto_responder:"0", open_tracking:"1" | |
39 | }; | |
40 | } | |
41 | } | |
42 | } | |
43 | }); //This route is used for creating new mails and editing the current mails | |
44 | } | |
45 | ]); | |
46 | //----------------------------------------- | |
47 | ||
48 | ||
49 | //This controller is used in creating new mail and editing current mails | |
50 | crmMailing.controller('mailingCtrl', function($scope, crmApi, selectedMail, $location,$route, $sce, $window) { | |
51 | ||
52 | //setting variables to the values we have got to the api | |
53 | $scope.submitted = false; | |
54 | $scope.partialUrl = partialUrl; | |
55 | $scope.campaignList = CRM.crmMailing.campNames; | |
56 | $scope.mailList = CRM.crmMailing.civiMails; | |
57 | $scope.mailNameList = _.pluck(CRM.crmCaseType.civiMails, 'name'); | |
58 | $scope.groupNamesList = CRM.crmMailing.groupNames; | |
59 | $scope.headerfooter = CRM.crmMailing.headerfooterList; | |
60 | $scope.fromAddress = CRM.crmMailing.fromAddress; | |
61 | $scope.tmpList = CRM.crmMailing.mesTemplate; | |
62 | $scope.mailingGrp = CRM.crmMailing.mailGrp; | |
63 | $scope.user_id = CRM.crmMailing.contactid; | |
64 | $scope.currentMailing = selectedMail; | |
65 | $scope.currentMailing.created_id = $scope.user_id; | |
66 | mltokens = CRM.crmMailing.mailTokens; | |
67 | $scope.pre = false; | |
68 | $scope.noOfRecipients = 0; | |
69 | $scope.testMailing = {}; | |
70 | $scope.testMailing.name = ""; | |
71 | $scope.testMailing.group = ""; | |
72 | window.ct = $scope.currentMailing; | |
73 | $scope.previewbody_html = ""; | |
74 | $scope.previewbody_text = ""; | |
75 | $scope.preview_subject = ""; | |
76 | $scope.param = {}; | |
77 | $scope.token = ""; | |
78 | chck = []; | |
79 | chck2 = []; | |
80 | $scope.from = {}; | |
81 | $scope.from.name = ""; | |
82 | $scope.from.email = ""; | |
83 | $scope.from.total = ""; | |
84 | $scope.reply ={}; | |
85 | $scope.reply.email = ""; | |
86 | $scope.replyaddress = []; | |
87 | for(var a in $scope.fromAddress){ | |
88 | var b = {}; | |
89 | var splt = $scope.fromAddress[a].label.split(" "); | |
90 | splt = splt[1].substring(1,(splt[1].length-1)); | |
91 | b.email = splt; | |
92 | $scope.replyaddress.push(b); | |
93 | } | |
94 | ||
95 | if ($scope.currentMailing.from_name != null) { | |
96 | $scope.from.name = $scope.currentMailing.from_name; | |
97 | $scope.from.email = $scope.currentMailing.from_email; | |
98 | $scope.from.total = $scope.from.name + " <" + $scope.from.email + ">"; | |
99 | $scope.reply.email = $scope.currentMailing.replyto_email; | |
100 | } | |
101 | ||
102 | $scope.mailid = []; | |
103 | ||
104 | for (var a in $scope.mailingGrp) { | |
105 | if ($scope.mailingGrp[a].mailing_id==$scope.currentMailing.id) { | |
106 | var b = $scope.mailingGrp[a].entity_id + " " + $scope.mailingGrp[a].entity_table +" " + $scope.mailingGrp[a].group_type; | |
107 | var c = $scope.mailingGrp[a].id; | |
108 | chck.push(b); | |
109 | $scope.mailid.push(c); | |
110 | } | |
111 | } | |
112 | ||
113 | if ($scope.currentMailing.msg_template_id!=null) { | |
114 | $scope.tst=$scope.currentMailing.msg_template_id; | |
115 | } | |
116 | //Making the object for data | |
117 | ||
118 | for (var a in chck) { | |
119 | var b ={} | |
120 | b.id = chck[a]; | |
121 | var splt = chck[a].split(" "); | |
122 | ||
123 | if(splt[1] == "civicrm_group"){ | |
124 | for(var c in $scope.groupNamesList){ | |
125 | if($scope.groupNamesList[c].id==splt[0]){ | |
126 | b.text = $scope.groupNamesList[c].title; | |
127 | } | |
128 | } | |
129 | } | |
130 | if(splt[1] == "civicrm_mailing"){ | |
131 | for(var c in $scope.mailList){ | |
132 | if($scope.mailList[c].id==splt[0]){ | |
133 | b.text = $scope.mailList[c].name; | |
134 | } | |
135 | } | |
136 | } | |
137 | chck2.push(b); | |
138 | } | |
139 | $scope.incGroup = chck2; | |
140 | ||
141 | ||
142 | $scope.mailingForm = function() { | |
143 | if ($scope.mailing_form.$valid) { | |
144 | // Submit as normal | |
145 | } | |
146 | else { | |
147 | $scope.mailing_form.submitted = true; | |
148 | } | |
149 | }; | |
150 | ||
151 | $scope.back = function (){ | |
152 | $window.location.href = "#/mailing" ; | |
153 | $route.reload(); | |
154 | }; | |
155 | ||
156 | $scope.tmp = function (tst){ | |
157 | $scope.currentMailing.msg_template_id=tst; | |
158 | if($scope.currentMailing.msg_template_id == null){ | |
159 | $scope.currentMailing.body_html=""; | |
160 | $scope.currentMailing.subject=""; | |
161 | } | |
162 | else{ | |
163 | for(var a in $scope.tmpList){ | |
164 | ||
165 | if($scope.tmpList[a].id==$scope.currentMailing.msg_template_id){ | |
166 | $scope.currentMailing.body_html=$scope.tmpList[a].msg_html; | |
167 | $scope.currentMailing.subject=$scope.tmpList[a].msg_subject; | |
168 | } | |
169 | } | |
170 | } | |
171 | }; | |
172 | //initializing variables we will use for checkboxes, or for purpose of ng-show | |
173 | $scope.acttab=0; | |
174 | $scope.composeS="1"; | |
175 | if($scope.currentMailing.forward_replies==0 && $scope.currentMailing.auto_responder==0){ | |
176 | $scope.trackreplies="0"; | |
177 | } | |
178 | else { | |
179 | $scope.trackreplies="1"; | |
180 | } | |
181 | if($scope.currentMailing.scheduled_date == null || $scope.currentMailing.scheduled_date == "") | |
182 | $scope.now="1"; | |
183 | else | |
184 | $scope.now="0"; | |
185 | ||
186 | $scope.reply = function(){ | |
187 | if($scope.trackreplies==0){ | |
188 | $scope.trackreplies=1; | |
189 | } | |
190 | else{ | |
191 | $scope.trackreplies=0; | |
192 | $scope.currentMailing.forward_replies=0; | |
193 | $scope.currentMailing.auto_responder=0; | |
194 | } | |
195 | } | |
196 | ||
197 | ||
198 | $scope.recclicked = function(){ | |
199 | //if($scope.acttab >=0){ | |
200 | $scope.acttab =0; | |
201 | //} | |
202 | }; | |
203 | ||
204 | $scope.conclicked = function(){ | |
205 | // if($scope.acttab >=1){ | |
206 | $scope.acttab =1; | |
207 | //} | |
208 | }; | |
209 | ||
210 | $scope.schedclicked = function(){ | |
211 | //if($scope.acttab >=2){ | |
212 | $scope.acttab =2; | |
213 | //} | |
214 | }; | |
215 | ||
216 | //to split the value of selectedMail.scheduled_date into the date and time separately | |
217 | $scope.scheddate={}; | |
218 | $scope.scheddate.date = ""; | |
219 | $scope.scheddate.time = ""; | |
220 | $scope.ans=""; | |
221 | ||
222 | $scope.checkNow = function(){ | |
223 | if($scope.now == 1 ){ | |
224 | $scope.now = 0; | |
225 | } | |
226 | else{ | |
227 | $scope.now = 1; | |
228 | $scope.currentMailing.scheduled_date = null; | |
229 | $scope.currentMailing.scheduled_id = null; | |
230 | $scope.scheddate.date = ""; | |
231 | $scope.scheddate.time = ""; | |
232 | } | |
233 | } | |
234 | ||
235 | // To split the scheduled_date into date and time. The date format is not accepting | |
236 | if(selectedMail.scheduled_date != null){ | |
237 | $scope.ans= selectedMail.scheduled_date.split(" "); | |
238 | $scope.scheddate.date=$scope.ans[0]; | |
239 | $scope.scheddate.time=$scope.ans[1]; | |
240 | } | |
241 | ||
242 | ||
243 | //changing the screen from compose on screen to upload content | |
244 | $scope.upldChange= function(composeS){ | |
245 | if(composeS=="1"){ | |
246 | return true; | |
247 | } | |
248 | else | |
249 | return false; | |
250 | }; | |
251 | //filter so we only get headers from mailing component | |
252 | $scope.isHeader= function(hf){ | |
253 | return hf.component_type == "Header"; | |
254 | }; | |
255 | //filter so we only get footers from mailing component | |
256 | $scope.isFooter= function(f){ | |
257 | return f.component_type == "Footer"; | |
258 | }; | |
259 | //filter so we only get auto-Responders from mailing component | |
260 | $scope.isAuto= function(au){ | |
261 | return au.component_type == "Reply"; | |
262 | }; | |
263 | //filter so we only get userDriven message templates | |
264 | $scope.isUserDriven= function(mstemp){ | |
265 | return (parseInt(mstemp.id)>58); | |
266 | }; | |
267 | //used for ng-show when trackreplies is selected. Only then we show forward replies and auto-responders options | |
268 | $scope.trackr= function(trackreplies){ | |
269 | if(trackreplies=="1"){ | |
270 | return true; | |
271 | } | |
272 | else | |
273 | return false; | |
274 | } | |
275 | ||
276 | $scope.isGrp= function(grp){ | |
277 | return grp.visibility == "Public Pages"; | |
278 | }; | |
279 | ||
280 | $scope.isCompMail= function(ml){ | |
281 | return ml.is_completed == 1; | |
282 | }; | |
283 | ||
284 | ||
285 | $scope.preview_update = function(){ | |
286 | var resulta =crmApi('Mailing','preview',{id:$scope.currentMailing.id}); | |
287 | resulta.success(function(data) { | |
288 | if (data.is_error == 0) { | |
289 | $scope.previewbody_html=data.values.html; | |
290 | $scope.previewbody_text=data.values.text; | |
291 | $scope.preview_subject=data.values.subject; | |
292 | $scope.pre = true; | |
293 | $scope.$digest(); | |
294 | $scope.$apply(); | |
295 | } | |
296 | }); | |
297 | }; | |
298 | ||
299 | $scope.isBody_text = function(){ | |
300 | if($scope.currentMailing.body_text == null || $scope.currentMailing.body_text == "" ) | |
301 | return false; | |
302 | else | |
303 | return true; | |
304 | }; | |
305 | ||
306 | $scope.deliberatelyTrustDangerousSnippet = function() { | |
307 | return $sce.trustAsHtml($scope.previewbody_html); | |
308 | }; | |
309 | ||
310 | $scope.deliberatelyTrustDangerousSnippet2 = function() { | |
311 | return $sce.trustAsHtml($scope.previewbody_text); | |
312 | }; | |
313 | ||
314 | $scope.deliberatelyTrustDangerousSnippet3 = function() { | |
315 | return $sce.trustAsHtml($scope.preview_subject); | |
316 | }; | |
317 | ||
318 | $scope.mailing_recipients= function() { | |
319 | var resulta =crmApi('MailingRecipients', 'get', {mailing_id: $scope.currentMailing.id, options: {limit:1000}}); | |
320 | resulta.success(function(data) { | |
321 | if (data.is_error == 0) { | |
322 | $scope.noOfRecipients=data.count; | |
323 | $scope.$digest(); | |
324 | $scope.$apply(); | |
325 | } | |
326 | }); | |
327 | } | |
328 | ||
329 | $scope.mailingGroup = function() { | |
330 | var resulta =crmApi('MailingGroup', 'get', {mailing_id: $scope.currentMailing.id, options: {limit:1000}}) | |
331 | resulta.success(function(data) { | |
332 | $scope.mailid = []; | |
333 | chck = []; | |
334 | angular.forEach(data.values, function(value,key){ | |
335 | var b = value.entity_id + " " + value.entity_table +" " + value.group_type; | |
336 | var c = value.id; | |
337 | chck.push(b); | |
338 | $scope.mailid.push(c); | |
339 | }); | |
340 | for(var a in chck) | |
341 | { var b ={} | |
342 | b.id = chck[a]; | |
343 | var splt = chck[a].split(" "); | |
344 | ||
345 | if(splt[1] == "civicrm_group"){ | |
346 | for(var c in $scope.groupNamesList){ | |
347 | if($scope.groupNamesList[c].id==splt[0]){ | |
348 | b.text = $scope.groupNamesList[c].title; | |
349 | } | |
350 | } | |
351 | } | |
352 | if(splt[1] == "civicrm_mailing"){ | |
353 | for(var c in $scope.mailList){ | |
354 | if($scope.mailList[c].id==splt[0]){ | |
355 | b.text = $scope.mailList[c].name; | |
356 | } | |
357 | } | |
358 | } | |
359 | chck2.push(b); | |
360 | } | |
361 | ||
362 | $scope.incGroup = chck2; | |
363 | $scope.mailing_recipients(); | |
364 | }); | |
365 | } | |
366 | ||
367 | $scope.save_repeat = function(){ | |
368 | if ($scope.from.total != "") { | |
369 | var splt = $scope.from.total.split(" "); | |
370 | var splta = splt[1].substring(1,(splt[1].length-1)); | |
371 | var spltb = splt[0]; | |
372 | $scope.currentMailing.from_email = splta; | |
373 | $scope.currentMailing.from_name = spltb; | |
374 | } | |
375 | ||
376 | if ($scope.currentMailing.scheduled_date == $scope.currentMailing.approval_date | |
377 | && $scope.currentMailing.scheduled_date != null) {; | |
378 | } | |
379 | else { | |
380 | $scope.currentMailing.scheduled_date= $scope.scheddate.date + " " + $scope.scheddate.time ; | |
381 | if ($scope.currentMailing.scheduled_date!=" ") { | |
382 | $scope.currentMailing.scheduled_id= $scope.user_id; | |
383 | } | |
384 | else { | |
385 | $scope.currentMailing.scheduled_date= null; | |
386 | } | |
387 | } | |
388 | ||
389 | ||
390 | } | |
391 | ||
392 | $scope.save_next = function() { | |
393 | $scope.save_repeat(); | |
394 | $scope.incGrp=[]; | |
395 | $scope.excGrp=[]; | |
396 | $scope.incMail=[]; | |
397 | $scope.excMail=[]; | |
398 | $scope.answer=""; | |
399 | for(req_id in chck){ | |
400 | $scope.answer = chck[req_id].split(" "); | |
401 | ||
402 | if($scope.answer[1] == "civicrm_mailing" && $scope.answer[2]=="include"){ | |
403 | $scope.incMail.push($scope.answer[0]); | |
404 | } | |
405 | else if($scope.answer[1] == "civicrm_mailing" && $scope.answer[2]=="exclude"){ | |
406 | $scope.excMail.push($scope.answer[0]); | |
407 | } | |
408 | if($scope.answer[1] == "civicrm_group" && $scope.answer[2]=="include"){ | |
409 | $scope.incGrp.push($scope.answer[0]); | |
410 | } | |
411 | else if($scope.answer[1] == "civicrm_group" && $scope.answer[2]=="exclude"){ | |
412 | $scope.excGrp.push($scope.answer[0]); | |
413 | } | |
414 | } | |
415 | ||
416 | if ($scope.mailid != null) { | |
417 | for (var a in $scope.mailid) { | |
418 | var result_2= crmApi('MailingGroup', 'delete', { | |
419 | id: $scope.mailid[a] | |
420 | }); | |
421 | } | |
422 | } | |
423 | ||
424 | var result = crmApi('Mailing', 'create', { | |
425 | id: $scope.currentMailing.id, | |
426 | name: $scope.currentMailing.name, | |
427 | visibility: $scope.currentMailing.visibility, | |
428 | created_id: $scope.currentMailing.created_id, | |
429 | subject: $scope.currentMailing.subject, | |
430 | msg_template_id: $scope.currentMailing.msg_template_id==null ? "" : $scope.currentMailing.msg_template_id, | |
431 | open_tracking: $scope.currentMailing.open_tracking, | |
432 | url_tracking: $scope.currentMailing.url_tracking, | |
433 | forward_replies: $scope.currentMailing.forward_replies, | |
434 | auto_responder: $scope.currentMailing.auto_responder, | |
435 | from_name: $scope.currentMailing.from_name, | |
436 | from_email: $scope.currentMailing.from_email, | |
437 | replyto_email: $scope.currentMailing.replyto_email, | |
438 | unsubscribe_id: $scope.currentMailing.unsubscribe_id, | |
439 | resubscribe_id: $scope.currentMailing.resubscribe_id, | |
440 | body_html: $scope.currentMailing.body_html, | |
441 | body_text: $scope.currentMailing.body_text, | |
442 | scheduled_date: $scope.currentMailing.scheduled_date==null ? "" : $scope.currentMailing.scheduled_date, | |
443 | scheduled_id: $scope.currentMailing.scheduled_id==null ? "" : $scope.currentMailing.scheduled_id, | |
444 | campaign_id: $scope.currentMailing.campaign_id==null ? "" : $scope.currentMailing.campaign_id, | |
445 | header_id: $scope.currentMailing.header_id, | |
446 | footer_id: $scope.currentMailing.footer_id, | |
447 | groups: {include: $scope.incGrp, | |
448 | exclude: $scope.excGrp | |
449 | }, | |
450 | mailings: {include: $scope.incMail, | |
451 | exclude: $scope.excMail | |
452 | }, | |
453 | is_completed: $scope.currentMailing.is_completed, | |
454 | approver_id: $scope.currentMailing.approver_id, | |
455 | approval_status_id: $scope.currentMailing.approval_status_id, | |
456 | approval_date: $scope.currentMailing.approval_date, | |
457 | dedupe_email: $scope.currentMailing.dedupe_email | |
458 | }, | |
459 | true); | |
460 | //var result = crmApi('Mailing', 'create', $scope.currentMailing, true); | |
461 | result.success(function(data) { | |
462 | if (data.is_error == 0) { | |
463 | $scope.currentMailing.id = data.id; | |
464 | $scope.mailingGroup(); | |
465 | } | |
466 | }); | |
467 | }; | |
468 | ||
469 | $scope.save_next_page2 = function() { | |
470 | $scope.save_repeat(); | |
471 | var result = crmApi('Mailing', 'create', { | |
472 | id: $scope.currentMailing.id, | |
473 | name: $scope.currentMailing.name, | |
474 | visibility: $scope.currentMailing.visibility, | |
475 | created_id: $scope.currentMailing.created_id, | |
476 | subject: $scope.currentMailing.subject, | |
477 | msg_template_id: $scope.currentMailing.msg_template_id==null ? "" : $scope.currentMailing.msg_template_id, | |
478 | open_tracking: $scope.currentMailing.open_tracking, | |
479 | url_tracking: $scope.currentMailing.url_tracking, | |
480 | forward_replies: $scope.currentMailing.forward_replies, | |
481 | auto_responder: $scope.currentMailing.auto_responder, | |
482 | from_name: $scope.currentMailing.from_name, | |
483 | from_email: $scope.currentMailing.from_email, | |
484 | replyto_email: $scope.currentMailing.replyto_email, | |
485 | unsubscribe_id: $scope.currentMailing.unsubscribe_id, | |
486 | resubscribe_id: $scope.currentMailing.resubscribe_id, | |
487 | body_html: $scope.currentMailing.body_html, | |
488 | body_text: $scope.currentMailing.body_text, | |
489 | scheduled_date: $scope.currentMailing.scheduled_date==null ? "" : $scope.currentMailing.scheduled_date, | |
490 | scheduled_id: $scope.currentMailing.scheduled_id==null ? "" : $scope.currentMailing.scheduled_id, | |
491 | campaign_id: $scope.currentMailing.campaign_id==null ? "" : $scope.currentMailing.campaign_id, | |
492 | header_id: $scope.currentMailing.header_id, | |
493 | footer_id: $scope.currentMailing.footer_id, | |
494 | is_completed: $scope.currentMailing.is_completed, | |
495 | approver_id: $scope.currentMailing.approver_id, | |
496 | approval_status_id: $scope.currentMailing.approval_status_id, | |
497 | approval_date: $scope.currentMailing.approval_date, | |
498 | dedupe_email: $scope.currentMailing.dedupe_email | |
499 | }, | |
500 | true); | |
501 | //var result = crmApi('Mailing', 'create', $scope.currentMailing, true); | |
502 | result.success(function(data) { | |
503 | if (data.is_error == 0) { | |
504 | $scope.currentMailing.id = data.id; | |
505 | } | |
506 | }); | |
507 | }; | |
508 | ||
509 | ||
510 | $scope.save = function() { | |
511 | $scope.save_next_page2(); | |
512 | $scope.back(); | |
513 | }; | |
514 | ||
515 | $scope.save_page1 = function() { | |
516 | $scope.save_next_page1(); | |
517 | $scope.back(); | |
518 | }; | |
519 | ||
520 | $scope.save_next_page1 = function() { | |
521 | if($scope.currentMailing.id == null){ | |
522 | $scope.currentMailing.subject = $scope.currentMailing.name; | |
523 | $scope.save_next(); | |
524 | } | |
525 | else { | |
526 | $scope.save_next(); | |
527 | } | |
528 | ||
529 | }; | |
530 | ||
531 | $scope.submitButton= function(){ | |
532 | $scope.currentMailing.approval_status_id = "1"; | |
533 | $scope.currentMailing.approver_id = $scope.user_id; | |
534 | var currentdate = new Date(); | |
535 | var yyyy = currentdate.getFullYear(); | |
536 | var mm = currentdate.getMonth() + 1; | |
537 | mm = mm<10 ? '0' + mm : mm; | |
538 | var dd = currentdate.getDate(); | |
539 | dd = dd<10 ? '0' + dd : dd; | |
540 | var hh = currentdate.getHours(); | |
541 | hh = hh<10 ? '0' + hh : hh; | |
542 | var min = currentdate.getMinutes(); | |
543 | min = min<10 ? '0' + min : min; | |
544 | var sec = currentdate.getSeconds(); | |
545 | sec = sec<10 ? '0' + sec : sec; | |
546 | $scope.currentMailing.approval_date = yyyy + "/"+ mm | |
547 | + "/" + dd + " " | |
548 | + hh + ":" | |
549 | + min + ":" + sec; | |
550 | if($scope.now == 1){ | |
551 | $scope.currentMailing.scheduled_date = $scope.currentMailing.approval_date; | |
552 | } | |
553 | $scope.save(); | |
554 | }; | |
555 | ||
556 | $scope.$watch('pre',function(){ | |
557 | if($scope.pre==true){ | |
558 | $('#prevmail').dialog({ | |
559 | title: 'Preview Mailing', | |
560 | width: 1080, | |
561 | height: 800, | |
562 | closed: false, | |
563 | cache: false, | |
564 | modal: true, | |
565 | close :function(){ | |
566 | $scope.pre = false; $scope.$apply(); | |
567 | } | |
568 | }); | |
569 | } | |
570 | },true); | |
571 | ||
572 | $scope.sendTest = function(){ | |
573 | var resulta =crmApi('Mailing','send_test',{test_email:$scope.testMailing.name, test_group:$scope.testMailing.group, | |
574 | mailing_id:$scope.currentMailing.id}); | |
575 | }; | |
576 | }); | |
577 | ||
578 | ||
579 | // Directive to go to the next tab | |
580 | /* crmMailing.directive('nexttab', function() { | |
581 | return { | |
582 | restrict: 'A', | |
583 | link: function(scope, element, attrs) { | |
584 | $(element).parent().parent().parent().parent().parent().tabs(); | |
585 | console.log($(element).parent().parent().parent().parent().parent()); | |
586 | // var myarr = new Array(1,2); | |
587 | //$(element).parent().parent().parent().parent().parent().tabs({disabled:myarr}); | |
588 | $(element).on("click",function() { | |
589 | scope.acttab=scope.acttab +1; | |
590 | /* var myArray1 = new Array( ); | |
591 | for ( var i = 0; i < 3; i++ ) { | |
592 | if(scope.acttab!=i) | |
593 | myArray1.push(i); | |
594 | }*/ | |
595 | //$(element).parent().parent().parent().parent().parent().tabs( "option", "disabled", myArray1 ); | |
596 | /* $(element).parent().parent().parent().parent().parent().tabs({active:scope.acttab}); | |
597 | console.log("sid"); | |
598 | }); | |
599 | } | |
600 | }; | |
601 | });*/ | |
602 | ||
603 | // Directive to go to the previous tab | |
604 | /*crmMailing.directive('prevtab', function() { | |
605 | return { | |
606 | restrict: 'A', | |
607 | link: function(scope, element, attrs) { | |
608 | $(element).parent().parent().parent().parent().parent().tabs(); | |
609 | //var myarr = new Array(1,2); | |
610 | //$(element).parent().parent().parent().parent().parent().tabs({disabled:myarr}); | |
611 | $(element).on("click",function() { | |
612 | scope.acttab=scope.acttab -1; | |
613 | /* var myArray1 = new Array( ); | |
614 | for ( var i = 0; i < 3; i++ ) { | |
615 | if(scope.acttab!=i) | |
616 | myArray1.push(i); | |
617 | }*/ | |
618 | // $(element).parent().parent().parent().parent().parent().tabs( "option", "disabled", myArray1 ); | |
619 | /* $(element).parent().parent().parent().parent().parent().tabs({active:scope.acttab}); | |
620 | console.log("sid"); | |
621 | }); | |
622 | } | |
623 | }; | |
624 | });*/ | |
625 | ||
626 | ||
627 | /*crmMailing.directive('prevtab', function () { | |
628 | return { | |
629 | // Restrict it to be an attribute in this case | |
630 | restrict: 'A', | |
631 | priority: 500, | |
632 | // responsible for registering DOM listeners as well as updating the DOM | |
633 | link: function (scope, element, attrs) { | |
634 | $(element).on("click", function () { | |
635 | var temp = scope.acttab - 1; | |
636 | scope.tab_upd_dec(); | |
637 | scope.$apply(); | |
638 | if (temp != 3) { | |
639 | $(".crmMailingTabs").tabs("option", "active", temp); | |
640 | } | |
641 | scope.$apply(); | |
642 | }); | |
643 | } | |
644 | }; | |
645 | });*/ | |
646 | ||
647 | /* crmMailing.directive('nexttab', function () { | |
648 | return { | |
649 | // Restrict it to be an attribute in this case | |
650 | restrict: 'A', | |
651 | priority: 500, | |
652 | // responsible for registering DOM listeners as well as updating the DOM | |
653 | link: function (scope, element, attrs) { | |
654 | var tabselector = $(".crmMailingTabs"); | |
655 | tabselector.tabs(scope.$eval(attrs.nexttab)); | |
656 | var myarr = new Array(1, 2, 3) | |
657 | // disable remaining tabs | |
658 | if(scope.sparestuff.isnew == true) | |
659 | tabselector.tabs({disabled: myarr}); | |
660 | $(element).on("click", function () { | |
661 | if (scope.tab_val == 0) { | |
662 | scope.create_abtest(); | |
663 | } | |
664 | else { | |
665 | if (scope.tab_val == 2) { | |
666 | scope.update_abtest(); | |
667 | if (scope.currentABTest.winner_criteria_id == 1) { | |
668 | scope.sparestuff.winnercriteria = "Open"; | |
669 | scope.$apply(); | |
670 | } | |
671 | ||
672 | scope.a_b_update(); | |
673 | } | |
674 | } | |
675 | scope.tab_upd(); | |
676 | var myArray1 = new Array(); | |
677 | for (var i = scope.max_tab + 1; i < 4; i++) { | |
678 | myArray1.push(i); | |
679 | } | |
680 | tabselector.tabs("option", "disabled", myArray1); | |
681 | tabselector.tabs("option", "active", scope.tab_val); | |
682 | scope.$apply(); | |
683 | }); | |
684 | } | |
685 | }; | |
686 | });*/ | |
687 | ||
688 | ||
689 | // Select 2 Widget for selecting the included group | |
690 | crmMailing.directive('chsgroup',function(){ | |
691 | return { | |
692 | restrict : 'AE', | |
693 | link: function(scope,element, attrs){ | |
694 | function format(item) { | |
695 | if(!item.id) { | |
696 | // return `text` for optgroup | |
697 | return item.text; | |
698 | } | |
699 | // return item template | |
700 | var a = item.id.split(" "); | |
701 | if(a[1]=="civicrm_group" && a[2]=="include") | |
702 | 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; | |
703 | if(a[1]=="civicrm_group" && a[2]=="exclude") | |
704 | 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; | |
705 | if(a[1]=="civicrm_mailing" && a[2]=="include") | |
706 | 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; | |
707 | if(a[1]=="civicrm_mailing" && a[2]=="exclude") | |
708 | 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; | |
709 | } | |
710 | ||
711 | $(element).select2({ | |
712 | width:"400px", | |
713 | placeholder: "Choose Recipients", | |
714 | formatResult: format, | |
715 | formatSelection: format, | |
716 | escapeMarkup: function(m) { return m; }, | |
717 | }).select2("data", scope.incGroup); | |
718 | ||
719 | ||
720 | $(element).on("select2-opening", function(){ | |
721 | scope.incGroup=chck; | |
722 | scope.$apply(); | |
723 | ||
724 | }); | |
725 | ||
726 | $(element).on('select2-selecting', function(e) { | |
727 | chck.push(e.val); | |
728 | scope.incGroup=chck; | |
729 | scope.$apply(); | |
730 | ||
731 | }); | |
732 | ||
733 | $(element).on("select2-removed", function(e) { | |
734 | var index = chck.indexOf(e.val); | |
735 | chck.splice(index, 1); | |
736 | scope.incGroup=chck; | |
737 | scope.$apply(); | |
738 | }); | |
739 | ||
740 | } | |
741 | }; | |
742 | }); | |
743 | ||
744 | crmMailing.directive('groupselect',function(){ | |
745 | return { | |
746 | restrict : 'AE', | |
747 | link: function(scope,element, attrs){ | |
748 | $(element).select2({width:"200px", data: mltokens, placeholder:"Insert Token"}); | |
749 | $(element).on('select2-selecting', function(e) { | |
750 | ||
751 | scope.$evalAsync('_resetSelection()'); | |
752 | var a = $(element).attr('id'); | |
753 | if(a=="htgroup"){ | |
754 | var msg = document.getElementById("body_html").value; | |
755 | var cursorlen = document.getElementById("body_html").selectionStart; | |
756 | var textlen = msg.length; | |
757 | document.getElementById("body_html").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); | |
758 | scope.currentMailing.body_html = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); | |
759 | var cursorPos = (cursorlen + e.val.length); | |
760 | document.getElementById("body_html").selectionStart = cursorPos; | |
761 | document.getElementById("body_html").selectionEnd = cursorPos; | |
762 | document.getElementById("body_html").focus(); | |
763 | } | |
764 | else if(a=="subgroup"){ | |
765 | var msg = document.getElementById("sub").value; | |
766 | var cursorlen = document.getElementById("sub").selectionStart; | |
767 | var textlen = msg.length; | |
768 | document.getElementById("sub").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); | |
769 | scope.currentMailing.subject = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); | |
770 | var cursorPos = (cursorlen + e.val.length); | |
771 | document.getElementById("sub").selectionStart = cursorPos; | |
772 | document.getElementById("sub").selectionEnd = cursorPos; | |
773 | document.getElementById("sub").focus(); | |
774 | } | |
775 | else if(a=="textgroup"){ | |
776 | var msg = document.getElementById("body_text").value; | |
777 | var cursorlen = document.getElementById("body_text").selectionStart; | |
778 | var textlen = msg.length; | |
779 | document.getElementById("body_text").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); | |
780 | scope.currentMailing.body_text = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); | |
781 | var cursorPos = (cursorlen + e.val.length); | |
782 | document.getElementById("body_text").selectionStart = cursorPos; | |
783 | document.getElementById("body_text").selectionEnd = cursorPos; | |
784 | document.getElementById("body_text").focus(); | |
785 | } | |
786 | scope.$apply(); | |
787 | e.preventDefault(); | |
788 | }) | |
789 | } | |
790 | }; | |
791 | }); | |
792 | ||
793 | ||
794 | ||
795 | // Used for the select date option. This is used for giving scheduled_date its date value | |
796 | crmMailing.directive('chsdate',function(){ | |
797 | return { | |
798 | restrict: 'AE', | |
799 | link: function(scope,element,attrs){ | |
800 | $(element).datepicker({ | |
801 | dateFormat: "yy-mm-dd", | |
802 | onSelect: function(date) { | |
803 | $(".ui-datepicker a").removeAttr("href"); | |
804 | scope.scheddate.date=date.toString(); | |
805 | scope.$apply(); | |
806 | } | |
807 | }); | |
808 | } | |
809 | }; | |
810 | }); | |
811 | ||
812 | crmMailing.directive('file', function(){ | |
813 | return { | |
814 | scope: { | |
815 | file: '=' | |
816 | }, | |
817 | link: function(scope, el, attrs){ | |
818 | el.bind('change', function(event){ | |
819 | var files = event.target.files; | |
820 | var file = files[0]; | |
821 | scope.file = file ? file : undefined; | |
822 | scope.$apply(); | |
823 | }); | |
824 | } | |
825 | }; | |
826 | }); | |
827 | ||
828 | ||
829 | crmMailing.directive('checktimeentry',function(){ | |
830 | return { | |
831 | restrict :'AE', | |
832 | link: function (scope, element, attrs) { | |
833 | $(element).timeEntry({show24Hours:true}); | |
834 | } | |
835 | } | |
836 | }); | |
837 | ||
838 | //This controller is used for creating the mailing list. Simply gets all the mailing data from civiAPI | |
839 | crmMailing.controller('mailingListCtrl', function($scope, crmApi, mailingList, $route) { | |
840 | if (global == 0) { | |
841 | global = global + 1; | |
842 | $route.reload(); | |
843 | } | |
844 | $scope.mailingList = mailingList.values; | |
845 | $scope.checkEmpty = function(){ | |
846 | if($scope.mailingList == "") | |
847 | return true; | |
848 | else | |
849 | return false; | |
850 | } | |
851 | $scope.deleteMail = function (mail) { | |
852 | crmApi('Mailing', 'delete', {id: mail.id}, { | |
853 | error: function (data) { | |
854 | CRM.alert(data.error_message, ts('Error')); | |
855 | } | |
856 | }) | |
857 | .then(function (data) { | |
858 | if (!data.is_error) { | |
859 | delete mailingList.values[mail.id]; | |
860 | $scope.$digest(); | |
861 | $route.reload(); | |
862 | } | |
863 | }); | |
864 | ||
865 | }; | |
866 | ||
867 | $scope.edit = function (){ | |
868 | global = global - 1; | |
869 | }; | |
870 | ||
871 | }); | |
872 | ||
873 | })(angular, CRM.$, CRM._); | |
874 | ||
875 | /* example of params | |
876 | [attachFile_1] => Array ( [uri] => /var/www/siddhant/drupal-7.27/sites/default/files/civicrm/custom/blog_2_odt_2c622a7b5e32415a92e81ed97d6554c7.unknown [type] => application/vnd.oasis.opendocument.text [location] => /var/www/siddhant/drupal-7.27/sites/default/files/civicrm/custom/blog_2_odt_2c622a7b5e32415a92e81ed97d6554c7.unknown [description] => dasdas [upload_date] => 20140706105804 [tag] => Array ( ) [attachment_taglist] => Array ( ) ) | |
877 | */ |