controller.js 2.14 KB
angular.module('focaAbmChofer')
    .controller('focaAbmChoferesController', [
        '$scope', 'focaAbmChoferService', '$location', 'focaModalService',
        function($scope, focaAbmChoferService, $location, focaModalService) {

            $scope.filters = '';
            $scope.choferes = [];
            $scope.choferesFiltrados = [];

            focaAbmChoferService.getChoferes().then(function(datos) {
                $scope.choferes = datos.data;
                $scope.choferesFiltrados = $scope.choferes;
            });

            

            $scope.editar = function(id) {
                $location.path('/chofer/' + id);
            };

            $scope.solicitarConfirmacion = function(chofer) {
                focaModalService.confirm('¿Está seguro que desea borrar el chofer ' +
                    chofer.nombre + ' ?').then(function(confirmed) {
                        if(confirmed) {
                            focaAbmChoferService.deleteChofer(chofer.id);
                            $scope.choferes.splice($scope.choferes.indexOf(chofer), 1);
                        }
                    });
            };
            

        }
    ])
    .controller('focaAbmChoferController', [
        '$scope', 'focaAbmChoferService', '$routeParams', '$location',
        function($scope, focaAbmChoferService, $routeParams, $location) {

            $scope.chofer = {};
            $scope.transportistas = [];

            focaAbmChoferService.getChofer($routeParams.id).then(function(res) {
                if(res.data) $scope.chofer = res.data;
            });

            focaAbmChoferService.getTransportistas().then(function(res) {
                $scope.transportistas = res.data;
            });

            $scope.cancelar = function() {
                $location.path('/chofer');
            };

            $scope.guardar = function() {
                $scope.chofer.idTransportista = $scope.chofer.transportista.COD;
                delete $scope.chofer.transportista;
                focaAbmChoferService.guardarChofer($scope.chofer).then(function() {
                    $location.path('/chofer');
                });
            };

        }
    ]);