1 (function (angular
, $, _
) {
2 //partials for the html pages
3 var partialUrl = function (relPath
) {
4 return CRM
.resourceUrls
['civicrm'] + '/partials/crmMailing/' + relPath
;
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
= []; //we store list of the tokens in this
11 var global
= 0; //use this to reload mailingList page once
13 //-------------------------------------------------------------------------------------------------------
14 crmMailing
.config(['$routeProvider',
15 function ($routeProvider
) {
16 $routeProvider
.when('/mailing', {
17 templateUrl
: partialUrl('mailingList.html'),
18 controller
: 'mailingListCtrl',
20 mailingList: function ($route
, crmApi
) {
21 return crmApi('Mailing', 'get', {});
25 }); //This route is used for generating the list of mails created.
27 $routeProvider
.when('/mailing/:id', {
28 templateUrl
: partialUrl('main.html'),
29 controller
: 'mailingCtrl',
31 selectedMail: function ($route
, crmApi
) {
32 if ($route
.current
.params
.id
!== 'new') {
33 return crmApi('Mailing', 'getsingle', {id
: $route
.current
.params
.id
});
36 //selected mail in case of a new mailing. some default values are set
37 return {visibility
: "Public Pages", url_tracking
: "1", dedupe_email
: "1", forward_replies
: "0", auto_responder
: "0", open_tracking
: "1"
42 }); //This route is used for creating new mails and editing the current mails
45 //-----------------------------------------
48 //This controller is used in creating new mail and editing current mails
49 crmMailing
.controller('mailingCtrl', function ($scope
, crmApi
, selectedMail
, $location
, $route
, $sce
, $window
) {
51 //setting variables to the values we have got to the api
52 $scope
.partialUrl
= partialUrl
;
53 $scope
.campaignList
= CRM
.crmMailing
.campNames
;
54 $scope
.mailList
= CRM
.crmMailing
.civiMails
;
55 $scope
.mailNameList
= _
.pluck(CRM
.crmCaseType
.civiMails
, 'name');
56 $scope
.groupNamesList
= CRM
.crmMailing
.groupNames
;
57 $scope
.headerfooter
= CRM
.crmMailing
.headerfooterList
;
58 $scope
.fromAddress
= CRM
.crmMailing
.fromAddress
;
59 $scope
.tmpList
= CRM
.crmMailing
.mesTemplate
;
60 $scope
.mailingGrp
= CRM
.crmMailing
.mailGrp
;
61 $scope
.user_id
= CRM
.crmMailing
.contactid
;
62 mltokens
= CRM
.crmMailing
.mailTokens
;
63 //set currentMailing to selectedMail
64 $scope
.currentMailing
= selectedMail
;
65 $scope
.currentMailing
.created_id
= $scope
.user_id
;
66 //when pre is true, preview mailing is opened
68 //counts number of recipients
69 $scope
.noOfRecipients
= 0;
70 //object testMailing for testMailing.name and testMailing.group
71 $scope
.testMailing
= {};
72 $scope
.testMailing
.name
= "";
73 $scope
.testMailing
.group
= "";
74 window
.ct
= $scope
.currentMailing
;
75 //previewbody_html stores value of HTML in editor, similar functionality of text and subject based on name
76 $scope
.previewbody_html
= "";
77 $scope
.previewbody_text
= "";
78 $scope
.preview_subject
= "";
81 //chck and chck2 are used for mailing groups
84 //from.name stores name of the sender, email stores the mail address of the sender, total stores the concatenation of the two
85 //reply.email stores the reply to email address
87 $scope
.from.name
= "";
88 $scope
.from.email
= "";
89 $scope
.from.total
= "";
91 $scope
.reply
.email
= "";
92 //replyaddress is the array used to save the set of fromemailAddress of the person
93 $scope
.replyaddress
= [];
94 for (var a
in $scope
.fromAddress
) {
96 var splt
= $scope
.fromAddress
[a
].label
.split(" ");
97 splt
= splt
[1].substring(1, (splt
[1].length
- 1));
99 $scope
.replyaddress
.push(b
);
101 //from.total retrieves the from.name + from.email value so it can be read by the select2 widget
102 if ($scope
.currentMailing
.from_name
!= null) {
103 $scope
.from.name
= $scope
.currentMailing
.from_name
;
104 $scope
.from.email
= $scope
.currentMailing
.from_email
;
105 $scope
.from.total
= '"' + $scope
.from.name
+ '"' + " <" + $scope
.from.email
+ ">";
106 $scope
.reply
.email
= $scope
.currentMailing
.replyto_email
;
110 //putting all the ids of mails corresponding to the current mailing in mailid.
111 for (var a
in $scope
.mailingGrp
) {
112 if ($scope
.mailingGrp
[a
].mailing_id
== $scope
.currentMailing
.id
) {
113 var b
= $scope
.mailingGrp
[a
].entity_id
+ " " + $scope
.mailingGrp
[a
].entity_table
+ " " + $scope
.mailingGrp
[a
].group_type
;
114 var c
= $scope
.mailingGrp
[a
].id
;
116 $scope
.mailid
.push(c
);
120 //used to put the Template id in tst so it can be used
122 if ($scope
.currentMailing
.msg_template_id
!= null) {
123 $scope
.tst
= $scope
.currentMailing
.msg_template_id
;
125 //Making the object for data in the mailing group related directive
127 for (var a
in chck
) {
130 var splt
= chck
[a
].split(" ");
132 if (splt
[1] == "civicrm_group") {
133 for (var c
in $scope
.groupNamesList
) {
134 if ($scope
.groupNamesList
[c
].id
== splt
[0]) {
135 b
.text
= $scope
.groupNamesList
[c
].title
;
139 if (splt
[1] == "civicrm_mailing") {
140 for (var c
in $scope
.mailList
) {
141 if ($scope
.mailList
[c
].id
== splt
[0]) {
142 b
.text
= $scope
.mailList
[c
].name
;
148 $scope
.incGroup
= chck2
;
149 //tabact is set to 0. stores value of active tab
151 //all tabs with tab index greater than maxtab will be disabled. if not a new mail, no tab will be disabled
152 //otherwise all except first tab disabled
153 if ($scope
.currentMailing
.id
!= null)
157 //increments active tab value and maxtab when next is clicked
158 $scope
.tabupdate = function () {
159 $scope
.tabact
= $scope
.tabact
+ 1;
160 $scope
.maxtab
= Math
.max($scope
.maxtab
, $scope
.tabact
);
162 //decrements active tab value
163 $scope
.prevtabupdate = function () {
164 $scope
.tabact
= $scope
.tabact
- 1;
166 //set active tab to 0 when recipient is clicked
167 $scope
.recclicked = function () {
171 //set active tab to 1 when content is clicked
172 //also call appropriate save function if clicked from recipient tab
173 $scope
.conclicked = function () {
174 if ($scope
.tabact
== 0)
175 $scope
.save_next_page1();
178 //set active tab to 2 when schedule and send is clicked
179 //also call appropriate save functions if clicked from recipient or content tab
180 $scope
.schedclicked = function () {
181 if ($scope
.tabact
== 0)
182 $scope
.save_next_page1();
183 else if ($scope
.tabact
== 1)
184 $scope
.save_next_page2();
187 //goes to the mailing list page
188 $scope
.back = function () {
189 $window
.location
.href
= "#/mailing";
192 //on changing the selected template, updates subject and body_html of currentMailing
193 $scope
.tmp = function (tst
) {
194 $scope
.currentMailing
.msg_template_id
= tst
;
195 if ($scope
.currentMailing
.msg_template_id
== null) {
196 $scope
.currentMailing
.body_html
= "";
197 $scope
.currentMailing
.subject
= "";
200 for (var a
in $scope
.tmpList
) {
202 if ($scope
.tmpList
[a
].id
== $scope
.currentMailing
.msg_template_id
) {
203 $scope
.currentMailing
.body_html
= $scope
.tmpList
[a
].msg_html
;
204 $scope
.currentMailing
.subject
= $scope
.tmpList
[a
].msg_subject
;
209 //initializing variables we will use for checkboxes, or for purpose of ng-show
210 $scope
.composeS
= "1";
211 if ($scope
.currentMailing
.forward_replies
== 0 && $scope
.currentMailing
.auto_responder
== 0) {
212 $scope
.trackreplies
= "0";
215 $scope
.trackreplies
= "1";
217 if ($scope
.currentMailing
.scheduled_date
== null || $scope
.currentMailing
.scheduled_date
== "")
222 $scope
.reply = function () {
223 if ($scope
.trackreplies
== 0) {
224 $scope
.trackreplies
= 1;
227 $scope
.trackreplies
= 0;
228 $scope
.currentMailing
.forward_replies
= 0;
229 $scope
.currentMailing
.auto_responder
= 0;
233 //joining scheddate.date and scheddate.time gives us scheduled date of current mailing
234 $scope
.scheddate
= {};
235 $scope
.scheddate
.date
= "";
236 $scope
.scheddate
.time
= "";
237 //checkNow decides whether we see the date picker or not. Depends on send immediately being on or off
238 $scope
.checkNow = function () {
239 if ($scope
.now
== 1) {
244 $scope
.currentMailing
.scheduled_date
= null;
245 $scope
.currentMailing
.scheduled_id
= null;
246 $scope
.scheddate
.date
= "";
247 $scope
.scheddate
.time
= "";
250 //changing the screen from compose on screen to upload content
251 $scope
.upldChange = function (composeS
) {
252 if (composeS
== "1") {
258 //filter so we only get headers from mailing component
259 $scope
.isHeader = function (hf
) {
260 return hf
.component_type
== "Header";
262 //filter so we only get footers from mailing component
263 $scope
.isFooter = function (f
) {
264 return f
.component_type
== "Footer";
266 //filter so we only get auto-Responders from mailing component
267 $scope
.isAuto = function (au
) {
268 return au
.component_type
== "Reply";
270 //filter so we only get userDriven message templates
271 $scope
.isUserDriven = function (mstemp
) {
272 return (parseInt(mstemp
.id
) > 58);
274 //used for ng-show when trackreplies is selected. Only then we show forward replies and auto-responders options
275 $scope
.trackr = function (trackreplies
) {
276 if (trackreplies
== "1") {
282 //we should only see groups with appropriate mailing visibility
283 $scope
.isGrp = function (grp
) {
284 return grp
.visibility
== "Public Pages";
286 //only completed mails are shown in the groupings
287 $scope
.isCompMail = function (ml
) {
288 return ml
.is_completed
== 1;
290 //This is used to open the update the values in preview mailing
291 $scope
.preview_update = function () {
292 var resulta
= crmApi('Mailing', 'preview', {id
: $scope
.currentMailing
.id
});
293 resulta
.success(function (data
) {
294 if (data
.is_error
== 0) {
295 $scope
.previewbody_html
= data
.values
.html
;
296 $scope
.previewbody_text
= data
.values
.text
;
297 $scope
.preview_subject
= data
.values
.subject
;
304 //checks if body_text is empty or not
305 $scope
.isBody_text = function () {
306 if ($scope
.currentMailing
.body_text
== null || $scope
.currentMailing
.body_text
== "")
312 $scope
.deliberatelyTrustDangerousSnippet = function () {
313 return $sce
.trustAsHtml($scope
.previewbody_html
);
316 $scope
.deliberatelyTrustDangerousSnippet2 = function () {
317 return $sce
.trustAsHtml($scope
.previewbody_text
);
320 $scope
.deliberatelyTrustDangerousSnippet3 = function () {
321 return $sce
.trustAsHtml($scope
.preview_subject
);
323 //gets number of mailing recipients
324 $scope
.mailing_recipients = function () {
325 var resulta
= crmApi('MailingRecipients', 'get', {mailing_id
: $scope
.currentMailing
.id
, options
: {limit
: 1000}});
326 resulta
.success(function (data
) {
327 if (data
.is_error
== 0) {
328 $scope
.noOfRecipients
= data
.count
;
334 //gets mailing groups associated with current mailing id. formats it in the required way
335 $scope
.mailingGroup = function () {
336 var resulta
= crmApi('MailingGroup', 'get', {mailing_id
: $scope
.currentMailing
.id
, options
: {limit
: 1000}})
337 resulta
.success(function (data
) {
340 angular
.forEach(data
.values
, function (value
, key
) {
341 var b
= value
.entity_id
+ " " + value
.entity_table
+ " " + value
.group_type
;
344 $scope
.mailid
.push(c
);
350 var splt
= chck
[a
].split(" ");
352 if (splt
[1] == "civicrm_group") {
353 for (var c
in $scope
.groupNamesList
) {
354 if ($scope
.groupNamesList
[c
].id
== splt
[0]) {
355 b
.text
= $scope
.groupNamesList
[c
].title
;
359 if (splt
[1] == "civicrm_mailing") {
360 for (var c
in $scope
.mailList
) {
361 if ($scope
.mailList
[c
].id
== splt
[0]) {
362 b
.text
= $scope
.mailList
[c
].name
;
369 $scope
.incGroup
= chck2
;
370 $scope
.mailing_recipients();
373 //save repeat is a function that is repeated in all versions of save
374 $scope
.save_repeat = function () {
375 if ($scope
.from.total
!= "") {
376 var splt
= $scope
.from.total
.split(" ");
377 var splta
= splt
[1].substring(1, (splt
[1].length
- 1));
378 var spltb
= splt
[0].substring(1, (splt
[0].length
- 1));
379 $scope
.currentMailing
.from_email
= splta
;
380 $scope
.currentMailing
.from_name
= spltb
;
383 //save_next is used in recipient page. stores mailing groups
384 $scope
.save_next = function () {
385 $scope
.save_repeat();
386 //splits the groups based on include exclude mailing and groups
392 for (req_id
in chck
) {
393 $scope
.answer
= chck
[req_id
].split(" ");
395 if ($scope
.answer
[1] == "civicrm_mailing" && $scope
.answer
[2] == "include") {
396 $scope
.incMail
.push($scope
.answer
[0]);
398 else if ($scope
.answer
[1] == "civicrm_mailing" && $scope
.answer
[2] == "exclude") {
399 $scope
.excMail
.push($scope
.answer
[0]);
401 if ($scope
.answer
[1] == "civicrm_group" && $scope
.answer
[2] == "include") {
402 $scope
.incGrp
.push($scope
.answer
[0]);
404 else if ($scope
.answer
[1] == "civicrm_group" && $scope
.answer
[2] == "exclude") {
405 $scope
.excGrp
.push($scope
.answer
[0]);
408 //deletes existing mailing groups of that id
409 if ($scope
.mailid
!= null) {
410 for (var a
in $scope
.mailid
) {
411 var result_2
= crmApi('MailingGroup', 'delete', {
417 var result
= crmApi('Mailing', 'create', {
418 id
: $scope
.currentMailing
.id
,
419 name
: $scope
.currentMailing
.name
,
420 visibility
: $scope
.currentMailing
.visibility
,
421 created_id
: $scope
.currentMailing
.created_id
,
422 subject
: $scope
.currentMailing
.subject
,
423 msg_template_id
: $scope
.currentMailing
.msg_template_id
== null ? "" : $scope
.currentMailing
.msg_template_id
,
424 open_tracking
: $scope
.currentMailing
.open_tracking
,
425 url_tracking
: $scope
.currentMailing
.url_tracking
,
426 forward_replies
: $scope
.currentMailing
.forward_replies
,
427 auto_responder
: $scope
.currentMailing
.auto_responder
,
428 from_name
: $scope
.currentMailing
.from_name
,
429 from_email
: $scope
.currentMailing
.from_email
,
430 replyto_email
: $scope
.currentMailing
.replyto_email
,
431 unsubscribe_id
: $scope
.currentMailing
.unsubscribe_id
,
432 resubscribe_id
: $scope
.currentMailing
.resubscribe_id
,
433 body_html
: $scope
.currentMailing
.body_html
,
434 body_text
: $scope
.currentMailing
.body_text
,
435 campaign_id
: $scope
.currentMailing
.campaign_id
== null ? "" : $scope
.currentMailing
.campaign_id
,
436 header_id
: $scope
.currentMailing
.header_id
,
437 footer_id
: $scope
.currentMailing
.footer_id
,
438 groups
: {include
: $scope
.incGrp
,
439 exclude
: $scope
.excGrp
441 mailings
: {include
: $scope
.incMail
,
442 exclude
: $scope
.excMail
444 is_completed
: $scope
.currentMailing
.is_completed
,
445 dedupe_email
: $scope
.currentMailing
.dedupe_email
448 //var result = crmApi('Mailing', 'create', $scope.currentMailing, true);
449 result
.success(function (data
) {
450 if (data
.is_error
== 0) {
451 $scope
.currentMailing
.id
= data
.id
;
452 $scope
.mailingGroup();
456 //in second page save neither groups or schedule date information.
457 $scope
.save_next_page2 = function () {
458 $scope
.save_repeat();
459 var result
= crmApi('Mailing', 'create', {
460 id
: $scope
.currentMailing
.id
,
461 name
: $scope
.currentMailing
.name
,
462 visibility
: $scope
.currentMailing
.visibility
,
463 created_id
: $scope
.currentMailing
.created_id
,
464 subject
: $scope
.currentMailing
.subject
,
465 msg_template_id
: $scope
.currentMailing
.msg_template_id
== null ? "" : $scope
.currentMailing
.msg_template_id
,
466 open_tracking
: $scope
.currentMailing
.open_tracking
,
467 url_tracking
: $scope
.currentMailing
.url_tracking
,
468 forward_replies
: $scope
.currentMailing
.forward_replies
,
469 auto_responder
: $scope
.currentMailing
.auto_responder
,
470 from_name
: $scope
.currentMailing
.from_name
,
471 from_email
: $scope
.currentMailing
.from_email
,
472 replyto_email
: $scope
.currentMailing
.replyto_email
,
473 unsubscribe_id
: $scope
.currentMailing
.unsubscribe_id
,
474 resubscribe_id
: $scope
.currentMailing
.resubscribe_id
,
475 body_html
: $scope
.currentMailing
.body_html
,
476 body_text
: $scope
.currentMailing
.body_text
,
477 campaign_id
: $scope
.currentMailing
.campaign_id
== null ? "" : $scope
.currentMailing
.campaign_id
,
478 header_id
: $scope
.currentMailing
.header_id
,
479 footer_id
: $scope
.currentMailing
.footer_id
,
480 is_completed
: $scope
.currentMailing
.is_completed
,
481 dedupe_email
: $scope
.currentMailing
.dedupe_email
484 //var result = crmApi('Mailing', 'create', $scope.currentMailing, true);
485 result
.success(function (data
) {
486 if (data
.is_error
== 0) {
487 $scope
.currentMailing
.id
= data
.id
;
491 //save scheduling information and not groups
492 $scope
.save_next_page3 = function () {
493 $scope
.save_repeat();
494 if ($scope
.currentMailing
.scheduled_date
== $scope
.currentMailing
.approval_date
495 && $scope
.currentMailing
.scheduled_date
!= null) {
499 $scope
.currentMailing
.scheduled_date
= $scope
.scheddate
.date
+ " " + $scope
.scheddate
.time
;
500 if ($scope
.currentMailing
.scheduled_date
!= " ") {
501 $scope
.currentMailing
.scheduled_id
= $scope
.user_id
;
504 $scope
.currentMailing
.scheduled_date
= null;
507 var result
= crmApi('Mailing', 'create', {
508 id
: $scope
.currentMailing
.id
,
509 name
: $scope
.currentMailing
.name
,
510 visibility
: $scope
.currentMailing
.visibility
,
511 created_id
: $scope
.currentMailing
.created_id
,
512 subject
: $scope
.currentMailing
.subject
,
513 msg_template_id
: $scope
.currentMailing
.msg_template_id
== null ? "" : $scope
.currentMailing
.msg_template_id
,
514 open_tracking
: $scope
.currentMailing
.open_tracking
,
515 url_tracking
: $scope
.currentMailing
.url_tracking
,
516 forward_replies
: $scope
.currentMailing
.forward_replies
,
517 auto_responder
: $scope
.currentMailing
.auto_responder
,
518 from_name
: $scope
.currentMailing
.from_name
,
519 from_email
: $scope
.currentMailing
.from_email
,
520 replyto_email
: $scope
.currentMailing
.replyto_email
,
521 unsubscribe_id
: $scope
.currentMailing
.unsubscribe_id
,
522 resubscribe_id
: $scope
.currentMailing
.resubscribe_id
,
523 body_html
: $scope
.currentMailing
.body_html
,
524 body_text
: $scope
.currentMailing
.body_text
,
525 scheduled_date
: $scope
.currentMailing
.scheduled_date
== null ? "" : $scope
.currentMailing
.scheduled_date
,
526 scheduled_id
: $scope
.currentMailing
.scheduled_id
== null ? "" : $scope
.currentMailing
.scheduled_id
,
527 campaign_id
: $scope
.currentMailing
.campaign_id
== null ? "" : $scope
.currentMailing
.campaign_id
,
528 header_id
: $scope
.currentMailing
.header_id
,
529 footer_id
: $scope
.currentMailing
.footer_id
,
530 is_completed
: $scope
.currentMailing
.is_completed
,
531 approver_id
: $scope
.currentMailing
.approver_id
,
532 approval_status_id
: $scope
.currentMailing
.approval_status_id
,
533 approval_date
: $scope
.currentMailing
.approval_date
,
534 dedupe_email
: $scope
.currentMailing
.dedupe_email
537 //var result = crmApi('Mailing', 'create', $scope.currentMailing, true);
538 result
.success(function (data
) {
539 if (data
.is_error
== 0) {
540 $scope
.currentMailing
.id
= data
.id
;
545 //call save of page2 and go to listing page
546 $scope
.save = function () {
547 $scope
.save_next_page2();
550 //call save of page1 and go to listing page
551 $scope
.save_page1 = function () {
552 $scope
.save_next_page1();
555 //if we save on page one, subject isnt defined. so we equate it to mailing name for now so we can save
556 $scope
.save_next_page1 = function () {
557 if ($scope
.currentMailing
.id
== null) {
558 $scope
.currentMailing
.subject
= $scope
.currentMailing
.name
;
566 //set approval date to current time, also schedule date based on send immediately or not. then call 3rd page save
567 //go back to listing page
568 $scope
.submitButton = function () {
569 $scope
.currentMailing
.approval_status_id
= "1";
570 $scope
.currentMailing
.approver_id
= $scope
.user_id
;
571 var currentdate
= new Date();
572 var yyyy
= currentdate
.getFullYear();
573 var mm
= currentdate
.getMonth() + 1;
574 mm
= mm
< 10 ? '0' + mm
: mm
;
575 var dd
= currentdate
.getDate();
576 dd
= dd
< 10 ? '0' + dd
: dd
;
577 var hh
= currentdate
.getHours();
578 hh
= hh
< 10 ? '0' + hh
: hh
;
579 var min
= currentdate
.getMinutes();
580 min
= min
< 10 ? '0' + min
: min
;
581 var sec
= currentdate
.getSeconds();
582 sec
= sec
< 10 ? '0' + sec
: sec
;
583 $scope
.currentMailing
.approval_date
= yyyy
+ "/" + mm
587 if ($scope
.now
== 1) {
588 $scope
.currentMailing
.scheduled_date
= $scope
.currentMailing
.approval_date
;
590 $scope
.save_next_page3();
593 //we use this to open the preview modal based on value of pre
594 $scope
.$watch('pre', function () {
595 if ($scope
.pre
== true) {
596 $('#prevmail').dialog({
597 title
: 'Preview Mailing',
610 //send test api called to send the test
611 $scope
.sendTest = function () {
612 var resulta
= crmApi('Mailing', 'send_test', {test_email
: $scope
.testMailing
.name
, test_group
: $scope
.testMailing
.group
,
613 mailing_id
: $scope
.currentMailing
.id
});
618 // Directive to go to the next tab
619 crmMailing
.directive('nexttab', function () {
622 link: function (scope
, element
, attrs
) {
623 var tabselector
= $(".crmMailingTabs");
624 var myarr
= new Array(1, 2);
625 if (scope
.currentMailing
.id
== null) {
626 tabselector
.tabs({disabled
: myarr
});
628 $(element
).on("click", function () {
630 var myArray1
= new Array( );
632 for (var i
= scope
.maxtab
+ 1; i
< 3; i
++) {
636 tabselector
.tabs("option", "disabled", myArray1
);
637 tabselector
.tabs({active
: scope
.tabact
});
644 // Directive to go to the previous tab
645 crmMailing
.directive('prevtab', function () {
648 link: function (scope
, element
, attrs
) {
649 var tabselector
= $(".crmMailingTabs");
651 $(element
).on("click", function () {
652 scope
.prevtabupdate();
654 var myArray1
= new Array( );
655 tabselector
.tabs({active
: scope
.tabact
});
662 // Select 2 Widget for selecting the included group
663 crmMailing
.directive('chsgroup', function () {
666 link: function (scope
, element
, attrs
) {
667 function format(item
) {
669 // return `text` for optgroup
672 // return item template
673 var a
= item
.id
.split(" ");
674 if (a
[1] == "civicrm_group" && a
[2] == "include")
675 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
;
676 if (a
[1] == "civicrm_group" && a
[2] == "exclude")
677 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
;
678 if (a
[1] == "civicrm_mailing" && a
[2] == "include")
679 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
;
680 if (a
[1] == "civicrm_mailing" && a
[2] == "exclude")
681 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
;
686 placeholder
: "Choose Recipients",
687 formatResult
: format
,
688 formatSelection
: format
,
689 escapeMarkup: function (m
) {
692 }).select2("data", scope
.incGroup
);
695 $(element
).on("select2-opening", function () {
696 scope
.incGroup
= chck
;
701 $(element
).on('select2-selecting', function (e
) {
703 scope
.incGroup
= chck
;
708 $(element
).on("select2-removed", function (e
) {
709 var index
= chck
.indexOf(e
.val
);
710 chck
.splice(index
, 1);
711 scope
.incGroup
= chck
;
718 //used for tokens select2 widget
719 crmMailing
.directive('groupselect', function () {
722 link: function (scope
, element
, attrs
) {
723 $(element
).select2({width
: "200px", data
: mltokens
, placeholder
: "Insert Token"});
724 $(element
).on('select2-selecting', function (e
) {
726 scope
.$evalAsync('_resetSelection()');
727 var a
= $(element
).attr('id');
728 if (a
== "htgroup") {
729 if (scope
.currentMailing
.body_html
== "" || scope
.currentMailing
.body_html
== null)
730 scope
.currentMailing
.body_html
= e
.val
;
732 scope
.currentMailing
.body_html
+= e
.val
;
734 else if (a
== "subgroup") {
735 var msg
= document
.getElementById("sub").value
;
736 var cursorlen
= document
.getElementById("sub").selectionStart
;
737 var textlen
= msg
.length
;
738 document
.getElementById("sub").value
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
739 scope
.currentMailing
.subject
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
740 var cursorPos
= (cursorlen
+ e
.val
.length
);
741 document
.getElementById("sub").selectionStart
= cursorPos
;
742 document
.getElementById("sub").selectionEnd
= cursorPos
;
743 document
.getElementById("sub").focus();
745 else if (a
== "textgroup") {
746 var msg
= document
.getElementById("body_text").value
;
747 var cursorlen
= document
.getElementById("body_text").selectionStart
;
748 var textlen
= msg
.length
;
749 document
.getElementById("body_text").value
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
750 scope
.currentMailing
.body_text
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
751 var cursorPos
= (cursorlen
+ e
.val
.length
);
752 document
.getElementById("body_text").selectionStart
= cursorPos
;
753 document
.getElementById("body_text").selectionEnd
= cursorPos
;
754 document
.getElementById("body_text").focus();
764 crmMailing
.directive('ckedit', function () {
767 link: function (scope
, elm
, attr
, ngModel
) {
768 var ck
= CKEDITOR
.replace(elm
[0]);
773 ck
.on('pasteState', function () {
774 scope
.$apply(function () {
775 ngModel
.$setViewValue(ck
.getData());
779 ngModel
.$render = function (value
) {
780 ck
.setData(ngModel
.$viewValue
);
786 // Used for the select date option. This is used for giving scheduled_date its date value
787 crmMailing
.directive('chsdate', function () {
790 link: function (scope
, element
, attrs
) {
791 $(element
).datepicker({
792 dateFormat
: "yy-mm-dd",
793 onSelect: function (date
) {
794 $(".ui-datepicker a").removeAttr("href");
795 scope
.scheddate
.date
= date
.toString();
802 //used for file upload
803 crmMailing
.directive('file', function () {
808 link: function (scope
, el
, attrs
) {
809 el
.bind('change', function (event
) {
810 var files
= event
.target
.files
;
812 scope
.file
= file
? file
: undefined;
818 //used to insert the time entry
819 crmMailing
.directive('checktimeentry', function () {
822 link: function (scope
, element
, attrs
) {
823 $(element
).timeEntry({show24Hours
: true});
829 //This controller is used for creating the mailing list. Simply gets all the mailing data from civiAPI
830 crmMailing
.controller('mailingListCtrl', function ($scope
, crmApi
, mailingList
, $route
) {
835 $scope
.mailingList
= mailingList
.values
;
836 $scope
.checkEmpty = function () {
837 if ($scope
.mailingList
== "")
842 $scope
.deleteMail = function (mail
) {
843 crmApi('Mailing', 'delete', {id
: mail
.id
}, {
844 error: function (data
) {
845 CRM
.alert(data
.error_message
, ts('Error'));
848 .then(function (data
) {
849 if (!data
.is_error
) {
850 delete mailingList
.values
[mail
.id
];
858 $scope
.edit = function () {
864 })(angular
, CRM
.$, CRM
._
);
867 [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 ( ) )