controller.js
2.17 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
angular.module('focaAbmVehiculo')
.controller('focaAbmVehiculosController', [
'$scope', 'focaAbmVehiculoService', '$location', 'focaModalService',
function($scope, focaAbmVehiculoService, $location, focaModalService) {
focaAbmVehiculoService.getVehiculos().then(function(datos) {
$scope.vehiculos = datos.data;
$scope.vehiculosFiltrados = $scope.vehiculos;
});
$scope.editar = function(id) {
$location.path('/vehiculo/' + id);
};
$scope.solicitarConfirmacion = function(vehiculo) {
focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
function(data) {
if(data) {
focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
$scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
}
}
);
};
}
])
.controller('focaAbmVehiculoController', [
'$scope', 'focaAbmVehiculoService', '$routeParams', '$location',
function($scope, focaAbmVehiculoService, $routeParams, $location) {
focaAbmVehiculoService.getVehiculo($routeParams.id).then(function(res) {
if(!res.data[0].transportista.COD) {
res.data[0].transportista = '';
}
$scope.vehiculo = res.data[0];
});
focaAbmVehiculoService.getTransportistas().then(function(res) {
$scope.transportistas = res.data;
});
$scope.cancelar = function() {
$location.path('/vehiculo');
};
$scope.guardar = function() {
$scope.vehiculo.idTransportista = $scope.vehiculo.transportista.COD;
delete $scope.vehiculo.transportista;
focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo).then(function() {
$location.path('/vehiculo');
});
};
}
]);