diff --git a/src/js/controller.js b/src/js/controller.js index 623391a..a17a0fb 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,5 +1,5 @@ angular.module('focaModalPrecioCondicion') - .controller('focaModalPrecioCondicionController', + .controller('focaModalPrecioCondicionController', [ '$timeout', '$filter', @@ -9,18 +9,18 @@ angular.module('focaModalPrecioCondicion') 'focaModalService', 'focaModalPrecioCondicionService', 'idListaPrecio', - function( + function ( $timeout, $filter, $scope, $uibModal, $uibModalInstance, focaModalService, focaModalPrecioCondicionService, idListaPrecio ) { - + $scope.filters = ''; $scope.ingreso = false; $scope.plazosNuevos = []; $scope.plazoACargar = - { - item: 1 - }; + { + item: 1 + }; // pagination $scope.numPerPage = 10; $scope.currentPage = 1; @@ -30,13 +30,13 @@ angular.module('focaModalPrecioCondicion') var funcionGet = idListaPrecio ? 'getPreciosCondicionesByIdListaPrecio' : 'getPreciosCondiciones'; - + focaModalPrecioCondicionService - [funcionGet](idListaPrecio) - .then(function(res) { + [funcionGet](idListaPrecio) + .then(function (res) { for (var i = 0; i < res.data.length; i++) { var plazosTemp = ''; - res.data[i].plazoPago.sort(function(a, b) { + res.data[i].plazoPago.sort(function (a, b) { return a.dias - b.dias; }); for (var j = 0; j < res.data[i].plazoPago.length; j++) { @@ -53,57 +53,57 @@ angular.module('focaModalPrecioCondicion') }); //METODOS - $scope.agregarPlazo = function(key) { - if(key === 13) { - if(!$scope.plazoACargar.dias) { + $scope.agregarPlazo = function (key) { + if (key === 13) { + if (!$scope.plazoACargar.dias) { focaModalService.alert('Ingrese cantidad de días'); return; } - var tieneEseDia = $scope.plazosNuevos.filter(function(a) { + var tieneEseDia = $scope.plazosNuevos.filter(function (a) { return a.dias === $scope.plazoACargar.dias; }); - if(tieneEseDia.length > 0) { + if (tieneEseDia.length > 0) { focaModalService.alert('Ya ha ingresado un plazo con esos días'); return; } $scope.plazosNuevos.push($scope.plazoACargar); $scope.plazoACargar = - { - item: $scope.plazosNuevos.length + 1 - }; + { + item: $scope.plazosNuevos.length + 1 + }; } }; - $scope.volver = function() { + $scope.volver = function () { $scope.ingreso = false; $scope.plazosNuevos = []; $scope.plazoACargar = - { - item: $scope.plazosNuevos.length + 1 - }; + { + item: $scope.plazosNuevos.length + 1 + }; }; - - $scope.quitarPlazo = function(key) { + + $scope.quitarPlazo = function (key) { $scope.plazosNuevos.splice(key, 1); $scope.plazoACargar = - { - item: $scope.plazosNuevos.length + 1 - }; + { + item: $scope.plazosNuevos.length + 1 + }; }; - $scope.search = function(pressed) { + $scope.search = function (pressed) { $scope.filteredPrecioCondicion = $filter('filter')( - $scope.precioCondicion, - {$: $scope.filters} + $scope.precioCondicion, + { $: $scope.filters } ); - if(pressed) { - if($scope.filteredPrecioCondicion.length === 0) { - $timeout(function() { + if (pressed) { + if ($scope.filteredPrecioCondicion.length === 0) { + $timeout(function () { angular.element('#search')[0].focus(); $scope.filters = ''; }); - }else { + } else { primera(); } } @@ -115,12 +115,12 @@ angular.module('focaModalPrecioCondicion') $scope.resetPage(); }; - $scope.resetPage = function() { + $scope.resetPage = function () { $scope.currentPage = 1; $scope.selectPage(1); }; - $scope.selectPage = function(page) { + $scope.selectPage = function (page) { var start = (page - 1) * $scope.numPerPage; var end = start + $scope.numPerPage; $scope.paginas = []; @@ -130,27 +130,27 @@ angular.module('focaModalPrecioCondicion') $scope.currentPage = page; }; - $scope.select = function(precioCondicion) { + $scope.select = function (precioCondicion) { $uibModalInstance.close(precioCondicion); }; - $scope.cancel = function() { + $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); }; - $scope.busquedaDown = function(key) { + $scope.busquedaDown = function (key) { if (key === 40) { primera(key); } }; - $scope.busquedaPress = function(key) { + $scope.busquedaPress = function (key) { if (key === 13) { $scope.search(true); } }; - $scope.itemProducto = function(key) { + $scope.itemProducto = function (key) { if (key === 38) { anterior(key); } @@ -167,8 +167,8 @@ angular.module('focaModalPrecioCondicion') avanzarPagina(); } }; - - $scope.verListaPrecio = function(id) { + + $scope.verListaPrecio = function (id) { $uibModal.open( { ariaLabelledBy: 'Busqueda de Productos', @@ -192,7 +192,7 @@ angular.module('focaModalPrecioCondicion') paginas.push(paginaActual); if (paginaActual - 1 > 1) { - + paginas.unshift(paginaActual - 1); if (paginaActual - 2 > 1) { paginas.unshift(paginaActual - 2); @@ -231,10 +231,10 @@ angular.module('focaModalPrecioCondicion') function siguiente() { if ($scope.selectedPrecioCondicion < - $scope.currentPagePrecioCondicion.length ) { + $scope.currentPagePrecioCondicion.length) { $scope.selectedPrecioCondicion++; } else { - avanzarPagina(); + avanzarPagina(); } }