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']);
9 //-------------------------------------------------------------------------------------------------------
10 crmMailing
.config(['$routeProvider',
11 function($routeProvider
) {
12 $routeProvider
.when('/mailing', {
13 templateUrl
: partialUrl('mailingList.html'),
14 controller
: 'mailingListCtrl',
16 mailingList: function($route
, crmApi
) {
17 return crmApi('Mailing', 'get', {});
21 }); //This route is used for generating the list of mails created.
25 $routeProvider
.when('/mailing/:id', {
26 templateUrl
: partialUrl('main.html'),
27 controller
: 'mailingCtrl',
29 selectedMail: function($route
, crmApi
) {
30 if ( $route
.current
.params
.id
!== 'new') {
31 return crmApi('Mailing', 'getsingle', {id
: $route
.current
.params
.id
});
34 //created_id has been set to my id. Does not save without created_id. Needs to made generic based on the user
35 return {name
: "New Mail", visibility
: "Public Pages", url_tracking
:"1", forward_replies
:"0", created_id
: "202", auto_responder
:"0", open_tracking
:"1",
40 }); //This route is used for creating new mails and editing the current mails
43 //-----------------------------------------
46 //This controller is used in creating new mail and editing current mails
47 crmMailing
.controller('mailingCtrl', function($scope
, crmApi
, selectedMail
) {
49 //Making some dummy api to see if my from email, reply to email works. To see if all options come in select box
52 'from_mail': 'rajgo94@gmail.com',
53 'reply_mail': 'rajgo94@gmail.com' },
55 'from_mail': 'rajgo94@gmail_2.com',
56 'reply_mail': 'rajgo94@gmail_2.com'},
58 'from_mail': 'rajgo94@gmail_3.com',
59 'reply_mail': 'rajgo94@gmail_3.com'}
61 //setting variables to the values we have got to the api
62 $scope
.partialUrl
= partialUrl
;
63 $scope
.campaignList
= CRM
.crmMailing
.campNames
;
64 $scope
.mailNameList
= _
.pluck(CRM
.crmCaseType
.civiMails
, 'name');
65 $scope
.groupNamesList
= CRM
.crmMailing
.groupNames
;
66 $scope
.headerfooter
= CRM
.crmMailing
.headerfooterList
;
67 $scope
.tmpList
= CRM
.crmMailing
.mesTemplate
;
68 $scope
.currentMailing
= selectedMail
;
69 window
.ct
= $scope
.currentMailing
;
71 //initializing variables we will use for checkboxes, or for purpose of ng-show
74 $scope
.trackreplies
="0";
77 //to split the value of selectedMail.scheduled_date into the date and time separately
79 $scope
.scheddate
.date
= "";
80 $scope
.scheddate
.time
= "";
84 $scope
.mailAutoResponder
="";
85 // To split the scheduled_date into date and time. The date format is not accepting
86 /* if(selectedMail.scheduled_date != ""){
87 $scope.ans= selectedMail.scheduled_date.split(" ");
88 $scope.scheddate.date=$scope.ans[0];
89 $scope.scheddate.time=$scope.ans[1];
92 console
.log(selectedMail
);
94 //changing the screen from compose on screen to upload content
95 $scope
.upldChange= function(composeS
){
102 //filter so we only get headers from mailing component
103 $scope
.isHeader= function(hf
){
104 return hf
.component_type
== "Header";
106 //filter so we only get footers from mailing component
107 $scope
.isFooter= function(f
){
108 return f
.component_type
== "Footer";
110 //filter so we only get auto-Responders from mailing component
111 $scope
.isAuto= function(au
){
112 return au
.component_type
== "Reply";
114 //filter so we only get userDriven message templates
115 $scope
.isUserDriven= function(mstemp
){
116 return (parseInt(mstemp
.id
)>58);
118 //used for ng-show when trackreplies is selected. Only then we show forward replies and auto-responders options
119 $scope
.trackr= function(trackreplies
){
120 if(trackreplies
=="1"){
127 $scope
.isGrp= function(grp
){
128 return grp
.visibility
== "Public Pages";
132 $scope
.save = function() {
133 $scope
.currentMailing
.scheduled_date
= $scope
.scheddate
.date
+ " " + $scope
.scheddate
.time
;
134 if($scope
.currentMailing
.scheduled_date
!=" "){
135 $scope
.currentMailing
.scheduled_id
= "202";
138 $scope
.currentMailing
.scheduled_date
= "";
140 var result
= crmApi('Mailing', 'create', $scope
.currentMailing
, true);
141 result
.success(function(data
) {
142 if (data
.is_error
== 0) {
143 $scope
.currentMailing
.id
= data
.id
;
152 // Directive to go to the next tab
153 crmMailing
.directive('nexttab', function() {
156 link: function(scope
, element
, attrs
) {
157 $(element
).parent().parent().tabs();
158 $(element
).on("click",function() {
159 scope
.acttab
=scope
.acttab
+1;
160 $(element
).parent().parent().tabs({active
:scope
.acttab
});
167 // Directive to go to the previous tab
168 crmMailing
.directive('prevtab', function() {
171 link: function(scope
, element
, attrs
) {
172 $(element
).parent().parent().tabs();
173 $(element
).on("click",function() {
174 scope
.acttab
=scope
.acttab
-1;
175 $(element
).parent().parent().tabs({active
:scope
.acttab
});
182 // Select 2 Widget for selecting the group
183 crmMailing
.directive('chsgroup',function(){
186 link: function(scope
,element
, attrs
){
189 placeholder
: "Include Group",
195 // Used for the select date option. This is used for giving scheduled_date its date value
196 crmMailing
.directive('chsdate',function(){
202 link: function(scope
,element
,attrs
){
203 $(element
).datepicker({
204 dateFormat
: 'yy-mm-dd',
205 onSelect: function(date
) {
206 $(".ui-datepicker a").removeAttr("href");
215 //browsing controller. to add selected files. not working currently
216 crmMailing.controller('browse', function($scope){
217 $scope.fileList = [];
218 $('#fileupload').bind('fileuploadadd', function(e, data){
219 // Add the files to the list
220 numFiles = $scope.fileList.length
221 for (var i=0; i < data.files.length; ++i) {
222 var file = data.files[i];
223 // .$apply to update angular when something else makes changes
225 $scope.fileList.push({name: file.name})
228 // Begin upload immediately
233 //adding directive. to add selected files. not working currently
234 crmMailing.directive('add',function(){
237 link: function(scope,element, attrs){
238 $(document).ready(function(){
239 $('#fileupload').fileupload({
247 //This controller is used for creating the mailing list. Simply gets all the mailing data from civiAPI
248 crmMailing
.controller('mailingListCtrl', function($scope
, crmApi
, mailingList
) {
249 $scope
.mailingList
= mailingList
.values
;
250 $scope
.mailStatus
= _
.pluck(CRM
.crmMailing
.mailStatus
, 'status');
253 })(angular
, CRM
.$, CRM
._
);