diff --git a/src/js/controller.js b/src/js/controller.js index 21cc8a9..a42489a 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,9 +1,9 @@ angular.module('focaAbmVehiculo') .controller('focaAbmVehiculosController', [ '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', - '$uibModal', 'focaBotoneraLateralService', '$timeout', + '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', function($scope, focaAbmVehiculoService, $location, focaModalService, - $uibModal, focaBotoneraLateralService, $timeout) { + $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { $scope.now = new Date(); $scope.botonera = [{ @@ -20,7 +20,13 @@ angular.module('focaAbmVehiculo') focaBotoneraLateralService.showGuardar(false); focaBotoneraLateralService.addCustomButton('Salir', salir); - if(focaAbmVehiculoService.transportistaSeleccionado.COD) { + if ($localStorage.vehiculo) { + var vehiculo = JSON.parse($localStorage.vehiculo); + if (!vehiculo.idVehiculo) { vehiculo.idVehiculo = 0; } + $location.path('/vehiculo/' + vehiculo.idVehiculo + '/' + vehiculo.idTransportista); + } + + if (focaAbmVehiculoService.transportistaSeleccionado.COD) { elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); } $scope.editar = function(id) { @@ -93,9 +99,9 @@ angular.module('focaAbmVehiculo') ]) .controller('focaAbmVehiculoController', [ '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', - 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', + 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', '$localStorage', '$filter', function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, - focaModalService, $timeout, focaBotoneraLateralService, $window) { + focaModalService, $timeout, focaBotoneraLateralService, $window, $localStorage, $filter) { $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; $scope.now = new Date(); $scope.focused = 1; @@ -104,13 +110,15 @@ angular.module('focaAbmVehiculo') $timeout(function() { focaBotoneraLateralService.showSalir(false); - focaBotoneraLateralService.showPausar(false); + focaBotoneraLateralService.showPausar(true); focaBotoneraLateralService.showCancelar(false); focaBotoneraLateralService.showGuardar(true, $scope.guardar); - focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); + focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); }); + + $timeout(function() {getLSVehiculo();}); - if($scope.nuevo) { + if ($scope.nuevo) { focaAbmVehiculoService .getTransportistaPorId($routeParams.idTransportista) .then(function(res) { @@ -125,7 +133,7 @@ angular.module('focaAbmVehiculo') } $scope.vehiculo = {}; focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { - if(res.data) { + if (res.data) { $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; @@ -150,9 +158,21 @@ angular.module('focaAbmVehiculo') $scope.next = function(key) { if (key === 13) $scope.focused++; }; - $scope.cancelar = function() { - $location.path('/vehiculo'); - }; + + function cancelar() { + if ($scope.formVehiculo.$pristine == false) { + focaModalService.confirm( + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' + ).then(function(data) { + if (data) { + $location.path('/vehiculo'); + } + }); + } else { + $location.path('/vehiculo'); + } + } + $scope.editar = function(key) { if (key) { $location.path('/vehiculo/' + $routeParams.idVehiculo + @@ -163,25 +183,24 @@ angular.module('focaAbmVehiculo') }; $scope.guardar = function(key) { - if (!$scope.vehiculo.codigo) { - focaModalService.alert('Ingrese unidad'); - return; - } else if (!$scope.vehiculo.tractor) { - focaModalService.alert('Ingrese dominio tractor'); - return; - } else if (!$scope.vehiculo.semi) { - focaModalService.alert('Ingrese dominio semi'); - return; - } else if (!$scope.vehiculo.capacidad) { - focaModalService.alert('Ingrse capacidad total'); - return; - } - - key = (typeof key === 'undefined') ? 13 : key; + if (key === 13) { + if (!$scope.vehiculo.codigo) { + focaModalService.alert('Ingrese unidad'); + return; + } else if (!$scope.vehiculo.tractor) { + focaModalService.alert('Ingrese dominio tractor'); + return; + } else if (!$scope.vehiculo.semi) { + focaModalService.alert('Ingrese dominio semi'); + return; + } else if (!$scope.vehiculo.capacidad) { + focaModalService.alert('Ingrese capacidad total'); + return; + } //Valida si existe numero de unidad - if(!validaTotalCargas() && !$scope.nuevo) { + if (!validaTotalCargas() && !$scope.nuevo) { focaModalService.alert('La suma de las capacidades de las cisternas' + ' debe ser igual a la capacidad total del vehículo'); return; @@ -206,11 +225,42 @@ angular.module('focaAbmVehiculo') } }; + + $scope.$watch('vehiculo', function(newValue) { + focaBotoneraLateralService.setPausarData({ + label:'vehiculo', + val: { + codigo: newValue.codigo, + tractor: newValue.tractor, + semi: newValue.semi, + capacidad: newValue.capacidad, + idVehiculo: newValue.idVehiculo, + idTransportista: newValue.idTransportista + } + }); + }, true); + + function getLSVehiculo() { + var vehiculo = JSON.parse($localStorage.vehiculo|| null); + if (vehiculo) { + setearVehiculo(vehiculo); + delete $localStorage.vehiculo; + } + } + + function setearVehiculo(vehiculo) { + $scope.vehiculo = vehiculo; + $scope.$broadcast('addCabecera', { + label: 'Vehiculo:', + valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' + }); + } + $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?').then( function(data) { - if(data) { + if (data) { focaAbmVehiculoService.deleteCisterna(idx); focaAbmVehiculoService .getCisternas($routeParams.idVehiculo) diff --git a/src/js/controllerCisterna.js b/src/js/controllerCisterna.js index d2a620f..dce830d 100644 --- a/src/js/controllerCisterna.js +++ b/src/js/controllerCisterna.js @@ -1,9 +1,9 @@ angular.module('focaAbmVehiculo') .controller('focaAbmVehiculoCisternaController', [ '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', + 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter', function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, - focaModalService, focaBotoneraLateralService, $timeout, $window) { + focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { $scope.nuevo = ($routeParams.idx > -1) ? false : true; $scope.editar = false; $scope.now = new Date(); @@ -23,11 +23,21 @@ angular.module('focaAbmVehiculo') //SETEO BOTONERA LATERAL $timeout(function() { focaBotoneraLateralService.showSalir(false); - focaBotoneraLateralService.showPausar(false); - focaBotoneraLateralService.showCancelar(true); + focaBotoneraLateralService.showPausar(true); + focaBotoneraLateralService.showCancelar(false); focaBotoneraLateralService.showGuardar(true, $scope.guardar); + focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); }); + // $timeout(function() {getLSCisterna();}); + + // if ($localStorage.cisterna) { + // var cisterna = JSON.parse($localStorage.cisterna); + // console.log('Cisterna datos: ' ,cisterna); + // if (!cisterna.codigo) { cisterna.idcisterna = 0; } + // $location.path('/vehiculo/' + vehiculo.idVehiculo + '/cisterna/'); + // } + if ($routeParams.idx != -1) { $scope.cisterna = [$routeParams.idx]; @@ -56,7 +66,16 @@ angular.module('focaAbmVehiculo') }); }); $scope.cancelar = function() { - $location.path('/vehiculo/' + $routeParams.idVehiculo); + + if ($scope.formCisterna.$pristine == false) { + focaModalService.confirm( + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' + ).then(function(data) { + if (data) { + $location.path('/vehiculo'); + } + }); + } }; $scope.guardar = function() { @@ -104,6 +123,33 @@ angular.module('focaAbmVehiculo') }); }; + /*$scope.$watch('cisterna', function(newValue) { + focaBotoneraLateralService.setPausarData({ + label:'cisterna', + val: { + codigo: newValue.codigo, + capacidad: newValue.capacidad, + unidadMedida: newValue.NOM + } + }); + }, true);*/ + + /*function getLSCisterna() { + var cisterna = JSON.parse($localStorage.cisterna|| null); + if (cisterna) { + setearcisterna(cisterna); + delete $localStorage.cisterna; + } + } + + function setearcisterna(cisterna) { + $scope.cisterna = cisterna; + $scope.$broadcast('addCabecera', { + label: 'cisterna:', + valor: $filter('rellenarDigitos')(cisterna.codigo) + ' - ' + }); + }*/ + function validaCodigo() { return new Promise(function(resolve, reject) { focaAbmVehiculoService