controller.js 2.17 KB
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');
                });
            };
        }
    ]);