283a0a2353f518bb35a341a553e451e435569656
[civicrm-core.git] / js / angular-newMailing.js
1 (function(angular, $, _) {
2
3 var partialUrl = function(relPath) {
4 return CRM.resourceUrls['civicrm'] + '/partials/crmMailingType/' + relPath;
5 };
6
7 var crmMailing = angular.module('crmMailing', ['ngRoute', 'ui.utils']);
8
9
10
11
12 //-------------------------------------------------------------------------------------------------------
13 crmMailing.config(['$routeProvider',
14 function($routeProvider) {
15 $routeProvider.when('/mailing', {
16 templateUrl: partialUrl('mailingList.html'),
17 controller: 'mailingListCtrl',
18 resolve: {
19 mailingList: function($route, crmApi) {
20 return crmApi('Mailing', 'get', {});
21 }
22
23 }
24 });
25
26
27
28 $routeProvider.when('/mailing/:id', {
29 templateUrl: partialUrl('main.html'),
30 controller: 'mailingCtrl',
31 resolve: {
32 selectedMail: function($route, crmApi) {
33 if ( $route.current.params.id !== 'new') {
34 return crmApi('Mailing', 'getsingle', {id: $route.current.params.id});
35 }
36 else {
37 return {name: "New Mail", visibility: "Public Pages", url_tracking:"1", forward_replies:"0", created_id: "202", auto_responder:"0", open_tracking:"1",
38 };
39 }
40 }
41 }
42 });
43 }
44 ]);
45 //-----------------------------------------
46 // Add a new record by name.
47 // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
48
49
50
51
52
53 crmMailing.controller('mailingCtrl', function($scope, crmApi, selectedMail) {
54
55 //Making some dummy api to see if my from email, reply to email works. To see if all options come in select
56 //
57 $scope.cool_api= [
58 {'name': 'Nexus S',
59 'from_mail': 'rajgo94@gmail.com',
60 'reply_mail': 'rajgo94@gmail.com' },
61 {'name': 'Motorola XOOMâ„¢ with Wi-Fi',
62 'from_mail': 'rajgo94@gmail2.com',
63 'reply_mail': 'rajgo94@gmail2.com'},
64 {'name': 'MOTOROLA XOOMâ„¢',
65 'from_mail': 'rajgo94@gmail3.com',
66 'reply_mail': 'rajgo94@gmail3.com'}
67 ];
68
69 $scope.partialUrl = partialUrl;
70 $scope.campaignList = CRM.crmMailing.campNames;
71 $scope.mailNameList = _.pluck(CRM.crmCaseType.civiMails, 'name');
72 $scope.groupNamesList = CRM.crmMailing.groupNames;
73 $scope.headerfooter = CRM.crmMailing.headerfooterList;
74 $scope.tmpList = CRM.crmMailing.mesTemplate;
75 $scope.incGroup = [];
76 $scope.excGroup = [];
77 $scope.testGroup = [];
78 $scope.currentMailing = selectedMail;
79 window.ct = $scope.currentMailing;
80 $scope.acttab=0;
81 $scope.composeS="1";
82 $scope.trackreplies="0";
83 $scope.now="1";
84 $scope.scheddate={};
85 $scope.scheddate.date = "";
86 $scope.scheddate.time = "";
87 $scope.ans="";
88 $scope.mailAutoResponder="";
89 ///changing upload on screen
90 /* if(selectedMail.scheduled_date != ""){
91 $scope.ans= selectedMail.scheduled_date.split(" ");
92 $scope.scheddate.date=$scope.ans[0];
93 $scope.scheddate.time=$scope.ans[1];
94 }*/
95
96 console.log(selectedMail);
97 $scope.upldChange= function(composeS){
98 if(composeS=="1"){
99 return true;
100 }
101 else
102 return false;
103 }
104
105 $scope.isHeader= function(hf){
106 return hf.component_type == "Header";
107 };
108
109 $scope.isFooter= function(f){
110 return f.component_type == "Footer";
111 };
112
113 $scope.isAuto= function(au){
114 return au.component_type == "Reply";
115 };
116
117 $scope.isUserDriven= function(mstemp){
118 return (parseInt(mstemp.id)>58);
119 };
120
121 $scope.trackr= function(trackreplies){
122 if(trackreplies=="1"){
123 return true;
124 }
125 else
126 return false;
127 }
128
129 /// Add a new group to mailing
130 /* $scope.addGroup = function(grp, groupName) {
131 var names = _.pluck(CRM.crmMailing.groupNames, 'name');
132 if (!_.contains(names, groupName)) {
133 grp.push({
134 name: groupName
135 });
136 }
137 }; */
138
139 $scope.save = function() {
140 $scope.currentMailing.scheduled_date= $scope.scheddate.date + " " + $scope.scheddate.time ;
141 if($scope.currentMailing.scheduled_date!=" "){
142 $scope.currentMailing.scheduled_id= "202";
143 $scope.currentMailing.scheduled_date= "";
144 }
145 var result = crmApi('Mailing', 'create', $scope.currentMailing, true);
146 result.success(function(data) {
147 if (data.is_error == 0) {
148 $scope.currentMailing.id = data.id;
149 console.log("OK");
150 }
151 console.log("OK2");
152 });
153 };
154 });
155
156
157
158 crmMailing.directive('nexttab', function() {
159 return {
160
161 restrict: 'A',
162 link: function(scope, element, attrs) {
163
164 $(element).parent().parent().tabs();
165
166 $(element).on("click",function() {
167 scope.acttab=scope.acttab +1;
168 $(element).parent().parent().tabs({active:scope.acttab});
169 console.log("sid");
170 });
171 }
172 };
173 });
174
175 crmMailing.directive('prevtab', function() {
176 return {
177
178 restrict: 'A',
179 link: function(scope, element, attrs) {
180
181 $(element).parent().parent().tabs();
182
183 $(element).on("click",function() {
184 scope.acttab=scope.acttab -1;
185 $(element).parent().parent().tabs({active:scope.acttab});
186 console.log("sid");
187 });
188 }
189 };
190 });
191
192
193 crmMailing.directive('chsgroup',function(){
194 return {
195 restrict : 'AE',
196 link: function(scope,element, attrs){
197 $(element).select2(
198 {width:"400px",
199 placeholder: "Include Group",
200 });
201 }
202 };
203
204 });
205
206
207 crmMailing.directive('chsdate',function(){
208 return {
209 scope :{
210 dat : '=send_date'
211 },
212 restrict: 'AE',
213 link: function(scope,element,attrs){
214 $(element).datepicker({
215 dateFormat: 'yy-mm-dd',
216 onSelect: function(date) {
217 $(".ui-datepicker a").removeAttr("href");
218 scope.dat =date;
219 }
220 });
221 }
222 };
223 });
224
225
226
227 crmMailing.controller('browse', function($scope){
228 $scope.fileList = [];
229 $('#fileupload').bind('fileuploadadd', function(e, data){
230 // Add the files to the list
231 numFiles = $scope.fileList.length
232 for (var i=0; i < data.files.length; ++i) {
233 var file = data.files[i];
234 // .$apply to update angular when something else makes changes
235 $scope.$apply(
236 $scope.fileList.push({name: file.name})
237 );
238 }
239 // Begin upload immediately
240 data.submit();
241 });
242 });
243
244
245 crmMailing.directive('add',function(){
246 return {
247 restrict : 'AE',
248 link: function(scope,element, attrs){
249 $(document).ready(function(){
250 $('#fileupload').fileupload({
251 dataType: 'json'
252 });
253 });
254
255
256 }
257 };
258 });
259
260
261 crmMailing.controller('mailingListCtrl', function($scope, crmApi, mailingList) {
262 $scope.mailingList = mailingList.values;
263 $scope.mailStatus = _.pluck(CRM.crmMailing.mailStatus, 'status');
264 });
265
266 })(angular, CRM.$, CRM._);
267
268
269