Commit 3b896ba943ff21b9c76293d412421fb4607d97d0

Authored by Luigi
1 parent b47480a700
Exists in master

Boton volver - crear y editar cisternas

src/js/controller.js
... ... @@ -101,15 +101,9 @@ angular.module('focaAbmVehiculo')
101 101 $scope.now = new Date();
102 102 $scope.focused = 1;
103 103 $scope.creando = false;
  104 + $scope.crear = false;
104 105 $scope.transportistaStamp = '';
105   - $scope.cisternasABorrar = [];
106 106 $scope.cisternas = [];
107   - $scope.cisterna = {
108   - codigo: '',
109   - capacidad: '',
110   - idUnidadMedida: 0,
111   - unidadMedida: {}
112   - };
113 107  
114 108 $timeout(function() {
115 109 focaBotoneraLateralService.showSalir(false);
... ... @@ -180,17 +174,41 @@ angular.module('focaAbmVehiculo')
180 174 }
181 175 };
182 176  
183   - $scope.editar = function(key, cisterna) {
184   - if (key === 'nuevo') {
185   - $scope.cisterna = {};
186   - $scope.creando = true;
187   - } else {
188   - $scope.cisterna = cisterna;
189   - $scope.creando = true;
  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;
  191 + }
  192 + if (cisterna.id !== undefined) {
  193 + $scope.cisternas[key] = $scope.inicial;
  194 + $scope.cisternas[key].editando = false;
190 195 }
  196 + $scope.crear = false;
191 197 };
192 198  
193   - $scope.seleccionarUnidadMedida = function() {
  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) {
194 212 var modalInstance = $uibModal.open(
195 213 {
196 214 ariaLabelledBy: 'Busqueda de Unidades de medida',
... ... @@ -200,8 +218,8 @@ angular.module('focaAbmVehiculo')
200 218 }
201 219 );
202 220 modalInstance.result.then(function(unidaMedida) {
203   - $scope.cisterna.idUnidadMedida = unidaMedida.ID;
204   - $scope.cisterna.unidadMedida = unidaMedida;
  221 + cisterna.idUnidadMedida = unidaMedida.ID;
  222 + cisterna.unidadMedida = unidaMedida;
205 223 });
206 224 };
207 225  
... ... @@ -214,6 +232,9 @@ angular.module('focaAbmVehiculo')
214 232 $scope.salir();
215 233 return;
216 234 }
  235 + $scope.cisternas.forEach( function(cisterna) {
  236 + if (cisterna.id === 0) cisterna.id = undefined;
  237 + });
