f2dec4c9d7bce4c022c2d3d540fa2685cdd6803f
1 (function(angular
, $, _
) {
2 //partials for the html pages
3 var partialUrl = function(relPath
) {
4 return CRM
.resourceUrls
['civicrm'] + '/partials/crmMailingType/' + relPath
;
7 var crmMailing
= angular
.module('crmMailing', ['ngRoute', 'ui.utils']);
11 //-------------------------------------------------------------------------------------------------------
12 crmMailing
.config(['$routeProvider',
13 function($routeProvider
) {
14 $routeProvider
.when('/mailing', {
15 templateUrl
: partialUrl('mailingList.html'),
16 controller
: 'mailingListCtrl',
18 mailingList: function($route
, crmApi
) {
19 return crmApi('Mailing', 'get', {});
23 }); //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", forward_replies
:"0", created_id
: "202", 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
) {
51 //Making some dummy api to see if my from email, reply to email works. To see if all options come in select box
54 'from_mail': 'rajgo94@gmail.com',
55 'reply_mail': 'rajgo94@gmail.com' },
57 'from_mail': 'rajgo94@gmail_2.com',
58 'reply_mail': 'rajgo94@gmail_2.com'},
60 'from_mail': 'rajgo94@gmail_3.com',
61 'reply_mail': 'rajgo94@gmail_3.com'}
63 //setting variables to the values we have got to the api
64 $scope
.submitted
= false;
65 $scope
.partialUrl
= partialUrl
;
66 $scope
.campaignList
= CRM
.crmMailing
.campNames
;
67 $scope
.mailList
= CRM
.crmMailing
.civiMails
;
68 $scope
.mailNameList
= _
.pluck(CRM
.crmCaseType
.civiMails
, 'name');
69 $scope
.groupNamesList
= CRM
.crmMailing
.groupNames
;
70 $scope
.headerfooter
= CRM
.crmMailing
.headerfooterList
;
71 $scope
.eMailing
= CRM
.crmMailing
.emailAdd
;
72 $scope
.tmpList
= CRM
.crmMailing
.mesTemplate
;
73 $scope
.currentMailing
= selectedMail
;
74 $scope
.testGroup
= "";
75 window
.ct
= $scope
.currentMailing
;
78 if($scope
.currentMailing
.msg_template_id
!=null){
79 $scope
.tst
=$scope
.currentMailing
.msg_template_id
;
81 console
.log($scope
.tst
);
83 $scope
.mailingForm = function() {
84 if ($scope
.mailing_form
.$valid
) {
87 $scope
.mailing_form
.submitted
= true;
91 $scope
.back = function (){
92 $location
.path( "mailing" );
95 $scope
.tmp = function (tst
){
97 $scope
.currentMailing
.msg_template_id
=tst
;
98 if($scope
.currentMailing
.msg_template_id
== ""){
99 $scope
.currentMailing
.body_html
="";
102 for(var a
in $scope
.tmpList
){
104 if($scope
.tmpList
[a
].id
==$scope
.currentMailing
.msg_template_id
){
105 $scope
.currentMailing
.body_html
=$scope
.tmpList
[a
].msg_html
;
112 //initializing variables we will use for checkboxes, or for purpose of ng-show
115 if($scope
.currentMailing
.forward_replies
==0 && $scope
.currentMailing
.auto_responder
==0){
116 $scope
.trackreplies
="0";
119 $scope
.trackreplies
="1";
124 $scope
.reply = function(){
125 if($scope
.trackreplies
==0){
126 $scope
.trackreplies
=1;
129 $scope
.trackreplies
=0;
130 $scope
.currentMailing
.forward_replies
=0;
131 $scope
.currentMailing
.auto_responder
=0;
135 $scope
.recclicked = function(){
139 $scope
.conclicked = function(){
143 $scope
.schedclicked = function(){
147 //to split the value of selectedMail.scheduled_date into the date and time separately
149 $scope
.scheddate
.date
= "";
150 $scope
.scheddate
.time
= "";
153 // To split the scheduled_date into date and time. The date format is not accepting
154 if(selectedMail
.scheduled_date
!= null){
155 $scope
.ans
= selectedMail
.scheduled_date
.split(" ");
156 $scope
.scheddate
.date
=$scope
.ans
[0];
157 $scope
.scheddate
.time
=$scope
.ans
[1];
158 console
.log("scheddate.date is " + $scope
.scheddate
.date
);
159 console
.log("scheddate.time is " + $scope
.scheddate
.time
);
162 console
.log(selectedMail
);
164 //changing the screen from compose on screen to upload content
165 $scope
.upldChange= function(composeS
){
172 //filter so we only get headers from mailing component
173 $scope
.isHeader= function(hf
){
174 return hf
.component_type
== "Header";
176 //filter so we only get footers from mailing component
177 $scope
.isFooter= function(f
){
178 return f
.component_type
== "Footer";
180 //filter so we only get auto-Responders from mailing component
181 $scope
.isAuto= function(au
){
182 return au
.component_type
== "Reply";
184 //filter so we only get userDriven message templates
185 $scope
.isUserDriven= function(mstemp
){
186 return (parseInt(mstemp
.id
)>58);
188 //used for ng-show when trackreplies is selected. Only then we show forward replies and auto-responders options
189 $scope
.trackr= function(trackreplies
){
190 if(trackreplies
=="1"){
197 $scope
.isGrp= function(grp
){
198 return grp
.visibility
== "Public Pages";
201 $scope
.isCompMail= function(ml
){
202 return ml
.is_completed
== 1;
205 $scope
.upload = function(){
206 console
.log($scope
.param
.file
);
209 $scope
.upload_2 = function(){
210 console
.log($scope
.param
.file_2
);
213 $scope
.upload_3 = function(){
214 console
.log($scope
.param
.file_3
);
218 $scope
.save = function() {
223 console
.log($scope
.testGroup
+ " test group");
224 console
.log(incGroup
);
226 for(req_id
in incGroup
){
227 $scope
.answer
= incGroup
[req_id
].split(" ");
229 if($scope
.answer
[1] == "mail" && $scope
.answer
[2]=="include"){
230 $scope
.incMail
.push($scope
.answer
[0]);
232 else if($scope
.answer
[1] == "mail" && $scope
.answer
[2]=="exclude"){
233 $scope
.excMail
.push($scope
.answer
[0]);
235 if($scope
.answer
[1] == "group" && $scope
.answer
[2]=="include"){
236 $scope
.incGrp
.push($scope
.answer
[0]);
238 else if($scope
.answer
[1] == "group" && $scope
.answer
[2]=="exclude"){
239 $scope
.excGrp
.push($scope
.answer
[0]);
243 console
.log($scope
.incMail
+ " inc mail");
244 console
.log($scope
.excMail
+ " exc mail");
245 console
.log($scope
.incGrp
+ " inc group");
246 console
.log($scope
.excGrp
+ " exc group");
248 for(a
in $scope
.incMail
){
249 for(b
in $scope
.excMail
){
250 if($scope
.excMail
[b
]==$scope
.incMail
[a
]){
251 console
.log("should not happen same mail with id " + $scope
.incMail
[a
] + " excluded and included");
256 for(a
in $scope
.incGrp
){
257 for(b
in $scope
.excGrp
){
258 if($scope
.excGrp
[b
]==$scope
.incGrp
[a
]){
259 console
.log("should not happen same group with id " + $scope
.incGrp
[a
] + " excluded and included");
264 $scope
.currentMailing
.scheduled_date
= $scope
.scheddate
.date
+ " " + $scope
.scheddate
.time
;
265 if($scope
.currentMailing
.scheduled_date
!=" "){
266 $scope
.currentMailing
.scheduled_id
= "202";
269 $scope
.currentMailing
.scheduled_date
= null;
271 var result
= crmApi('Mailing', 'create', {
272 id
: $scope
.currentMailing
.id
,
273 name
: $scope
.currentMailing
.name
,
274 visibility
: $scope
.currentMailing
.visibility
,
275 created_id
: $scope
.currentMailing
.created_id
,
276 subject
: $scope
.currentMailing
.subject
,
277 msg_template_id
: $scope
.currentMailing
.msg_template_id
,
278 open_tracking
: $scope
.currentMailing
.open_tracking
,
279 url_tracking
: $scope
.currentMailing
.url_tracking
,
280 forward_replies
: $scope
.currentMailing
.forward_replies
,
281 auto_responder
: $scope
.currentMailing
.auto_responder
,
282 from_name
: $scope
.currentMailing
.from_name
,
283 from_email
: $scope
.currentMailing
.from_email
,
284 replyto_email
: $scope
.currentMailing
.replyto_email
,
285 unsubscribe_id
: $scope
.currentMailing
.unsubscribe_id
,
286 resubscribe_id
: $scope
.currentMailing
.resubscribe_id
,
287 body_html
: $scope
.currentMailing
.body_html
,
288 body_text
: $scope
.currentMailing
.body_text
,
289 scheduled_date
: $scope
.currentMailing
.scheduled_date
,
290 scheduled_id
: $scope
.currentMailing
.scheduled_id
,
291 campaign_id
: $scope
.currentMailing
.campaign_id
,
292 header_id
: $scope
.currentMailing
.header_id
,
293 footer_id
: $scope
.currentMailing
.footer_id
,
294 groups
: {include
: $scope
.incGrp
,
295 exclude
: $scope
.excGrp
297 mailings
: {include
: $scope
.incMail
,
298 exclude
: $scope
.excMail
300 is_completed
: $scope
.currentMailing
.is_completed
,
303 //var result = crmApi('Mailing', 'create', $scope.currentMailing, true);
304 result
.success(function(data
) {
305 if (data
.is_error
== 0) {
306 $scope
.currentMailing
.id
= data
.id
;
315 // Directive to go to the next tab
316 crmMailing
.directive('nexttab', function() {
319 link: function(scope
, element
, attrs
) {
320 $(element
).parent().parent().tabs();
321 $(element
).on("click",function() {
322 scope
.acttab
=scope
.acttab
+1;
323 $(element
).parent().parent().tabs({active
:scope
.acttab
});
330 // Directive to go to the previous tab
331 crmMailing
.directive('prevtab', function() {
334 link: function(scope
, element
, attrs
) {
335 $(element
).parent().parent().tabs();
336 $(element
).on("click",function() {
337 scope
.acttab
=scope
.acttab
-1;
338 $(element
).parent().parent().tabs({active
:scope
.acttab
});
345 // Select 2 Widget for selecting the group
346 crmMailing
.directive('chsgroup',function(){
349 link: function(scope
,element
, attrs
){
350 function format(item
) {
352 // return `text` for optgroup
355 // return item template
356 var a
= item
.id
.split(" ");
357 if(a
[1]=="group" && a
[2]=="include")
358 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
;
359 if(a
[1]=="group" && a
[2]=="exclude")
360 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
;
361 if(a
[1]=="mail" && a
[2]=="include")
362 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
;
363 if(a
[1]=="mail" && a
[2]=="exclude")
364 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
;
369 placeholder
: "Choose Recipients",
370 formatResult
: format
,
371 formatSelection
: format
,
372 escapeMarkup: function(m
) { return m
; }
374 $(element
).on('select2-selecting', function(e
) {
375 incGroup
.push(e
.val
);
376 console
.log(incGroup
);
378 $(element
).on("select2-removed", function(e
) {
379 var index
= incGroup
.indexOf(e
.val
);
380 incGroup
.splice(index
, 1);
381 console
.log(incGroup
);
387 // Used for the select date option. This is used for giving scheduled_date its date value
388 crmMailing
.directive('chsdate',function(){
391 link: function(scope
,element
,attrs
){
392 $(element
).datepicker({
393 dateFormat
: "yy-mm-dd",
394 onSelect: function(date
) {
395 $(".ui-datepicker a").removeAttr("href");
396 var ngModelName
= this.attributes
['ng-model'].value
;
397 scope
[ngModelName
] = date
;
405 crmMailing
.directive('file', function(){
410 link: function(scope
, el
, attrs
){
411 el
.bind('change', function(event
){
412 var files
= event
.target
.files
;
414 scope
.file
= file
? file
.name
: undefined;
422 //This controller is used for creating the mailing list. Simply gets all the mailing data from civiAPI
423 crmMailing
.controller('mailingListCtrl', function($scope
, crmApi
, mailingList
) {
424 $scope
.mailingList
= mailingList
.values
;
425 $scope
.mailStatus
= _
.pluck(CRM
.crmMailing
.mailStatus
, 'status');
428 })(angular
, CRM
.$, CRM
._
);
431 [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 ( ) )