Commit 58888f80223892e396b55e65015dba45b668b669
1 parent
fb66976cf0
Exists in
master
Agregar Cisternas (Modificado)
Showing
3 changed files
with
33 additions
and
36 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -102,6 +102,7 @@ angular.module('focaAbmVehiculo') |
| 102 | 102 | $scope.focused = 1; |
| 103 | 103 | $scope.creando = false; |
| 104 | 104 | $scope.transportistaStamp = ''; |
| 105 | + $scope.cisternasABorrar = []; | |
| 105 | 106 | $scope.cisternas = []; |
| 106 | 107 | $scope.cisterna = { |
| 107 | 108 | codigo: '', |
| ... | ... | @@ -205,7 +206,6 @@ angular.module('focaAbmVehiculo') |
| 205 | 206 | }; |
| 206 | 207 | |
| 207 | 208 | $scope.guardar = function(key) { |
| 208 | - | |
| 209 | 209 | key = (typeof key === 'undefined') ? 13 : key; |
| 210 | 210 | |
| 211 | 211 | if (key === 13) { |
| ... | ... | @@ -231,9 +231,12 @@ angular.module('focaAbmVehiculo') |
| 231 | 231 | //Valida si existe numero de unidad |
| 232 | 232 | if (!validaTotalCargas() && !$scope.nuevo) { |
| 233 | 233 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
| 234 | - ' debe ser igual a la capacidad total del vehículo'); | |
| 234 | + ' debe ser igual a la capacidad total del vehículo'); | |
| 235 | 235 | return; |
| 236 | 236 | } |
| 237 | + | |
| 238 | + borrarCisternas(); | |
| 239 | + | |
| 237 | 240 | validaCodigoUnidad().then(function() { |
| 238 | 241 | delete $scope.vehiculo.transportista; |
| 239 | 242 | delete $scope.vehiculo.cisternas; |
| ... | ... | @@ -279,6 +282,17 @@ angular.module('focaAbmVehiculo') |
| 279 | 282 | return false; |
| 280 | 283 | } |
| 281 | 284 | |
| 285 | + function borrarCisternas() { | |
| 286 | + $scope.cisternasABorrar.forEach(cisternaABorrar => { | |
| 287 | + focaAbmVehiculoService.deleteCisterna(cisternaABorrar); | |
| 288 | + focaAbmVehiculoService | |
| 289 | + .getCisternas($routeParams.idVehiculo) | |
| 290 | + .then(function(res) { | |
| 291 | + $scope.cisternas = res; | |
| 292 | + }); | |
| 293 | + }); | |
| 294 | + } | |
| 295 | + | |
| 282 | 296 | function setearVehiculo(vehiculo) { |
| 283 | 297 | $scope.vehiculo = vehiculo; |
| 284 | 298 | $scope.$broadcast('addCabecera', { |
| ... | ... | @@ -287,20 +301,15 @@ angular.module('focaAbmVehiculo') |
| 287 | 301 | }); |
| 288 | 302 | } |
| 289 | 303 | |
| 290 | - $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | |
| 291 | - focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | |
| 292 | - cisterna.id + ' ' + cisterna.codigo + ' ?').then( | |
| 293 | - function(data) { | |
| 294 | - if (data) { | |
| 295 | - focaAbmVehiculoService.deleteCisterna(idx); | |
| 296 | - focaAbmVehiculoService | |
| 297 | - .getCisternas($routeParams.idVehiculo) | |
| 298 | - .then(function(res) { | |
| 299 | - $scope.cisternas = res; | |
| 300 | - }); | |
| 301 | - } | |
| 304 | + $scope.solicitarConfirmacionTabla = function(cisterna, idx){ | |
| 305 | + focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?') | |
| 306 | + .then( function(data) { | |
| 307 | + if (data) { | |
| 308 | + $scope.cisternasABorrar.push(cisterna); | |
| 309 | + $scope.cisternas.splice(idx,1); | |
| 302 | 310 | } |
| 303 | - ); | |
| 311 | + }); | |
| 312 | + return; | |
| 304 | 313 | }; |
| 305 | 314 | |
| 306 | 315 | function validaCodigoUnidad() { |
| ... | ... | @@ -330,7 +339,7 @@ angular.module('focaAbmVehiculo') |
| 330 | 339 | total += parseInt(cisterna.capacidad); |
| 331 | 340 | } |
| 332 | 341 | }); |
| 333 | - return $scope.vehiculo.capacidad === total; | |
| 342 | + return $scope.vehiculo.capacidad >= total; | |
| 334 | 343 | } |
| 335 | 344 | function guardarCisternas() { |
| 336 | 345 | var cisternas = $scope.cisternas.map(function(cisterna) { |
| ... | ... | @@ -347,7 +356,7 @@ angular.module('focaAbmVehiculo') |
| 347 | 356 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
| 348 | 357 | } |
| 349 | 358 | |
| 350 | - $scope.guardarCisterna = function() { | |
| 359 | + $scope.agregarCisterna = function() { | |
| 351 | 360 | if (!$scope.cisterna.codigo) { |
| 352 | 361 | focaModalService.alert('Ingrese codigo de cisterna'); |
| 353 | 362 | return; |
| ... | ... | @@ -374,22 +383,10 @@ angular.module('focaAbmVehiculo') |
| 374 | 383 | function saveCisterna () { |
| 375 | 384 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
| 376 | 385 | delete $scope.cisterna.vehiculo; |
| 377 | - var auxCisternas = $scope.cisternas; | |
| 378 | 386 | if (!$scope.cisterna.id) { |
| 379 | - auxCisternas.push($scope.cisterna); | |
| 387 | + $scope.cisternas.push($scope.cisterna); | |
| 388 | + $scope.$apply(); | |
| 380 | 389 | } |
| 381 | - guardarCisternas(auxCisternas) | |
| 382 | - .then(function() { | |
| 383 | - focaAbmVehiculoService | |
| 384 | - .getCisternas($routeParams.idVehiculo) | |
| 385 | - .then(function(res) { | |
| 386 | - $scope.cisternas = res; | |
| 387 | - $scope.cisterna = {}; | |
| 388 | - }); | |
| 389 | - }) | |
| 390 | - .catch(function (err) { | |
| 391 | - console.log('Err: ', err); | |
| 392 | - }); | |
| 393 | 390 | } |
| 394 | 391 | |
| 395 | 392 | if ($routeParams.idx !== -1) { |
src/js/service.js
| ... | ... | @@ -47,10 +47,10 @@ angular.module('focaAbmVehiculo') |
| 47 | 47 | guardarCisternas: function(cisternas) { |
| 48 | 48 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); |
| 49 | 49 | }, |
| 50 | - deleteCisterna: function(idx) { | |
| 51 | - cisternas[idx].desactivado = true; | |
| 50 | + deleteCisterna: function(cisterna) { | |
| 51 | + cisterna.desactivado = true; | |
| 52 | 52 | cisternasPristine = false; |
| 53 | - return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisternas[idx].id); | |
| 53 | + return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisterna.id); | |
| 54 | 54 | }, |
| 55 | 55 | cleanCisternas: function() { |
| 56 | 56 | cisternas = []; |
src/views/foca-abm-vehiculos-item.html
| ... | ... | @@ -138,7 +138,7 @@ |
| 138 | 138 | <td align="center"> |
| 139 | 139 | <button |
| 140 | 140 | class="btn btn-outline-dark boton-accion" |
| 141 | - ng-click="guardarCisterna()" | |
| 141 | + ng-click="agregarCisterna()" | |
| 142 | 142 | > |
| 143 | 143 | <i class="fa fa-save"></i> |
| 144 | 144 | </button> |
| ... | ... | @@ -161,7 +161,7 @@ |
| 161 | 161 | <button |
| 162 | 162 | class="btn btn-outline-dark boton-accion" |
| 163 | 163 | title="Eliminar" |
| 164 | - ng-click="solicitarConfirmacionCisterna(cisterna, key)" | |
| 164 | + ng-click="solicitarConfirmacionTabla(cisterna,$index)" | |
| 165 | 165 | > |
| 166 | 166 | <i class="fa fa-trash"></i> |
| 167 | 167 | </button> |