Blame view

app/views/fbo-flight/flightDept.controller.js 8.91 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
65
66
            FBOFlight.registerUser(formdata).then(function(result) {
              $scope.registerId = result;
              $scope.data.accountId = $scope.registerId;
104d51edf   Rishav   all new api imple...
67
              $scope.aircraft.accountId = $scope.registerId;
16fa2ad10   Rishav   adding aircraft o...
68
69
70
              if($scope.aircraft.accountId == $scope.registerId){
                $scope.saveCompanyData();
              }
104d51edf   Rishav   all new api imple...
71
72
73
              toastr.success('Created Successfully', {
                closeButton: true
              })
db8e1f992   Rishav   pending user api,...
74
              $state.go('index.flightDept');
1956e3844   Rishav   handle errors
75
            }, function (err) {
16fa2ad10   Rishav   adding aircraft o...
76
                toastr.error('Error in registeration', {
1956e3844   Rishav   handle errors
77
78
79
                  closeButton: true
                })
            });
db8e1f992   Rishav   pending user api,...
80
          }
5c6477d3d   Rishav   Admin Acufuel set...
81
        }
0a4eb77cc   Rishav   FBO admin impleme...
82
83
  
        $scope.data.cardType = 'creditCard';
7379f005b   Rishav   FBO client page d...
84
85
86
        var cardData = {}
        cardData.paymentMethodList = [];
        $scope.addCard = function(){
1956e3844   Rishav   handle errors
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
          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...
102
103
104
105
        }
  
        getData();
        function getData(){
16fa2ad10   Rishav   adding aircraft o...
106
        FBOFlight.getAircraftMake().then(function(result) {
104d51edf   Rishav   all new api imple...
107
            $scope.aircraftMakeList = result;
104d51edf   Rishav   all new api imple...
108
          })
7379f005b   Rishav   FBO client page d...
109
        }
d5fb510e5   Rishav   fbo client page i...
110

16fa2ad10   Rishav   adding aircraft o...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
        $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,...
134
135
          })
        }
16fa2ad10   Rishav   adding aircraft o...
136
137
138
139
140
        $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...
141
142
          })
        }
1956e3844   Rishav   handle errors
143

16fa2ad10   Rishav   adding aircraft o...
144
145
146
147
148
149
150
151
152
153
154
        $scope.aircraftListData = {};
        $scope.addData = [];
  
        $scope.saveCompanyData = function(){
          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...
155
          }
16fa2ad10   Rishav   adding aircraft o...
156
157
          $scope.aircraftListData.aircraftList = $scope.addData;
          $scope.aircraftListData.accountId = $scope.aircraft.accountId;
104d51edf   Rishav   all new api imple...
158
          
16fa2ad10   Rishav   adding aircraft o...
159
160
161
162
163
164
165
166
167
168
169
          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,...
170
          });
1956e3844   Rishav   handle errors
171
          
104d51edf   Rishav   all new api imple...
172
        }
16fa2ad10   Rishav   adding aircraft o...
173
174
175
176
177
178
179
180
181
182
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
        // 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...
252
    });