Blame view

app/partials/viewcontact/viewcontact.controller.js 7.97 KB
3cab9e8a3   Rishav   implement view co...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acufuel')
d1fe89776   Rishav Singla   view fuel vendor ...
5
  	.controller('viewcontactController', ['$scope', '$stateParams', '$state', 'ViewcontactService', 'ViewCompanyService', function($scope, $stateParams, $state, ViewcontactService, ViewCompanyService) {
67c7d62d3   Swarn Singh   view contact page...
6
7
          $scope.showLoader = true;
          $scope.showUpdateBtn = false;
3cab9e8a3   Rishav   implement view co...
8
  	    var contactId = $stateParams.id;
9fabc0d40   Swarn Singh   fuel manager and ...
9
  	    $scope.contactDetail = {};
d1fe89776   Rishav Singla   view fuel vendor ...
10
          var contactCompanyId = "";
3cab9e8a3   Rishav   implement view co...
11
12
          ViewcontactService.getContact(contactId).then(function(result) {
            $scope.contactDetail = result;
67c7d62d3   Swarn Singh   view contact page...
13
            $scope.showLoader = false;
d1fe89776   Rishav Singla   view fuel vendor ...
14
            contactCompanyId = result.owner.id;
3cab9e8a3   Rishav   implement view co...
15
          })
9fabc0d40   Swarn Singh   fuel manager and ...
16

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

52f1874fe   Jaideep Singh   dashboard price m...
198
              ViewCompanyService.addPrimaryContact(primaryContactData).then(function(result) {
1c12f1ead   Rishav   primary contact e...
199
200
201
202
                console.log(result)
              })
            
          }
da24c95c8   Rishav Singla   confirmation mess...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  
          var deleteContact = "";
          $scope.deleteContact = function(id){
              $('#delete2').css('display', 'block');
              deleteContact = id;
          }
  
          $scope.contactDelete = function(){
            ViewcontactService.deleteContact(deleteContact).then(function(result) {
              console.log(result)
              if(result.success){
                  deleteContact = "";
                  $('#delete2').css('display', 'none');
                  toastr.success(''+result.success+'', {
                      closeButton: true
                  })
d1fe89776   Rishav Singla   view fuel vendor ...
219
                  $state.go('app.viewCompany', {"id": contactCompanyId});
da24c95c8   Rishav Singla   confirmation mess...
220
221
222
223
224
225
226
227
              }
              
            })
          }
  
          $scope.cancelDelete = function(){
              $('#delete2').css('display', 'none');
          }
3cab9e8a3   Rishav   implement view co...
228
229
    
      }]);