Blame view

app/partials/viewcontact/viewcontact.controller.js 6.34 KB
3cab9e8a3   Rishav   implement view co...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acufuel')
1c12f1ead   Rishav   primary contact e...
5
  	.controller('viewcontactController', ['$scope', '$stateParams', 'ViewcontactService', 'ViewCompanyService', function($scope, $stateParams, 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 = {};
c555af312   Rishav   price email, comp...
10
          var value = "";
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;
3cab9e8a3   Rishav   implement view co...
14
          })
9fabc0d40   Swarn Singh   fuel manager and ...
15
16
17
18
19
20
21
22
23
  
          $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...
24
  			selectedId = $scope.contactIdList[index];
9fabc0d40   Swarn Singh   fuel manager and ...
25
26
27
          })
          
          $scope.nextContact = function(){
67c7d62d3   Swarn Singh   view contact page...
28
              $scope.showLoader = true;
9fabc0d40   Swarn Singh   fuel manager and ...
29
30
31
32
          	index = index + one;
          	selectedId = $scope.contactIdList[index];
  		        ViewcontactService.getContact(selectedId).then(function(result) {
  			    $scope.contactDetail = result;
67c7d62d3   Swarn Singh   view contact page...
33
                  $scope.showLoader = false;
9fabc0d40   Swarn Singh   fuel manager and ...
34
35
36
37
  			})
          }
  
          $scope.prevContact = function(){
67c7d62d3   Swarn Singh   view contact page...
38
              $scope.showLoader = true;
9fabc0d40   Swarn Singh   fuel manager and ...
39
40
41
42
          	index = index - one;
          	selectedId = $scope.contactIdList[index];
  		        ViewcontactService.getContact(selectedId).then(function(result) {
  			       $scope.contactDetail = result;
67c7d62d3   Swarn Singh   view contact page...
43
                     $scope.showLoader = false;
9fabc0d40   Swarn Singh   fuel manager and ...
44
45
  			})
          }
74c8ae4bb   Rishav   remove old toogle...
46
47
48
49
50
51
52
53
          $scope.changePriceEmail = function(id){
              var statusData = "status=" + $scope.contactDetail.priceEmail;
              ViewcontactService.changePriceEmail(id, statusData).then(function(result) {
                  if(result.success){
                      toastr.success(''+result.success+'', {
                          closeButton: true
                      })
                  }
c555af312   Rishav   price email, comp...
54
55
              })
          }
9fabc0d40   Swarn Singh   fuel manager and ...
56
57
58
59
60
61
62
63
64
65
66
67
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;
          	}
          }, 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(){
          	$scope.editName = false;
67c7d62d3   Swarn Singh   view contact page...
80
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
81
82
83
          }
          $scope.addressEdit = function(){
          	$scope.editAddress = false;
67c7d62d3   Swarn Singh   view contact page...
84
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
85
86
87
          }
          $scope.phoneEdit = function(){
          	$scope.editPhone = false;
67c7d62d3   Swarn Singh   view contact page...
88
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
89
90
91
          }
          $scope.mobileEdit = function(){
          	$scope.editMobile = false;
67c7d62d3   Swarn Singh   view contact page...
92
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
93
94
95
          }
          $scope.emailEdit = function(){
          	$scope.editEmail = false;
67c7d62d3   Swarn Singh   view contact page...
96
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
97
98
99
          }
          $scope.notesEdit = function(){
          	$scope.editContactNotes = false;
67c7d62d3   Swarn Singh   view contact page...
100
              $scope.showUpdateBtn = true;
9fabc0d40   Swarn Singh   fuel manager and ...
101
102
103
104
105
106
          }
  
          $scope.conData = {};
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.updateContact = function(data){
67c7d62d3   Swarn Singh   view contact page...
107
              $scope.showLoader = true;
9fabc0d40   Swarn Singh   fuel manager and ...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
          	$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...
138
                      $scope.showUpdateBtn = false;
9fabc0d40   Swarn Singh   fuel manager and ...
139
140
141
142
143
  	            }else{
  	            	toastr.error(''+result.statusText+'', {
  	                	closeButton: true
  	                })
  	            }
67c7d62d3   Swarn Singh   view contact page...
144
                  $scope.showLoader = false;
9fabc0d40   Swarn Singh   fuel manager and ...
145
146
  	        })
          }
7152ff131   Rishav   model handle
147
148
149
150
151
152
153
154
155
156
157
  
          $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...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
  
          $scope.checkPrimaryContact = function(companyId){
              if($scope.contactDetail.primaryContact == true){
              ViewCompanyService.checkPrimaryContact(companyId).then(function(result) {
                console.log(result)
                if(result.status == 422){
                  $('#primaryContact').css('display', 'block');
                }
              })
            }
          }
  
          $scope.cancelPrimaryContact = function(){
            $('#primaryContact').css('display', 'none');
9642a0a91   Rishav   checkbox
172
173
            $scope.contactDetail.primaryContact = false;
            console.log($scope.contactDetail.primaryContact)
1c12f1ead   Rishav   primary contact e...
174
175
176
177
178
179
180
181
182
183
184
          }
  
          $scope.sendPrimaryContact = function(id){
            $('#primaryContact').css('display', 'none');
              var priamryContactData = "companyContactId=" + id + "&primary=" + $scope.contactDetail.primaryContact;
  
              ViewCompanyService.addPrimaryContact(priamryContactData).then(function(result) {
                console.log(result)
              })
            
          }
3cab9e8a3   Rishav   implement view co...
185
186
    
      }]);