Blame view

app/partials/viewcontact/viewcontact.controller.js 10.3 KB
3cab9e8a3   Rishav   implement view co...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acufuel')
1b71872b2   Kuldeep Arora   email and code be...
5
      .controller('viewcontactController', ['$scope', '$rootScope', '$stateParams', '$state', 'ViewcontactService', 'ViewCompanyService', function($scope, $rootScope, $stateParams, $state, ViewcontactService, ViewCompanyService) {
956e0d9ed   Swarn Singh   contact view effe...
6
7
8
9
10
11
12
13
14
15
  
          $(document).ready(function() {
              $('.animation_select').click( function(){
                  $('#animation_box').removeAttr('class').attr('class', '');
                  var animation = $(this).attr("data-animation");
                  $('#animation_box').addClass('animated');
                  $('#animation_box').addClass(animation);
                  return false;
              });
          });
67c7d62d3   Swarn Singh   view contact page...
16
17
          $scope.showLoader = true;
          $scope.showUpdateBtn = false;
1b71872b2   Kuldeep Arora   email and code be...
18
19
          var contactId = $stateParams.id;
          $scope.contactDetail = {};
d1fe89776   Rishav Singla   view fuel vendor ...
20
          var contactCompanyId = "";
3cab9e8a3   Rishav   implement view co...
21
22
          ViewcontactService.getContact(contactId).then(function(result) {
            $scope.contactDetail = result;
67c7d62d3   Swarn Singh   view contact page...
23
            $scope.showLoader = false;
d1fe89776   Rishav Singla   view fuel vendor ...
24
            contactCompanyId = result.owner.id;
3cab9e8a3   Rishav   implement view co...
25
          })
9fabc0d40   Swarn Singh   fuel manager and ...
26

98b2beef1   Swarn Singh   contact view go b...
27
28
29
          $scope.goBack = function(){
              window.history.back();
          }
9fabc0d40   Swarn Singh   fuel manager and ...
30
31
32
33
34
35
          $scope.contactIdList = {};
          var index;
          var one = 1;
          var selectedId;
  
          ViewcontactService.getContactsList(contactId).then(function(list){
1b71872b2   Kuldeep Arora   email and code be...
36
37
38
              $scope.contactIdList = list;
              index = $scope.contactIdList.indexOf(contactId);
              selectedId = $scope.contactIdList[index];
9fabc0d40   Swarn Singh   fuel manager and ...
39
40
41
          })
          
          $scope.nextContact = function(){
956e0d9ed   Swarn Singh   contact view effe...
42
              //$scope.showLoader = true;
1b71872b2   Kuldeep Arora   email and code be...
43
44
45
46
              index = index + one;
              selectedId = $scope.contactIdList[index];
                  ViewcontactService.getContact(selectedId).then(function(result) {
                  $scope.contactDetail = result;
956e0d9ed   Swarn Singh   contact view effe...
47
                  //$scope.showLoader = false;
1b71872b2   Kuldeep Arora   email and code be...
48
              })
9fabc0d40   Swarn Singh   fuel manager and ...
49
50
51
          }
  
          $scope.prevContact = function(){
956e0d9ed   Swarn Singh   contact view effe...
52
              //$scope.showLoader = true;
1b71872b2   Kuldeep Arora   email and code be...
53
54
55
56
              index = index - one;
              selectedId = $scope.contactIdList[index];
                  ViewcontactService.getContact(selectedId).then(function(result) {
                     $scope.contactDetail = result;
956e0d9ed   Swarn Singh   contact view effe...
57
                     //$scope.showLoader = false;
1b71872b2   Kuldeep Arora   email and code be...
58
              })
9fabc0d40   Swarn Singh   fuel manager and ...
59
          }
74c8ae4bb   Rishav   remove old toogle...
60
61
62
63
          $scope.changePriceEmail = function(id){
              var statusData = "status=" + $scope.contactDetail.priceEmail;
              ViewcontactService.changePriceEmail(id, statusData).then(function(result) {
                  if(result.success){
e196b9b74   Anchit Jindal   new changes added
64
                      //$('#toogleMail').css('display', 'block');
da24c95c8   Rishav Singla   confirmation mess...
65
                      if($scope.contactDetail.priceEmail == true){
1b71872b2   Kuldeep Arora   email and code be...
66
67
68
                          toastr.success('You have enabled price distribution for this contact', {
                              closeButton: true
                          })
e196b9b74   Anchit Jindal   new changes added
69
                         // $scope.messageText = 'You have enabled price distribution for this contact';
da24c95c8   Rishav Singla   confirmation mess...
70
                      }else{
1b71872b2   Kuldeep Arora   email and code be...
71
72
73
                          toastr.success('You have disabled price distribution for this contact', {
                              closeButton: true
                          })
e196b9b74   Anchit Jindal   new changes added
74
                          //$scope.messageText = 'You have disabled price distribution for this contact';
da24c95c8   Rishav Singla   confirmation mess...
75
                      }
74c8ae4bb   Rishav   remove old toogle...
76
                  }
c555af312   Rishav   price email, comp...
77
78
              })
          }
da24c95c8   Rishav Singla   confirmation mess...
79
80
81
          $scope.cancelToogle = function(){
            $('#toogleMail').css('display', 'none');
          }
8f7dbe97c   Swarn Singh   fuel order comple...
82
83
          $scope.disableNext = true;
          $scope.disablePrev = true;
9fabc0d40   Swarn Singh   fuel manager and ...
84
          setInterval(function(){
1b71872b2   Kuldeep Arora   email and code be...
85
86
87
88
89
90
91
92
93
94
95
              var checkMaxLength = $scope.contactIdList.length - one;
              if (index === checkMaxLength) {
                  $scope.disableNext = true;
              }else{
                  $scope.disableNext = false;
              }
              if (index === 0) {
                  $scope.disablePrev = true;
              }else{
                  $scope.disablePrev = false;
              }
8f7dbe97c   Swarn Singh   fuel order comple...
96
          }, 1);
9fabc0d40   Swarn Singh   fuel manager and ...
97
98
99
100
101
102
103
104
105
106
  
          $scope.editName = true;
          $scope.editCompany = true;
          $scope.editAddress = true;
          $scope.editPhone = true;
          $scope.editMobile = true;
          $scope.editEmail = true;
          $scope.editContactNotes = true;
  
          $scope.nameEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
107
              $scope.editName = false;
67c7d62d3   Swarn Singh   view contact page...
108
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
109
110
          }
          $scope.addressEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
111
              $scope.editAddress = false;
67c7d62d3   Swarn Singh   view contact page...
112
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
113
114
          }
          $scope.phoneEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
115
              $scope.editPhone = false;
67c7d62d3   Swarn Singh   view contact page...
116
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
117
118
          }
          $scope.mobileEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
