Commit b460273d5619846b618fcba5b6483d75561a4b99
1 parent
12c9450c7b
Exists in
master
paginacion
Showing
1 changed file
with
92 additions
and
5 deletions
Show diff stats
src/js/controller.js
... | ... | @@ -19,7 +19,7 @@ angular.module('focaModalVendedores') |
19 | 19 | $scope.currentPage = 1; |
20 | 20 | $scope.filteredVendedores = []; |
21 | 21 | $scope.currentPageVendedores = []; |
22 | - $scope.selectVendedores = 0; | |
22 | + $scope.selectVendedores = -1; | |
23 | 23 | |
24 | 24 | $scope.search = function () { |
25 | 25 | $scope.filteredVendedores = $filter('filter')($scope.vendedores, { $: $scope.filters }); |
... | ... | @@ -37,17 +37,104 @@ angular.module('focaModalVendedores') |
37 | 37 | $scope.currentPageVendedores = $scope.filteredVendedores.slice(start, end); |
38 | 38 | } |
39 | 39 | |
40 | - $scope.select = function(vendedor) { | |
40 | + $scope.select = function (vendedor) { | |
41 | 41 | $uibModalInstance.close(vendedor); |
42 | 42 | } |
43 | 43 | |
44 | - $scope.cancel = function() { | |
44 | + $scope.cancel = function () { | |
45 | 45 | $uibModalInstance.dismiss('cancel'); |
46 | 46 | } |
47 | + $scope.busquedaDown = function (key) { | |
48 | + if (key === 40) { | |
49 | + primera(key); | |
50 | + } | |
51 | + }; | |
47 | 52 | |
48 | - $scope.enter = function(key) { | |
53 | + $scope.busquedaPress = function (key) { | |
49 | 54 | if (key === 13) { |
50 | - console.table($scope.currentPageVendedores); | |
55 | + primera(key); | |
56 | + } | |
57 | + }; | |
58 | + | |
59 | + $scope.itemProducto = function (key) { | |
60 | + if (key === 38) { | |
61 | + anterior(key); | |
62 | + } | |
63 | + | |
64 | + if (key === 40) { | |
65 | + siguiente(key); | |
66 | + } | |
67 | + | |
68 | + if (key === 37) { | |
69 | + retrocederPagina(); | |
70 | + } | |
71 | + | |
72 | + if (key === 39) { | |
73 | + avanzarPagina(); | |
74 | + } | |
75 | + }; | |
76 | + | |
77 | + function calcularPages(paginaActual) { | |
78 | + var paginas = []; | |
79 | + paginas.push(paginaActual); | |
80 | + | |
81 | + if (paginaActual - 1 > 1) { | |
82 | + | |
83 | + paginas.unshift(paginaActual - 1); | |
84 | + if (paginaActual - 2 > 1) { | |
85 | + paginas.unshift(paginaActual - 2); | |
86 | + } | |
87 | + } | |
88 | + | |
89 | + if (paginaActual + 1 < $scope.lastPage) { | |
90 | + paginas.push(paginaActual + 1); | |
91 | + if (paginaActual + 2 < $scope.lastPage) { | |
92 | + paginas.push(paginaActual + 2); | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + if (paginaActual !== 1) { | |
97 | + paginas.unshift(1); | |
98 | + } | |
99 | + | |
100 | + if (paginaActual !== $scope.lastPage) { | |
101 | + paginas.push($scope.lastPage); | |
102 | + } | |
103 | + | |
104 | + return paginas; | |
105 | + } | |
106 | + | |
107 | + function primera() { | |
108 | + $scope.selectedProducto = 0; | |
109 | + } | |
110 | + | |
111 | + function anterior() { | |
112 | + if ($scope.selectedProducto === 0 && $scope.currentPage > 1) { | |
113 | + retrocederPagina(); | |
114 | + } else { | |
115 | + $scope.selectedProducto--; | |
116 | + } | |
117 | + } | |
118 | + | |
119 | + function siguiente() { | |
120 | + if ($scope.selectedProducto < $scope.currentPageProductos.length - 1) { | |
121 | + $scope.selectedProducto++; | |
122 | + } else { | |
123 | + avanzarPagina(); | |
124 | + } | |
125 | + } | |
126 | + | |
127 | + function retrocederPagina() { | |
128 | + if ($scope.currentPage > 1) { | |
129 | + $scope.selectPage($scope.currentPage - 1); | |
130 | + $scope.selectedProducto = $scope.numPerPage - 1; | |
131 | + } | |
132 | + } | |
133 | + | |
134 | + function avanzarPagina() { | |
135 | + if ($scope.currentPage < $scope.lastPage) { | |
136 | + $scope.selectPage($scope.currentPage + 1); | |
137 | + $scope.selectedProducto = 0; | |
51 | 138 | } |
52 | 139 | } |
53 | 140 | }] |