Blame view

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

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

104d51edf   Rishav   all new api imple...
84
        $scope.getModal = function(){
db8e1f992   Rishav   pending user api,...
85
86
          var makeId = $scope.aircraft.make;
          FBOFlight.getModal(makeId).then(function(result) {
104d51edf   Rishav   all new api imple...
87
88
            $scope.aircraftModalList = result;
            $scope.aircraft.model = $scope.aircraftModalList[0];
db8e1f992   Rishav   pending user api,...
89
90
91
92
93
94
95
96
97
98
99
              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];
104d51edf   Rishav   all new api imple...
100
101
          })
        }
1956e3844   Rishav   handle errors
102
103
104
105
106
107
  
        $scope.openModal = function(){
          if($scope.aircraft.accountId == undefined){
            toastr.error('Please Add Contact Information', {
              closeButton: true
            })
226dc1e57   Rishav   code changes acco...
108
            $('#myModal4').modal('hide');
1956e3844   Rishav   handle errors
109
110
111
112
113
          }else{
            $('#myModal4').modal('show');
          }
          
        }
104d51edf   Rishav   all new api imple...
114
115
116
117
118
        $scope.aircraftData = {};
        $scope.aircraftData.aircraftList = [];
        $scope.getCraftList = [];
        $scope.addAircraft = function(){
          $scope.aircraftData.aircraftList.push($scope.aircraft);
104d51edf   Rishav   all new api imple...
119
120
          if ($scope.getCraftList.indexOf($scope.aircraft) == -1) {
              $scope.getCraftList.push($scope.aircraft);
104d51edf   Rishav   all new api imple...
121
122
123
124
125
126
127
128
          }
          
          FBOFlight.addAircraft($scope.aircraftData).then(function(result) {
            $('#myModal4').modal('hide');
            $scope.reset();
            toastr.success('Created Successfully', {
              closeButton: true
            })
db8e1f992   Rishav   pending user api,...
129
130
131
132
133
134
135
          }, function (err) {
              toastr.error('Error in Adding Aircraft', {
                closeButton: true
              })
              $('#myModal4').modal('hide');
              $scope.getCraftList.splice($scope.aircraft);
          });
1956e3844   Rishav   handle errors
136
          
104d51edf   Rishav   all new api imple...
137
138
139
140
141
142
143
144
        }
  
        $scope.reset = function() {
          $scope.aircraft = {};
          $scope.aircraft.accountId = $scope.data.accountId;
          $scope.aircraftData.aircraftList = [];
          getData();
        }
5c6477d3d   Rishav   Admin Acufuel set...
145
    });