Blame view

app/partials/viewVendorContact/viewVendorContact.Controller.js 8.76 KB
d1fe89776   Rishav Singla   view fuel vendor ...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acufuel')
1b71872b2   Kuldeep Arora   email and code be...
5
      .controller('viewVendorContactController', ['$scope', '$stateParams', '$state', 'ViewvendorContactService', 'ViewFuelVendorService', function($scope, $stateParams, $state, ViewvendorContactService, ViewFuelVendorService) {
d1fe89776   Rishav Singla   view fuel vendor ...
6
7
          $scope.showLoader = true;
          $scope.showUpdateBtn = false;
1b71872b2   Kuldeep Arora   email and code be...
8
9
          var contactId = $stateParams.id;
          $scope.contactDetail = {};
d1fe89776   Rishav Singla   view fuel vendor ...
10
11
12
13
14
15
16
17
18
19
20
21
22
          var contactCompanyId = "";
          ViewvendorContactService.getContact(contactId).then(function(result) {
            $scope.contactDetail = result;
            $scope.showLoader = false;
            contactCompanyId = result.owner.id;
          })
  
          $scope.contactIdList = {};
          var index;
          var one = 1;
          var selectedId;
  
          ViewvendorContactService.getContactsList(contactId).then(function(list){
1b71872b2   Kuldeep Arora   email and code be...
23
24
25
              $scope.contactIdList = list;
              index = $scope.contactIdList.indexOf(contactId);
              selectedId = $scope.contactIdList[index];
d1fe89776   Rishav Singla   view fuel vendor ...
26
27
28
29
          })
          
          $scope.nextContact = function(){
              $scope.showLoader = true;
1b71872b2   Kuldeep Arora   email and code be...
30
31
32
33
              index = index + one;
              selectedId = $scope.contactIdList[index];
                  ViewvendorContactService.getContact(selectedId).then(function(result) {
                  $scope.contactDetail = result;
d1fe89776   Rishav Singla   view fuel vendor ...
34
                  $scope.showLoader = false;
1b71872b2   Kuldeep Arora   email and code be...
35
              })
d1fe89776   Rishav Singla   view fuel vendor ...
36
37
38
39
          }
  
          $scope.prevContact = function(){
              $scope.showLoader = true;
1b71872b2   Kuldeep Arora   email and code be...
40
41
42
43
              index = index - one;
              selectedId = $scope.contactIdList[index];
                  ViewvendorContactService.getContact(selectedId).then(function(result) {
                     $scope.contactDetail = result;
d1fe89776   Rishav Singla   view fuel vendor ...
44
                     $scope.showLoader = false;
1b71872b2   Kuldeep Arora   email and code be...
45
              })
d1fe89776   Rishav Singla   view fuel vendor ...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
          }
  
          $scope.changePriceEmail = function(id){
              var statusData = "status=" + $scope.contactDetail.priceEmail;
              ViewvendorContactService.changePriceEmail(id, statusData).then(function(result) {
                  if(result.success){
                      $('#toogleMail').css('display', 'block');
                      if($scope.contactDetail.priceEmail == true){
                          $scope.messageText = 'You have enabled price distribution for this contact';
                      }else{
                          $scope.messageText = 'You have disabled price distribution for this contact';
                      }
                  }
              })
          }
  
          $scope.cancelToogle = function(){
            $('#toogleMail').css('display', 'none');
          }
  
          setInterval(function(){
1b71872b2   Kuldeep Arora   email and code be...
67
68
69
70
71
72
73
74
75
76
77
              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;
              }
d1fe89776   Rishav Singla   view fuel vendor ...
78
79
80
81
82
83
84
85
86
87
88
          }, 3);
  
          $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...
89
              $scope.editName = false;
d1fe89776   Rishav Singla   view fuel vendor ...
90
91
92
              $scope.showUpdateBtn = true;
          }
          $scope.addressEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
93
              $scope.editAddress = false;
d1fe89776   Rishav Singla   view fuel vendor ...
94
95
96
              $scope.showUpdateBtn = true;
          }
          $scope.phoneEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
97
              $scope.editPhone = false;
d1fe89776   Rishav Singla   view fuel vendor ...
98
99
100
              $scope.showUpdateBtn = true;
          }
          $scope.mobileEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
101
              $scope.editMobile = false;
d1fe89776   Rishav Singla   view fuel vendor ...
102
103
104
              $scope.showUpdateBtn = true;
          }
          $scope.emailEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
105
              $scope.editEmail = false;
