Commit 7c6be3b387e3574bc3eb67f41263440e2f78d117

Authored by Luigi
1 parent 1f9869ff74
Exists in master and in 2 other branches develop, lab

Arreglo validacion DNI

Showing 1 changed file with 20 additions and 18 deletions   Show diff stats
src/js/controller.js
... ... @@ -60,29 +60,14 @@ angular.module('focaAbmChofer')
60 60 };
61 61  
62 62 $scope.agregarChofer = function (chofer) {
63   - if (!chofer) {
  63 + if (!chofer.nombre) {
64 64 focaModalService.alert('Ingrese nombre');
65 65 return;
66 66 } else if (!chofer.idTipoDocumento) {
67 67 focaModalService.alert('Ingrese tipo documento');
68 68 return;
69   - } else if (!chofer.dni) {
70   - focaModalService.alert('Ingrese DNI');
71   - return;
72   - } else if (!chofer.telefono) {
73   - focaModalService.alert('Ingrese teléfono');
74   - return;
75   - }
76   -
77   - validaDni(chofer).then(function() {
78   - chofer.idTransportista = focaAbmChoferService.transportistaSeleccionado.COD;
79   - delete chofer.transportista;
80   - }, function() {
81   - focaModalService.alert('Dni existente');
82   - $scope.editando = true;
83   - });
84   - $scope.crear = true;
85   - chofer.editando = false;
  69 + }
  70 + validaDni(chofer);
86 71 };
87 72  
88 73 $scope.tipoDocumento = function (idTipoDocumento) {
... ... @@ -189,6 +174,14 @@ angular.module('focaAbmChofer')
189 174 }
190 175  
191 176 function validaDni(chofer) {
  177 + if (!chofer.dni) {
  178 + focaModalService.alert('Ingrese DNI');
  179 + return;
  180 + } else if (!chofer.telefono) {
  181 + focaModalService.alert('Ingrese teléfono');
  182 + return;
  183 + }
  184 +
192 185 return new Promise(function(resolve, reject) {
193 186 focaAbmChoferService
194 187 .getChoferPorDni(chofer.dni)
... ... @@ -199,7 +192,16 @@ angular.module('focaAbmChofer')
199 192 } else {
200 193 resolve();
201 194 }
  195 + })
  196 + .then(function() {
  197 + chofer.idTransportista = focaAbmChoferService.transportistaSeleccionado.COD;
  198 + delete chofer.transportista;
  199 + }, function() {
  200 + focaModalService.alert('Dni existente');
  201 + $scope.editando = true;
202 202 });
  203 + $scope.crear = true;
  204 + chofer.editando = false;
203 205 });
204 206 }
205 207