Blame view

app/views/fbo-flight/flightDept.controller.js 8.19 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 = {};
089f3a3c2   Rishav   check username av...
13
14
15
16
17
18
19
20
21
22
23
  
        $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
              })
            }
          })
        }
5c6477d3d   Rishav   Admin Acufuel set...
24
        $scope.userData = function(){
16fa2ad10   Rishav   adding aircraft o...
25
          
db8e1f992   Rishav   pending user api,...
26
27
28
29
30
31
32
33
34
          if($scope.user.email == undefined || $scope.user.email == null){
            toastr.error('Please enter your email first', {
              closeButton: true
            })
          }else if($scope.user.firstName == undefined || $scope.user.firstName == null){
            toastr.error('Please enter your First Name', {
              closeButton: true
            })
          }else{
5c6477d3d   Rishav   Admin Acufuel set...
35
36
37
38
39
40
41
42
            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...
43
            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...
44
45
46
            FBOFlight.registerUser(formdata).then(function(result) {
              $scope.registerId = result;
              $scope.data.accountId = $scope.registerId;
104d51edf   Rishav   all new api imple...
47
              $scope.aircraft.accountId = $scope.registerId;
16fa2ad10   Rishav   adding aircraft o...
48
49
50
              if($scope.aircraft.accountId == $scope.registerId){
                $scope.saveCompanyData();
              }
104d51edf   Rishav   all new api imple...
51
52
53
              toastr.success('Created Successfully', {
                closeButton: true
              })
db8e1f992   Rishav   pending user api,...
54
              $state.go('index.flightDept');
1956e3844   Rishav   handle errors
55
            }, function (err) {
16fa2ad10   Rishav   adding aircraft o...
56
                toastr.error('Error in registeration', {
1956e3844   Rishav   handle errors
57
58
59
                  closeButton: true
                })
            });
db8e1f992   Rishav   pending user api,...
60
          }
5c6477d3d   Rishav   Admin Acufuel set...
61
        }
0a4eb77cc   Rishav   FBO admin impleme...
62
63
  
        $scope.data.cardType = 'creditCard';
7379f005b   Rishav   FBO client page d...
64
65
66
        var cardData = {}
        cardData.paymentMethodList = [];
        $scope.addCard = function(){
1956e3844   Rishav   handle errors
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
          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...
82
83
84
85
        }
  
        getData();
        function getData(){
16fa2ad10   Rishav   adding aircraft o...
86
        FBOFlight.getAircraftMake().then(function(result) {
104d51edf   Rishav   all new api imple...
87
            $scope.aircraftMakeList = result;
104d51edf   Rishav   all new api imple...
88
          })
7379f005b   Rishav   FBO client page d...
89
        }
d5fb510e5   Rishav   fbo client page i...
90

16fa2ad10   Rishav   adding aircraft o...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
        $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,...
114
115
          })
        }
16fa2ad10   Rishav   adding aircraft o...
116
117
118
119
120
        $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...
121
122
          })
        }
1956e3844   Rishav   handle errors
123

16fa2ad10   Rishav   adding aircraft o...
124
125
126
127
128
129
130
131
132
133
134
        $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...
135
          }
16fa2ad10   Rishav   adding aircraft o...
136
137
          $scope.aircraftListData.aircraftList = $scope.addData;
          $scope.aircraftListData.accountId = $scope.aircraft.accountId;
104d51edf   Rishav   all new api imple...
138
          
16fa2ad10   Rishav   adding aircraft o...
139
140
141
142
143
144
145
146
147
148
149
          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,...
150
          });
1956e3844   Rishav   handle errors
151
          
104d51edf   Rishav   all new api imple...
152
        }
16fa2ad10   Rishav   adding aircraft o...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
        // 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...
232
    });