Commit 2f621a2c3dc48f0d3e20f208e55487a26a5f189b

Authored by Jose Pinto
1 parent 2d4580fb71
Exists in master and in 1 other branch develop

ok validaciones vehiculo y cisterna

src/js/controller.js
... ... @@ -154,7 +154,7 @@ angular.module('focaAbmVehiculo')
154 154 };
155 155  
156 156 function salir() {
157   - if (!$scope.formVehiculo.$pristine) {
  157 + if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
158 158 focaModalService.confirm(
159 159 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
160 160 ).then(function(data) {
... ... @@ -181,8 +181,8 @@ angular.module('focaAbmVehiculo')
181 181  
182 182 if (key === 13) {
183 183  
184   - if ($scope.formVehiculo.$pristine) {
185   - $scope.cancelar();
  184 + if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
  185 + salir();
186 186 return;
187 187 }
188 188  
... ... @@ -299,7 +299,7 @@ angular.module('focaAbmVehiculo')
299 299 total += parseInt(cisterna.capacidad);
300 300 }
301 301 });
302   - return $scope.vehiculo.capacidad === total;
  302 + return $scope.vehiculo.capacidad == total;
303 303 }
304 304  
305 305 function guardarCisternas() {
... ... @@ -316,5 +316,6 @@ angular.module('focaAbmVehiculo')
316 316  
317 317 return focaAbmVehiculoService.guardarCisternas(cisternas);
318 318 }
  319 +
319 320 }
320 321 ]);
src/js/controllerCisterna.js
1 1 angular.module('focaAbmVehiculo')
2 2 .controller('focaAbmVehiculoCisternaController', [
3 3 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
4   - 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter',
  4 + 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window',
5 5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
6   - focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) {
  6 + focaModalService, focaBotoneraLateralService, $timeout, $window) {
7 7 $scope.nuevo = ($routeParams.idx > -1) ? false : true;
8 8 $scope.editar = false;
9 9 $scope.now = new Date();
... ... @@ -66,6 +66,8 @@ angular.module('focaAbmVehiculo')
66 66 $location.path('/vehiculo');
67 67 }
68 68 });
  69 + } else {
  70 + $window.history.back();
69 71 }
70 72 };
71 73  
... ... @@ -74,9 +76,7 @@ angular.module('focaAbmVehiculo')
74 76 if ($scope.formCisterna.$pristine) {
75 77 $scope.cancelar();
76 78 return;
77   - }
78   -
79   - if (!$scope.cisterna.codigo) {
  79 + } else if (!$scope.cisterna.codigo) {
80 80 focaModalService.alert('Ingrese codigo de cisterna');
81 81 return;
82 82 } else if (!$scope.cisterna.capacidad) {
... ... @@ -130,7 +130,7 @@ angular.module('focaAbmVehiculo')
130 130 cisternas.forEach(function(cisterna, idx) {
131 131 //SI EL CODIGO YA EXISTE
132 132 if (cisterna.codigo === $scope.cisterna.codigo &&
133   - idx !== $routeParams.idx &&
  133 + idx != $routeParams.idx &&
134 134 !cisterna.desactivado) {
135 135 reject('Código de cisterna existente');
136 136 }
1 1 angular.module('focaAbmVehiculo')
2 2 .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 3 var cisternas = [];
  4 + var cisternasPristine = true;
4 5 return {
5 6 getVehiculos: function() {
6 7 return $http.get(API_ENDPOINT.URL + '/vehiculo');
... ... @@ -18,9 +19,11 @@ angular.module('focaAbmVehiculo')
18 19 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id);
19 20 },
20 21 getCisternas: function(idVehiculo) {
21   - if(cisternas.length) {
  22 + if (cisternas.length) {
  23 + cisternasPristine = true;
22 24 return Promise.resolve(angular.copy(cisternas));
23   - }else {
  25 + } else {
  26 + cisternasPristine = true;
24 27 return new Promise(function(resolve) {
25 28 $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo)
26 29 .then(function(res) {
... ... @@ -31,12 +34,14 @@ angular.module('focaAbmVehiculo')
31 34 }
32 35 },
33 36 guardarCisterna: function(cisterna, idx) {
34   - if(idx !== '-1') {
  37 + if (idx !== '-1') {
35 38 //update
36 39 cisternas[idx] = cisterna;
37   - }else {
  40 + cisternasPristine = false;
  41 + } else {
38 42 //insert
39 43 cisternas.push(cisterna);
  44 + cisternasPristine = false;
40 45 }
41 46 },
42 47 guardarCisternas: function(cisternas) {
... ... @@ -44,6 +49,7 @@ angular.module('focaAbmVehiculo')
44 49 },
45 50 deleteCisterna: function(idx) {
46 51 cisternas[idx].desactivado = true;
  52 + cisternasPristine = false;
47 53 },
48 54 cleanCisternas: function() {
49 55 cisternas = [];