Commit 107f38cfbcdb298fa4f586e7c8aecf663a183260
1 parent
a329cbddc9
Exists in
master
Modificar - borrar cisterna
Showing
5 changed files
with
48 additions
and
273 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -100,13 +100,14 @@ angular.module('focaAbmVehiculo') |
| 100 | 100 | $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; |
| 101 | 101 | $scope.now = new Date(); |
| 102 | 102 | $scope.focused = 1; |
| 103 | + $scope.creando = false; | |
| 103 | 104 | $scope.editando = false; |
| 104 | 105 | $scope.transportistaStamp = ''; |
| 105 | 106 | $scope.cisternas = []; |
| 106 | - | |
| 107 | 107 | $scope.cisterna = { |
| 108 | 108 | codigo: '', |
| 109 | 109 | capacidad: '', |
| 110 | + idUnidadMedida: {}, | |
| 110 | 111 | unidadMedida: {} |
| 111 | 112 | }; |
| 112 | 113 | |
| ... | ... | @@ -181,11 +182,11 @@ angular.module('focaAbmVehiculo') |
| 181 | 182 | |
| 182 | 183 | $scope.editar = function(key, cisterna) { |
| 183 | 184 | if (key === 'nuevo') { |
| 184 | - $scope.editando = true; | |
| 185 | + $scope.cisterna = {}; | |
| 186 | + $scope.creando = true; | |
| 185 | 187 | } else { |
| 186 | - console.log('Editar: '); | |
| 187 | 188 | $scope.cisterna = cisterna; |
| 188 | - $scope.editando = true; | |
| 189 | + $scope.creando = true; | |
| 189 | 190 | } |
| 190 | 191 | }; |
| 191 | 192 | |
| ... | ... | @@ -330,7 +331,7 @@ angular.module('focaAbmVehiculo') |
| 330 | 331 | total += parseInt(cisterna.capacidad); |
| 331 | 332 | } |
| 332 | 333 | }); |
| 333 | - return $scope.vehiculo.capacidad == total; | |
| 334 | + return $scope.vehiculo.capacidad === total; | |
| 334 | 335 | } |
| 335 | 336 | function guardarCisternas() { |
| 336 | 337 | var cisternas = $scope.cisternas.map(function(cisterna) { |
| ... | ... | @@ -358,24 +359,34 @@ angular.module('focaAbmVehiculo') |
| 358 | 359 | focaModalService.alert('Ingrese unidad de medida'); |
| 359 | 360 | return; |
| 360 | 361 | } |
| 361 | - $scope.editando = false; | |
| 362 | - validaCodigo() | |
| 363 | - .then(function() { | |
| 364 | - saveCisterna(); | |
| 365 | - }, function(err) { | |
| 366 | - focaModalService.alert(err); | |
| 367 | - }); | |
| 362 | + $scope.creando = false; | |
| 363 | + if (!$scope.cisterna.id) { | |
| 364 | + validaCodigo() | |
| 365 | + .then(function() { | |
| 366 | + saveCisterna(); | |
| 367 | + }, function(err) { | |
| 368 | + focaModalService.alert(err); | |
| 369 | + }); | |
| 370 | + } else { | |
| 371 | + saveCisterna(); | |
| 372 | + } | |
| 368 | 373 | }; |
| 369 | 374 | |
| 370 | 375 | function saveCisterna () { |
| 371 | 376 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
| 372 | 377 | delete $scope.cisterna.vehiculo; |
| 373 | 378 | var auxCisternas = $scope.cisternas; |
| 374 | - auxCisternas.push($scope.cisterna); | |
| 379 | + if (!$scope.cisterna.id) { | |
| 380 | + auxCisternas.push($scope.cisterna); | |
| 381 | + } | |
| 375 | 382 | guardarCisternas(auxCisternas) |
| 376 | - .then(function(result) { | |
| 377 | - $scope.cisternas = result.data; | |
| 378 | - $scope.cisterna = {}; | |
| 383 | + .then(function() { | |
| 384 | + focaAbmVehiculoService | |
| 385 | + .getCisternas($routeParams.idVehiculo) | |
| 386 | + .then(function(res) { | |
| 387 | + $scope.cisternas = res; | |
| 388 | + $scope.cisterna = {}; | |
| 389 | + }); | |
| 379 | 390 | }) |
| 380 | 391 | .catch(function (err) { |
| 381 | 392 | console.log('Err: ', err); |
| ... | ... | @@ -401,7 +412,7 @@ angular.module('focaAbmVehiculo') |
| 401 | 412 | cisternas.forEach(function(cisterna, idx) { |
| 402 | 413 | //SI EL CODIGO YA EXISTE |
| 403 | 414 | if (cisterna.codigo === $scope.cisterna.codigo && |
| 404 | - idx != $routeParams.idx && | |
| 415 | + idx !== $routeParams.idx && | |
| 405 | 416 | !cisterna.desactivado) { |
| 406 | 417 | reject('Cรณdigo de cisterna existente'); |
| 407 | 418 | } |
src/js/controllerCisterna.js
| ... | ... | @@ -1,174 +0,0 @@ |
| 1 | -angular.module('focaAbmVehiculo') | |
| 2 | - .controller('focaAbmVehiculoCisternaController', [ | |
| 3 | - '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | |
| 4 | - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window','$localStorage', | |
| 5 | - function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | |
| 6 | - focaModalService, focaBotoneraLateralService, $timeout, $window, $localStorage) { | |
| 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 | - $timeout(function (){getLSCisterna();}); | |
| 33 | - | |
| 34 | - if ($routeParams.idx !== -1) { | |
| 35 | - $scope.cisterna = [$routeParams.idx]; | |
| 36 | - focaAbmVehiculoService | |
| 37 | - .getCisternas($routeParams.idVehiculo) | |
| 38 | - .then(function(res) { | |
| 39 | - $scope.cisterna = res[$routeParams.idx]; | |
| 40 | - }); | |
| 41 | - } | |
| 42 | - | |
| 43 | - focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | |
| 44 | - var codigo = ('00000' + res.data.transportista.COD).slice(-5); | |
| 45 | - $scope.transportista = res.data.transportista.COD; | |
| 46 | - $scope.capacidadVechiulo = res.data.capacidad; | |
| 47 | - $scope.$broadcast('addCabecera', { | |
| 48 | - label: 'Transportista:', | |
| 49 | - valor: codigo + ' - ' + res.data.transportista.NOM | |
| 50 | - }); | |
| 51 | - $scope.$broadcast('addCabecera', { | |
| 52 | - label: 'Unidad:', | |
| 53 | - valor: res.data.codigo | |
| 54 | - }); | |
| 55 | - $scope.$broadcast('addCabecera', { | |
| 56 | - label: 'Capacidad total vehรญculo:', | |
| 57 | - valor: res.data.capacidad | |
| 58 | - }); | |
| 59 | - }); | |
| 60 | - | |
| 61 | - $scope.salir = function() { | |
| 62 | - | |
| 63 | - if (!$scope.formCisterna.$pristine) { | |
| 64 | - focaModalService.confirm( | |
| 65 | - 'ยฟEstรก seguro de que desea salir? Se perderรกn todos los datos cargados.' | |
| 66 | - ).then(function(data) { | |
| 67 | - if (data) { | |
| 68 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | |
| 69 | - $scope.transportista); | |
| 70 | - } | |
| 71 | - }); | |
| 72 | - } else { | |
| 73 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | |
| 74 | - $scope.transportista); | |
| 75 | - } | |
| 76 | - }; | |
| 77 | - | |
| 78 | - $scope.guardar = function() { | |
| 79 | - | |
| 80 | - if ($scope.formCisterna.$pristine) { | |
| 81 | - $scope.salir(); | |
| 82 | - return; | |
| 83 | - } else if (!$scope.cisterna.codigo) { | |
| 84 | - focaModalService.alert('Ingrese codigo de cisterna'); | |
| 85 | - return; | |
| 86 | - } else if (!$scope.cisterna.capacidad) { | |
| 87 | - focaModalService.alert('Ingrese capacidad'); | |
| 88 | - return; | |
| 89 | - } else if (!$scope.cisterna.idUnidadMedida) { | |
| 90 | - focaModalService.alert('Ingrese unidad de medida'); | |
| 91 | - return; | |
| 92 | - } | |
| 93 | - | |
| 94 | - validaCodigo() | |
| 95 | - .then(function() { | |
| 96 | - $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | |
| 97 | - delete $scope.cisterna.vehiculo; | |
| 98 | - | |
| 99 | - focaAbmVehiculoService | |
| 100 | - .guardarCisterna($scope.cisterna, $routeParams.idx); | |
| 101 | - | |
| 102 | - $timeout(function() { | |
| 103 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + | |
| 104 | - '/' + $scope.transportista); | |
| 105 | - }, 0); | |
| 106 | - }, function(err) { | |
| 107 | - focaModalService.alert(err); | |
| 108 | - }); | |
| 109 | - | |
| 110 | - }; | |
| 111 | - | |
| 112 | - $scope.seleccionarUnidadMedida = function() { | |
| 113 | - var modalInstance = $uibModal.open( | |
| 114 | - { | |
| 115 | - ariaLabelledBy: 'Busqueda de Unidades de medida', | |
| 116 | - templateUrl: 'modal-unidad-medida.html', | |
| 117 | - controller: 'focaModalUnidadMedidaCtrl', | |
| 118 | - size: 'lg' | |
| 119 | - } | |
| 120 | - ); | |
| 121 | - modalInstance.result.then(function(unidaMedida) { | |
| 122 | - $scope.cisterna.idUnidadMedida = unidaMedida.ID; | |
| 123 | - $scope.cisterna.unidadMedida = unidaMedida; | |
| 124 | - }); | |
| 125 | - }; | |
| 126 | - | |
| 127 | - $scope.$watch('cisterna', function(newValue) { | |
| 128 | - focaBotoneraLateralService.setPausarData({ | |
| 129 | - label:'cisterna', | |
| 130 | - val: newValue | |
| 131 | - }); | |
| 132 | - }, true); | |
| 133 | - | |
| 134 | - function getLSCisterna() { | |
| 135 | - var cisterna = JSON.parse($localStorage.cisterna|| null); | |
| 136 | - if (cisterna) { | |
| 137 | - setearVehiculo(cisterna); | |
| 138 | - delete $localStorage.cisterna; | |
| 139 | - } | |
| 140 | - } | |
| 141 | - | |
| 142 | - function setearVehiculo(cisterna) { | |
| 143 | - $scope.cisterna = cisterna; | |
| 144 | - $scope.$broadcast('addCabecera', { | |
| 145 | - label: 'Codigo de Cisterna:', | |
| 146 | - valor: cisterna.codigo | |
| 147 | - }); | |
| 148 | - } | |
| 149 | - | |
| 150 | - function validaCodigo() { | |
| 151 | - return new Promise(function(resolve, reject) { | |
| 152 | - focaAbmVehiculoService | |
| 153 | - .getCisternas($routeParams.idVehiculo) | |
| 154 | - .then(function(res) { | |
| 155 | - var cisternas = res; | |
| 156 | - var totalCargado = 0; | |
| 157 | - cisternas.forEach(function(cisterna, idx) { | |
| 158 | - //SI EL CODIGO YA EXISTE | |
| 159 | - if (cisterna.codigo === $scope.cisterna.codigo && | |
| 160 | - idx != $routeParams.idx && | |
| 161 | - !cisterna.desactivado) { | |
| 162 | - reject('Cรณdigo de cisterna existente'); | |
| 163 | - } | |
| 164 | - if (idx !== $routeParams.idx && | |
| 165 | - !cisterna.desactivado) { | |
| 166 | - totalCargado += cisterna.capacidad; | |
| 167 | - } | |
| 168 | - }); | |
| 169 | - resolve(); | |
| 170 | - }); | |
| 171 | - }); | |
| 172 | - } | |
| 173 | - } | |
| 174 | - ]); |
src/js/service.js
| ... | ... | @@ -50,6 +50,7 @@ angular.module('focaAbmVehiculo') |
| 50 | 50 | deleteCisterna: function(idx) { |
| 51 | 51 | cisternas[idx].desactivado = true; |
| 52 | 52 | cisternasPristine = false; |
| 53 | + return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisternas[idx].id); | |
| 53 | 54 | }, |
| 54 | 55 | cleanCisternas: function() { |
| 55 | 56 | 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
| ... | ... | @@ -91,7 +91,7 @@ |
| 91 | 91 | </tr> |
| 92 | 92 | </thead> |
| 93 | 93 | <tbody> |
| 94 | - <tr ng-show="editando"> | |
| 94 | + <tr ng-show="creando"> | |
| 95 | 95 | <td align="center"> |
| 96 | 96 | <input |
| 97 | 97 | class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" |
| ... | ... | @@ -116,24 +116,24 @@ |
| 116 | 116 | > |
| 117 | 117 | </td> |
| 118 | 118 | <td align="center"> |
| 119 | - <div class="input-group"> | |
| 120 | - <input | |
| 121 | - ng-model="cisterna.unidadMedida.NOM" | |
| 122 | - class="form-control" | |
| 123 | - readonly | |
| 124 | - /> | |
| 125 | - <div class="input-group-append"> | |
| 126 | - <button | |
| 127 | - ladda="searchLoading" | |
| 128 | - class="btn btn-outline-secondary form-control" | |
| 129 | - type="button" | |
| 130 | - ng-click="seleccionarUnidadMedida()" | |
| 131 | - foca-focus="focused == 3" | |
| 132 | - > | |
| 133 | - <i class="fa fa-search" aria-hidden="true"></i> | |
| 134 | - </button> | |
| 135 | - </div> | |
| 136 | - </div> | |
| 119 | + <div class="input-group"> | |
| 120 | + <input | |
| 121 | + ng-model="cisterna.unidadMedida.NOM" | |
| 122 | + class="form-control" | |
| 123 | + readonly | |
| 124 | + /> | |
| 125 | + <div class="input-group-append"> | |
| 126 | + <button | |
| 127 | + ladda="searchLoading" | |
| 128 | + class="btn btn-outline-secondary form-control" | |
| 129 | + type="button" | |
| 130 | + ng-click="seleccionarUnidadMedida()" | |
| 131 | + foca-focus="focused == 3" | |
| 132 | + > | |
| 133 | + <i class="fa fa-search" aria-hidden="true"></i> | |
| 134 | + </button> | |
| 135 | + </div> | |
| 136 | + </div> | |
| 137 | 137 | </td> |
| 138 | 138 | <td align="center"> |
| 139 | 139 | <button |