Blame view

app/partials/viewcontact/viewcontact.controller.js 5.07 KB
3cab9e8a3   Rishav   implement view co...
1
2
3
4
5
6
7
8
9
10
11
12
  'use strict';
  
   //Load controller
    angular.module('acufuel')
  
  	.controller('viewcontactController', ['$scope', '$stateParams', 'ViewcontactService', function($scope, $stateParams, ViewcontactService) {
  
  	  	$(function() {
  	         $('#toggle-five').bootstrapToggle();
  	    })
  
  	    var contactId = $stateParams.id;
9fabc0d40   Swarn Singh   fuel manager and ...
13
  	    $scope.contactDetail = {};
c555af312   Rishav   price email, comp...
14
          var value = "";
3cab9e8a3   Rishav   implement view co...
15
16
          ViewcontactService.getContact(contactId).then(function(result) {
            $scope.contactDetail = result;
c555af312   Rishav   price email, comp...
17
            checkValue($scope.contactDetail.priceEmail);
3cab9e8a3   Rishav   implement view co...
18
          })
9fabc0d40   Swarn Singh   fuel manager and ...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  
          $scope.contactIdList = {};
          var index;
          var one = 1;
          var selectedId;
  
          ViewcontactService.getContactsList(contactId).then(function(list){
          	$scope.contactIdList = list;
  			index = $scope.contactIdList.indexOf(contactId);
  			selectedId = $scope.contactIdList[index]
          })
          
          $scope.nextContact = function(){
          	index = index + one;
          	selectedId = $scope.contactIdList[index];
  		        ViewcontactService.getContact(selectedId).then(function(result) {
  			    $scope.contactDetail = result;
c555af312   Rishav   price email, comp...
36
                  checkValue($scope.contactDetail.priceEmail);
9fabc0d40   Swarn Singh   fuel manager and ...
37
38
39
40
41
42
43
44
  			})
          }
  
          $scope.prevContact = function(){
          	index = index - one;
          	selectedId = $scope.contactIdList[index];
  		        ViewcontactService.getContact(selectedId).then(function(result) {
  			       $scope.contactDetail = result;
c555af312   Rishav   price email, comp...
45
                     checkValue($scope.contactDetail.priceEmail);
9fabc0d40   Swarn Singh   fuel manager and ...
46
47
  			})
          }
c555af312   Rishav   price email, comp...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
          function checkValue(priceEmail){
              if(priceEmail == true){
                  value = 'on';
              }else{
                  console.log("nai")
                  value = 'off'
              }
              $('#toggle-five').bootstrapToggle(value)
          }
  
          $scope.changePriceEmail = function(){
              $('#toggle-five').bootstrapToggle();
              $('#toggle-five').change(function() {
                  $scope.activate = $(this).prop('checked');
                  console.log($scope.activate)
                  var statusData = "status=" + $scope.activate;
                  ViewcontactService.changePriceEmail(contactId, statusData).then(function(result) {
                      if(result.success){
                          toastr.success(''+result.success+'', {
                              closeButton: true
                          })
                      }
                  })
              })
          }
9fabc0d40   Swarn Singh   fuel manager and ...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
          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;
          }
          $scope.addressEdit = function(){
          	$scope.editAddress = false;
          }
          $scope.phoneEdit = function(){
          	$scope.editPhone = false;
          }
          $scope.mobileEdit = function(){
          	$scope.editMobile = false;
          }
          $scope.emailEdit = function(){
          	$scope.editEmail = false;
          }
          $scope.notesEdit = function(){
          	$scope.editContactNotes = false;
          }
  
          $scope.conData = {};
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.updateContact = function(data){
          	$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
  	            	})
  	            }else{
  	            	toastr.error(''+result.statusText+'', {
  	                	closeButton: true
  	                })
  	            }
  	        })
          }
3cab9e8a3   Rishav   implement view co...
155
156
    
      }]);