Blame view

app/views/fbo-flight/flightDept.controller.js 9.22 KB
e4e496d13   Rishav   setup admin acufu...
1
2
3
  'use strict';
  
   //Load controller
9835dbe3e   Rishav   module name changes
4
    angular.module('acuefuel')
e4e496d13   Rishav   setup admin acufu...
5

089f3a3c2   Rishav   check username av...
6
  	.controller('FlightDeptController', function ($scope, $uibModal, $state, FBOFlight, FBOAdmin) {
2d8381335   Rishav   menu highlighted ...
7
8
9
        $(document).ready(function(){
          $('.fboflight').addClass('active');
        });
0a4eb77cc   Rishav   FBO admin impleme...
10
        $scope.data = {};
5c6477d3d   Rishav   Admin Acufuel set...
11
        $scope.user = {};
104d51edf   Rishav   all new api imple...
12
        $scope.aircraft = {};
e2bce8d01   Swarn Singh   validation on Fli...
13
14
15
        $scope.user.companyName = '';
        $scope.user.email = '';
        $scope.user.password = '';
089f3a3c2   Rishav   check username av...
16
17
18
19
20
21
22
23
24
25
26
  
        $scope.checkUsername = function(){
          FBOAdmin.checkUsernameEmail($scope.user.email).then(function(status) {
            console.log(status)
            if(status != 200){
              toastr.error('This email has alreay taken', {
                closeButton: true
              })
            }
          })
        }
e2bce8d01   Swarn Singh   validation on Fli...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
        $scope.comnayNameInvalid = false;
        $scope.emailInvalid = false;
        $scope.passwordInvalid = false;
  
        $scope.companyNameValid = function(){
          $scope.comnayNameInvalid = false;
          $('.companyNameError').removeClass('customErrorInput');
        }
        $scope.emailValid = function(){
          $scope.emailInvalid = false;
          $('.emailIdError').removeClass('customErrorInput');
        }
        $scope.passwordValid = function(){
          $scope.passwordInvalid = false;
          $('.invalidPassword').removeClass('customErrorInput');
        }
5c6477d3d   Rishav   Admin Acufuel set...
43
        $scope.userData = function(){
e2bce8d01   Swarn Singh   validation on Fli...
44
45
46
47
48
49
50
51
52
53
  
          if ($scope.user.companyName == '') {
            $scope.comnayNameInvalid = true;
            $('.companyNameError').addClass('customErrorInput');
          }else if ($scope.user.email == '') {
            $scope.emailInvalid = true;
            $('.emailIdError').addClass('customErrorInput');
          }else if ($scope.user.password == '') {
            $scope.passwordInvalid = true;
            $('.invalidPassword').addClass('customErrorInput');
db8e1f992   Rishav   pending user api,...
54
          }else{
5c6477d3d   Rishav   Admin Acufuel set...
55
56
57
58
59
60
61
62
            if($scope.status == true){
              $scope.user.status = 'active';
            }else{
              $scope.user.status = 'inactive';
            }
            $scope.user.username = $scope.user.email;
            $scope.user.userType = 'flightDetp';
            console.log($scope.user)
d5fb510e5   Rishav   fbo client page i...
63
            var formdata = "companyName=" + $scope.user.companyName + "&email=" + $scope.user.email + "&username=" + $scope.user.username + "&firstName=" + $scope.user.firstName + "&lastName=" + $scope.user.lastName + "&password=" + $scope.user.password + "&phone=" + $scope.user.phone + "&mobile=" + $scope.user.mobile + "&status=" + $scope.user.status + "&userType=" + $scope.user.userType + "&clientNote=" + $scope.user.clientNote;
7379f005b   Rishav   FBO client page d...
64
            FBOFlight.registerUser(formdata).then(function(result) {
a19001fdd   Anchit Jindal   new code added
65
66
              $scope.registerId = result.id;
              $scope.companyId = result.companyId;
7379f005b   Rishav   FBO client page d...
67
              $scope.data.accountId = $scope.registerId;
a19001fdd   Anchit Jindal   new code added
68
69
              $scope.aircraft.accountId = $scope.companyId;
              if($scope.aircraft.accountId == $scope.companyId){
16fa2ad10   Rishav   adding aircraft o...
70
71
                $scope.saveCompanyData();
              }
104d51edf   Rishav   all new api imple...
72
73
74
              toastr.success('Created Successfully', {
                closeButton: true
              })
db8e1f992   Rishav   pending user api,...
75
              $state.go('index.flightDept');
1956e3844   Rishav   handle errors
76
            }, function (err) {
16fa2ad10   Rishav   adding aircraft o...
77
                toastr.error('Error in registeration', {
1956e3844   Rishav   handle errors
78
79
80
                  closeButton: true
                })
            });
db8e1f992   Rishav   pending user api,...
81
          }
5c6477d3d   Rishav   Admin Acufuel set...
82
        }
0a4eb77cc   Rishav   FBO admin impleme...
83
84
  
        $scope.data.cardType = 'creditCard';
7379f005b   Rishav   FBO client page d...
85
86
87
        var cardData = {}
        cardData.paymentMethodList = [];
        $scope.addCard = function(){
1956e3844   Rishav   handle errors
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
          if($scope.aircraft.accountId == undefined){
            toastr.error('Please Add Contact Information', {
              closeButton: true
            })
          }else{
            cardData.paymentMethodList.push($scope.data);
            console.log("cardData", cardData);
            FBOFlight.addCardInformation(cardData).then(function(result) {
              console.log(result)
                toastr.success('Created Successfully', {
                  closeButton: true
                })
            })
          }
          
104d51edf   Rishav   all new api imple...
103
104
105
106
        }
  
        getData();
        function getData(){
16fa2ad10   Rishav   adding aircraft o...
107
        FBOFlight.getAircraftMake().then(function(result) {
104d51edf   Rishav   all new api imple...
108
            $scope.aircraftMakeList = result;
104d51edf   Rishav   all new api imple...
109
          })
7379f005b   Rishav   FBO client page d...
110
        }
d5fb510e5   Rishav   fbo client page i...
111

16fa2ad10   Rishav   adding aircraft o...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
        $scope.aircraftDetails = [{ 
            'tail':'',
            'make': '',
            'model': '',
            'sizeId' : ''
        }];
      
        $scope.addNew = function(){
            $scope.aircraftDetails.push({ 
              'tail':'',
              'make': '',
              'model': '',
              'sizeId' : ''
            });
            console.log($scope.aircraftDetails)
        };
  
        $scope.getModal = function(makeId, index){
        $scope.aircraft.make = makeId;
          //var makeId = makeId;
          FBOFlight.getModal($scope.aircraft.make).then(function(result) {
            $scope.aircraftDetails[index].aircraftModalList = result;
            //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0];
db8e1f992   Rishav   pending user api,...
135
136
          })
        }
16fa2ad10   Rishav   adding aircraft o...
137
138
139
140
141
        $scope.getSize = function(model, index){
          FBOFlight.getAircraftSize($scope.aircraft.make, model).then(function(result) {
            $scope.aircraftDetails[index].aircraftSizeList = result;
            //$scope.aircraftDetails[index].size = $scope.aircraftSizeList[0];
            console.log($scope.aircraftDetails[index])
104d51edf   Rishav   all new api imple...
142
143
          })
        }
1956e3844   Rishav   handle errors
144

16fa2ad10   Rishav   adding aircraft o...
145
146
147
148
        $scope.aircraftListData = {};
        $scope.addData = [];
  
        $scope.saveCompanyData = function(){
a19001fdd   Anchit Jindal   new code added
149
      	  console.log('=========2========',$scope.aircraftDetails);
16fa2ad10   Rishav   adding aircraft o...
150
151
152
153
154
155
156
          for(var i=0; i<$scope.aircraftDetails.length;i++){
              $scope.addData.push({ 
                'tail': $scope.aircraftDetails[i].tail,
                'make': $scope.aircraftDetails[i].make,
                'model': $scope.aircraftDetails[i].model,
                'sizeId' : $scope.aircraftDetails[i].sizeId
              });
104d51edf   Rishav   all new api imple...
157
          }
16fa2ad10   Rishav   adding aircraft o...
158
159
          $scope.aircraftListData.aircraftList = $scope.addData;
          $scope.aircraftListData.accountId = $scope.aircraft.accountId;
104d51edf   Rishav   all new api imple...
160
          
16fa2ad10   Rishav   adding aircraft o...
161
162
163
164
165
166
167
168
169
170
171
          FBOFlight.addAircraft($scope.aircraftListData).then(function(result) {
            console.log(result)
            if(result != null && result.success){
                toastr.success(''+result.success+'', {
                  closeButton: true
                })
            }else{
                toastr.error(''+result.statusText+'', {
                  closeButton: true
                })
            }
db8e1f992   Rishav   pending user api,...
172
          });
1956e3844   Rishav   handle errors
173
          
104d51edf   Rishav   all new api imple...
174
        }
a19001fdd   Anchit Jindal   new code added
175
176
177
178
179
180
181
        getCompanyName();
        function getCompanyName(){
  			$scope.showLoader = true;
  			FBOFlight.getCompanyName().then(function(result) {
  	        	$scope.compNameList = result;
  	        })
  		}
104d51edf   Rishav   all new api imple...
182

16fa2ad10   Rishav   adding aircraft o...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
        // getData();
        // function getData(){
        //   FBOFlight.getAircraftMake().then(function(result) {
        //     $scope.aircraftMakeList = result;
        //     $scope.aircraft.make = $scope.aircraftMakeList[0];
        //     FBOFlight.getModal($scope.aircraft.make).then(function(result) {
        //       $scope.aircraftModalList = result;
        //       $scope.aircraft.model = $scope.aircraftModalList[0];
        //         FBOFlight.getAircraftSize($scope.aircraft.make, $scope.aircraft.model).then(function(result) {
        //           $scope.aircraftSizeList = result;
        //           $scope.aircraft.size = $scope.aircraftSizeList[0];
        //         })
        //     })
              
        //   })
        // }
        
  
        // $scope.getModal = function(){
        //   var makeId = $scope.aircraft.make;
        //   FBOFlight.getModal(makeId).then(function(result) {
        //     $scope.aircraftModalList = result;
        //     $scope.aircraft.model = $scope.aircraftModalList[0];
        //       FBOFlight.getAircraftSize(makeId, $scope.aircraft.model).then(function(result) {
        //         $scope.aircraftSizeList = result;
        //         $scope.aircraft.size = $scope.aircraftSizeList[0];
        //       })
        //   })
        // }
  
        // $scope.getSize = function(){
        //   FBOFlight.getAircraftSize($scope.aircraft.make, $scope.aircraft.model).then(function(result) {
        //     $scope.aircraftSizeList = result;
        //     $scope.aircraft.size = $scope.aircraftSizeList[0];
        //   })
        // }
  
        // $scope.openModal = function(){
        //   if($scope.aircraft.accountId == undefined){
        //     toastr.error('Please Add Contact Information', {
        //       closeButton: true
        //     })
        //     $('#myModal4').modal('hide');
        //   }else{
        //     $('#myModal4').modal('show');
        //   }
          
        // }
        // $scope.aircraftData = {};
        // $scope.aircraftData.aircraftList = [];
        // $scope.getCraftList = [];
        // $scope.addAircraft = function(){
        //   $scope.aircraftData.aircraftList.push($scope.aircraft);
        //   if ($scope.getCraftList.indexOf($scope.aircraft) == -1) {
        //       $scope.getCraftList.push($scope.aircraft);
        //   }
          
        //   FBOFlight.addAircraft($scope.aircraftData).then(function(result) {
        //     $('#myModal4').modal('hide');
        //     $scope.reset();
        //     toastr.success('Created Successfully', {
        //       closeButton: true
        //     })
        //   }, function (err) {
        //       toastr.error('Error in Adding Aircraft', {
        //         closeButton: true
        //       })
        //       $('#myModal4').modal('hide');
        //       $scope.getCraftList.splice($scope.aircraft);
        //   });
          
        // }
  
        // $scope.reset = function() {
        //   $scope.aircraft = {};
        //   $scope.aircraft.accountId = $scope.data.accountId;
        //   $scope.aircraftData.aircraftList = [];
        //   getData();
        // }
5c6477d3d   Rishav   Admin Acufuel set...
262
    });