119
              $scope.editMobile = false;
67c7d62d3   Swarn Singh   view contact page...
120
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
121
122
          }
          $scope.emailEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
123
              $scope.editEmail = false;
67c7d62d3   Swarn Singh   view contact page...
124
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
125
126
          }
          $scope.notesEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
127
              $scope.editContactNotes = false;
67c7d62d3   Swarn Singh   view contact page...
128
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
129
130
131
132
133
134
          }
  
          $scope.conData = {};
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.updateContact = function(data){
67c7d62d3   Swarn Singh   view contact page...
135
              $scope.showLoader = true;
1b71872b2   Kuldeep Arora   email and code be...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
              $scope.editName = true;
              $scope.editCompany = true;
              $scope.editAddress = true;
              $scope.editPhone = true;
              $scope.editMobile = true;
              $scope.editEmail = true;
              $scope.editContactNotes = true;
  
              $scope.conData.address = data.address;
              $scope.conData.email = data.email;
              $scope.conData.firstName = data.firstName;
              $scope.conData.id = data.id;
              $scope.conData.lastName = data.lastName;
              $scope.conData.mobilePhone = data.mobilePhone;
              $scope.conData.note = data.note;
              $scope.conData.password = data.password;
              $scope.conData.priceEmail = data.priceEmail;
              $scope.conData.primaryContact = data.primaryContact;
              $scope.conData.title = data.title;
              $scope.conData.userName = data.userName;
              $scope.conData.workPhone = data.workPhone;
              $scope.conData.companyId = data.owner.id;
  
              $scope.contactData.contactList.push($scope.conData);
              $scope.contactData.contactList.push();
              ViewcontactService.updateContact($scope.contactData).then(function(result) {
                  if(result.success){
                      toastr.success(''+result.success+'', {
                          closeButton: true
                      })
67c7d62d3   Swarn Singh   view contact page...
166
                      $scope.showUpdateBtn = false;
1b71872b2   Kuldeep Arora   email and code be...
167
168
169
170
171
                  }else{
                      toastr.error(''+result.statusText+'', {
                          closeButton: true
                      })
                  }
67c7d62d3   Swarn Singh   view contact page...
172
                  $scope.showLoader = false;
1b71872b2   Kuldeep Arora   email and code be...
173
              })
9fabc0d40   Swarn Singh   fuel manager and ...
174
          }
7152ff131   Rishav   model handle
175
176
177
178
179
180
181
182
183
184
185
  
          $scope.cancelContact = function(){
              $scope.editName = true;
              $scope.editCompany = true;
              $scope.editAddress = true;
              $scope.editPhone = true;
              $scope.editMobile = true;
              $scope.editEmail = true;
              $scope.editContactNotes = true;
              $scope.showUpdateBtn = false;
          }
