controller.js 3.87 KB
angular.module('focaCrearLogin')
    .controller('focaCrearLoginController', [
        '$scope', '$timeout', '$uibModal', 'focaCrearLoginService','focaBotoneraLateralService',
        function($scope, $timeout, $uibModal, focaCrearLoginService, focaBotoneraLateralService) {
            config();



            //METODOS
            function init() {
                $scope.now = new Date();
                $scope.seleccionado = '';
                $scope.cuentas = [];
                $scope.$broadcast('removeCabecera', {
                    label: 'Selección:',
                    valor: $scope.seleccionado
                });
            }

            function config() {
                $scope.botonera = [
                    {
                        label: 'Transportista',
                        image: 'cliente.png'
                    },
                    {
                        label: 'Cobrador',
                        image: 'cliente.png'
                    },
                    {
                        label: 'Vendedor',
                        image: 'cliente.png'
                    }
                ];
                
                $timeout(function() {
                    focaBotoneraLateralService.showSalir(true);
                    focaBotoneraLateralService.showPausar(false);
                    focaBotoneraLateralService.showCancelar(false);
                    focaBotoneraLateralService.showGuardar(false);
                });

                init();
            }

            $scope.seleccionarTransportista = function() {
                $scope.seleccionado = 'Transportistas';
                
                focaCrearLoginService.getListaChoferes().then(setearTabla);
            };

            $scope.seleccionarCobrador = function() {
                $scope.seleccionado = 'Cobradores';
                
                focaCrearLoginService.getListaCobradores().then(setearTabla);
            };

            $scope.seleccionarVendedor = function() {
                $scope.seleccionado = 'Vendedores';
                
                focaCrearLoginService.getListaVendedores().then(setearTabla);
            };

            $scope.openModalAcceso = function(cuenta) {
                var parametros = {
                    cuenta: cuenta,
                    tipo: $scope.seleccionado
                }
                
                var modalInstance = $uibModal.open(
                    {
                        ariaLabelledBy: 'Configuracion de Logueo',
                        templateUrl: 'modal-login.html',
                        controller: 'focaModalLoginController',
                        size: 'md',
                        resolve: {
                            parametros: function() {
                                return parametros;
                            }
                        }
                    }
                );
                
                modalInstance.result.then(
                    function(result) {
                        init();
                    }, function() {}
                );
            }

            function setearTabla(datos) {
                $scope.cuentas = datos.data;

                if ($scope.seleccionado == 'Cobradores' ||
                    $scope.seleccionado == 'Vendedores'
                ) {
                    for (var i = $scope.cuentas.length - 1; i >= 0; i--) {  
                        $scope.cuentas[i].id = $scope.cuentas[i].CodVen;
                        $scope.cuentas[i].nombre = $scope.cuentas[i].NomVen;
                        $scope.cuentas[i].dni = $scope.cuentas[i].DNI;
                        $scope.cuentas[i].telefono = $scope.cuentas[i].TelVen;
                    }       
                }

                $scope.$broadcast('removeCabecera', {
                    label: 'Selección:',
                    valor: $scope.seleccionado
                });
            }
        }
    ]);