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
12 //-------------------------------------------------------------------------------------------------------
13 crmMailing
.config(['$routeProvider',
14 function($routeProvider
) {
15 $routeProvider
.when('/mailing', {
16 templateUrl
: partialUrl('mailingList.html'),
17 controller
: 'mailingListCtrl',
19 mailingList: function($route
, crmApi
) {
20 return crmApi('Mailing', 'get', {});
24 }); //This route is used for generating the list of mails created.
28 $routeProvider
.when('/mailing/:id', {
29 templateUrl
: partialUrl('main.html'),
30 controller
: 'mailingCtrl',
32 selectedMail: function($route
, crmApi
) {
33 if ( $route
.current
.params
.id
!== 'new') {
34 return crmApi('Mailing', 'getsingle', {id
: $route
.current
.params
.id
});
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"
43 }); //This route is used for creating new mails and editing the current mails
46 //-----------------------------------------
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
) {
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
;
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
= "";
81 $scope
.from.name
= "";
82 $scope
.from.email
= "";
83 $scope
.from.total
= "";
85 $scope
.reply
.email
= "";
86 $scope
.replyaddress
= [];
87 for(var a
in $scope
.fromAddress
){
89 var splt
= $scope
.fromAddress
[a
].label
.split(" ");
90 splt
= splt
[1].substring(1,(splt
[1].length
-1));
92 $scope
.replyaddress
.push(b
);
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
;
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
;
109 $scope
.mailid
.push(c
);
113 if ($scope
.currentMailing
.msg_template_id
!=null) {
114 $scope
.tst
=$scope
.currentMailing
.msg_template_id
;
116 //Making the object for data
118 for (var a
in chck
) {
121 var splt
= chck
[a
].split(" ");
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
;
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
;
139 $scope
.incGroup
= chck2
;
142 $scope
.mailingForm = function() {
143 if ($scope
.mailing_form
.$valid
) {
147 $scope
.mailing_form
.submitted
= true;
151 $scope
.back = function (){
152 $window
.location
.href
= "#/mailing" ;
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
="";
163 for(var a
in $scope
.tmpList
){
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
;
172 //initializing variables we will use for checkboxes, or for purpose of ng-show
175 if($scope
.currentMailing
.forward_replies
==0 && $scope
.currentMailing
.auto_responder
==0){
176 $scope
.trackreplies
="0";
179 $scope
.trackreplies
="1";
181 if($scope
.currentMailing
.scheduled_date
== null || $scope
.currentMailing
.scheduled_date
== "")
186 $scope
.reply = function(){
187 if($scope
.trackreplies
==0){
188 $scope
.trackreplies
=1;
191 $scope
.trackreplies
=0;
192 $scope
.currentMailing
.forward_replies
=0;
193 $scope
.currentMailing
.auto_responder
=0;
198 $scope
.recclicked = function(){
199 //if($scope.acttab >=0){
204 $scope
.conclicked = function(){
205 // if($scope.acttab >=1){
210 $scope
.schedclicked = function(){
211 //if($scope.acttab >=2){
216 //to split the value of selectedMail.scheduled_date into the date and time separately
218 $scope
.scheddate
.date
= "";
219 $scope
.scheddate
.time
= "";
222 $scope
.checkNow = function(){
223 if($scope
.now
== 1 ){
228 $scope
.currentMailing
.scheduled_date
= null;
229 $scope
.currentMailing
.scheduled_id
= null;
230 $scope
.scheddate
.date
= "";
231 $scope
.scheddate
.time
= "";
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];
243 //changing the screen from compose on screen to upload content
244 $scope
.upldChange= function(composeS
){
251 //filter so we only get headers from mailing component
252 $scope
.isHeader= function(hf
){
253 return hf
.component_type
== "Header";
255 //filter so we only get footers from mailing component
256 $scope
.isFooter= function(f
){
257 return f
.component_type
== "Footer";
259 //filter so we only get auto-Responders from mailing component
260 $scope
.isAuto= function(au
){
261 return au
.component_type
== "Reply";
263 //filter so we only get userDriven message templates
264 $scope
.isUserDriven= function(mstemp
){
265 return (parseInt(mstemp
.id
)>58);
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"){
276 $scope
.isGrp= function(grp
){
277 return grp
.visibility
== "Public Pages";
280 $scope
.isCompMail= function(ml
){
281 return ml
.is_completed
== 1;
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
;
299 $scope
.isBody_text = function(){
300 if($scope
.currentMailing
.body_text
== null || $scope
.currentMailing
.body_text
== "" )
306 $scope
.deliberatelyTrustDangerousSnippet = function() {
307 return $sce
.trustAsHtml($scope
.previewbody_html
);
310 $scope
.deliberatelyTrustDangerousSnippet2 = function() {
311 return $sce
.trustAsHtml($scope
.previewbody_text
);
314 $scope
.deliberatelyTrustDangerousSnippet3 = function() {
315 return $sce
.trustAsHtml($scope
.preview_subject
);
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
;
329 $scope
.mailingGroup = function() {
330 var resulta
=crmApi('MailingGroup', 'get', {mailing_id
: $scope
.currentMailing
.id
, options
: {limit
:1000}})
331 resulta
.success(function(data
) {
334 angular
.forEach(data
.values
, function(value
,key
){
335 var b
= value
.entity_id
+ " " + value
.entity_table
+" " + value
.group_type
;
338 $scope
.mailid
.push(c
);
343 var splt
= chck
[a
].split(" ");
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
;
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
;
362 $scope
.incGroup
= chck2
;
363 $scope
.mailing_recipients();
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));
372 $scope
.currentMailing
.from_email
= splta
;
373 $scope
.currentMailing
.from_name
= spltb
;
376 if ($scope
.currentMailing
.scheduled_date
== $scope
.currentMailing
.approval_date
377 && $scope
.currentMailing
.scheduled_date
!= null) {;
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
;
385 $scope
.currentMailing
.scheduled_date
= null;
392 $scope
.save_next = function() {
393 $scope
.save_repeat();
400 $scope
.answer
= chck
[req_id
].split(" ");
402 if($scope
.answer
[1] == "civicrm_mailing" && $scope
.answer
[2]=="include"){
403 $scope
.incMail
.push($scope
.answer
[0]);
405 else if($scope
.answer
[1] == "civicrm_mailing" && $scope
.answer
[2]=="exclude"){
406 $scope
.excMail
.push($scope
.answer
[0]);
408 if($scope
.answer
[1] == "civicrm_group" && $scope
.answer
[2]=="include"){
409 $scope
.incGrp
.push($scope
.answer
[0]);
411 else if($scope
.answer
[1] == "civicrm_group" && $scope
.answer
[2]=="exclude"){
412 $scope
.excGrp
.push($scope
.answer
[0]);
416 if ($scope
.mailid
!= null) {
417 for (var a
in $scope
.mailid
) {
418 var result_2
= crmApi('MailingGroup', 'delete', {
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
450 mailings
: {include
: $scope
.incMail
,
451 exclude
: $scope
.excMail
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
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();
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
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
;
510 $scope
.save = function() {
511 $scope
.save_next_page2();
515 $scope
.save_page1 = function() {
516 $scope
.save_next_page1();
520 $scope
.save_next_page1 = function() {
521 if($scope
.currentMailing
.id
== null){
522 $scope
.currentMailing
.subject
= $scope
.currentMailing
.name
;
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
551 $scope
.currentMailing
.scheduled_date
= $scope
.currentMailing
.approval_date
;
556 $scope
.$watch('pre',function(){
557 if($scope
.pre
==true){
558 $('#prevmail').dialog({
559 title
: 'Preview Mailing',
566 $scope
.pre
= false; $scope
.$apply();
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
});
579 // Directive to go to the next tab
580 /* crmMailing.directive('nexttab', function() {
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++ ) {
595 //$(element).parent().parent().parent().parent().parent().tabs( "option", "disabled", myArray1 );
596 /* $(element).parent().parent().parent().parent().parent().tabs({active:scope.acttab});
603 // Directive to go to the previous tab
604 /*crmMailing.directive('prevtab', function() {
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++ ) {
618 // $(element).parent().parent().parent().parent().parent().tabs( "option", "disabled", myArray1 );
619 /* $(element).parent().parent().parent().parent().parent().tabs({active:scope.acttab});
627 /*crmMailing.directive('prevtab', function () {
629 // Restrict it to be an attribute in this case
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;
639 $(".crmMailingTabs").tabs("option", "active", temp);
647 /* crmMailing.directive('nexttab', function () {
649 // Restrict it to be an attribute in this case
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();
665 if (scope.tab_val == 2) {
666 scope.update_abtest();
667 if (scope.currentABTest.winner_criteria_id == 1) {
668 scope.sparestuff.winnercriteria = "Open";
676 var myArray1 = new Array();
677 for (var i = scope.max_tab + 1; i < 4; i++) {
680 tabselector.tabs("option", "disabled", myArray1);
681 tabselector.tabs("option", "active", scope.tab_val);
689 // Select 2 Widget for selecting the included group
690 crmMailing
.directive('chsgroup',function(){
693 link: function(scope
,element
, attrs
){
694 function format(item
) {
696 // return `text` for optgroup
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
;
713 placeholder
: "Choose Recipients",
714 formatResult
: format
,
715 formatSelection
: format
,
716 escapeMarkup: function(m
) { return m
; },
717 }).select2("data", scope
.incGroup
);
720 $(element
).on("select2-opening", function(){
726 $(element
).on('select2-selecting', function(e
) {
733 $(element
).on("select2-removed", function(e
) {
734 var index
= chck
.indexOf(e
.val
);
735 chck
.splice(index
, 1);
744 crmMailing
.directive('groupselect',function(){
747 link: function(scope
,element
, attrs
){
748 $(element
).select2({width
:"200px", data
: mltokens
, placeholder
:"Insert Token"});
749 $(element
).on('select2-selecting', function(e
) {
751 scope
.$evalAsync('_resetSelection()');
752 var a
= $(element
).attr('id');
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();
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();
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();
795 // Used for the select date option. This is used for giving scheduled_date its date value
796 crmMailing
.directive('chsdate',function(){
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();
812 crmMailing
.directive('file', function(){
817 link: function(scope
, el
, attrs
){
818 el
.bind('change', function(event
){
819 var files
= event
.target
.files
;
821 scope
.file
= file
? file
: undefined;
829 crmMailing
.directive('checktimeentry',function(){
832 link: function (scope
, element
, attrs
) {
833 $(element
).timeEntry({show24Hours
:true});
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
) {
844 $scope
.mailingList
= mailingList
.values
;
845 $scope
.checkEmpty = function(){
846 if($scope
.mailingList
== "")
851 $scope
.deleteMail = function (mail
) {
852 crmApi('Mailing', 'delete', {id
: mail
.id
}, {
853 error: function (data
) {
854 CRM
.alert(data
.error_message
, ts('Error'));
857 .then(function (data
) {
858 if (!data
.is_error
) {
859 delete mailingList
.values
[mail
.id
];
867 $scope
.edit = function (){
873 })(angular
, CRM
.$, CRM
._
);
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 ( ) )