Commit 432f6c3b043bbff760b2144b019ac80eb59edfcc

Authored by Eric Fernandez
Exists in master

Merge branch 'develop' into 'master'

Develop

See merge request !41
... ... @@ -47,10 +47,10 @@
47 47 "strict": false,
48 48  
49 49 // Prohibit use of explicitly undeclared variables.
50   - "undef": true,
  50 + "undef": false,
51 51  
52 52 // Warn when variables are defined but never used.
53   - "unused": true,
  53 + "unused": false,
54 54  
55 55 // Para que funcione en angular
56 56 "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"],
... ... @@ -36,7 +36,7 @@
36 36 },
37 37 "devDependencies": {
38 38 "angular": "^1.7.5",
39   - "angular-mocks": "^1.7.7",
  39 + "angular-mocks": "^1.7.8",
40 40 "angular-route": "^1.7.7",
41 41 "bootstrap": "^4.1.3",
42 42 "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git",
spec/controllerSpec.js
... ... @@ -29,6 +29,7 @@ describe('Controladores abm vehículo', function() {
29 29 showGuardar: function() { return; },
30 30 addCustomButton: function() { return; }
31 31 },
  32 + $localStorage: {},
32 33 $timeout: {}
33 34 });
34 35  
... ... @@ -38,7 +39,9 @@ describe('Controladores abm vehículo', function() {
38 39  
39 40 it('Crea fecha nueva', function() {
40 41 //arrange
41   - var scope = {};
  42 + var scope = {
  43 + $watch: function() {}
  44 + };
42 45 var controller = $controller('focaAbmVehiculosController', {
43 46 $scope: scope,
44 47 focaAbmVehiculoService: {
... ... @@ -55,6 +58,7 @@ describe('Controladores abm vehículo', function() {
55 58 showGuardar: function() { return; },
56 59 addCustomButton: function() { return; }
57 60 },
  61 + $localStorage: {},
58 62 $timeout: {}
59 63 });
60 64  
... ... @@ -67,7 +71,9 @@ describe('Controladores abm vehículo', function() {
67 71  
68 72 it('$scope setea botonera lateral', function() {
69 73 //arrange
70   - var scope = {};
  74 + var scope = {
  75 + $watch: function() {}
  76 + };
71 77 var controller = $controller('focaAbmVehiculosController', {
72 78 $scope: scope,
73 79 focaAbmVehiculoService: {
... ... @@ -84,7 +90,8 @@ describe('Controladores abm vehículo', function() {
84 90 showGuardar: function() { return; },
85 91 addCustomButton: function() { return; }
86 92 },
87   - $timeout: {}
  93 + $timeout: {},
  94 + $localStorage: {}
88 95 });
89 96  
90 97 //act
... ... @@ -97,7 +104,9 @@ describe('Controladores abm vehículo', function() {
97 104 it('$scope.editar lleva a la ruta correcta', function() {
98 105 inject(function($location) {
99 106 //arrange
100   - var scope = {};
  107 + var scope = {
  108 + $watch: function() {}
  109 + };
101 110 var controller = $controller('focaAbmVehiculosController', {
102 111 $scope: scope,
103 112 focaAbmVehiculoService: {
... ... @@ -114,7 +123,8 @@ describe('Controladores abm vehículo', function() {
114 123 showGuardar: function() { return; },
115 124 addCustomButton: function() { return; }
116 125 },
117   - $timeout: {}
  126 + $timeout: {},
  127 + $localStorage: {}
118 128 });
119 129  
120 130 //act
... ... @@ -128,7 +138,9 @@ describe('Controladores abm vehículo', function() {
128 138  
129 139 it('Solicita confirmacion', function() {
130 140 //arrange
131   - var scope = {};
  141 + var scope = {
  142 + $watch: function() {}
  143 + };
132 144 var focaModalService = {
133 145 confirm: function() {}
134 146 };
... ... @@ -148,7 +160,8 @@ describe('Controladores abm vehículo', function() {
148 160 showGuardar: function() { return; },
149 161 addCustomButton: function() { return; }
150 162 },
151   - $timeout: {}
  163 + $timeout: {},
  164 + $localStorage: {}
152 165 });
153 166  
154 167 //act
... ... @@ -186,7 +199,8 @@ describe('Controladores abm vehículo', function() {
186 199 showGuardar: function() { return; },
187 200 addCustomButton: function() { return; }
188 201 },
189   - $timeout: {}
  202 + $timeout: {},
  203 + $localStorage: {}
190 204 });
191 205 var promesa = Promise.resolve(true);
192 206  
... ... @@ -206,7 +220,9 @@ describe('Controladores abm vehículo', function() {
206 220  
207 221 it('Se selecciona transportista', function() {
208 222 //arrange
209   - var scope = {};
  223 + var scope = {
  224 + $watch: function() {}
  225 + };
210 226 var focaModalService = {
211 227 modal: function() {}
212 228 };
... ... @@ -226,7 +242,8 @@ describe('Controladores abm vehículo', function() {
226 242 showGuardar: function() { return; },
227 243 addCustomButton: function() { return; }
228 244 },
229   - $timeout: {}
  245 + $timeout: {},
  246 + $localStorage: {}
230 247 });
231 248  
232 249 //act
... ... @@ -241,7 +258,9 @@ describe('Controladores abm vehículo', function() {
241 258 inject(function($timeout) {
242 259  
243 260 //arrange
244   - var scope = {};
  261 + var scope = {
  262 + $watch: function() {}
  263 + };
245 264 var focaModalService = {
246 265 modal: function() { return; }
247 266 };
... ... @@ -268,6 +287,7 @@ describe('Controladores abm vehículo', function() {
268 287 showGuardar: function() { return; },
269 288 addCustomButton: function() { return; }
270 289 },
  290 + $localStorage: {},
271 291 $timeout: $timeout
272 292 });
273 293 var promesa = Promise.resolve({COD: '', NOM: ''});
... ... @@ -301,7 +321,9 @@ describe('Controladores abm vehículo', function() {
301 321  
302 322 //arrange
303 323 var controller = $controller('focaAbmVehiculoController', {
304   - $scope: {},
  324 + $scope: {
  325 + $watch: function() {}
  326 + },
305 327 focaAbmVehiculoService: {
306 328 getVehiculo: function() {
307 329 return {
... ... @@ -321,6 +343,7 @@ describe('Controladores abm vehículo', function() {
321 343 showGuardar: function() { return; },
322 344 addCustomButton: function() { return; }
323 345 },
  346 + $localStorage: {},
324 347 $window: {}
325 348 });
326 349  
... ... @@ -332,7 +355,9 @@ describe('Controladores abm vehículo', function() {
332 355 it('Se busca el transportista cuando es nuevo', function() {
333 356  
334 357 //arrange
335   - var scope = {};
  358 + var scope = {
  359 + $watch: function() {}
  360 + };
336 361 var focaAbmVehiculoService = {
337 362 getVehiculo: function() {
338 363 return {
... ... @@ -363,6 +388,7 @@ describe('Controladores abm vehículo', function() {
363 388 showGuardar: function() { return; },
364 389 addCustomButton: function() { return; }
365 390 },
  391 + $localStorage: {},
366 392 $window: {}
367 393 });
368 394  
... ... @@ -373,7 +399,9 @@ describe('Controladores abm vehículo', function() {
373 399 it('No se busca el transportista cuando es nuevo', function() {
374 400  
375 401 //arrange
376   - var scope = {};
  402 + var scope = {
  403 + $watch: function() {}
  404 + };
377 405 var focaAbmVehiculoService = {
378 406 getVehiculo: function() {
379 407 return {
... ... @@ -402,6 +430,7 @@ describe('Controladores abm vehículo', function() {
402 430 showGuardar: function() { return; },
403 431 addCustomButton: function() { return; }
404 432 },
  433 + $localStorage: {},
405 434 $window: {}
406 435 });
407 436  
... ... @@ -413,7 +442,13 @@ describe('Controladores abm vehículo', function() {
413 442  
414 443 inject(function($location) {
415 444 //arrange
416   - var scope = {};
  445 + var scope = {
  446 + $watch: function() {},
  447 + cancelar: function() {},
  448 + formVehiculo: {
  449 + $pristine: true
  450 + }
  451 + };
417 452 var controller = $controller('focaAbmVehiculoController', {
418 453 $scope: scope,
419 454 focaAbmVehiculoService: {
... ... @@ -435,11 +470,13 @@ describe('Controladores abm vehículo', function() {
435 470 showGuardar: function() { return; },
436 471 addCustomButton: function() { return; }
437 472 },
438   - $window: {}
  473 + $localStorage: {},
  474 + $window: {},
  475 +
439 476 });
440 477  
441 478 //act
442   - scope.cancelar();
  479 + scope.salir();
443 480  
444 481 //assert
445 482 expect($location.url()).toEqual('/vehiculo');
... ... @@ -450,7 +487,9 @@ describe('Controladores abm vehículo', function() {
450 487  
451 488 inject(function($location) {
452 489 //arrange
453   - var scope = {};
  490 + var scope = {
  491 + $watch: function() {}
  492 + };
454 493 var controller = $controller('focaAbmVehiculoController', {
455 494 $scope: scope,
456 495 focaAbmVehiculoService: {
... ... @@ -474,6 +513,7 @@ describe('Controladores abm vehículo', function() {
474 513 showGuardar: function() { return; },
475 514 addCustomButton: function() { return; }
476 515 },
  516 + $localStorage: {},
477 517 $window: {}
478 518 });
479 519  
... ... @@ -490,7 +530,9 @@ describe('Controladores abm vehículo', function() {
490 530  
491 531 inject(function($location) {
492 532 //arrange
493   - var scope = {};
  533 + var scope = {
  534 + $watch: function() {}
  535 + };
494 536 var controller = $controller('focaAbmVehiculoController', {
495 537 $scope: scope,
496 538 focaAbmVehiculoService: {
... ... @@ -514,6 +556,7 @@ describe('Controladores abm vehículo', function() {
514 556 showGuardar: function() { return; },
515 557 addCustomButton: function() { return; }
516 558 },
  559 + $localStorage: {},
517 560 $window: {}
518 561 });
519 562  
... ... @@ -532,7 +575,9 @@ describe('Controladores abm vehículo', function() {
532 575 var focaModalService = {
533 576 confirm: function() {}
534 577 };
535   - var scope = {};
  578 + var scope = {
  579 + $watch: function() {}
  580 + };
536 581 var controller = $controller('focaAbmVehiculoController', {
537 582 $scope: scope,
538 583 focaAbmVehiculoService: {
... ... @@ -556,6 +601,7 @@ describe('Controladores abm vehículo', function() {
556 601 showGuardar: function() { return; },
557 602 addCustomButton: function() { return; }
558 603 },
  604 + $localStorage: {},
559 605 $window: {}
560 606 });
561 607  
... ... @@ -570,7 +616,9 @@ describe('Controladores abm vehículo', function() {
570 616 it('Elimina y obtiene cisternas al dar confirmar', function(done) {
571 617  
572 618 //arrange
573   - var scope = {};
  619 + var scope = {
  620 + $watch: function() {}
  621 + };
574 622 var focaModalService = {
575 623 confirm: function() {}
576 624 };
... ... @@ -598,6 +646,7 @@ describe('Controladores abm vehículo', function() {
598 646 showGuardar: function() { return; },
599 647 addCustomButton: function() { return; }
600 648 },
  649 + $localStorage: {},
601 650 $window: {}
602 651 });
603 652 var promesa = Promise.resolve(true);
src/js/controller.js
1 1 angular.module('focaAbmVehiculo')
2 2 .controller('focaAbmVehiculosController', [
3 3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService',
4   - '$uibModal', 'focaBotoneraLateralService', '$timeout',
  4 + '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage',
5 5 function($scope, focaAbmVehiculoService, $location, focaModalService,
6   - $uibModal, focaBotoneraLateralService, $timeout) {
  6 + $uibModal, focaBotoneraLateralService, $timeout, $localStorage) {
7 7  
8 8 $scope.now = new Date();
9 9 $scope.botonera = [{
... ... @@ -20,7 +20,7 @@ angular.module('focaAbmVehiculo')
20 20 focaBotoneraLateralService.showGuardar(false);
21 21 focaBotoneraLateralService.addCustomButton('Salir', salir);
22 22  
23   - if(focaAbmVehiculoService.transportistaSeleccionado.COD) {
  23 + if (focaAbmVehiculoService.transportistaSeleccionado.COD) {
24 24 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado);
25 25 }
26 26 $scope.editar = function(id) {
... ... @@ -28,9 +28,9 @@ angular.module('focaAbmVehiculo')
28 28 };
29 29 $scope.solicitarConfirmacion = function(vehiculo) {
30 30 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
31   - vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
  31 + vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
32 32 function(data) {
33   - if(data) {
  33 + if (data) {
34 34 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
35 35 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
36 36 }
... ... @@ -77,7 +77,7 @@ angular.module('focaAbmVehiculo')
77 77 });
78 78 buscar(transportista.COD);
79 79 }
80   -
  80 +
81 81 function buscar(idTransportista) {
82 82 focaAbmVehiculoService
83 83 .getVehiculosPorTransportista(idTransportista)
... ... @@ -93,9 +93,9 @@ angular.module('focaAbmVehiculo')
93 93 ])
94 94 .controller('focaAbmVehiculoController', [
95 95 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
96   - 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window',
  96 + 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter',
97 97 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
98   - focaModalService, $timeout, focaBotoneraLateralService, $window) {
  98 + focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) {
99 99 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
100 100 $scope.now = new Date();
101 101 $scope.focused = 1;
... ... @@ -104,13 +104,15 @@ angular.module('focaAbmVehiculo')
104 104  
105 105 $timeout(function() {
106 106 focaBotoneraLateralService.showSalir(false);
107   - focaBotoneraLateralService.showPausar(false);
  107 + focaBotoneraLateralService.showPausar(true);
108 108 focaBotoneraLateralService.showCancelar(false);
109 109 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
110   - focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar);
  110 + focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
111 111 });
  112 +
  113 + $timeout(function() {getLSVehiculo();});
112 114  
113   - if($scope.nuevo) {
  115 + if ($scope.nuevo) {
114 116 focaAbmVehiculoService
115 117 .getTransportistaPorId($routeParams.idTransportista)
116 118 .then(function(res) {
... ... @@ -125,7 +127,7 @@ angular.module('focaAbmVehiculo')
125 127 }
126 128 $scope.vehiculo = {};
127 129 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
128   - if(res.data) {
  130 + if (res.data) {
129 131 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5);
130 132 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM;
131 133  
... ... @@ -150,9 +152,21 @@ angular.module('focaAbmVehiculo')
150 152 $scope.next = function(key) {
151 153 if (key === 13) $scope.focused++;
152 154 };
153   - $scope.cancelar = function() {
154   - $location.path('/vehiculo');
155   - };
  155 +
  156 + $scope.salir = function() {
  157 + if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
  158 + focaModalService.confirm(
  159 + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
  160 + ).then(function(data) {
  161 + if (data) {
  162 + $location.path('/vehiculo');
  163 + }
  164 + });
  165 + } else {
  166 + $location.path('/vehiculo');
  167 + }
  168 + }
  169 +
156 170 $scope.editar = function(key) {
157 171 if (key) {
158 172 $location.path('/vehiculo/' + $routeParams.idVehiculo +
... ... @@ -163,25 +177,30 @@ angular.module('focaAbmVehiculo')
163 177 };
164 178 $scope.guardar = function(key) {
165 179  
166   - if (!$scope.vehiculo.codigo) {
167   - focaModalService.alert('Ingrese unidad');
168   - return;
169   - } else if (!$scope.vehiculo.tractor) {
170   - focaModalService.alert('Ingrese dominio tractor');
171   - return;
172   - } else if (!$scope.vehiculo.semi) {
173   - focaModalService.alert('Ingrese dominio semi');
174   - return;
175   - } else if (!$scope.vehiculo.capacidad) {
176   - focaModalService.alert('Ingrse capacidad total');
177   - return;
178   - }
179   -
180   -
181 180 key = (typeof key === 'undefined') ? 13 : key;
  181 +
182 182 if (key === 13) {
  183 +
  184 + if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
  185 + $scope.salir();
  186 + return;
  187 + }
  188 +
  189 + if (!$scope.vehiculo.codigo) {
  190 + focaModalService.alert('Ingrese unidad');
  191 + return;
  192 + } else if (!$scope.vehiculo.tractor) {
  193 + focaModalService.alert('Ingrese dominio tractor');
  194 + return;
  195 + } else if (!$scope.vehiculo.semi) {
  196 + focaModalService.alert('Ingrese dominio semi');
  197 + return;
  198 + } else if (!$scope.vehiculo.capacidad) {
  199 + focaModalService.alert('Ingrese capacidad total');
  200 + return;
  201 + }
183 202 //Valida si existe numero de unidad
184   - if(!validaTotalCargas() && !$scope.nuevo) {
  203 + if (!validaTotalCargas() && !$scope.nuevo) {
185 204 focaModalService.alert('La suma de las capacidades de las cisternas' +
186 205 ' debe ser igual a la capacidad total del vehículo');
187 206 return;
... ... @@ -206,11 +225,42 @@ angular.module('focaAbmVehiculo')
206 225 }
207 226  
208 227 };
  228 +
  229 + $scope.$watch('vehiculo', function(newValue) {
  230 + focaBotoneraLateralService.setPausarData({
  231 + label:'vehiculo',
  232 + val: {
  233 + codigo: newValue.codigo,
  234 + tractor: newValue.tractor,
  235 + semi: newValue.semi,
  236 + capacidad: newValue.capacidad,
  237 + idVehiculo: newValue.idVehiculo,
  238 + idTransportista: newValue.idTransportista
  239 + }
  240 + });
  241 + }, true);
  242 +
  243 + function getLSVehiculo() {
  244 + var vehiculo = JSON.parse($localStorage.vehiculo|| null);
  245 + if (vehiculo) {
  246 + setearVehiculo(vehiculo);
  247 + delete $localStorage.vehiculo;
  248 + }
  249 + }
  250 +
  251 + function setearVehiculo(vehiculo) {
  252 + $scope.vehiculo = vehiculo;
  253 + $scope.$broadcast('addCabecera', {
  254 + label: 'Vehiculo:',
  255 + valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - '
  256 + });
  257 + }
  258 +
209 259 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) {
210 260 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
211   - cisterna.id + ' ' + cisterna.codigo + ' ?').then(
  261 + cisterna.id + ' ' + cisterna.codigo + ' ?').then(
212 262 function(data) {
213   - if(data) {
  263 + if (data) {
214 264 focaAbmVehiculoService.deleteCisterna(idx);
215 265 focaAbmVehiculoService
216 266 .getCisternas($routeParams.idVehiculo)
... ... @@ -233,9 +283,9 @@ angular.module('focaAbmVehiculo')
233 283 vehiculo.id !== $scope.vehiculo.id;
234 284 });
235 285  
236   - if(existe.length) {
  286 + if (existe.length) {
237 287 reject(existe);
238   - }else {
  288 + } else {
239 289 resolve();
240 290 }
241 291 });
... ... @@ -245,7 +295,7 @@ angular.module('focaAbmVehiculo')
245 295 function validaTotalCargas() {
246 296 var total = 0;
247 297 $scope.cisternas.forEach(function(cisterna) {
248   - if(!cisterna.desactivado) {
  298 + if (!cisterna.desactivado) {
249 299 total += parseInt(cisterna.capacidad);
250 300 }
251 301 });
... ... @@ -266,5 +316,6 @@ angular.module('focaAbmVehiculo')
266 316  
267 317 return focaAbmVehiculoService.guardarCisternas(cisternas);
268 318 }
  319 +
269 320 }
270 321 ]);
src/js/controllerCisterna.js
... ... @@ -23,13 +23,13 @@ angular.module('focaAbmVehiculo')
23 23 //SETEO BOTONERA LATERAL
24 24 $timeout(function() {
25 25 focaBotoneraLateralService.showSalir(false);
26   - focaBotoneraLateralService.showPausar(false);
27   - focaBotoneraLateralService.showCancelar(true);
  26 + focaBotoneraLateralService.showPausar(true);
  27 + focaBotoneraLateralService.showCancelar(false);
28 28 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
  29 + focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
29 30 });
30 31  
31   - if ($routeParams.idx != -1) {
32   -
  32 + if ($routeParams.idx !== -1) {
33 33 $scope.cisterna = [$routeParams.idx];
34 34 focaAbmVehiculoService
35 35 .getCisternas($routeParams.idVehiculo)
... ... @@ -55,12 +55,30 @@ angular.module('focaAbmVehiculo')
55 55 valor: res.data.capacidad
56 56 });
57 57 });
58   - $scope.cancelar = function() {
59   - $location.path('/vehiculo/' + $routeParams.idVehiculo);
  58 +
  59 + $scope.salir = function() {
  60 +
  61 + if (!$scope.formCisterna.$pristine) {
  62 + focaModalService.confirm(
  63 + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
  64 + ).then(function(data) {
  65 + if (data) {
  66 + $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' +
  67 + $scope.transportista);
  68 + }
  69 + });
  70 + } else {
  71 + $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' +
  72 + $scope.transportista);
  73 + }
60 74 };
61   - $scope.guardar = function() {
62 75  
63   - if (!$scope.cisterna.codigo) {
  76 + $scope.guardar = function() {
  77 +
  78 + if ($scope.formCisterna.$pristine) {
  79 + $scope.salir();
  80 + return;
  81 + } else if (!$scope.cisterna.codigo) {
64 82 focaModalService.alert('Ingrese codigo de cisterna');
65 83 return;
66 84 } else if (!$scope.cisterna.capacidad) {
... ... @@ -78,7 +96,7 @@ angular.module('focaAbmVehiculo')
78 96  
79 97 focaAbmVehiculoService
80 98 .guardarCisterna($scope.cisterna, $routeParams.idx);
81   -
  99 +
82 100 $timeout(function() {
83 101 $location.path('/vehiculo/' + $routeParams.idVehiculo +
84 102 '/' + $scope.transportista);
... ... @@ -113,12 +131,12 @@ angular.module('focaAbmVehiculo')
113 131 var totalCargado = 0;
114 132 cisternas.forEach(function(cisterna, idx) {
115 133 //SI EL CODIGO YA EXISTE
116   - if(cisterna.codigo === $scope.cisterna.codigo &&
  134 + if (cisterna.codigo === $scope.cisterna.codigo &&
117 135 idx != $routeParams.idx &&
118 136 !cisterna.desactivado) {
119 137 reject('Código de cisterna existente');
120 138 }
121   - if(idx != $routeParams.idx &&
  139 + if (idx !== $routeParams.idx &&
122 140 !cisterna.desactivado) {
123 141 totalCargado += cisterna.capacidad;
124 142 }
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 = [];