diff --git a/src/js/controller.js b/src/js/controller.js index 290faf4..198903f 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -100,13 +100,14 @@ angular.module('focaAbmVehiculo') $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; $scope.now = new Date(); $scope.focused = 1; + $scope.creando = false; $scope.editando = false; $scope.transportistaStamp = ''; $scope.cisternas = []; - $scope.cisterna = { codigo: '', capacidad: '', + idUnidadMedida: {}, unidadMedida: {} }; @@ -181,11 +182,11 @@ angular.module('focaAbmVehiculo') $scope.editar = function(key, cisterna) { if (key === 'nuevo') { - $scope.editando = true; + $scope.cisterna = {}; + $scope.creando = true; } else { - console.log('Editar: '); $scope.cisterna = cisterna; - $scope.editando = true; + $scope.creando = true; } }; @@ -330,7 +331,7 @@ angular.module('focaAbmVehiculo') total += parseInt(cisterna.capacidad); } }); - return $scope.vehiculo.capacidad == total; + return $scope.vehiculo.capacidad === total; } function guardarCisternas() { var cisternas = $scope.cisternas.map(function(cisterna) { @@ -358,24 +359,34 @@ angular.module('focaAbmVehiculo') focaModalService.alert('Ingrese unidad de medida'); return; } - $scope.editando = false; - validaCodigo() - .then(function() { - saveCisterna(); - }, function(err) { - focaModalService.alert(err); - }); + $scope.creando = false; + if (!$scope.cisterna.id) { + validaCodigo() + .then(function() { + saveCisterna(); + }, function(err) { + focaModalService.alert(err); + }); + } else { + saveCisterna(); + } }; function saveCisterna () { $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); delete $scope.cisterna.vehiculo; var auxCisternas = $scope.cisternas; - auxCisternas.push($scope.cisterna); + if (!$scope.cisterna.id) { + auxCisternas.push($scope.cisterna); + } guardarCisternas(auxCisternas) - .then(function(result) { - $scope.cisternas = result.data; - $scope.cisterna = {}; + .then(function() { + focaAbmVehiculoService + .getCisternas($routeParams.idVehiculo) + .then(function(res) { + $scope.cisternas = res; + $scope.cisterna = {}; + }); }) .catch(function (err) { console.log('Err: ', err); @@ -401,7 +412,7 @@ angular.module('focaAbmVehiculo') cisternas.forEach(function(cisterna, idx) { //SI EL CODIGO YA EXISTE if (cisterna.codigo === $scope.cisterna.codigo && - idx != $routeParams.idx && + idx !== $routeParams.idx && !cisterna.desactivado) { reject('Código de cisterna existente'); } diff --git a/src/js/controllerCisterna.js b/src/js/controllerCisterna.js deleted file mode 100644 index 38c129a..0000000 --- a/src/js/controllerCisterna.js +++ /dev/null @@ -1,174 +0,0 @@ -angular.module('focaAbmVehiculo') - .controller('focaAbmVehiculoCisternaController', [ - '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window','$localStorage', - function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, - focaModalService, focaBotoneraLateralService, $timeout, $window, $localStorage) { - $scope.nuevo = ($routeParams.idx > -1) ? false : true; - $scope.editar = false; - $scope.now = new Date(); - $scope.cisterna = { - codigo: '', - capacidad: '', - unidadMedida: {} - }; - - $scope.focused = $scope.nuevo ? 1 : 2; - $scope.next = function(key) { - if (key === 13) $scope.focused++; - }; - $scope.capacidadVechiulo = 0; - $scope.transportista = ''; - - //SETEO BOTONERA LATERAL - $timeout(function() { - focaBotoneraLateralService.showSalir(false); - focaBotoneraLateralService.showPausar(true); - focaBotoneraLateralService.showCancelar(false); - focaBotoneraLateralService.showGuardar(true, $scope.guardar); - focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); - }); - - $timeout(function (){getLSCisterna();}); - - if ($routeParams.idx !== -1) { - $scope.cisterna = [$routeParams.idx]; - focaAbmVehiculoService - .getCisternas($routeParams.idVehiculo) - .then(function(res) { - $scope.cisterna = res[$routeParams.idx]; - }); - } - - focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { - var codigo = ('00000' + res.data.transportista.COD).slice(-5); - $scope.transportista = res.data.transportista.COD; - $scope.capacidadVechiulo = res.data.capacidad; - $scope.$broadcast('addCabecera', { - label: 'Transportista:', - valor: codigo + ' - ' + res.data.transportista.NOM - }); - $scope.$broadcast('addCabecera', { - label: 'Unidad:', - valor: res.data.codigo - }); - $scope.$broadcast('addCabecera', { - label: 'Capacidad total vehículo:', - valor: res.data.capacidad - }); - }); - - $scope.salir = function() { - - if (!$scope.formCisterna.$pristine) { - focaModalService.confirm( - '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' - ).then(function(data) { - if (data) { - $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + - $scope.transportista); - } - }); - } else { - $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + - $scope.transportista); - } - }; - - $scope.guardar = function() { - - if ($scope.formCisterna.$pristine) { - $scope.salir(); - return; - } else if (!$scope.cisterna.codigo) { - focaModalService.alert('Ingrese codigo de cisterna'); - return; - } else if (!$scope.cisterna.capacidad) { - focaModalService.alert('Ingrese capacidad'); - return; - } else if (!$scope.cisterna.idUnidadMedida) { - focaModalService.alert('Ingrese unidad de medida'); - return; - } - - validaCodigo() - .then(function() { - $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); - delete $scope.cisterna.vehiculo; - - focaAbmVehiculoService - .guardarCisterna($scope.cisterna, $routeParams.idx); - - $timeout(function() { - $location.path('/vehiculo/' + $routeParams.idVehiculo + - '/' + $scope.transportista); - }, 0); - }, function(err) { - focaModalService.alert(err); - }); - - }; - - $scope.seleccionarUnidadMedida = function() { - var modalInstance = $uibModal.open( - { - ariaLabelledBy: 'Busqueda de Unidades de medida', - templateUrl: 'modal-unidad-medida.html', - controller: 'focaModalUnidadMedidaCtrl', - size: 'lg' - } - ); - modalInstance.result.then(function(unidaMedida) { - $scope.cisterna.idUnidadMedida = unidaMedida.ID; - $scope.cisterna.unidadMedida = unidaMedida; - }); - }; - - $scope.$watch('cisterna', function(newValue) { - focaBotoneraLateralService.setPausarData({ - label:'cisterna', - val: newValue - }); - }, true); - - function getLSCisterna() { - var cisterna = JSON.parse($localStorage.cisterna|| null); - if (cisterna) { - setearVehiculo(cisterna); - delete $localStorage.cisterna; - } - } - - function setearVehiculo(cisterna) { - $scope.cisterna = cisterna; - $scope.$broadcast('addCabecera', { - label: 'Codigo de Cisterna:', - valor: cisterna.codigo - }); - } - - function validaCodigo() { - return new Promise(function(resolve, reject) { - focaAbmVehiculoService - .getCisternas($routeParams.idVehiculo) - .then(function(res) { - var cisternas = res; - var totalCargado = 0; - cisternas.forEach(function(cisterna, idx) { - //SI EL CODIGO YA EXISTE - if (cisterna.codigo === $scope.cisterna.codigo && - idx != $routeParams.idx && - !cisterna.desactivado) { - reject('Código de cisterna existente'); - } - if (idx !== $routeParams.idx && - !cisterna.desactivado) { - totalCargado += cisterna.capacidad; - } - }); - resolve(); - }); - }); - } - } - ]); diff --git a/src/js/service.js b/src/js/service.js index b9295b8..6822b6b 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -50,6 +50,7 @@ angular.module('focaAbmVehiculo') deleteCisterna: function(idx) { cisternas[idx].desactivado = true; cisternasPristine = false; + return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisternas[idx].id); }, cleanCisternas: function() { cisternas = []; diff --git a/src/views/foca-abm-cisterna-item.html b/src/views/foca-abm-cisterna-item.html deleted file mode 100644 index 8ee62d9..0000000 --- a/src/views/foca-abm-cisterna-item.html +++ /dev/null @@ -1,63 +0,0 @@ -
- -
-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
- -
-
-
-
diff --git a/src/views/foca-abm-vehiculos-item.html b/src/views/foca-abm-vehiculos-item.html index 2b4ad27..81edb6c 100644 --- a/src/views/foca-abm-vehiculos-item.html +++ b/src/views/foca-abm-vehiculos-item.html @@ -91,7 +91,7 @@ - + -
- -
- -
-
+
+ +
+ +
+