controller.js 1.28 KB
angular.module('focaGestionTerminal')
    .controller('gestionTerminalController',
    [
        '$scope',
        'gestionTerminalService',
        'netTesting',
        function($scope, gestionTerminalesService, netTesting) {
            $scope.empresa = {};
            $scope.empresas = [];

            gestionTerminalesService.getEmpresas().then(function(res) {

                $scope.empresas = res.data;
            });
            
            $scope.guardar = function() {

                netTesting.ping($scope.empresa.url, function() {

                    if (arguments[1] === 'disconnected') {
                        $scope.mensaje = "La url indicada no tiene conección";
                        return;
                    }

                    gestionTerminalesService.insertEmpresa(
                        { empresa: $scope.empresa}).then(function() {

                        $scope.mensaje = "Empresa guardada con éxito";
                        $scope.empresas.push($scope.terminal);
                        $scope.empresa = {};
                        $scope.empresaGuardada = true;

                    }).catch(function() {

                        $scope.mensaje = "Hubo un error al guardar la empresa";
                    });

                });
            };

        }]);