283a0a2353f518bb35a341a553e451e435569656
1 (function(angular
, $, _
) {
3 var partialUrl = function(relPath
) {
4 return CRM
.resourceUrls
['civicrm'] + '/partials/crmMailingType/' + relPath
;
7 var crmMailing
= angular
.module('crmMailing', ['ngRoute', 'ui.utils']);
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', {});
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 return {name
: "New Mail", visibility
: "Public Pages", url_tracking
:"1", forward_replies
:"0", created_id
: "202", auto_responder
:"0", open_tracking
:"1",
45 //-----------------------------------------
46 // Add a new record by name.
47 // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
53 crmMailing
.controller('mailingCtrl', function($scope
, crmApi
, selectedMail
) {
55 //Making some dummy api to see if my from email, reply to email works. To see if all options come in select
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'}
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
;
77 $scope
.testGroup
= [];
78 $scope
.currentMailing
= selectedMail
;
79 window
.ct
= $scope
.currentMailing
;
82 $scope
.trackreplies
="0";
85 $scope
.scheddate
.date
= "";
86 $scope
.scheddate
.time
= "";
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];
96 console
.log(selectedMail
);
97 $scope
.upldChange= function(composeS
){
105 $scope
.isHeader= function(hf
){
106 return hf
.component_type
== "Header";
109 $scope
.isFooter= function(f
){
110 return f
.component_type
== "Footer";
113 $scope
.isAuto= function(au
){
114 return au
.component_type
== "Reply";
117 $scope
.isUserDriven= function(mstemp
){
118 return (parseInt(mstemp
.id
)>58);
121 $scope
.trackr= function(trackreplies
){
122 if(trackreplies
=="1"){
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)) {
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
= "";
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
;
158 crmMailing
.directive('nexttab', function() {
162 link: function(scope
, element
, attrs
) {
164 $(element
).parent().parent().tabs();
166 $(element
).on("click",function() {
167 scope
.acttab
=scope
.acttab
+1;
168 $(element
).parent().parent().tabs({active
:scope
.acttab
});
175 crmMailing
.directive('prevtab', function() {
179 link: function(scope
, element
, attrs
) {
181 $(element
).parent().parent().tabs();
183 $(element
).on("click",function() {
184 scope
.acttab
=scope
.acttab
-1;
185 $(element
).parent().parent().tabs({active
:scope
.acttab
});
193 crmMailing
.directive('chsgroup',function(){
196 link: function(scope
,element
, attrs
){
199 placeholder
: "Include Group",
207 crmMailing
.directive('chsdate',function(){
213 link: function(scope
,element
,attrs
){
214 $(element
).datepicker({
215 dateFormat
: 'yy-mm-dd',
216 onSelect: function(date
) {
217 $(".ui-datepicker a").removeAttr("href");
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
236 $scope
.fileList
.push({name
: file
.name
})
239 // Begin upload immediately
245 crmMailing
.directive('add',function(){
248 link: function(scope
,element
, attrs
){
249 $(document
).ready(function(){
250 $('#fileupload').fileupload({
261 crmMailing
.controller('mailingListCtrl', function($scope
, crmApi
, mailingList
) {
262 $scope
.mailingList
= mailingList
.values
;
263 $scope
.mailStatus
= _
.pluck(CRM
.crmMailing
.mailStatus
, 'status');
266 })(angular
, CRM
.$, CRM
._
);