d1fe89776   Rishav Singla   view fuel vendor ...
106
107
108
              $scope.showUpdateBtn = true;
          }
          $scope.notesEdit = function(){
1b71872b2   Kuldeep Arora   email and code be...
109
              $scope.editContactNotes = false;
d1fe89776   Rishav Singla   view fuel vendor ...
110
111
112
113
114
115
116
117
              $scope.showUpdateBtn = true;
          }
  
          $scope.conData = {};
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.updateContact = function(data){
              $scope.showLoader = true;
1b71872b2   Kuldeep Arora   email and code be...
118
119
120
121
122
123
124
              $scope.editName = true;
              $scope.editCompany = true;
              $scope.editAddress = true;
              $scope.editPhone = true;
              $scope.editMobile = true;
              $scope.editEmail = true;
              $scope.editContactNotes = true;
d1fe89776   Rishav Singla   view fuel vendor ...
125

1b71872b2   Kuldeep Arora   email and code be...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
              $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;
d1fe89776   Rishav Singla   view fuel vendor ...
140

1b71872b2   Kuldeep Arora   email and code be...
141
142
143
144
145
146
147
              $scope.contactData.contactList.push($scope.conData);
              $scope.contactData.contactList.push();
              ViewvendorContactService.updateContact($scope.contactData).then(function(result) {
                  if(result.success){
                      toastr.success(''+result.success+'', {
                          closeButton: true
                      })
d1fe89776   Rishav Singla   view fuel vendor ...
148
                      $scope.showUpdateBtn = false;
1b71872b2   Kuldeep Arora   email and code be...
149
150
151
152
153
                  }else{
                      toastr.error(''+result.statusText+'', {
                          closeButton: true
                      })
                  }
d1fe89776   Rishav Singla   view fuel vendor ...
154
                  $scope.showLoader = false;
1b71872b2   Kuldeep Arora   email and code be...
155
              })
d1fe89776   Rishav Singla   view fuel vendor ...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
          }
  
          $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;
          }
  
          $scope.checkPrimaryContact = function(companyId){
              if($scope.contactDetail.primaryContact == true){
              ViewFuelVendorService.checkPrimaryContact(companyId).then(function(result) {
                console.log(result)
52f1874fe   Jaideep Singh   dashboard price m...
173
                if(result.status == 422 || result.status == 200){
d1fe89776   Rishav Singla   view fuel vendor ...
174
175
176
                  $('#primaryContact').css('display', 'block');
                }
              })
52f1874fe   Jaideep Singh   dashboard price m...
177
178
179
180
181
182
            }else{
                var primaryContactData = "companyContactId=" + $scope.contactDetail.id + "&primary=false";
  
              ViewCompanyService.addPrimaryContact(primaryContactData).then(function(result) {
                console.log(result)
              })
d1fe89776   Rishav Singla   view fuel vendor ...
183
184
            }
          }
9d840540f   Anchit Jindal   fixed bugs and ne...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
          
          $scope.sendMail = function() {
          	$scope.showLoader = true;
          	ViewvendorContactService.sendMailTo(contactId).then(function(result) {
              	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;
              })
          }
d1fe89776   Rishav Singla   view fuel vendor ...
202
203
204
205
206
207
208
209
210
  
          $scope.cancelPrimaryContact = function(){
            $('#primaryContact').css('display', 'none');
            $scope.contactDetail.primaryContact = false;
            console.log($scope.contactDetail.primaryContact)
          }
  
          $scope.sendPrimaryContact = function(id){
            $('#primaryContact').css('display', 'none');
ccab6d2eb   Anchit Jindal   minor changes imp...
211
              var priamryContactData = "vendorContactId=" + id + "&primary=" + $scope.contactDetail.primaryContact;
d1fe89776   Rishav Singla   view fuel vendor ...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
  
              ViewFuelVendorService.addPrimaryContact(priamryContactData).then(function(result) {
                console.log(result)
              })
            
          }
  
          var deleteContact = "";
          $scope.deleteContact = function(id){
              $('#delete2').css('display', 'block');
              deleteContact = id;
          }
  
          $scope.contactDelete = function(){
            ViewvendorContactService.deleteContact(deleteContact).then(function(result) {
              console.log(result)
              if(result.success){
                  deleteContact = "";
                  $('#delete2').css('display', 'none');
                  toastr.success(''+result.success+'', {
                      closeButton: true
                  })
                  $state.go('app.viewFuelVendor', {"id": contactCompanyId});
              }
              
            })
          }
  
          $scope.cancelDelete = function(){
              $('#delete2').css('display', 'none');
          }
    
      }]);