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
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 //created_id has been set to my id. Does not save without created_id. Needs to made generic based on the user
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
.submitted
= false;
53 $scope
.partialUrl
= partialUrl
;
54 $scope
.campaignList
= CRM
.crmMailing
.campNames
;
55 $scope
.mailList
= CRM
.crmMailing
.civiMails
;
56 $scope
.mailNameList
= _
.pluck(CRM
.crmCaseType
.civiMails
, 'name');
57 $scope
.groupNamesList
= CRM
.crmMailing
.groupNames
;
58 $scope
.headerfooter
= CRM
.crmMailing
.headerfooterList
;
59 $scope
.fromAddress
= CRM
.crmMailing
.fromAddress
;
60 $scope
.tmpList
= CRM
.crmMailing
.mesTemplate
;
61 $scope
.mailingGrp
= CRM
.crmMailing
.mailGrp
;
62 $scope
.user_id
= CRM
.crmMailing
.contactid
;
63 $scope
.currentMailing
= selectedMail
;
64 $scope
.currentMailing
.created_id
= $scope
.user_id
;
65 mltokens
= CRM
.crmMailing
.mailTokens
;
67 $scope
.noOfRecipients
= 0;
68 $scope
.testMailing
= {};
69 $scope
.testMailing
.name
= "";
70 $scope
.testMailing
.group
= "";
71 window
.ct
= $scope
.currentMailing
;
72 $scope
.previewbody_html
= "";
73 $scope
.previewbody_text
= "";
74 $scope
.preview_subject
= "";
80 $scope
.from.name
= "";
81 $scope
.from.email
= "";
82 $scope
.from.total
= "";
84 $scope
.reply
.email
= "";
85 $scope
.replyaddress
= [];
86 for(var a
in $scope
.fromAddress
){
88 var splt
= $scope
.fromAddress
[a
].label
.split(" ");
89 splt
= splt
[1].substring(1,(splt
[1].length
-1));
91 $scope
.replyaddress
.push(b
);
94 if ($scope
.currentMailing
.from_name
!= null) {
95 $scope
.from.name
= $scope
.currentMailing
.from_name
;
96 $scope
.from.email
= $scope
.currentMailing
.from_email
;
97 $scope
.from.total
= '"'+ $scope
.from.name
+'"' + " <" + $scope
.from.email
+ ">";
98 $scope
.reply
.email
= $scope
.currentMailing
.replyto_email
;
103 for (var a
in $scope
.mailingGrp
) {
104 if ($scope
.mailingGrp
[a
].mailing_id
==$scope
.currentMailing
.id
) {
105 var b
= $scope
.mailingGrp
[a
].entity_id
+ " " + $scope
.mailingGrp
[a
].entity_table
+" " + $scope
.mailingGrp
[a
].group_type
;
106 var c
= $scope
.mailingGrp
[a
].id
;
108 $scope
.mailid
.push(c
);
112 if ($scope
.currentMailing
.msg_template_id
!=null) {
113 $scope
.tst
=$scope
.currentMailing
.msg_template_id
;
115 //Making the object for data
117 for (var a
in chck
) {
120 var splt
= chck
[a
].split(" ");
122 if(splt
[1] == "civicrm_group"){
123 for(var c
in $scope
.groupNamesList
){
124 if($scope
.groupNamesList
[c
].id
==splt
[0]){
125 b
.text
= $scope
.groupNamesList
[c
].title
;
129 if(splt
[1] == "civicrm_mailing"){
130 for(var c
in $scope
.mailList
){
131 if($scope
.mailList
[c
].id
==splt
[0]){
132 b
.text
= $scope
.mailList
[c
].name
;
138 $scope
.incGroup
= chck2
;
140 if($scope
.currentMailing
.id
!= null)
144 $scope
.tabupdate = function(){
145 $scope
.tabact
= $scope
.tabact
+ 1;
146 $scope
.maxtab
= Math
.max($scope
.maxtab
,$scope
.tabact
);
149 $scope
.prevtabupdate = function(){
150 $scope
.tabact
= $scope
.tabact
- 1;
153 $scope
.mailingForm = function() {
154 if ($scope
.mailing_form
.$valid
) {
158 $scope
.mailing_form
.submitted
= true;
162 $scope
.back = function (){
163 $window
.location
.href
= "#/mailing" ;
167 $scope
.tmp = function (tst
){
168 $scope
.currentMailing
.msg_template_id
=tst
;
169 if($scope
.currentMailing
.msg_template_id
== null){
170 $scope
.currentMailing
.body_html
="";
171 $scope
.currentMailing
.subject
="";
174 for(var a
in $scope
.tmpList
){
176 if($scope
.tmpList
[a
].id
==$scope
.currentMailing
.msg_template_id
){
177 $scope
.currentMailing
.body_html
=$scope
.tmpList
[a
].msg_html
;
178 $scope
.currentMailing
.subject
=$scope
.tmpList
[a
].msg_subject
;
183 //initializing variables we will use for checkboxes, or for purpose of ng-show
185 if($scope
.currentMailing
.forward_replies
==0 && $scope
.currentMailing
.auto_responder
==0){
186 $scope
.trackreplies
="0";
189 $scope
.trackreplies
="1";
191 if($scope
.currentMailing
.scheduled_date
== null || $scope
.currentMailing
.scheduled_date
== "")
196 $scope
.reply = function(){
197 if($scope
.trackreplies
==0){
198 $scope
.trackreplies
=1;
201 $scope
.trackreplies
=0;
202 $scope
.currentMailing
.forward_replies
=0;
203 $scope
.currentMailing
.auto_responder
=0;
208 $scope
.recclicked = function(){
213 $scope
.conclicked = function(){
214 if($scope
.tabact
== 0)
215 $scope
.save_next_page1();
220 $scope
.schedclicked = function(){
221 if($scope
.tabact
== 0)
222 $scope
.save_next_page1();
223 else if($scope
.tabact
== 1)
224 $scope
.save_next_page2();
228 //to split the value of selectedMail.scheduled_date into the date and time separately
230 $scope
.scheddate
.date
= "";
231 $scope
.scheddate
.time
= "";
234 $scope
.checkNow = function(){
235 if($scope
.now
== 1 ){
240 $scope
.currentMailing
.scheduled_date
= null;
241 $scope
.currentMailing
.scheduled_id
= null;
242 $scope
.scheddate
.date
= "";
243 $scope
.scheddate
.time
= "";
247 //changing the screen from compose on screen to upload content
248 $scope
.upldChange= function(composeS
){
255 //filter so we only get headers from mailing component
256 $scope
.isHeader= function(hf
){
257 return hf
.component_type
== "Header";
259 //filter so we only get footers from mailing component
260 $scope
.isFooter= function(f
){
261 return f
.component_type
== "Footer";
263 //filter so we only get auto-Responders from mailing component
264 $scope
.isAuto= function(au
){
265 return au
.component_type
== "Reply";
267 //filter so we only get userDriven message templates
268 $scope
.isUserDriven= function(mstemp
){
269 return (parseInt(mstemp
.id
)>58);
271 //used for ng-show when trackreplies is selected. Only then we show forward replies and auto-responders options
272 $scope
.trackr= function(trackreplies
){
273 if(trackreplies
=="1"){
280 $scope
.isGrp= function(grp
){
281 return grp
.visibility
== "Public Pages";
284 $scope
.isCompMail= function(ml
){
285 return ml
.is_completed
== 1;
289 $scope
.preview_update = function(){
290 var resulta
=crmApi('Mailing','preview',{id
:$scope
.currentMailing
.id
});
291 resulta
.success(function(data
) {
292 if (data
.is_error
== 0) {
293 $scope
.previewbody_html
=data
.values
.html
;
294 $scope
.previewbody_text
=data
.values
.text
;
295 $scope
.preview_subject
=data
.values
.subject
;
303 $scope
.isBody_text = function(){
304 if($scope
.currentMailing
.body_text
== null || $scope
.currentMailing
.body_text
== "" )
310 $scope
.deliberatelyTrustDangerousSnippet = function() {
311 return $sce
.trustAsHtml($scope
.previewbody_html
);
314 $scope
.deliberatelyTrustDangerousSnippet2 = function() {
315 return $sce
.trustAsHtml($scope
.previewbody_text
);
318 $scope
.deliberatelyTrustDangerousSnippet3 = function() {
319 return $sce
.trustAsHtml($scope
.preview_subject
);
322 $scope
.mailing_recipients= function() {
323 var resulta
=crmApi('MailingRecipients', 'get', {mailing_id
: $scope
.currentMailing
.id
, options
: {limit
:1000}});
324 resulta
.success(function(data
) {
325 if (data
.is_error
== 0) {
326 $scope
.noOfRecipients
=data
.count
;
333 $scope
.mailingGroup = function() {
334 var resulta
=crmApi('MailingGroup', 'get', {mailing_id
: $scope
.currentMailing
.id
, options
: {limit
:1000}})
335 resulta
.success(function(data
) {
338 angular
.forEach(data
.values
, function(value
,key
){
339 var b
= value
.entity_id
+ " " + value
.entity_table
+" " + value
.group_type
;
342 $scope
.mailid
.push(c
);
347 var splt
= chck
[a
].split(" ");
349 if(splt
[1] == "civicrm_group"){
350 for(var c
in $scope
.groupNamesList
){
351 if($scope
.groupNamesList
[c
].id
==splt
[0]){
352 b
.text
= $scope
.groupNamesList
[c
].title
;
356 if(splt
[1] == "civicrm_mailing"){
357 for(var c
in $scope
.mailList
){
358 if($scope
.mailList
[c
].id
==splt
[0]){
359 b
.text
= $scope
.mailList
[c
].name
;
366 $scope
.incGroup
= chck2
;
367 $scope
.mailing_recipients();
371 $scope
.save_repeat = function(){
372 if ($scope
.from.total
!= "") {
373 var splt
= $scope
.from.total
.split(" ");
374 var splta
= splt
[1].substring(1,(splt
[1].length
-1));
375 var spltb
= splt
[0].substring(1,(splt
[0].length
-1));
376 $scope
.currentMailing
.from_email
= splta
;
377 $scope
.currentMailing
.from_name
= spltb
;
381 $scope
.save_next = function() {
382 $scope
.save_repeat();
389 $scope
.answer
= chck
[req_id
].split(" ");
391 if($scope
.answer
[1] == "civicrm_mailing" && $scope
.answer
[2]=="include"){
392 $scope
.incMail
.push($scope
.answer
[0]);
394 else if($scope
.answer
[1] == "civicrm_mailing" && $scope
.answer
[2]=="exclude"){
395 $scope
.excMail
.push($scope
.answer
[0]);
397 if($scope
.answer
[1] == "civicrm_group" && $scope
.answer
[2]=="include"){
398 $scope
.incGrp
.push($scope
.answer
[0]);
400 else if($scope
.answer
[1] == "civicrm_group" && $scope
.answer
[2]=="exclude"){
401 $scope
.excGrp
.push($scope
.answer
[0]);
405 if ($scope
.mailid
!= null) {
406 for (var a
in $scope
.mailid
) {
407 var result_2
= crmApi('MailingGroup', 'delete', {
413 var result
= crmApi('Mailing', 'create', {
414 id
: $scope
.currentMailing
.id
,
415 name
: $scope
.currentMailing
.name
,
416 visibility
: $scope
.currentMailing
.visibility
,
417 created_id
: $scope
.currentMailing
.created_id
,
418 subject
: $scope
.currentMailing
.subject
,
419 msg_template_id
: $scope
.currentMailing
.msg_template_id
==null ? "" : $scope
.currentMailing
.msg_template_id
,
420 open_tracking
: $scope
.currentMailing
.open_tracking
,
421 url_tracking
: $scope
.currentMailing
.url_tracking
,
422 forward_replies
: $scope
.currentMailing
.forward_replies
,
423 auto_responder
: $scope
.currentMailing
.auto_responder
,
424 from_name
: $scope
.currentMailing
.from_name
,
425 from_email
: $scope
.currentMailing
.from_email
,
426 replyto_email
: $scope
.currentMailing
.replyto_email
,
427 unsubscribe_id
: $scope
.currentMailing
.unsubscribe_id
,
428 resubscribe_id
: $scope
.currentMailing
.resubscribe_id
,
429 body_html
: $scope
.currentMailing
.body_html
,
430 body_text
: $scope
.currentMailing
.body_text
,
431 campaign_id
: $scope
.currentMailing
.campaign_id
==null ? "" : $scope
.currentMailing
.campaign_id
,
432 header_id
: $scope
.currentMailing
.header_id
,
433 footer_id
: $scope
.currentMailing
.footer_id
,
434 groups
: {include
: $scope
.incGrp
,
435 exclude
: $scope
.excGrp
437 mailings
: {include
: $scope
.incMail
,
438 exclude
: $scope
.excMail
440 is_completed
: $scope
.currentMailing
.is_completed
,
441 dedupe_email
: $scope
.currentMailing
.dedupe_email
444 //var result = crmApi('Mailing', 'create', $scope.currentMailing, true);
445 result
.success(function(data
) {
446 if (data
.is_error
== 0) {
447 $scope
.currentMailing
.id
= data
.id
;
448 $scope
.mailingGroup();
453 $scope
.save_next_page2 = function() {
454 $scope
.save_repeat();
455 var result
= crmApi('Mailing', 'create', {
456 id
: $scope
.currentMailing
.id
,
457 name
: $scope
.currentMailing
.name
,
458 visibility
: $scope
.currentMailing
.visibility
,
459 created_id
: $scope
.currentMailing
.created_id
,
460 subject
: $scope
.currentMailing
.subject
,
461 msg_template_id
: $scope
.currentMailing
.msg_template_id
==null ? "" : $scope
.currentMailing
.msg_template_id
,
462 open_tracking
: $scope
.currentMailing
.open_tracking
,
463 url_tracking
: $scope
.currentMailing
.url_tracking
,
464 forward_replies
: $scope
.currentMailing
.forward_replies
,
465 auto_responder
: $scope
.currentMailing
.auto_responder
,
466 from_name
: $scope
.currentMailing
.from_name
,
467 from_email
: $scope
.currentMailing
.from_email
,
468 replyto_email
: $scope
.currentMailing
.replyto_email
,
469 unsubscribe_id
: $scope
.currentMailing
.unsubscribe_id
,
470 resubscribe_id
: $scope
.currentMailing
.resubscribe_id
,
471 body_html
: $scope
.currentMailing
.body_html
,
472 body_text
: $scope
.currentMailing
.body_text
,
473 campaign_id
: $scope
.currentMailing
.campaign_id
==null ? "" : $scope
.currentMailing
.campaign_id
,
474 header_id
: $scope
.currentMailing
.header_id
,
475 footer_id
: $scope
.currentMailing
.footer_id
,
476 is_completed
: $scope
.currentMailing
.is_completed
,
477 dedupe_email
: $scope
.currentMailing
.dedupe_email
480 //var result = crmApi('Mailing', 'create', $scope.currentMailing, true);
481 result
.success(function(data
) {
482 if (data
.is_error
== 0) {
483 $scope
.currentMailing
.id
= data
.id
;
488 $scope
.save_next_page3 = function() {
489 $scope
.save_repeat();
490 if ($scope
.currentMailing
.scheduled_date
== $scope
.currentMailing
.approval_date
491 && $scope
.currentMailing
.scheduled_date
!= null) {;
494 $scope
.currentMailing
.scheduled_date
= $scope
.scheddate
.date
+ " " + $scope
.scheddate
.time
;
495 if ($scope
.currentMailing
.scheduled_date
!=" ") {
496 $scope
.currentMailing
.scheduled_id
= $scope
.user_id
;
499 $scope
.currentMailing
.scheduled_date
= null;
502 var result
= crmApi('Mailing', 'create', {
503 id
: $scope
.currentMailing
.id
,
504 name
: $scope
.currentMailing
.name
,
505 visibility
: $scope
.currentMailing
.visibility
,
506 created_id
: $scope
.currentMailing
.created_id
,
507 subject
: $scope
.currentMailing
.subject
,
508 msg_template_id
: $scope
.currentMailing
.msg_template_id
==null ? "" : $scope
.currentMailing
.msg_template_id
,
509 open_tracking
: $scope
.currentMailing
.open_tracking
,
510 url_tracking
: $scope
.currentMailing
.url_tracking
,
511 forward_replies
: $scope
.currentMailing
.forward_replies
,
512 auto_responder
: $scope
.currentMailing
.auto_responder
,
513 from_name
: $scope
.currentMailing
.from_name
,
514 from_email
: $scope
.currentMailing
.from_email
,
515 replyto_email
: $scope
.currentMailing
.replyto_email
,
516 unsubscribe_id
: $scope
.currentMailing
.unsubscribe_id
,
517 resubscribe_id
: $scope
.currentMailing
.resubscribe_id
,
518 body_html
: $scope
.currentMailing
.body_html
,
519 body_text
: $scope
.currentMailing
.body_text
,
520 scheduled_date
: $scope
.currentMailing
.scheduled_date
==null ? "" : $scope
.currentMailing
.scheduled_date
,
521 scheduled_id
: $scope
.currentMailing
.scheduled_id
==null ? "" : $scope
.currentMailing
.scheduled_id
,
522 campaign_id
: $scope
.currentMailing
.campaign_id
==null ? "" : $scope
.currentMailing
.campaign_id
,
523 header_id
: $scope
.currentMailing
.header_id
,
524 footer_id
: $scope
.currentMailing
.footer_id
,
525 is_completed
: $scope
.currentMailing
.is_completed
,
526 approver_id
: $scope
.currentMailing
.approver_id
,
527 approval_status_id
: $scope
.currentMailing
.approval_status_id
,
528 approval_date
: $scope
.currentMailing
.approval_date
,
529 dedupe_email
: $scope
.currentMailing
.dedupe_email
532 //var result = crmApi('Mailing', 'create', $scope.currentMailing, true);
533 result
.success(function(data
) {
534 if (data
.is_error
== 0) {
535 $scope
.currentMailing
.id
= data
.id
;
541 $scope
.save = function() {
542 $scope
.save_next_page2();
546 $scope
.save_page1 = function() {
547 $scope
.save_next_page1();
551 $scope
.save_next_page1 = function() {
552 if($scope
.currentMailing
.id
== null){
553 $scope
.currentMailing
.subject
= $scope
.currentMailing
.name
;
562 $scope
.submitButton= function(){
563 $scope
.currentMailing
.approval_status_id
= "1";
564 $scope
.currentMailing
.approver_id
= $scope
.user_id
;
565 var currentdate
= new Date();
566 var yyyy
= currentdate
.getFullYear();
567 var mm
= currentdate
.getMonth() + 1;
568 mm
= mm
<10 ? '0' + mm
: mm
;
569 var dd
= currentdate
.getDate();
570 dd
= dd
<10 ? '0' + dd
: dd
;
571 var hh
= currentdate
.getHours();
572 hh
= hh
<10 ? '0' + hh
: hh
;
573 var min
= currentdate
.getMinutes();
574 min
= min
<10 ? '0' + min
: min
;
575 var sec
= currentdate
.getSeconds();
576 sec
= sec
<10 ? '0' + sec
: sec
;
577 $scope
.currentMailing
.approval_date
= yyyy
+ "/"+ mm
582 $scope
.currentMailing
.scheduled_date
= $scope
.currentMailing
.approval_date
;
584 $scope
.save_next_page3();
588 $scope
.$watch('pre',function(){
589 if($scope
.pre
==true){
590 $('#prevmail').dialog({
591 title
: 'Preview Mailing',
598 $scope
.pre
= false; $scope
.$apply();
604 $scope
.sendTest = function(){
605 var resulta
=crmApi('Mailing','send_test',{test_email
:$scope
.testMailing
.name
, test_group
:$scope
.testMailing
.group
,
606 mailing_id
:$scope
.currentMailing
.id
});
611 // Directive to go to the next tab
612 crmMailing
.directive('nexttab', function() {
615 link: function(scope
, element
, attrs
) {
616 var tabselector
= $(".crmMailingTabs");
617 var myarr
= new Array(1,2);
618 if(scope
.currentMailing
.id
==null){
619 tabselector
.tabs({disabled
:myarr
});
621 $(element
).on("click",function() {
623 var myArray1
= new Array( );
625 for ( var i
= scope
.maxtab
+ 1; i
< 3; i
++ ) {
629 tabselector
.tabs( "option", "disabled", myArray1
);
630 tabselector
.tabs({active
:scope
.tabact
});
637 // Directive to go to the previous tab
638 crmMailing
.directive('prevtab', function() {
641 link: function(scope
, element
, attrs
) {
642 var tabselector
= $(".crmMailingTabs");
644 $(element
).on("click",function() {
645 scope
.prevtabupdate();
647 var myArray1
= new Array( );
648 tabselector
.tabs({active
:scope
.tabact
});
655 // Select 2 Widget for selecting the included group
656 crmMailing
.directive('chsgroup',function(){
659 link: function(scope
,element
, attrs
){
660 function format(item
) {
662 // return `text` for optgroup
665 // return item template
666 var a
= item
.id
.split(" ");
667 if(a
[1]=="civicrm_group" && a
[2]=="include")
668 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
;
669 if(a
[1]=="civicrm_group" && a
[2]=="exclude")
670 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
;
671 if(a
[1]=="civicrm_mailing" && a
[2]=="include")
672 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
;
673 if(a
[1]=="civicrm_mailing" && a
[2]=="exclude")
674 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
;
679 placeholder
: "Choose Recipients",
680 formatResult
: format
,
681 formatSelection
: format
,
682 escapeMarkup: function(m
) { return m
; },
683 }).select2("data", scope
.incGroup
);
686 $(element
).on("select2-opening", function(){
692 $(element
).on('select2-selecting', function(e
) {
699 $(element
).on("select2-removed", function(e
) {
700 var index
= chck
.indexOf(e
.val
);
701 chck
.splice(index
, 1);
710 crmMailing
.directive('groupselect',function(){
713 link: function(scope
,element
, attrs
){
714 $(element
).select2({width
:"200px", data
: mltokens
, placeholder
:"Insert Token"});
715 $(element
).on('select2-selecting', function(e
) {
717 scope
.$evalAsync('_resetSelection()');
718 var a
= $(element
).attr('id');
720 if(scope
.currentMailing
.body_html
=="" || scope
.currentMailing
.body_html
== null)
721 scope
.currentMailing
.body_html
= e
.val
;
723 scope
.currentMailing
.body_html
+= e
.val
;
725 else if(a
=="subgroup"){
726 var msg
= document
.getElementById("sub").value
;
727 var cursorlen
= document
.getElementById("sub").selectionStart
;
728 var textlen
= msg
.length
;
729 document
.getElementById("sub").value
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
730 scope
.currentMailing
.subject
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
731 var cursorPos
= (cursorlen
+ e
.val
.length
);
732 document
.getElementById("sub").selectionStart
= cursorPos
;
733 document
.getElementById("sub").selectionEnd
= cursorPos
;
734 document
.getElementById("sub").focus();
736 else if(a
=="textgroup"){
737 var msg
= document
.getElementById("body_text").value
;
738 var cursorlen
= document
.getElementById("body_text").selectionStart
;
739 var textlen
= msg
.length
;
740 document
.getElementById("body_text").value
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
741 scope
.currentMailing
.body_text
= msg
.substring(0, cursorlen
) + e
.val
+ msg
.substring(cursorlen
, textlen
);
742 var cursorPos
= (cursorlen
+ e
.val
.length
);
743 document
.getElementById("body_text").selectionStart
= cursorPos
;
744 document
.getElementById("body_text").selectionEnd
= cursorPos
;
745 document
.getElementById("body_text").focus();
755 crmMailing
.directive('ckedit', function() {
758 link: function(scope
, elm
, attr
, ngModel
) {
759 var ck
= CKEDITOR
.replace(elm
[0]);
761 if (!ngModel
) return;
763 ck
.on('pasteState', function() {
764 scope
.$apply(function() {
765 ngModel
.$setViewValue(ck
.getData());
769 ngModel
.$render = function(value
) {
770 ck
.setData(ngModel
.$viewValue
);
776 // Used for the select date option. This is used for giving scheduled_date its date value
777 crmMailing
.directive('chsdate',function(){
780 link: function(scope
,element
,attrs
){
781 $(element
).datepicker({
782 dateFormat
: "yy-mm-dd",
783 onSelect: function(date
) {
784 $(".ui-datepicker a").removeAttr("href");
785 scope
.scheddate
.date
=date
.toString();
793 crmMailing
.directive('file', function(){
798 link: function(scope
, el
, attrs
){
799 el
.bind('change', function(event
){
800 var files
= event
.target
.files
;
802 scope
.file
= file
? file
: undefined;
810 crmMailing
.directive('checktimeentry',function(){
813 link: function (scope
, element
, attrs
) {
814 $(element
).timeEntry({show24Hours
:true});
820 //This controller is used for creating the mailing list. Simply gets all the mailing data from civiAPI
821 crmMailing
.controller('mailingListCtrl', function($scope
, crmApi
, mailingList
, $route
) {
826 $scope
.mailingList
= mailingList
.values
;
827 $scope
.checkEmpty = function(){
828 if($scope
.mailingList
== "")
833 $scope
.deleteMail = function (mail
) {
834 crmApi('Mailing', 'delete', {id
: mail
.id
}, {
835 error: function (data
) {
836 CRM
.alert(data
.error_message
, ts('Error'));
839 .then(function (data
) {
840 if (!data
.is_error
) {
841 delete mailingList
.values
[mail
.id
];
849 $scope
.edit = function (){
855 })(angular
, CRM
.$, CRM
._
);
858 [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 ( ) )