Commit b9d2b80bbcfcd091bfa7aabb55448235030328d6
Exists in
master
Merge branch 'master' into 'develop'
Master See merge request !43
Showing
6 changed files
Show diff stats
spec/controllerSpec.js
| ... | ... | @@ -325,6 +325,11 @@ describe('Controladores abm vehículo', function() { |
| 325 | 325 | $watch: function() {} |
| 326 | 326 | }, |
| 327 | 327 | focaAbmVehiculoService: { |
| 328 | + getCisternas: function() { | |
| 329 | + return { | |
| 330 | + then: function() { return; } | |
| 331 | + }; | |
| 332 | + }, | |
| 328 | 333 | getVehiculo: function() { |
| 329 | 334 | return { |
| 330 | 335 | then: function() { return; } |
| ... | ... | @@ -359,6 +364,12 @@ describe('Controladores abm vehículo', function() { |
| 359 | 364 | $watch: function() {} |
| 360 | 365 | }; |
| 361 | 366 | var focaAbmVehiculoService = { |
| 367 | + | |
| 368 | + getCisternas: function() { | |
| 369 | + return { | |
| 370 | + then: function() { return; } | |
| 371 | + }; | |
| 372 | + }, | |
| 362 | 373 | getVehiculo: function() { |
| 363 | 374 | return { |
| 364 | 375 | then: function() { return; } |
| ... | ... | @@ -403,6 +414,13 @@ describe('Controladores abm vehículo', function() { |
| 403 | 414 | $watch: function() {} |
| 404 | 415 | }; |
| 405 | 416 | var focaAbmVehiculoService = { |
| 417 | + | |
| 418 | + getCisternas: function() { | |
| 419 | + return { | |
| 420 | + then: function() { return; } | |
| 421 | + }; | |
| 422 | + }, | |
| 423 | + | |
| 406 | 424 | getVehiculo: function() { |
| 407 | 425 | return { |
| 408 | 426 | then: function() { return; } |
| ... | ... | @@ -452,6 +470,11 @@ describe('Controladores abm vehículo', function() { |
| 452 | 470 | var controller = $controller('focaAbmVehiculoController', { |
| 453 | 471 | $scope: scope, |
| 454 | 472 | focaAbmVehiculoService: { |
| 473 | + getCisternas: function() { | |
| 474 | + return { | |
| 475 | + then: function() { return; } | |
| 476 | + }; | |
| 477 | + }, | |
| 455 | 478 | getVehiculo: function() { |
| 456 | 479 | return { |
| 457 | 480 | then: function() { return; } |
| ... | ... | @@ -493,6 +516,11 @@ describe('Controladores abm vehículo', function() { |
| 493 | 516 | var controller = $controller('focaAbmVehiculoController', { |
| 494 | 517 | $scope: scope, |
| 495 | 518 | focaAbmVehiculoService: { |
| 519 | + getCisternas: function() { | |
| 520 | + return { | |
| 521 | + then: function() { return; } | |
| 522 | + }; | |
| 523 | + }, | |
| 496 | 524 | getVehiculo: function() { |
| 497 | 525 | return { |
| 498 | 526 | then: function() { return; } |
| ... | ... | @@ -536,6 +564,11 @@ describe('Controladores abm vehículo', function() { |
| 536 | 564 | var controller = $controller('focaAbmVehiculoController', { |
| 537 | 565 | $scope: scope, |
| 538 | 566 | focaAbmVehiculoService: { |
| 567 | + getCisternas: function() { | |
| 568 | + return { | |
| 569 | + then: function() { return; } | |
| 570 | + }; | |
| 571 | + }, | |
| 539 | 572 | getVehiculo: function() { |
| 540 | 573 | return { |
| 541 | 574 | then: function() { return; } |
| ... | ... | @@ -581,6 +614,11 @@ describe('Controladores abm vehículo', function() { |
| 581 | 614 | var controller = $controller('focaAbmVehiculoController', { |
| 582 | 615 | $scope: scope, |
| 583 | 616 | focaAbmVehiculoService: { |
| 617 | + getCisternas: function() { | |
| 618 | + return { | |
| 619 | + then: function() { return; } | |
| 620 | + }; | |
| 621 | + }, | |
| 584 | 622 | getVehiculo: function() { |
| 585 | 623 | return { |
| 586 | 624 | then: function() { return; } |
| ... | ... | @@ -602,7 +640,7 @@ describe('Controladores abm vehículo', function() { |
| 602 | 640 | addCustomButton: function() { return; } |
| 603 | 641 | }, |
| 604 | 642 | $localStorage: {}, |
| 605 | - $window: {} | |
| 643 | + $window: {}, | |
| 606 | 644 | }); |
| 607 | 645 | |
| 608 | 646 | //act |
| ... | ... | @@ -628,7 +666,11 @@ describe('Controladores abm vehículo', function() { |
| 628 | 666 | then: function() { return; } |
| 629 | 667 | }; |
| 630 | 668 | }, |
| 631 | - getCisternas: function() { return; }, | |
| 669 | + getCisternas: function() { | |
| 670 | + return { | |
| 671 | + then: function() { return; } | |
| 672 | + }; | |
| 673 | + }, | |
| 632 | 674 | deleteCisterna: function() { return; } |
| 633 | 675 | }; |
| 634 | 676 | var controller = $controller('focaAbmVehiculoController', { |
src/js/controller.js
| ... | ... | @@ -97,8 +97,11 @@ angular.module('focaAbmVehiculo') |
| 97 | 97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 98 | 98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { |
| 99 | 99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
| 100 | + $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; | |
| 100 | 101 | $scope.now = new Date(); |
| 101 | 102 | $scope.focused = 1; |
| 103 | + $scope.creando = false; | |
| 104 | + $scope.crear = false; | |
| 102 | 105 | $scope.transportistaStamp = ''; |
| 103 | 106 | $scope.cisternas = []; |
| 104 | 107 | |
| ... | ... | @@ -109,8 +112,6 @@ angular.module('focaAbmVehiculo') |
| 109 | 112 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 110 | 113 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); |
| 111 | 114 | }); |
| 112 | - | |
| 113 | - $timeout(function() {getLSVehiculo();}); | |
| 114 | 115 | |
| 115 | 116 | if ($scope.nuevo) { |
| 116 | 117 | focaAbmVehiculoService |
| ... | ... | @@ -126,26 +127,32 @@ angular.module('focaAbmVehiculo') |
| 126 | 127 | }); |
| 127 | 128 | } |
| 128 | 129 | $scope.vehiculo = {}; |
| 130 | + | |
| 129 | 131 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 132 | + | |
| 130 | 133 | if (res.data) { |
| 131 | - $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | |
| 132 | - $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | |
| 134 | + var vehiculoSeteado = getLSVehiculo(); | |
| 135 | + if (vehiculoSeteado === false) { | |
| 136 | + $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | |
| 137 | + $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | |
| 133 | 138 | |
| 134 | - $scope.vehiculo = res.data; | |
| 135 | - $scope.$broadcast('addCabecera', { | |
| 136 | - label: 'Transportista:', | |
| 137 | - valor: $scope.transportistaStamp | |
| 138 | - }); | |
| 139 | - $scope.$broadcast('addCabecera', { | |
| 140 | - label: 'Unidad:', | |
| 141 | - valor: res.data.codigo | |
| 142 | - }); | |
| 139 | + $scope.vehiculo = res.data; | |
| 140 | + $scope.$broadcast('addCabecera', { | |
| 141 | + label: 'Transportista:', | |
| 142 | + valor: $scope.transportistaStamp | |
| 143 | + }); | |
| 144 | + $scope.$broadcast('addCabecera', { | |
| 145 | + label: 'Unidad:', | |
| 146 | + valor: res.data.codigo | |
| 147 | + }); | |
| 148 | + } | |
| 149 | + | |
| 143 | 150 | focaAbmVehiculoService |
| 144 | 151 | .getCisternas($routeParams.idVehiculo) |
| 145 | 152 | .then(function(res) { |
| 146 | 153 | $scope.cisternas = res; |
| 147 | 154 | $scope.$apply(); |
| 148 | - }); | |
| 155 | + }); | |
| 149 | 156 | } |
| 150 | 157 | }); |
| 151 | 158 | |
| ... | ... | @@ -165,18 +172,58 @@ angular.module('focaAbmVehiculo') |
| 165 | 172 | } else { |
| 166 | 173 | $location.path('/vehiculo'); |
| 167 | 174 | } |
| 168 | - } | |
| 175 | + }; | |
| 169 | 176 | |
| 170 | - $scope.editar = function(key) { | |
| 171 | - if (key) { | |
| 172 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + | |
| 173 | - '/cisterna/' + key); | |
| 174 | - } else { | |
| 175 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | |
| 177 | + $scope.editar = function(cisterna) { | |
| 178 | + $scope.cisternas.forEach(function(cisterna) { | |
| 179 | + cisterna.editando = false; | |
| 180 | + $scope.crear = true; | |
| 181 | + }); | |
| 182 | + cisterna.editando = true; | |
| 183 | + $scope.inicial = angular.copy(cisterna); | |
| 184 | + }; | |
| 185 | + | |
| 186 | + $scope.volver = function(cisterna, key) { | |
| 187 | + if (cisterna.id === undefined || !$scope.crear) { | |
| 188 | + $scope.cisternas.shift(cisterna); | |
| 189 | + $scope.crear = false; | |
| 190 | + return; | |
| 176 | 191 | } |
| 192 | + if (cisterna.id !== undefined) { | |
| 193 | + $scope.cisternas[key] = $scope.inicial; | |
| 194 | + $scope.cisternas[key].editando = false; | |
| 195 | + } | |
| 196 | + $scope.crear = false; | |
| 197 | + }; | |
| 198 | + | |
| 199 | + $scope.crearCisterna = function() { | |
| 200 | + var cisterna = { | |
| 201 | + codigo: '', | |
| 202 | + capacidad: '', | |
| 203 | + idUnidadMedida: 0, | |
| 204 | + unidadMedida: {}, | |
| 205 | + editando: true, | |
| 206 | + }; | |
| 207 | + $scope.cisternas.unshift(cisterna); | |
| 208 | + $scope.crear = true; | |
| 209 | + }; | |
| 210 | + | |
| 211 | + $scope.seleccionarUnidadMedida = function(cisterna) { | |
| 212 | + var modalInstance = $uibModal.open( | |
| 213 | + { | |
| 214 | + ariaLabelledBy: 'Busqueda de Unidades de medida', | |
| 215 | + templateUrl: 'modal-unidad-medida.html', | |
| 216 | + controller: 'focaModalUnidadMedidaCtrl', | |
| 217 | + size: 'lg' | |
| 218 | + } | |
| 219 | + ); | |
| 220 | + modalInstance.result.then(function(unidaMedida) { | |
| 221 | + cisterna.idUnidadMedida = unidaMedida.ID; | |
| 222 | + cisterna.unidadMedida = unidaMedida; | |
| 223 | + }); | |
| 177 | 224 | }; |
| 178 | - $scope.guardar = function(key) { | |
| 179 | 225 | |
| 226 | + $scope.guardar = function(key) { | |
| 180 | 227 | key = (typeof key === 'undefined') ? 13 : key; |
| 181 | 228 | |
| 182 | 229 | if (key === 13) { |
| ... | ... | @@ -185,6 +232,9 @@ angular.module('focaAbmVehiculo') |
| 185 | 232 | $scope.salir(); |
| 186 | 233 | return; |
| 187 | 234 | } |
| 235 | + $scope.cisternas.forEach( function(cisterna) { | |
| 236 | + if (cisterna.id === 0) cisterna.id = undefined; | |
| 237 | + }); | |
| 188 | 238 | |
| 189 | 239 | if (!$scope.vehiculo.codigo) { |
| 190 | 240 | focaModalService.alert('Ingrese unidad'); |
| ... | ... | @@ -202,9 +252,10 @@ angular.module('focaAbmVehiculo') |
| 202 | 252 | //Valida si existe numero de unidad |
| 203 | 253 | if (!validaTotalCargas() && !$scope.nuevo) { |
| 204 | 254 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
| 205 | - ' debe ser igual a la capacidad total del vehículo'); | |
| 255 | + ' debe ser igual a la capacidad total del vehículo'); | |
| 206 | 256 | return; |
| 207 | 257 | } |
| 258 | + | |
| 208 | 259 | validaCodigoUnidad().then(function() { |
| 209 | 260 | delete $scope.vehiculo.transportista; |
| 210 | 261 | delete $scope.vehiculo.cisternas; |
| ... | ... | @@ -214,7 +265,7 @@ angular.module('focaAbmVehiculo') |
| 214 | 265 | $location.path('/vehiculo/' + res.data.id + |
| 215 | 266 | '/' + res.data.idTransportista); |
| 216 | 267 | } else { |
| 217 | - guardarCisternas().then(function() { | |
| 268 | + guardarCisternas($scope.cisternas).then(function() { | |
| 218 | 269 | $location.path('/vehiculo'); |
| 219 | 270 | }); |
| 220 | 271 | } |
| ... | ... | @@ -223,9 +274,8 @@ angular.module('focaAbmVehiculo') |
| 223 | 274 | focaModalService.alert('Código de unidad existente'); |
| 224 | 275 | }); |
| 225 | 276 | } |
| 226 | - | |
| 227 | 277 | }; |
| 228 | - | |
| 278 | + //Agregar propiedades de cisterna | |
| 229 | 279 | $scope.$watch('vehiculo', function(newValue) { |
| 230 | 280 | focaBotoneraLateralService.setPausarData({ |
| 231 | 281 | label:'vehiculo', |
| ... | ... | @@ -245,7 +295,9 @@ angular.module('focaAbmVehiculo') |
| 245 | 295 | if (vehiculo) { |
| 246 | 296 | setearVehiculo(vehiculo); |
| 247 | 297 | delete $localStorage.vehiculo; |
| 298 | + return true; | |
| 248 | 299 | } |
| 300 | + return false; | |
| 249 | 301 | } |
| 250 | 302 | |
| 251 | 303 | function setearVehiculo(vehiculo) { |
| ... | ... | @@ -256,20 +308,14 @@ angular.module('focaAbmVehiculo') |
| 256 | 308 | }); |
| 257 | 309 | } |
| 258 | 310 | |
| 259 | - $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | |
| 260 | - focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | |
| 261 | - cisterna.id + ' ' + cisterna.codigo + ' ?').then( | |
| 262 | - function(data) { | |
| 263 | - if (data) { | |
| 264 | - focaAbmVehiculoService.deleteCisterna(idx); | |
| 265 | - focaAbmVehiculoService | |
| 266 | - .getCisternas($routeParams.idVehiculo) | |
| 267 | - .then(function(res) { | |
| 268 | - $scope.cisternas = res; | |
| 269 | - }); | |
| 270 | - } | |
| 311 | + $scope.solicitarConfirmacionTabla = function(cisterna) { | |
| 312 | + focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?') | |
| 313 | + .then( function(data) { | |
| 314 | + if (data) { | |
| 315 | + cisterna.desactivado = true; | |
| 271 | 316 | } |
| 272 | - ); | |
| 317 | + }); | |
| 318 | + return; | |
| 273 | 319 | }; |
| 274 | 320 | |
| 275 | 321 | function validaCodigoUnidad() { |
| ... | ... | @@ -299,9 +345,8 @@ angular.module('focaAbmVehiculo') |
| 299 | 345 | total += parseInt(cisterna.capacidad); |
| 300 | 346 | } |
| 301 | 347 | }); |
| 302 | - return $scope.vehiculo.capacidad == total; | |
| 348 | + return $scope.vehiculo.capacidad >= total; | |
| 303 | 349 | } |
| 304 | - | |
| 305 | 350 | function guardarCisternas() { |
| 306 | 351 | var cisternas = $scope.cisternas.map(function(cisterna) { |
| 307 | 352 | return { |
| ... | ... | @@ -317,5 +362,60 @@ angular.module('focaAbmVehiculo') |
| 317 | 362 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
| 318 | 363 | } |
| 319 | 364 | |
| 365 | + $scope.agregarCisterna = function(cisterna) { | |
| 366 | + if (!cisterna) { | |
| 367 | + focaModalService.alert('Ingrese valores'); | |
| 368 | + return; | |
| 369 | + } else if (!cisterna.codigo) { | |
| 370 | + focaModalService.alert('Ingrese codigo de cisterna'); | |
| 371 | + return; | |
| 372 | + } else if (!cisterna.capacidad) { | |
| 373 | + focaModalService.alert('Ingrese capacidad'); | |
| 374 | + return; | |
| 375 | + } else if (!cisterna.idUnidadMedida) { | |
| 376 | + focaModalService.alert('Ingrese unidad de medida'); | |
| 377 | + return; | |
| 378 | + } | |
| 379 | + | |
| 380 | + validaCodigo(cisterna); | |
| 381 | + cisterna.id = 0; | |
| 382 | + }; | |
| 383 | + | |
| 384 | + if ($routeParams.idx !== -1) { | |
| 385 | + $scope.cisterna = [$routeParams.idx]; | |
| 386 | + focaAbmVehiculoService | |
| 387 | + .getCisternas($routeParams.idVehiculo) | |
| 388 | + .then(function(res) { | |
| 389 | + $scope.cisterna = res[$routeParams.idx]; | |
| 390 | + }); | |
| 391 | + } | |
| 392 | + | |
| 393 | + function validaCodigo(cisterna) { | |
| 394 | + focaAbmVehiculoService | |
| 395 | + .getCisternas($routeParams.idVehiculo) | |
| 396 | + .then(function(res) { | |
| 397 | + var cisternas = res; | |
| 398 | + var totalCargado = 0; | |
| 399 | + cisternas.forEach(function(cisternaBase, idx) { | |
| 400 | + //SI EL CODIGO YA EXISTE | |
| 401 | + if (cisternaBase.codigo === cisterna.codigo && | |
| 402 | + idx !== $routeParams.idx && | |
| 403 | + cisternaBase.desactivado === false && | |
| 404 | + cisternaBase.id !== cisterna.id | |
| 405 | + ) | |
| 406 | + { | |
| 407 | + focaModalService.alert('Código de cisterna existente'); | |
| 408 | + } | |
| 409 | + if (idx !== $routeParams.idx && | |
| 410 | + !cisternaBase.desactivado) { | |
| 411 | + totalCargado += cisternaBase.capacidad; | |
| 412 | + } | |
| 413 | + }); | |
| 414 | + $timeout( function(){ | |
| 415 | + cisterna.editando = false; | |
| 416 | + $scope.crear = false; | |
| 417 | + }); | |
| 418 | + }); | |
| 419 | + } | |
| 320 | 420 | } |
| 321 | 421 | ]); |
src/js/controllerCisterna.js
| ... | ... | @@ -1,149 +0,0 @@ |
| 1 | -angular.module('focaAbmVehiculo') | |
| 2 | - .controller('focaAbmVehiculoCisternaController', [ | |
| 3 | - '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | |
| 4 | - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', | |
| 5 | - function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | |
| 6 | - focaModalService, focaBotoneraLateralService, $timeout, $window) { | |
| 7 | - $scope.nuevo = ($routeParams.idx > -1) ? false : true; | |
| 8 | - $scope.editar = false; | |
| 9 | - $scope.now = new Date(); | |
| 10 | - $scope.cisterna = { | |
| 11 | - codigo: '', | |
| 12 | - capacidad: '', | |
| 13 | - unidadMedida: {} | |
| 14 | - }; | |
| 15 | - | |
| 16 | - $scope.focused = $scope.nuevo ? 1 : 2; | |
| 17 | - $scope.next = function(key) { | |
| 18 | - if (key === 13) $scope.focused++; | |
| 19 | - }; | |
| 20 | - $scope.capacidadVechiulo = 0; | |
| 21 | - $scope.transportista = ''; | |
| 22 | - | |
| 23 | - //SETEO BOTONERA LATERAL | |
| 24 | - $timeout(function() { | |
| 25 | - focaBotoneraLateralService.showSalir(false); | |
| 26 | - focaBotoneraLateralService.showPausar(true); | |
| 27 | - focaBotoneraLateralService.showCancelar(false); | |
| 28 | - focaBotoneraLateralService.showGuardar(true, $scope.guardar); | |
| 29 | - focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | |
| 30 | - }); | |
| 31 | - | |
| 32 | - if ($routeParams.idx !== -1) { | |
| 33 | - $scope.cisterna = [$routeParams.idx]; | |
| 34 | - focaAbmVehiculoService | |
| 35 | - .getCisternas($routeParams.idVehiculo) | |
| 36 | - .then(function(res) { | |
| 37 | - $scope.cisterna = res[$routeParams.idx]; | |
| 38 | - }); | |
| 39 | - } | |
| 40 | - | |
| 41 | - focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | |
| 42 | - var codigo = ('00000' + res.data.transportista.COD).slice(-5); | |
| 43 | - $scope.transportista = res.data.transportista.COD; | |
| 44 | - $scope.capacidadVechiulo = res.data.capacidad; | |
| 45 | - $scope.$broadcast('addCabecera', { | |
| 46 | - label: 'Transportista:', | |
| 47 | - valor: codigo + ' - ' + res.data.transportista.NOM | |
| 48 | - }); | |
| 49 | - $scope.$broadcast('addCabecera', { | |
| 50 | - label: 'Unidad:', | |
| 51 | - valor: res.data.codigo | |
| 52 | - }); | |
| 53 | - $scope.$broadcast('addCabecera', { | |
| 54 | - label: 'Capacidad total vehículo:', | |
| 55 | - valor: res.data.capacidad | |
| 56 | - }); | |
| 57 | - }); | |
| 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 | - } | |
| 74 | - }; | |
| 75 | - | |
| 76 | - $scope.guardar = function() { | |
| 77 | - | |
| 78 | - if ($scope.formCisterna.$pristine) { | |
| 79 | - $scope.salir(); | |
| 80 | - return; | |
| 81 | - } else if (!$scope.cisterna.codigo) { | |
| 82 | - focaModalService.alert('Ingrese codigo de cisterna'); | |
| 83 | - return; | |
| 84 | - } else if (!$scope.cisterna.capacidad) { | |
| 85 | - focaModalService.alert('Ingrese capacidad'); | |
| 86 | - return; | |
| 87 | - } else if (!$scope.cisterna.idUnidadMedida) { | |
| 88 | - focaModalService.alert('Ingrese unidad de medida'); | |
| 89 | - return; | |
| 90 | - } | |
| 91 | - | |
| 92 | - validaCodigo() | |
| 93 | - .then(function() { | |
| 94 | - $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | |
| 95 | - delete $scope.cisterna.vehiculo; | |
| 96 | - | |
| 97 | - focaAbmVehiculoService | |
| 98 | - .guardarCisterna($scope.cisterna, $routeParams.idx); | |
| 99 | - | |
| 100 | - $timeout(function() { | |
| 101 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + | |
| 102 | - '/' + $scope.transportista); | |
| 103 | - }, 0); | |
| 104 | - }, function(err) { | |
| 105 | - focaModalService.alert(err); | |
| 106 | - }); | |
| 107 | - | |
| 108 | - }; | |
| 109 | - | |
| 110 | - $scope.seleccionarUnidadMedida = function() { | |
| 111 | - var modalInstance = $uibModal.open( | |
| 112 | - { | |
| 113 | - ariaLabelledBy: 'Busqueda de Unidades de medida', | |
| 114 | - templateUrl: 'modal-unidad-medida.html', | |
| 115 | - controller: 'focaModalUnidadMedidaCtrl', | |
| 116 | - size: 'lg' | |
| 117 | - } | |
| 118 | - ); | |
| 119 | - modalInstance.result.then(function(unidaMedida) { | |
| 120 | - $scope.cisterna.idUnidadMedida = unidaMedida.ID; | |
| 121 | - $scope.cisterna.unidadMedida = unidaMedida; | |
| 122 | - }); | |
| 123 | - }; | |
| 124 | - | |
| 125 | - function validaCodigo() { | |
| 126 | - return new Promise(function(resolve, reject) { | |
| 127 | - focaAbmVehiculoService | |
| 128 | - .getCisternas($routeParams.idVehiculo) | |
| 129 | - .then(function(res) { | |
| 130 | - var cisternas = res; | |
| 131 | - var totalCargado = 0; | |
| 132 | - cisternas.forEach(function(cisterna, idx) { | |
| 133 | - //SI EL CODIGO YA EXISTE | |
| 134 | - if (cisterna.codigo === $scope.cisterna.codigo && | |
| 135 | - idx != $routeParams.idx && | |
| 136 | - !cisterna.desactivado) { | |
| 137 | - reject('Código de cisterna existente'); | |
| 138 | - } | |
| 139 | - if (idx !== $routeParams.idx && | |
| 140 | - !cisterna.desactivado) { | |
| 141 | - totalCargado += cisterna.capacidad; | |
| 142 | - } | |
| 143 | - }); | |
| 144 | - resolve(); | |
| 145 | - }); | |
| 146 | - }); | |
| 147 | - } | |
| 148 | - } | |
| 149 | - ]); |
src/js/service.js
| ... | ... | @@ -19,10 +19,6 @@ angular.module('focaAbmVehiculo') |
| 19 | 19 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); |
| 20 | 20 | }, |
| 21 | 21 | getCisternas: function(idVehiculo) { |
| 22 | - if (cisternas.length) { | |
| 23 | - cisternasPristine = true; | |
| 24 | - return Promise.resolve(angular.copy(cisternas)); | |
| 25 | - } else { | |
| 26 | 22 | cisternasPristine = true; |
| 27 | 23 | return new Promise(function(resolve) { |
| 28 | 24 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) |
| ... | ... | @@ -31,7 +27,6 @@ angular.module('focaAbmVehiculo') |
| 31 | 27 | resolve(res.data); |
| 32 | 28 | }); |
| 33 | 29 | }); |
| 34 | - } | |
| 35 | 30 | }, |
| 36 | 31 | guardarCisterna: function(cisterna, idx) { |
| 37 | 32 | if (idx !== '-1') { |
| ... | ... | @@ -47,9 +42,10 @@ angular.module('focaAbmVehiculo') |
| 47 | 42 | guardarCisternas: function(cisternas) { |
| 48 | 43 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); |
| 49 | 44 | }, |
| 50 | - deleteCisterna: function(idx) { | |
| 51 | - cisternas[idx].desactivado = true; | |
| 45 | + deleteCisterna: function(cisterna) { | |
| 46 | + cisterna.desactivado = true; | |
| 52 | 47 | cisternasPristine = false; |
| 48 | + return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisterna.id); | |
| 53 | 49 | }, |
| 54 | 50 | cleanCisternas: function() { |
| 55 | 51 | cisternas = []; |
src/views/foca-abm-cisterna-item.html
| ... | ... | @@ -1,63 +0,0 @@ |
| 1 | -<div class="row"> | |
| 2 | - <foca-cabecera-facturador | |
| 3 | - titulo="'Vehículo cisterna'" | |
| 4 | - fecha="now" | |
| 5 | - class="mb-0 col-lg-12" | |
| 6 | - ></foca-cabecera-facturador> | |
| 7 | -</div> | |
| 8 | -<div class="row"></div> | |
| 9 | -<form name="formCisterna"> | |
| 10 | - <div class="form-group row"> | |
| 11 | - <label class="offset-sm-1 col-sm-2 col-form-label">Código de cisterna</label> | |
| 12 | - <div class="col-sm-4"> | |
| 13 | - <input | |
| 14 | - class="form-control" | |
| 15 | - type="text" | |
| 16 | - ng-required="true" | |
| 17 | - ng-model="cisterna.codigo" | |
| 18 | - ng-keypress="next($event.keyCode)" | |
| 19 | - foca-focus="focused == 1" | |
| 20 | - ng-focus="focused = 1" | |
| 21 | - ng-disabled="!nuevo" | |
| 22 | - teclado-virtual | |
| 23 | - /> | |
| 24 | - </div> | |
| 25 | - </div> | |
| 26 | - <div class="form-group row"> | |
| 27 | - <label class="offset-sm-1 col-sm-2 col-form-label">Capacidad</label> | |
| 28 | - <div class="col-sm-4"> | |
| 29 | - <input | |
| 30 | - class="form-control" | |
| 31 | - type="text" | |
| 32 | - teclado-virtual | |
| 33 | - foca-tipo-input | |
| 34 | - ng-model="cisterna.capacidad" | |
| 35 | - ng-required="true" | |
| 36 | - ng-keypress="next($event.keyCode)" | |
| 37 | - foca-focus="focused == 2" | |
| 38 | - ng-focus="focused = 2" | |
| 39 | - /> | |
| 40 | - </div> | |
| 41 | - </div> | |
| 42 | - <div class="form-group row"> | |
| 43 | - <label class="offset-sm-1 col-sm-2 col-form-label">Unidad de medida</label> | |
| 44 | - <div class="col-sm-4 input-group"> | |
| 45 | - <input | |
| 46 | - ng-model="cisterna.unidadMedida.NOM" | |
| 47 | - class="form-control" | |
| 48 | - readonly | |
| 49 | - /> | |
| 50 | - <div class="input-group-append"> | |
| 51 | - <button | |
| 52 | - ladda="searchLoading" | |
| 53 | - class="btn btn-outline-secondary form-control" | |
| 54 | - type="button" | |
| 55 | - ng-click="seleccionarUnidadMedida()" | |
| 56 | - foca-focus="focused == 3" | |
| 57 | - > | |
| 58 | - <i class="fa fa-search" aria-hidden="true"></i> | |
| 59 | - </button> | |
| 60 | - </div> | |
| 61 | - </div> | |
| 62 | - </div> | |
| 63 | -</form> |
src/views/foca-abm-vehiculos-item.html
| ... | ... | @@ -74,43 +74,162 @@ |
| 74 | 74 | </form> |
| 75 | 75 | <div ng-show="!nuevo"> |
| 76 | 76 | <h5 class="pl-4 table-title">Cisternas</h5> |
| 77 | - <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> | |
| 77 | + <table class="table table-default table-hover table-sm table-abm table-striped mb-0" > | |
| 78 | 78 | <thead> |
| 79 | 79 | <tr> |
| 80 | - <th class="px-5">Código</th> | |
| 81 | - <th class="text-right px-5">Capacidad</th> | |
| 82 | - <th class="text-center px-4"> | |
| 80 | + <th class="text-center px-4">Código</th> | |
| 81 | + <th class="text-center">Capacidad</th> | |
| 82 | + <th class="text-center">Unidad de Medida</th> | |
| 83 | + <th class="text-center"> | |
| 83 | 84 | <button |
| 84 | 85 | class="btn btn-outline-debo boton-accion" |
| 85 | 86 | title="Agregar" |
| 86 | - ng-click="editar(-1)"> | |
| 87 | + ng-click="crearCisterna()" | |
| 88 | + ng-disabled="crear"> | |
| 87 | 89 | <i class="fa fa-plus"></i> |
| 88 | 90 | </button> |
| 89 | 91 | </th> |
| 90 | - </tr> | |
| 92 | + </tr> | |
| 91 | 93 | </thead> |
| 92 | 94 | <tbody> |
| 93 | - <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" | |
| 94 | - ng-show="!cisterna.desactivado"> | |
| 95 | - <td ng-bind="cisterna.codigo" class="px-5"></td> | |
| 96 | - <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td> | |
| 97 | - <td class="text-center px-4"> | |
| 95 | + <tr ng-show="creando"> | |
| 96 | + <td align="center"> | |
| 97 | + <input | |
| 98 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
| 99 | + ng-model="cisterna.codigo" | |
| 100 | + ng-keypress="next($event.keyCode)" | |
| 101 | + foca-focus="focused == 1" | |
| 102 | + ng-focus="focused = 1" | |
| 103 | + ng-disabled="!nuevoCisterna" | |
| 104 | + teclado-virtual | |
| 105 | + > | |
| 106 | + </td> | |
| 107 | + <td align="center"> | |
| 108 | + <input | |
| 109 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
| 110 | + teclado-virtual | |
| 111 | + foca-tipo-input | |
| 112 | + ng-model="cisterna.capacidad" | |
| 113 | + ng-required="true" | |
| 114 | + ng-keypress="next($event.keyCode)" | |
| 115 | + foca-focus="focused == 2" | |
| 116 | + ng-focus="focused = 2" | |
| 117 | + > | |
| 118 | + </td> | |
| 119 | + <td align="center"> | |
| 120 | + <div class="input-group"> | |
| 121 | + <input | |
| 122 | + ng-model="cisterna.unidadMedida.NOM" | |
| 123 | + class="form-control" | |
| 124 | + readonly | |
| 125 | + /> | |
| 126 | + <div class="input-group-append"> | |
| 127 | + <button | |
| 128 | + ladda="searchLoading" | |
| 129 | + class="btn btn-outline-secondary form-control" | |
| 130 | + type="button" | |
| 131 | + ng-click="seleccionarUnidadMedida()" | |
| 132 | + foca-focus="focused == 3" | |
| 133 | + > | |
| 134 | + <i class="fa fa-search" aria-hidden="true"></i> | |
| 135 | + </button> | |
| 136 | + </div> | |
| 137 | + </div> | |
| 138 | + </td> | |
| 139 | + <td align="center"> | |
| 140 | + <button | |
| 141 | + class="btn btn-outline-dark boton-accion" | |
| 142 | + ng-click="agregarCisterna()" | |
| 143 | + > | |
| 144 | + <i class="fa fa-save"></i> | |
| 145 | + </button> | |
| 146 | + </td> | |
| 147 | + </tr> | |
| 148 | + | |
| 149 | + <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" ng-hide="cisterna.desactivado"> | |
| 150 | + <td ng-bind="cisterna.codigo" class="text-center" ng-hide="cisterna.editando"></td> | |
| 151 | + <td align="center" ng-show="cisterna.editando"> | |
| 152 | + <input | |
| 153 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
| 154 | + ng-model="cisterna.codigo" | |
| 155 | + ng-keypress="next($event.keyCode)" | |
| 156 | + foca-focus="focused == 1" | |
| 157 | + ng-focus="focused = 1" | |
| 158 | + teclado-virtual | |
| 159 | + esc-key="volver(cisterna, key)" | |
| 160 | + > | |
| 161 | + </td> | |
| 162 | + <td ng-bind="cisterna.capacidad" class="text-center" ng-hide="cisterna.editando"></td> | |
| 163 | + <td align="center" ng-show="cisterna.editando" > | |
| 164 | + <input | |
| 165 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
| 166 | + teclado-virtual | |
| 167 | + foca-tipo-input | |
| 168 | + ng-model="cisterna.capacidad" | |
| 169 | + ng-required="true" | |
| 170 | + ng-keypress="next($event.keyCode)" | |
| 171 | + foca-focus="focused == 2" | |
| 172 | + ng-focus="focused = 2" | |
| 173 | + esc-key="volver(cisterna, key)" | |
| 174 | + > | |
| 175 | + </td> | |
| 176 | + <td ng-bind="cisterna.unidadMedida.NOM" class="text-center" ng-hide="cisterna.editando"></td> | |
| 177 | + <td align="center" ng-show="cisterna.editando"> | |
| 178 | + <div class="input-group"> | |
| 179 | + <input | |
| 180 | + ng-model="cisterna.unidadMedida.NOM" | |
| 181 | + class="form-control" | |
| 182 | + readonly | |
| 183 | + esc-key="volver(cisterna, key)" | |
| 184 | + /> | |
| 185 | + <div class="input-group-append"> | |
| 186 | + <button | |
| 187 | + ladda="searchLoading" | |
| 188 | + class="btn btn-outline-secondary form-control" | |
| 189 | + type="button" | |
| 190 | + ng-click="seleccionarUnidadMedida(cisterna)" | |
| 191 | + foca-focus="focused == 3" | |
| 192 | + > | |
| 193 | + <i class="fa fa-search" aria-hidden="true"></i> | |
| 194 | + </button> | |
| 195 | + </div> | |
| 196 | + </div> | |
| 197 | + </td> | |
| 198 | + <td class="text-center" ng-hide="cisterna.editando"> | |
| 98 | 199 | <button |
| 99 | 200 | class="btn btn-outline-dark boton-accion" |
| 100 | 201 | title="Editar" |
| 101 | - ng-click="editar(key)" | |
| 202 | + ng-click="editar(cisterna)" | |
| 102 | 203 | > |
| 103 | 204 | <i class="fa fa-pencil"></i> |
| 104 | 205 | </button> |
| 105 | 206 | <button |
| 106 | 207 | class="btn btn-outline-dark boton-accion" |
| 107 | 208 | title="Eliminar" |
| 108 | - ng-click="solicitarConfirmacionCisterna(cisterna, key)" | |
| 209 | + ng-click="solicitarConfirmacionTabla(cisterna, $index)" | |
| 109 | 210 | > |
| 110 | 211 | <i class="fa fa-trash"></i> |
| 111 | 212 | </button> |
| 112 | 213 | </td> |
| 214 | + <td align="center" ng-show="cisterna.editando" > | |
| 215 | + <button | |
| 216 | + class="btn btn-outline-dark boton-accion" | |
| 217 | + ng-click="agregarCisterna(cisterna)" | |
| 218 | + > | |
| 219 | + <i class="fa fa-save"></i> | |
| 220 | + </button> | |
| 221 | + <button | |
| 222 | + class="btn btn-outline-dark boton-accion" | |
| 223 | + ng-click="volver(cisterna, key)" | |
| 224 | + > | |
| 225 | + <i class="fa fa-undo" aria-hidden="true"></i> | |
| 226 | + </button> | |
| 227 | + </td> | |
| 228 | + </tr> | |
| 229 | + | |
| 230 | + <tr ng-repeat="(key, cisterna) in cisternas" ng-show="false"> | |
| 113 | 231 | </tr> |
| 232 | + | |
| 114 | 233 | </body> |
| 115 | 234 | </table> |
| 116 | 235 | </div> |