diff --git a/spec/controllerSpec.js b/spec/controllerSpec.js index a519627..2f05ed9 100644 --- a/spec/controllerSpec.js +++ b/spec/controllerSpec.js @@ -19,6 +19,7 @@ describe('Controladores de abm chofer', function() { transportistaSeleccionado: function() { return; } }, $location: {}, + $localStorage: {}, $uibModal: {}, focaModalService: {}, focaBotoneraLateralService: {}, @@ -42,6 +43,7 @@ describe('Controladores de abm chofer', function() { transportistaSeleccionado: function() { return; } }, $location: {}, + $localStorage: {}, $uibModal: {}, focaModalService: focaModalService, focaBotoneraLateralService: {}, @@ -75,6 +77,7 @@ describe('Controladores de abm chofer', function() { $scope: scope, focaAbmChoferService: focaAbmChoferService, $location: {}, + $localStorage: {}, $uibModal: {}, focaModalService: focaModalService, focaBotoneraLateralService: {}, @@ -108,6 +111,7 @@ describe('Controladores de abm chofer', function() { transportistaSeleccionado: function() { } }, $location: {}, + $localStorage: {}, $uibModal: {}, focaModalService: focaModalService, focaBotoneraLateralService: {}, @@ -129,7 +133,9 @@ describe('Controladores de abm chofer', function() { it('Existe el controlador focaAbmChoferController', function() { //arrange var controlador = $controller('focaAbmChoferController', { - $scope: {}, + $scope: { + $watch: function() {} + }, focaAbmChoferService: { getTiposDocumento: function() { return { @@ -149,6 +155,7 @@ describe('Controladores de abm chofer', function() { }, $routeParams: {}, $location: {}, + $localStorage: {}, focaBotoneraLateralService: {}, $timeout: function() { return; }, focaModalService: {} @@ -161,7 +168,9 @@ describe('Controladores de abm chofer', function() { it('$scope.cancelar lleva a la ruta correcta', function() { inject(function($location) { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var controlador = $controller('focaAbmChoferController', { $scope: scope, focaAbmChoferService: { @@ -183,6 +192,7 @@ describe('Controladores de abm chofer', function() { }, $routeParams: {}, $location: $location, + $localStorage: {}, focaBotoneraLateralService: {}, $timeout: function() { return; }, focaModalService: {} @@ -200,7 +210,10 @@ describe('Controladores de abm chofer', function() { it('$scope.guardar guarda chofer al validarDNI() da ok', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function(){}, + chofer: {} + }; var focaAbmChoferService = { getTiposDocumento: function() { return { @@ -225,14 +238,19 @@ describe('Controladores de abm chofer', function() { focaAbmChoferService: focaAbmChoferService, $routeParams: {}, $location: {}, + $localStorage: {}, focaBotoneraLateralService: {}, $timeout: function() { return; }, - focaModalService: {} + focaModalService: { + alert: function() {} + } }); console.info(controlador); var resolveFake = { data: false }; var promesaChoferPorDni = Promise.resolve(resolveFake); - + scope.chofer.nombre = true; + scope.chofer.idTipoDocumento = true; + scope.chofer.dni = true; //act spyOn(focaAbmChoferService, 'guardarChofer').and.returnValue({ then: function() { }}); spyOn(focaAbmChoferService, 'getChoferPorDni').and.returnValue(promesaChoferPorDni); @@ -250,7 +268,9 @@ describe('Controladores de abm chofer', function() { it('$scope.guardar da alerta chofer al validarDNI() da reject', function(done) { //arrange - var scope = {}; + var scope = { + $watch: function() {} + }; var focaModalService = { alert: function() { } }; @@ -277,6 +297,7 @@ describe('Controladores de abm chofer', function() { focaAbmChoferService: focaAbmChoferService, $routeParams: {}, $location: {}, + $localStorage: {}, focaBotoneraLateralService: {}, $timeout: function() { return; }, focaModalService: focaModalService diff --git a/src/js/controller.js b/src/js/controller.js index 3fa9dd2..173f2c2 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -20,13 +20,13 @@ angular.module('focaAbmChofer') focaBotoneraLateralService.showCancelar(false); focaBotoneraLateralService.showGuardar(false); focaBotoneraLateralService.addCustomButton('Salir', salir); - }); + }); if (focaAbmChoferService.transportistaSeleccionado.COD) { elegirTransportista(focaAbmChoferService.transportistaSeleccionado); } - $scope.editar = function(id) { + $scope.editar = function(id) { $location.path('/chofer/' + id + '/' + $scope.idTransportista); }; @@ -89,7 +89,7 @@ angular.module('focaAbmChofer') focaAbmChoferService.transportistaSeleccionado = {}; $location.path('/'); } - + if ($localStorage.chofer) { var chofer = JSON.parse($localStorage.chofer); if (!chofer.id) { chofer.id = 0; } @@ -127,7 +127,7 @@ angular.module('focaAbmChofer') }); $timeout(function() {getLSChofer();}); - + if ($scope.nuevo) { focaAbmChoferService .getTransportistaPorId($routeParams.idTransportista) @@ -158,15 +158,15 @@ angular.module('focaAbmChofer') }); function setearChofer(chofer) { - $scope.chofer = chofer; + $scope.chofer = chofer; $scope.$broadcast('addCabecera', { label: 'Transportista:', valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - ' - }); + }); } function getLSChofer() { var chofer = JSON.parse($localStorage.chofer || null); - + if (chofer) { setearChofer(chofer); delete $localStorage.chofer; @@ -179,19 +179,23 @@ angular.module('focaAbmChofer') $scope.guardar = function(key) { - if (!$scope.chofer.nombre) { - focaModalService.alert('Ingrese nombre'); - return; - } else if (!$scope.chofer.idTipoDocumento) { - focaModalService.alert('Seleccione tipo de documento'); - return; - } else if (!$scope.chofer.dni) { - focaModalService.alert('Ingrese DNI'); - return; - } - key = (typeof key === 'undefined') ? 13 : key; if (key === 13) { + console.log('Datos: ', $scope.chofer); + if (!$scope.chofer.nombre) { + focaModalService.alert('Ingrese nombre'); + return; + } else if (!$scope.chofer.idTipoDocumento) { + focaModalService.alert('Seleccione tipo de documento'); + return; + } else if (!$scope.chofer.dni) { + focaModalService.alert('Ingrese DNI'); + return; + } else if (!$scope.chofer.telefono) { + focaModalService.alert('Ingrese número de teléfono'); + return; + } + validaDni().then(function() { $scope.chofer.idTransportista = $routeParams.idTransportista; delete $scope.chofer.transportista; @@ -203,7 +207,7 @@ angular.module('focaAbmChofer') }); } }; - + $scope.$watch('chofer', function(newValue) { focaBotoneraLateralService.setPausarData({ label: 'chofer', diff --git a/src/views/foca-abm-choferes-item.html b/src/views/foca-abm-choferes-item.html index 97e6eba..dfcb2ec 100644 --- a/src/views/foca-abm-choferes-item.html +++ b/src/views/foca-abm-choferes-item.html @@ -38,14 +38,17 @@
@@ -54,13 +57,16 @@