Blame view

app/views/fbo-flight/flightDept.controller.js 7.87 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

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

16fa2ad10   Rishav   adding aircraft o...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
        $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,...
103
104
          })
        }
16fa2ad10   Rishav   adding aircraft o...
105
106
107
108
109
        $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...
110
111
          })
        }
1956e3844   Rishav   handle errors
112

16fa2ad10   Rishav   adding aircraft o...
113
114
115
116
117
118
119
120
121
122
123
        $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...
124
          }
16fa2ad10   Rishav   adding aircraft o...
125
126
          $scope.aircraftListData.aircraftList = $scope.addData;
          $scope.aircraftListData.accountId = $scope.aircraft.accountId;
104d51edf   Rishav   all new api imple...
127
          
16fa2ad10   Rishav   adding aircraft o...
128
129
130
131
132
133
134
135
136
137
138
          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,...
139
          });
1956e3844   Rishav   handle errors
140
          
104d51edf   Rishav   all new api imple...
141
        }
16fa2ad10   Rishav   adding aircraft o...
142
143
144
145
146
147
148
149
150
151
152
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
        // 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...
221
    });