217 238  
218 239 if (!$scope.vehiculo.codigo) {
219 240 focaModalService.alert('Ingrese unidad');
... ... @@ -235,8 +256,6 @@ angular.module('focaAbmVehiculo')
235 256 return;
236 257 }
237 258  
238   - borrarCisternas();
239   -
240 259 validaCodigoUnidad().then(function() {
241 260 delete $scope.vehiculo.transportista;
242 261 delete $scope.vehiculo.cisternas;
... ... @@ -246,7 +265,7 @@ angular.module('focaAbmVehiculo')
246 265 $location.path('/vehiculo/' + res.data.id +
247 266 '/' + res.data.idTransportista);
248 267 } else {
249   - guardarCisternas().then(function() {
  268 + guardarCisternas($scope.cisternas).then(function() {
250 269 $location.path('/vehiculo');
251 270 });
252 271 }
... ... @@ -256,7 +275,6 @@ angular.module('focaAbmVehiculo')
256 275 });
257 276 }
258 277 };
259   -
260 278 //Agregar propiedades de cisterna
261 279 $scope.$watch('vehiculo', function(newValue) {
262 280 focaBotoneraLateralService.setPausarData({
... ... @@ -282,17 +300,6 @@ angular.module('focaAbmVehiculo')
282 300 return false;
283 301 }
284 302  
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   -
296 303 function setearVehiculo(vehiculo) {
297 304 $scope.vehiculo = vehiculo;
298 305 $scope.$broadcast('addCabecera', {
... ... @@ -301,12 +308,11 @@ angular.module('focaAbmVehiculo')
301 308 });
302 309 }
303 310  
304   - $scope.solicitarConfirmacionTabla = function(cisterna, idx){
  311 + $scope.solicitarConfirmacionTabla = function(cisterna) {
305 312 focaModalService.confirm('ยฟEstรก seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?')
306 313 .then( function(data) {
307 314 if (data) {
308   - $scope.cisternasABorrar.push(cisterna);
309   - $scope.cisternas.splice(idx,1);
  315 + cisterna.desactivado = true;
310 316 }
311 317 });
312 318 return;
... ... @@ -352,41 +358,28 @@ angular.module('focaAbmVehiculo')
352 358 desactivado: cisterna.desactivado
353 359 };
354 360 });
355   -
  361 +
356 362 return focaAbmVehiculoService.guardarCisternas(cisternas);
357 363 }
358 364  
359   - $scope.agregarCisterna = function() {
360   - if (!$scope.cisterna.codigo) {
  365 + $scope.agregarCisterna = function(cisterna) {
  366 + if (!cisterna) {
  367 + focaModalService.alert('Ingrese valores');
  368 + return;
  369 + } else if (!cisterna.codigo) {
361 370 focaModalService.alert('Ingrese codigo de cisterna');
362 371 return;
363   - } else if (!$scope.cisterna.capacidad) {
  372 + } else if (!cisterna.capacidad) {
364 373 focaModalService.alert('Ingrese capacidad');
365 374 return;
366   - } else if (!$scope.cisterna.idUnidadMedida) {
  375 + } else if (!cisterna.idUnidadMedida) {
367 376 focaModalService.alert('Ingrese unidad de medida');
368 377 return;
369 378 }
370   - $scope.creando = false;
371   - if (!$scope.cisterna.id) {
372   - validaCodigo()
373   - .then(function() {
374   - saveCisterna();
375   - }, function(err) {
376   - focaModalService.alert(err);
377   - });
378   - } else {
379   - saveCisterna();
380   - }
381   - };
382 379  
383   - function saveCisterna () {
384   - $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo);
385   - delete $scope.cisterna.vehiculo;
386   - if (!$scope.cisterna.id) {
387   - $timeout(function() { $scope.cisternas.push($scope.cisterna);});
388   - }
389   - }
  380 + validaCodigo(cisterna);
  381 + cisterna.id = 0;
  382 + };
390 383  
391 384 if ($routeParams.idx !== -1) {
392 385 $scope.cisterna = [$routeParams.idx];
... ... @@ -397,28 +390,32 @@ angular.module('focaAbmVehiculo')
397 390 });
398 391 }
399 392  
400   - function validaCodigo() {
401   - return new Promise(function(resolve, reject) {
402   - focaAbmVehiculoService
403   - .getCisternas($routeParams.idVehiculo)
404   - .then(function(res) {
405   - var cisternas = res;
406   - var totalCargado = 0;
407   - cisternas.forEach(function(cisterna, idx) {
408   - //SI EL CODIGO YA EXISTE
409   - if (cisterna.codigo === $scope.cisterna.codigo &&
410   - idx !== $routeParams.idx &&
411   - !cisterna.desactivado) {
412   - reject('Cรณdigo de cisterna existente');
413   - }
414   - if (idx !== $routeParams.idx &&
415   - !cisterna.desactivado) {
416   - totalCargado += cisterna.capacidad;
  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;
417 412 }
418 413 });
419   - resolve();
  414 + $timeout( function(){
  415 + cisterna.editando = false;
  416 + $scope.crear = false;
  417 + });
420 418 });
421   - });
422 419 }
423 420 }
424 421 ]);
... ... @@ -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') {
src/views/foca-abm-vehiculos-item.html
... ... @@ -74,7 +74,7 @@
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 80 <th class="text-center px-4">Cรณdigo</th>
... ... @@ -84,11 +84,12 @@
84 84 <button
85 85 class="btn btn-outline-debo boton-accion"
86 86 title="Agregar"
87   - ng-click="editar('nuevo')">
  87 + ng-click="crearCisterna()"
  88 + ng-disabled="crear">
88 89 <i class="fa fa-plus"></i>
89 90 </button>
90 91 </th>
91   - </tr>
  92 + </tr>
92 93 </thead>
93 94 <tbody>
94 95 <tr ng-show="creando">
... ... @@ -145,28 +146,90 @@
145 146 </td>
146 147 </tr>
147 148  
148   - <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros"
149   - ng-show="!cisterna.desactivado">
150   - <td ng-bind="cisterna.codigo" class="text-center"></td>
151   - <td ng-bind="cisterna.capacidad" class="text-center"></td>
152   - <td ng-bind="cisterna.unidadMedida.NOM" class="text-center"></td>
153   - <td class="text-center">
  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">
154 199 <button
155 200 class="btn btn-outline-dark boton-accion"
156 201 title="Editar"
157   - ng-click="editar('',cisterna)"
  202 + ng-click="editar(cisterna)"
158 203 >
159 204 <i class="fa fa-pencil"></i>
160 205 </button>
161 206 <button
162 207 class="btn btn-outline-dark boton-accion"
163 208 title="Eliminar"
164   - ng-click="solicitarConfirmacionTabla(cisterna,$index)"
  209 + ng-click="solicitarConfirmacionTabla(cisterna, $index)"
165 210 >
166 211 <i class="fa fa-trash"></i>
167 212 </button>
168 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">
169 231 </tr>
  232 +
170 233 </body>
171 234 </table>
172 235 </div>