Commit 3ba4ed978d6010ffbf0487ba0636a059e5df377c
1 parent
cbb9be6d59
Exists in
master
and in
1 other branch
Cambio para enfocar primer item de la lista.
Showing
1 changed file
with
1 additions
and
1 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalCotizacion') | 1 | angular.module('focaModalCotizacion') |
2 | .controller('focaModalCotizacionController', | 2 | .controller('focaModalCotizacionController', |
3 | [ | 3 | [ |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'focaModalCotizacionService', | 7 | 'focaModalCotizacionService', |
8 | 'idMoneda', | 8 | 'idMoneda', |
9 | function($filter, $scope, $uibModalInstance, focaModalCotizacionService, idMoneda) { | 9 | function($filter, $scope, $uibModalInstance, focaModalCotizacionService, idMoneda) { |
10 | focaModalCotizacionService.getCotizaciones(idMoneda).then( | 10 | focaModalCotizacionService.getCotizaciones(idMoneda).then( |
11 | function(res) {console.log(res.data); | 11 | function(res) {console.log(res.data); |
12 | $scope.moneda = res.data[0]; | 12 | $scope.moneda = res.data[0]; |
13 | $scope.cotizacion = res.data[0].cotizaciones; | 13 | $scope.cotizacion = res.data[0].cotizaciones; |
14 | $scope.search(); | 14 | $scope.search(); |
15 | } | 15 | } |
16 | ); | 16 | ); |
17 | 17 | ||
18 | // pagination | 18 | // pagination |
19 | $scope.numPerPage = 10; | 19 | $scope.numPerPage = 10; |
20 | $scope.currentPage = 1; | 20 | $scope.currentPage = 1; |
21 | $scope.filteredCotizacion = []; | 21 | $scope.filteredCotizacion = []; |
22 | $scope.currentPageCotizacion = []; | 22 | $scope.currentPageCotizacion = []; |
23 | $scope.selectedCotizacion = -1; | 23 | $scope.selectedCotizacion = 0; |
24 | 24 | ||
25 | //METODOS | 25 | //METODOS |
26 | $scope.search = function() { | 26 | $scope.search = function() { |
27 | $scope.filteredCotizacion = $filter('filter')( | 27 | $scope.filteredCotizacion = $filter('filter')( |
28 | $scope.cotizacion, | 28 | $scope.cotizacion, |
29 | {$: $scope.filters} | 29 | {$: $scope.filters} |
30 | ); | 30 | ); |
31 | 31 | ||
32 | $scope.lastPage = Math.ceil( | 32 | $scope.lastPage = Math.ceil( |
33 | $scope.filteredCotizacion.length / $scope.numPerPage | 33 | $scope.filteredCotizacion.length / $scope.numPerPage |
34 | ); | 34 | ); |
35 | 35 | ||
36 | $scope.resetPage(); | 36 | $scope.resetPage(); |
37 | }; | 37 | }; |
38 | 38 | ||
39 | $scope.resetPage = function() { | 39 | $scope.resetPage = function() { |
40 | $scope.currentPage = 1; | 40 | $scope.currentPage = 1; |
41 | $scope.selectPage(1); | 41 | $scope.selectPage(1); |
42 | }; | 42 | }; |
43 | 43 | ||
44 | $scope.selectPage = function(page) { | 44 | $scope.selectPage = function(page) { |
45 | var start = (page - 1) * $scope.numPerPage; | 45 | var start = (page - 1) * $scope.numPerPage; |
46 | var end = start + $scope.numPerPage; | 46 | var end = start + $scope.numPerPage; |
47 | $scope.paginas = []; | 47 | $scope.paginas = []; |
48 | $scope.paginas = calcularPages(page); | 48 | $scope.paginas = calcularPages(page); |
49 | $scope.currentPageCotizacion = | 49 | $scope.currentPageCotizacion = |
50 | $scope.filteredCotizacion.slice(start, end); | 50 | $scope.filteredCotizacion.slice(start, end); |
51 | $scope.currentPage = page; | 51 | $scope.currentPage = page; |
52 | }; | 52 | }; |
53 | 53 | ||
54 | $scope.select = function(cotizacion) { | 54 | $scope.select = function(cotizacion) { |
55 | $uibModalInstance.close(cotizacion); | 55 | $uibModalInstance.close(cotizacion); |
56 | }; | 56 | }; |
57 | 57 | ||
58 | $scope.cancel = function() { | 58 | $scope.cancel = function() { |
59 | $uibModalInstance.dismiss('cancel'); | 59 | $uibModalInstance.dismiss('cancel'); |
60 | }; | 60 | }; |
61 | 61 | ||
62 | $scope.busquedaDown = function(key) { | 62 | $scope.busquedaDown = function(key) { |
63 | if (key === 40) { | 63 | if (key === 40) { |
64 | primera(key); | 64 | primera(key); |
65 | } | 65 | } |
66 | }; | 66 | }; |
67 | 67 | ||
68 | $scope.busquedaPress = function(key) { | 68 | $scope.busquedaPress = function(key) { |
69 | if (key === 13) { | 69 | if (key === 13) { |
70 | primera(key); | 70 | primera(key); |
71 | } | 71 | } |
72 | }; | 72 | }; |
73 | 73 | ||
74 | $scope.itemProducto = function(key) { | 74 | $scope.itemProducto = function(key) { |
75 | if (key === 38) { | 75 | if (key === 38) { |
76 | anterior(key); | 76 | anterior(key); |
77 | } | 77 | } |
78 | 78 | ||
79 | if (key === 40) { | 79 | if (key === 40) { |
80 | siguiente(key); | 80 | siguiente(key); |
81 | } | 81 | } |
82 | 82 | ||
83 | if (key === 37) { | 83 | if (key === 37) { |
84 | retrocederPagina(); | 84 | retrocederPagina(); |
85 | } | 85 | } |
86 | 86 | ||
87 | if (key === 39) { | 87 | if (key === 39) { |
88 | avanzarPagina(); | 88 | avanzarPagina(); |
89 | } | 89 | } |
90 | }; | 90 | }; |
91 | 91 | ||
92 | function calcularPages(paginaActual) { | 92 | function calcularPages(paginaActual) { |
93 | var paginas = []; | 93 | var paginas = []; |
94 | paginas.push(paginaActual); | 94 | paginas.push(paginaActual); |
95 | 95 | ||
96 | if (paginaActual - 1 > 1) { | 96 | if (paginaActual - 1 > 1) { |
97 | 97 | ||
98 | paginas.unshift(paginaActual - 1); | 98 | paginas.unshift(paginaActual - 1); |
99 | if (paginaActual - 2 > 1) { | 99 | if (paginaActual - 2 > 1) { |
100 | paginas.unshift(paginaActual - 2); | 100 | paginas.unshift(paginaActual - 2); |
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
104 | if (paginaActual + 1 < $scope.lastPage) { | 104 | if (paginaActual + 1 < $scope.lastPage) { |
105 | paginas.push(paginaActual + 1); | 105 | paginas.push(paginaActual + 1); |
106 | if (paginaActual + 2 < $scope.lastPage) { | 106 | if (paginaActual + 2 < $scope.lastPage) { |
107 | paginas.push(paginaActual + 2); | 107 | paginas.push(paginaActual + 2); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | if (paginaActual !== 1) { | 111 | if (paginaActual !== 1) { |
112 | paginas.unshift(1); | 112 | paginas.unshift(1); |
113 | } | 113 | } |
114 | 114 | ||
115 | if (paginaActual !== $scope.lastPage) { | 115 | if (paginaActual !== $scope.lastPage) { |
116 | paginas.push($scope.lastPage); | 116 | paginas.push($scope.lastPage); |
117 | } | 117 | } |
118 | 118 | ||
119 | return paginas; | 119 | return paginas; |
120 | } | 120 | } |
121 | 121 | ||
122 | function primera() { | 122 | function primera() { |
123 | $scope.selectedCotizacion = 0; | 123 | $scope.selectedCotizacion = 0; |
124 | } | 124 | } |
125 | 125 | ||
126 | function anterior() { | 126 | function anterior() { |
127 | if ($scope.selectedCotizacion === 0 && $scope.currentPage > 1) { | 127 | if ($scope.selectedCotizacion === 0 && $scope.currentPage > 1) { |
128 | retrocederPagina(); | 128 | retrocederPagina(); |
129 | } else { | 129 | } else { |
130 | $scope.selectedCotizacion--; | 130 | $scope.selectedCotizacion--; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | function siguiente() { | 134 | function siguiente() { |
135 | if ($scope.selectedCotizacion < | 135 | if ($scope.selectedCotizacion < |
136 | $scope.currentPageCotizacion.length - 1 ) { | 136 | $scope.currentPageCotizacion.length - 1 ) { |
137 | $scope.selectedCotizacion++; | 137 | $scope.selectedCotizacion++; |
138 | } else { | 138 | } else { |
139 | avanzarPagina(); | 139 | avanzarPagina(); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | function retrocederPagina() { | 143 | function retrocederPagina() { |
144 | if ($scope.currentPage > 1) { | 144 | if ($scope.currentPage > 1) { |
145 | $scope.selectPage($scope.currentPage - 1); | 145 | $scope.selectPage($scope.currentPage - 1); |
146 | $scope.selectedCotizacion = $scope.numPerPage - 1; | 146 | $scope.selectedCotizacion = $scope.numPerPage - 1; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | function avanzarPagina() { | 150 | function avanzarPagina() { |
151 | if ($scope.currentPage < $scope.lastPage) { | 151 | if ($scope.currentPage < $scope.lastPage) { |
152 | $scope.selectPage($scope.currentPage + 1); | 152 | $scope.selectPage($scope.currentPage + 1); |
153 | $scope.selectedCotizacion = 0; | 153 | $scope.selectedCotizacion = 0; |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } | 156 | } |
157 | ] | 157 | ] |
158 | ); | 158 | ); |
159 | 159 |