Commit 51c9800474fefcd60faa0fb41a71931bac13349e
1 parent
6708bf36de
Exists in
master
Validacion al salir - Boton check al guardar cisterna
Showing
2 changed files
with
29 additions
and
15 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -171,10 +171,14 @@ angular.module('focaAbmVehiculo') |
| 171 | 171 | }; |
| 172 | 172 | |
| 173 | 173 | $scope.salir = function () { |
| 174 | - if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | |
| 175 | - focaModalService.confirm( | |
| 176 | - '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | |
| 177 | - ).then(function (data) { | |
| 174 | + var cisternaEdit = []; | |
| 175 | + $scope.cisternas.forEach( function (cisterna) { | |
| 176 | + if (cisterna.editando === true) { | |
| 177 | + cisternaEdit.push(cisterna); | |
| 178 | + } | |
| 179 | + }); | |
| 180 | + if (!$scope.formVehiculo.$pristine || cisternaEdit.length > 0) { | |
| 181 | + focaModalService.confirm('¿Está seguro de que desea salir? Se perderán todos los datos cargados.').then(function (data) { | |
| 178 | 182 | if (data) { |
| 179 | 183 | $location.path('/vehiculo'); |
| 180 | 184 | } |
| ... | ... | @@ -245,9 +249,13 @@ angular.module('focaAbmVehiculo') |
| 245 | 249 | $scope.salir(); |
| 246 | 250 | return; |
| 247 | 251 | } |
| 248 | - $scope.cisternas.forEach(function (cisterna) { | |
| 249 | - if (cisterna.id === 0) cisterna.id = undefined; | |
| 250 | - }); | |
| 252 | + | |
| 253 | + for (var i = 0; i < $scope.cisternas.length; i++) { | |
| 254 | + if (!validarCisterna($scope.cisternas[i])){ | |
| 255 | + return; | |
| 256 | + } | |
| 257 | + if ($scope.cisternas[i].id === 0) $scope.cisternas[i].id = undefined; | |
| 258 | + } | |
| 251 | 259 | |
| 252 | 260 | if (!$scope.vehiculo.codigo) { |
| 253 | 261 | focaModalService.alert('Ingrese unidad'); |
| ... | ... | @@ -376,23 +384,29 @@ angular.module('focaAbmVehiculo') |
| 376 | 384 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
| 377 | 385 | } |
| 378 | 386 | |
| 379 | - $scope.agregarCisterna = function (cisterna) { | |
| 387 | + function validarCisterna(cisterna) { | |
| 380 | 388 | if (!cisterna) { |
| 381 | 389 | focaModalService.alert('Ingrese valores'); |
| 382 | - return; | |
| 390 | + return false; | |
| 383 | 391 | } else if (!cisterna.codigo) { |
| 384 | 392 | focaModalService.alert('Ingrese codigo de cisterna'); |
| 385 | - return; | |
| 393 | + return false; | |
| 386 | 394 | } else if (!cisterna.capacidad) { |
| 387 | 395 | focaModalService.alert('Ingrese capacidad'); |
| 388 | - return; | |
| 396 | + return false; | |
| 389 | 397 | } else if (!cisterna.idUnidadMedida) { |
| 390 | 398 | focaModalService.alert('Ingrese unidad de medida'); |
| 391 | - return; | |
| 399 | + return false; | |
| 392 | 400 | } else if (cisterna.id === undefined) { |
| 393 | 401 | cisterna.id = 0; |
| 394 | 402 | } |
| 395 | - | |
| 403 | + return true; | |
| 404 | + } | |
| 405 | + | |
| 406 | + $scope.agregarCisterna = function (cisterna) { | |
| 407 | + if(!validarCisterna(cisterna)) { | |
| 408 | + return; | |
| 409 | + } | |
| 396 | 410 | validaTotalCargas(); |
| 397 | 411 | validaCodigo(cisterna); |
| 398 | 412 | }; |
src/views/foca-abm-vehiculos-item.html
| ... | ... | @@ -146,7 +146,7 @@ |
| 146 | 146 | class="btn btn-outline-dark boton-accion" |
| 147 | 147 | ng-click="agregarCisterna()" |
| 148 | 148 | > |
| 149 | - <i class="fa fa-save"></i> | |
| 149 | + <i class="fa fa-check"></i> | |
| 150 | 150 | </button> |
| 151 | 151 | </td> |
| 152 | 152 | </tr> |
| ... | ... | @@ -223,7 +223,7 @@ |
| 223 | 223 | class="btn btn-outline-dark boton-accion" |
| 224 | 224 | ng-click="agregarCisterna(cisterna)" |
| 225 | 225 | > |
| 226 | - <i class="fa fa-save"></i> | |
| 226 | + <i class="fa fa-check"></i> | |
| 227 | 227 | </button> |
| 228 | 228 | <button |
| 229 | 229 | class="btn btn-outline-dark boton-accion" |