1c12f1ead   Rishav   primary contact e...
186
187
188
189
  
          $scope.checkPrimaryContact = function(companyId){
              if($scope.contactDetail.primaryContact == true){
              ViewCompanyService.checkPrimaryContact(companyId).then(function(result) {
5ff103048   Kuldeep Arora   updates
190
               // console.log(result)
52f1874fe   Jaideep Singh   dashboard price m...
191
                if(result.status == 422 || result.status == 200){
1c12f1ead   Rishav   primary contact e...
192
193
194
                  $('#primaryContact').css('display', 'block');
                }
              })
52f1874fe   Jaideep Singh   dashboard price m...
195
196
197
198
            }else{
                var primaryContactData = "companyContactId=" + $scope.contactDetail.id + "&primary=false";
  
              ViewCompanyService.addPrimaryContact(primaryContactData).then(function(result) {
5ff103048   Kuldeep Arora   updates
199
               // console.log(result)
52f1874fe   Jaideep Singh   dashboard price m...
200
              })
1c12f1ead   Rishav   primary contact e...
201
202
203
204
205
            }
          }
  
          $scope.cancelPrimaryContact = function(){
            $('#primaryContact').css('display', 'none');
9642a0a91   Rishav   checkbox
206
            $scope.contactDetail.primaryContact = false;
5ff103048   Kuldeep Arora   updates
207
           // console.log($scope.contactDetail.primaryContact)
1c12f1ead   Rishav   primary contact e...
208
209
210
211
          }
  
          $scope.sendPrimaryContact = function(id){
            $('#primaryContact').css('display', 'none');
52f1874fe   Jaideep Singh   dashboard price m...
212
              var primaryContactData = "companyContactId=" + id + "&primary=" + $scope.contactDetail.primaryContact;
1c12f1ead   Rishav   primary contact e...
213

52f1874fe   Jaideep Singh   dashboard price m...
214
              ViewCompanyService.addPrimaryContact(primaryContactData).then(function(result) {
5ff103048   Kuldeep Arora   updates
215
              //  console.log(result)
1c12f1ead   Rishav   primary contact e...
216
217
218
              })
            
          }
da24c95c8   Rishav Singla   confirmation mess...
219
220
221
  
          var deleteContact = "";
          $scope.deleteContact = function(id){
5ff103048   Kuldeep Arora   updates
222
223
224
               $('#delete2').css('display', 'block');
                deleteContact = id;
              
da24c95c8   Rishav Singla   confirmation mess...
225
226
227
228
          }
  
          $scope.contactDelete = function(){
            ViewcontactService.deleteContact(deleteContact).then(function(result) {
5ff103048   Kuldeep Arora   updates
229
              //console.log(result)
da24c95c8   Rishav Singla   confirmation mess...
230
231
232
233
234
              if(result.success){
                  deleteContact = "";
                  $('#delete2').css('display', 'none');
                  toastr.success(''+result.success+'', {
                      closeButton: true
5ff103048   Kuldeep Arora   updates
235
236
237
238
239
240
241
242
243
244
245
                  })  
                  //console.log("$rootScope.previousState",$rootScope.previousState)
                  if($rootScope.previousState=='app.ContactView')
                  {
                      $state.go('app.ContactView');    
                  }
                  else
                  {
                      
                      $state.go('app.viewCompany', {"id": contactCompanyId});
                  }
da24c95c8   Rishav Singla   confirmation mess...
246
247
248
249
250
251
252
253
              }
              
            })
          }
  
          $scope.cancelDelete = function(){
              $('#delete2').css('display', 'none');
          }
229e98b83   Mr. Hot Foods   api hit on send p...
254
255
256
257
258
259
260
261
262
  
            $scope.confirmMail = function(){
            
                  $('#confirm1').css('display', 'block');
              
          }
  
          $scope.saveAndCloseConfirm = function(){
              $('#confirm1').css('display', 'none');
9d840540f   Anchit Jindal   fixed bugs and ne...
263
              $scope.showLoader = true;
229e98b83   Mr. Hot Foods   api hit on send p...
264
              ViewcontactService.sendMailTo(contactId).then(function(result) {
9d840540f   Anchit Jindal   fixed bugs and ne...
265
266
267
268
269
270
271
272
273
274
275
              	console.log(result);
              	if (result != null && result.success) {
                      toastr.success('' + result.success + '', {
                          closeButton: true
                      })
                  } else {
                      toastr.error('Error Sending Email', {
                          closeButton: true
                      })
                  }
              	$scope.showLoader = false;
229e98b83   Mr. Hot Foods   api hit on send p...
276
277
278
279
280
281
282
              })
          }
          $scope.cancelAndCloseConfirm = function(){
              $scope.sendEmail = {};
              $scope.sendEmail.pricing = '';
              $('#confirm1').css('display', 'none');
          }
3cab9e8a3   Rishav   implement view co...
283
284
    
      }]);