From a329cbddc9e0977755f8e961bb55222fa21a4db9 Mon Sep 17 00:00:00 2001 From: Luigi Date: Mon, 22 Apr 2019 15:16:58 -0300 Subject: [PATCH] Identacion --- src/js/controller.js | 734 +++++++++++++++++++++++++-------------------------- 1 file changed, 367 insertions(+), 367 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index beb4833..290faf4 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,418 +1,418 @@ - angular.module('focaAbmVehiculo') - .controller('focaAbmVehiculosController', [ - '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', - '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', - function($scope, focaAbmVehiculoService, $location, focaModalService, - $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { +angular.module('focaAbmVehiculo') + .controller('focaAbmVehiculosController', [ + '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', + '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', + function($scope, focaAbmVehiculoService, $location, focaModalService, + $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { - $scope.now = new Date(); - $scope.botonera = [{ - label: 'Transportista', - image: 'cliente.png' - }]; + $scope.now = new Date(); + $scope.botonera = [{ + label: 'Transportista', + image: 'cliente.png' + }]; - focaAbmVehiculoService.cleanCisternas(); + focaAbmVehiculoService.cleanCisternas(); - //SETEO BOTONERA LATERAL - focaBotoneraLateralService.showSalir(false); - focaBotoneraLateralService.showPausar(false); - focaBotoneraLateralService.showCancelar(false); - focaBotoneraLateralService.showGuardar(false); - focaBotoneraLateralService.addCustomButton('Salir', salir); + //SETEO BOTONERA LATERAL + focaBotoneraLateralService.showSalir(false); + focaBotoneraLateralService.showPausar(false); + focaBotoneraLateralService.showCancelar(false); + focaBotoneraLateralService.showGuardar(false); + focaBotoneraLateralService.addCustomButton('Salir', salir); - if (focaAbmVehiculoService.transportistaSeleccionado.COD) { - elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); - } - $scope.editar = function(id) { - $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); - }; - $scope.solicitarConfirmacion = function(vehiculo) { - focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + - vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( - function(data) { - if (data) { - focaAbmVehiculoService.deleteVehiculo(vehiculo.id); - $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); - } - } - ); - }; - $scope.seleccionarTransportista = function() { - var parametrosModal = { - titulo: 'Búsqueda de Transportista', - query: '/transportista', - columnas: [ - { - nombre: 'Código', - propiedad: 'COD' - }, - { - nombre: 'Nombre', - propiedad: 'NOM' - }, - { - nombre: 'CUIT', - propiedad: 'CUIT' + if (focaAbmVehiculoService.transportistaSeleccionado.COD) { + elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); + } + $scope.editar = function(id) { + $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); + }; + $scope.solicitarConfirmacion = function(vehiculo) { + focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + + vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( + function(data) { + if (data) { + focaAbmVehiculoService.deleteVehiculo(vehiculo.id); + $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); } - ] - }; - focaModalService.modal(parametrosModal).then( - function(transportista) { - elegirTransportista(transportista); - focaAbmVehiculoService.transportistaSeleccionado = transportista; - }, function() { - } ); + }; + $scope.seleccionarTransportista = function() { + var parametrosModal = { + titulo: 'Búsqueda de Transportista', + query: '/transportista', + columnas: [ + { + nombre: 'Código', + propiedad: 'COD' + }, + { + nombre: 'Nombre', + propiedad: 'NOM' + }, + { + nombre: 'CUIT', + propiedad: 'CUIT' + } + ] }; - function elegirTransportista(transportista) { - var codigo = ('00000' + transportista.COD).slice(-5); - $scope.idTransportista = transportista.COD; - $scope.filtros = transportista.NOM.trim(); - $timeout(function() { - $scope.$broadcast('addCabecera', { - label: 'Transportista:', - valor: codigo + ' - ' + transportista.NOM - }); + focaModalService.modal(parametrosModal).then( + function(transportista) { + elegirTransportista(transportista); + focaAbmVehiculoService.transportistaSeleccionado = transportista; + }, function() { + + } + ); + }; + function elegirTransportista(transportista) { + var codigo = ('00000' + transportista.COD).slice(-5); + $scope.idTransportista = transportista.COD; + $scope.filtros = transportista.NOM.trim(); + $timeout(function() { + $scope.$broadcast('addCabecera', { + label: 'Transportista:', + valor: codigo + ' - ' + transportista.NOM }); - buscar(transportista.COD); - } + }); + buscar(transportista.COD); + } - function buscar(idTransportista) { - focaAbmVehiculoService - .getVehiculosPorTransportista(idTransportista) - .then(function(datos) { - $scope.vehiculos = datos.data; - }); - } - function salir() { - focaAbmVehiculoService.transportistaSeleccionado = {}; - $location.path('/'); - } + function buscar(idTransportista) { + focaAbmVehiculoService + .getVehiculosPorTransportista(idTransportista) + .then(function(datos) { + $scope.vehiculos = datos.data; + }); } - ]) - .controller('focaAbmVehiculoController', [ - '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', - 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', - function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, - focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { - $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; - $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; - $scope.now = new Date(); - $scope.focused = 1; - $scope.editando = false; - $scope.transportistaStamp = ''; - $scope.cisternas = []; + function salir() { + focaAbmVehiculoService.transportistaSeleccionado = {}; + $location.path('/'); + } + } + ]) + .controller('focaAbmVehiculoController', [ + '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', + 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', + function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, + focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { + $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; + $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; + $scope.now = new Date(); + $scope.focused = 1; + $scope.editando = false; + $scope.transportistaStamp = ''; + $scope.cisternas = []; - $scope.cisterna = { - codigo: '', - capacidad: '', - unidadMedida: {} - }; + $scope.cisterna = { + codigo: '', + capacidad: '', + unidadMedida: {} + }; - $timeout(function() { - focaBotoneraLateralService.showSalir(false); - focaBotoneraLateralService.showPausar(true); - focaBotoneraLateralService.showCancelar(false); - focaBotoneraLateralService.showGuardar(true, $scope.guardar); - focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); - }); + $timeout(function() { + focaBotoneraLateralService.showSalir(false); + focaBotoneraLateralService.showPausar(true); + focaBotoneraLateralService.showCancelar(false); + focaBotoneraLateralService.showGuardar(true, $scope.guardar); + focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); + }); - if ($scope.nuevo) { - focaAbmVehiculoService - .getTransportistaPorId($routeParams.idTransportista) - .then(function(res) { - var codigo = ('00000' + res.data.COD).slice(-5); - $scope.vehiculo.idTransportista = res.data.COD; - $scope.vehiculo.transportista = res.data; - $scope.$broadcast('addCabecera', { - label: 'Transportista:', - valor: codigo + ' - ' + res.data.NOM - }); + if ($scope.nuevo) { + focaAbmVehiculoService + .getTransportistaPorId($routeParams.idTransportista) + .then(function(res) { + var codigo = ('00000' + res.data.COD).slice(-5); + $scope.vehiculo.idTransportista = res.data.COD; + $scope.vehiculo.transportista = res.data; + $scope.$broadcast('addCabecera', { + label: 'Transportista:', + valor: codigo + ' - ' + res.data.NOM }); - } - $scope.vehiculo = {}; + }); + } + $scope.vehiculo = {}; - focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { - - if (res.data) { - var vehiculoSeteado = getLSVehiculo(); - if (vehiculoSeteado === false) { - $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); - $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; + focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { + + if (res.data) { + var vehiculoSeteado = getLSVehiculo(); + if (vehiculoSeteado === false) { + $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); + $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; - $scope.vehiculo = res.data; - $scope.$broadcast('addCabecera', { - label: 'Transportista:', - valor: $scope.transportistaStamp - }); - $scope.$broadcast('addCabecera', { - label: 'Unidad:', - valor: res.data.codigo - }); - } - - focaAbmVehiculoService - .getCisternas($routeParams.idVehiculo) - .then(function(res) { - $scope.cisternas = res; - $scope.$apply(); + $scope.vehiculo = res.data; + $scope.$broadcast('addCabecera', { + label: 'Transportista:', + valor: $scope.transportistaStamp }); - } - }); - - $scope.next = function(key) { - if (key === 13) $scope.focused++; - }; - - $scope.salir = function() { - if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { - focaModalService.confirm( - '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' - ).then(function(data) { - if (data) { - $location.path('/vehiculo'); - } + $scope.$broadcast('addCabecera', { + label: 'Unidad:', + valor: res.data.codigo }); - } else { - $location.path('/vehiculo'); } - }; + + focaAbmVehiculoService + .getCisternas($routeParams.idVehiculo) + .then(function(res) { + $scope.cisternas = res; + $scope.$apply(); + }); + } + }); - $scope.editar = function(key, cisterna) { - if (key === 'nuevo') { - $scope.editando = true; - } else { - console.log('Editar: '); - $scope.cisterna = cisterna; - $scope.editando = true; - } - }; + $scope.next = function(key) { + if (key === 13) $scope.focused++; + }; - $scope.seleccionarUnidadMedida = function() { - var modalInstance = $uibModal.open( - { - ariaLabelledBy: 'Busqueda de Unidades de medida', - templateUrl: 'modal-unidad-medida.html', - controller: 'focaModalUnidadMedidaCtrl', - size: 'lg' + $scope.salir = function() { + if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { + focaModalService.confirm( + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' + ).then(function(data) { + if (data) { + $location.path('/vehiculo'); } - ); - modalInstance.result.then(function(unidaMedida) { - $scope.cisterna.idUnidadMedida = unidaMedida.ID; - $scope.cisterna.unidadMedida = unidaMedida; }); - }; + } else { + $location.path('/vehiculo'); + } + }; - $scope.guardar = function(key) { - - key = (typeof key === 'undefined') ? 13 : key; + $scope.editar = function(key, cisterna) { + if (key === 'nuevo') { + $scope.editando = true; + } else { + console.log('Editar: '); + $scope.cisterna = cisterna; + $scope.editando = true; + } + }; - if (key === 13) { + $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; + }); + }; - if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { - $scope.salir(); - return; - } + $scope.guardar = function(key) { + + key = (typeof key === 'undefined') ? 13 : 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('Ingrese capacidad total'); - return; - } - //Valida si existe numero de unidad - 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; - } - validaCodigoUnidad().then(function() { - delete $scope.vehiculo.transportista; - delete $scope.vehiculo.cisternas; - focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) - .then(function(res) { - if ($scope.nuevo) { - $location.path('/vehiculo/' + res.data.id + - '/' + res.data.idTransportista); - } else { - guardarCisternas().then(function() { - $location.path('/vehiculo'); - }); - } - }); - }, function() { - focaModalService.alert('Código de unidad existente'); - }); + if (key === 13) { + + if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { + $scope.salir(); + return; } - }; - //Agregar propiedades de cisterna - $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 - } + 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) { + focaModalService.alert('La suma de las capacidades de las cisternas' + + ' debe ser igual a la capacidad total del vehículo'); + return; + } + validaCodigoUnidad().then(function() { + delete $scope.vehiculo.transportista; + delete $scope.vehiculo.cisternas; + focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) + .then(function(res) { + if ($scope.nuevo) { + $location.path('/vehiculo/' + res.data.id + + '/' + res.data.idTransportista); + } else { + guardarCisternas().then(function() { + $location.path('/vehiculo'); + }); + } + }); + }, function() { + focaModalService.alert('Código de unidad existente'); }); - }, true); + } + }; - function getLSVehiculo() { - var vehiculo = JSON.parse($localStorage.vehiculo|| null); - if (vehiculo) { - setearVehiculo(vehiculo); - delete $localStorage.vehiculo; - return true; + //Agregar propiedades de cisterna + $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 } - return false; - } + }); + }, true); - function setearVehiculo(vehiculo) { - $scope.vehiculo = vehiculo; - $scope.$broadcast('addCabecera', { - label: 'Vehiculo:', - valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' - }); + function getLSVehiculo() { + var vehiculo = JSON.parse($localStorage.vehiculo|| null); + if (vehiculo) { + setearVehiculo(vehiculo); + delete $localStorage.vehiculo; + return true; } + return false; + } - $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { - focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + - cisterna.id + ' ' + cisterna.codigo + ' ?').then( - function(data) { - if (data) { - focaAbmVehiculoService.deleteCisterna(idx); - focaAbmVehiculoService - .getCisternas($routeParams.idVehiculo) - .then(function(res) { - $scope.cisternas = res; - }); - } - } - ); - }; + function setearVehiculo(vehiculo) { + $scope.vehiculo = vehiculo; + $scope.$broadcast('addCabecera', { + label: 'Vehiculo:', + valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' + }); + } - function validaCodigoUnidad() { - return new Promise(function(resolve, reject) { - focaAbmVehiculoService - .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) - .then(function(res) { - //Valida si existe numero de unidad - var existe = res.data.filter(function(vehiculo) { - return vehiculo.codigo === $scope.vehiculo.codigo && - vehiculo.id !== $scope.vehiculo.id; - }); + $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { + focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + + cisterna.id + ' ' + cisterna.codigo + ' ?').then( + function(data) { + if (data) { + focaAbmVehiculoService.deleteCisterna(idx); + focaAbmVehiculoService + .getCisternas($routeParams.idVehiculo) + .then(function(res) { + $scope.cisternas = res; + }); + } + } + ); + }; - if (existe.length) { - reject(existe); - } else { - resolve(); - } + function validaCodigoUnidad() { + return new Promise(function(resolve, reject) { + focaAbmVehiculoService + .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) + .then(function(res) { + //Valida si existe numero de unidad + var existe = res.data.filter(function(vehiculo) { + return vehiculo.codigo === $scope.vehiculo.codigo && + vehiculo.id !== $scope.vehiculo.id; }); - }); - } - function validaTotalCargas() { - var total = 0; - $scope.cisternas.forEach(function(cisterna) { - if (!cisterna.desactivado) { - total += parseInt(cisterna.capacidad); - } - }); - return $scope.vehiculo.capacidad == total; + if (existe.length) { + reject(existe); + } else { + resolve(); + } + }); + }); + } + + function validaTotalCargas() { + var total = 0; + $scope.cisternas.forEach(function(cisterna) { + if (!cisterna.desactivado) { + total += parseInt(cisterna.capacidad); + } + }); + return $scope.vehiculo.capacidad == total; + } + function guardarCisternas() { + var cisternas = $scope.cisternas.map(function(cisterna) { + return { + id: cisterna.id, + capacidad: parseFloat(cisterna.capacidad), + codigo: cisterna.codigo, + idUnidadMedida: cisterna.idUnidadMedida, + idVehiculo: $routeParams.idVehiculo, + desactivado: cisterna.desactivado + }; + }); + + return focaAbmVehiculoService.guardarCisternas(cisternas); + } + + $scope.guardarCisterna = function() { + 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; } - function guardarCisternas() { - var cisternas = $scope.cisternas.map(function(cisterna) { - return { - id: cisterna.id, - capacidad: parseFloat(cisterna.capacidad), - codigo: cisterna.codigo, - idUnidadMedida: cisterna.idUnidadMedida, - idVehiculo: $routeParams.idVehiculo, - desactivado: cisterna.desactivado - }; + $scope.editando = false; + validaCodigo() + .then(function() { + saveCisterna(); + }, function(err) { + focaModalService.alert(err); }); - - return focaAbmVehiculoService.guardarCisternas(cisternas); - } + }; - $scope.guardarCisterna = function() { - 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; - } - $scope.editando = false; - validaCodigo() - .then(function() { - saveCisterna(); - }, function(err) { - focaModalService.alert(err); - }); - }; + function saveCisterna () { + $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); + delete $scope.cisterna.vehiculo; + var auxCisternas = $scope.cisternas; + auxCisternas.push($scope.cisterna); + guardarCisternas(auxCisternas) + .then(function(result) { + $scope.cisternas = result.data; + $scope.cisterna = {}; + }) + .catch(function (err) { + console.log('Err: ', err); + }); + } - function saveCisterna () { - $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); - delete $scope.cisterna.vehiculo; - var auxCisternas = $scope.cisternas; - auxCisternas.push($scope.cisterna); - guardarCisternas(auxCisternas) - .then(function(result) { - $scope.cisternas = result.data; - $scope.cisterna = {}; - }) - .catch(function (err) { - console.log('Err: ', err); + if ($routeParams.idx !== -1) { + $scope.cisterna = [$routeParams.idx]; + focaAbmVehiculoService + .getCisternas($routeParams.idVehiculo) + .then(function(res) { + $scope.cisterna = res[$routeParams.idx]; }); - } + } - if ($routeParams.idx !== -1) { - $scope.cisterna = [$routeParams.idx]; + function validaCodigo() { + return new Promise(function(resolve, reject) { focaAbmVehiculoService .getCisternas($routeParams.idVehiculo) .then(function(res) { - $scope.cisterna = res[$routeParams.idx]; - }); - } - - 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(); + 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(); + }); + }); } - ]); + } + ]); -- 1.9.1