customers.controller.js
7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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
221
222
223
224
225
226
227
228
229
'use strict';
//Load controller
angular.module('acufuel')
.controller('customersController', ['$scope', '$rootScope', '$uibModal', '$filter', 'CustomersService', customersController]);
function customersController($scope, $rootScope, $uibModal, $filter, CustomersService) {
$(document).ready(function() {
$('#example').DataTable();
});
$scope.data = {};
$scope.aircraft = {};
$scope.data.activate = true;
$scope.customerList = [{
"companyName": "Name and inc",
"Fleet": 3,
"phone":"1010101010",
"contact":"jimmy",
"Base":"Kiad",
"status":'Active',
"source": "tenant",
"allIn" : "$123"
},{
"companyName": "Name and inc",
"Fleet": 3,
"phone":"1010101010",
"contact":"jimmy",
"Base":"Kiad",
"status":'Inactive',
"source": "tenant",
"allIn" : "$123"
},{
"companyName": "Name and inc",
"Fleet": 3,
"phone":"1010101010",
"contact":"jimmy",
"Base":"Kiad",
"status":'Active',
"source": "tenant",
"allIn" : "$123"
},{
"companyName": "Name and inc",
"Fleet": 3,
"phone":"1010101010",
"contact":"jimmy",
"Base":"Kiad",
"status":'Active',
"source": "tenant",
"allIn" : "$123"
}]
$(function() {
$('#toggle-one2').bootstrapToggle();
$('#toggle-one2').change(function() {
$('#console-event').html('Toggle: ' + $(this).prop('checked'));
$scope.data.activate = $(this).prop('checked');
})
})
getData();
function getData(){
CustomersService.getAircraftMake().then(function(result) {
console.log("result", result)
$scope.aircraftMakeList = result;
$scope.aircraft.make = $scope.aircraftMakeList[0];
CustomersService.getModal($scope.aircraft.make).then(function(result) {
$scope.aircraftModalList = result;
$scope.aircraft.model = $scope.aircraftModalList[0];
CustomersService.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;
CustomersService.getModal(makeId).then(function(result) {
$scope.aircraftModalList = result;
$scope.aircraft.model = $scope.aircraftModalList[0];
CustomersService.getAircraftSize(makeId, $scope.aircraft.model).then(function(result) {
$scope.aircraftSizeList = result;
$scope.aircraft.size = $scope.aircraftSizeList[0];
})
})
}
$scope.getSize = function(){
CustomersService.getAircraftSize($scope.aircraft.make, $scope.aircraft.model).then(function(result) {
$scope.aircraftSizeList = result;
$scope.aircraft.size = $scope.aircraftSizeList[0];
})
}
$scope.addFirstData = function(sel, step){
// console.log($scope.data)
// var companyData = "companyName=" + $scope.data.companyName + "&masterMargin=" + $scope.data.masterMargin
// + "&addressOne=" + $scope.data.addressOne + "&addressTwo=" + $scope.data.addressTwo + "&city=" + $scope.data.city + "&state="
// + $scope.data.state + "&country=" + $scope.data.country + "&zipcode=" + $scope.data.zipcode + "&internalNote="
// + $scope.data.internalNote + "&certificateType=" + $scope.data.certificateType + "&baseTenant=" + $scope.data.baseTenant
// + "&fuelerlinxCustomer=" + $scope.data.fuelerlinxCustomer + "&contractFuelVendor=" + $scope.data.contractFuelVendor
// + "&activate=" + $scope.data.activate + "&baseIcao=" + $scope.data.baseIcao;
// CustomersService.addCompany(companyData).then(function(result) {
// console.log(result)
// $scope.accountId = result;
//$scope.aircraft.accountId = $scope.accountId;
// })
$(sel).trigger('next.m.' + step);
getData();
}
$scope.users = [
{id: 1, name: 'awesome user1', status: 2, group: 4, groupName: 'admin'},
{id: 2, name: 'awesome user2', status: undefined, group: 3, groupName: 'vip'},
{id: 3, name: 'awesome user3', status: 2, group: null}
];
$scope.statuses = [
{value: 1, text: 'status1'},
{value: 2, text: 'status2'},
{value: 3, text: 'status3'},
{value: 4, text: 'status4'}
];
$scope.groups = [];
$scope.loadGroups = function() {
return $scope.groups.length ? null : $http.get('/groups').success(function(data) {
$scope.groups = data;
});
};
$scope.showGroup = function(user) {
if(user.group && $scope.groups.length) {
var selected = $filter('filter')($scope.groups, {id: user.group});
return selected.length ? selected[0].text : 'Not set';
} else {
return user.groupName || 'Not set';
}
};
$scope.showStatus = function(user) {
var selected = [];
if(user.status) {
selected = $filter('filter')($scope.statuses, {value: user.status});
}
return selected.length ? selected[0].text : 'Not set';
};
$scope.checkName = function(data, id) {
if (id === 2 && data !== 'awesome') {
return "Username 2 should be `awesome`";
}
};
// filter users to show
$scope.filterUser = function(user) {
return user.isDeleted !== true;
};
// mark user as deleted
$scope.deleteUser = function(id) {
var filtered = $filter('filter')($scope.users, {id: id});
if (filtered.length) {
filtered[0].isDeleted = true;
}
};
// add user
$scope.addUser = function() {
$scope.users.push({
id: $scope.users.length+1,
name: '',
status: null,
group: null,
isNew: true
});
};
// cancel all changes
$scope.cancel = function() {
for (var i = $scope.users.length; i--;) {
var user = $scope.users[i];
// undelete
if (user.isDeleted) {
delete user.isDeleted;
}
// remove new
if (user.isNew) {
$scope.users.splice(i, 1);
}
};
};
// save edits
$scope.saveTable = function() {
var results = [];
for (var i = $scope.users.length; i--;) {
var user = $scope.users[i];
// actually delete user
if (user.isDeleted) {
$scope.users.splice(i, 1);
}
// mark as not new
if (user.isNew) {
user.isNew = false;
}
// send on server
results.push($http.post('/saveUser', user));
}
return $q.all(results);
};
$scope.appendText = function() {
getData();
var newRow = $('<tr> <td> <input type="text" style="width:100px;" ng-model="aircraft.tail" class="form-control"> </td> <td style="width: 25%;"> <select class="form-control" ng-model="aircraft.make" ng-change="getModal()"> <option ng-repeat="make in aircraftMakeList">{{make}}</option> </select> </td> <td style="width: 20%;"> <select class="form-control" ng-model="aircraft.model" ng-change="getSize()"> <option ng-repeat="model in aircraftModalList">{{model}}</option> </select> </td> <td style="width: 25%;"> <select class="form-control" ng-model="aircraft.size"> <option ng-repeat="size in aircraftSizeList">{{size}}</option> </select> </td> <td> <select class="form-control"> <option>Margin1</option> <option>Margin2</option> </select> </td> </tr>');
$('table.addRow').append(newRow);
}
}