Commit 9e8d1adda767a35ff0c3f805940f7138d62f397d
1 parent
3965c72666
Exists in
master
identación
Showing
1 changed file
with
5 additions
and
3 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalPrecioCondicion') | 1 | angular.module('focaModalPrecioCondicion') |
2 | .controller('focaModalPrecioCondicionController', | 2 | .controller('focaModalPrecioCondicionController', |
3 | [ | 3 | [ |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'focaModalService', | 7 | 'focaModalService', |
8 | 'focaModalPrecioCondicionService', | 8 | 'focaModalPrecioCondicionService', |
9 | function($filter, $scope, $uibModalInstance, focaModalService, | 9 | function( |
10 | focaModalPrecioCondicionService) { | 10 | $filter, $scope, $uibModalInstance, |
11 | focaModalService, focaModalPrecioCondicionService | ||
12 | ) { | ||
11 | 13 | ||
12 | focaModalPrecioCondicionService.getPreciosCondicionesPlazosPagos().then( | 14 | focaModalPrecioCondicionService.getPreciosCondicionesPlazosPagos().then( |
13 | function(res) { | 15 | function(res) { |
14 | for(var i = 0; i < res.data.length; i++) { | 16 | for(var i = 0; i < res.data.length; i++) { |
15 | var plazosTemp = ''; | 17 | var plazosTemp = ''; |
16 | for(var j = 0; j < res.data[i].plazoPago.length; j++) { | 18 | for(var j = 0; j < res.data[i].plazoPago.length; j++) { |
17 | plazosTemp += res.data[i].plazoPago[j].dias + ' '; | 19 | plazosTemp += res.data[i].plazoPago[j].dias + ' '; |
18 | } | 20 | } |
19 | res.data[i].plazos = plazosTemp.trim(); | 21 | res.data[i].plazos = plazosTemp.trim(); |
20 | } | 22 | } |
21 | $scope.precioCondicion = res.data; | 23 | $scope.precioCondicion = res.data; |
22 | $scope.search(); | 24 | $scope.search(); |
23 | } | 25 | } |
24 | ); | 26 | ); |
25 | $scope.ingreso = false; | 27 | $scope.ingreso = false; |
26 | $scope.plazosNuevos =[]; | 28 | $scope.plazosNuevos = []; |
27 | $scope.plazoACargar = | 29 | $scope.plazoACargar = |
28 | { | 30 | { |
29 | item: 1 | 31 | item: 1 |
30 | }; | 32 | }; |
31 | // pagination | 33 | // pagination |
32 | $scope.numPerPage = 10; | 34 | $scope.numPerPage = 10; |
33 | $scope.currentPage = 1; | 35 | $scope.currentPage = 1; |
34 | $scope.filteredPrecioCondicion = []; | 36 | $scope.filteredPrecioCondicion = []; |
35 | $scope.currentPagePrecioCondicion = []; | 37 | $scope.currentPagePrecioCondicion = []; |
36 | $scope.selectedPrecioCondicion = -1; | 38 | $scope.selectedPrecioCondicion = -1; |
37 | 39 | ||
38 | //METODOS | 40 | //METODOS |
39 | 41 | ||
40 | $scope.agregarPlazo = function(key) { | 42 | $scope.agregarPlazo = function(key) { |
41 | if(key === 13) { | 43 | if(key === 13) { |
42 | if(!$scope.plazoACargar.dias) { | 44 | if(!$scope.plazoACargar.dias) { |
43 | focaModalService.alert('Ingrese cantidad de días'); | 45 | focaModalService.alert('Ingrese cantidad de días'); |
44 | return; | 46 | return; |
45 | } | 47 | } |
46 | var tieneEseDia = $scope.plazosNuevos.filter(function(a) { | 48 | var tieneEseDia = $scope.plazosNuevos.filter(function(a) { |
47 | return a.dias === $scope.plazoACargar.dias; | 49 | return a.dias === $scope.plazoACargar.dias; |
48 | }); | 50 | }); |
49 | if(tieneEseDia.length > 0) { | 51 | if(tieneEseDia.length > 0) { |
50 | focaModalService.alert('Ya ha ingresado un plazo con esos días'); | 52 | focaModalService.alert('Ya ha ingresado un plazo con esos días'); |
51 | return; | 53 | return; |
52 | } | 54 | } |
53 | $scope.plazosNuevos.push($scope.plazoACargar); | 55 | $scope.plazosNuevos.push($scope.plazoACargar); |
54 | $scope.plazoACargar = | 56 | $scope.plazoACargar = |
55 | { | 57 | { |
56 | item: $scope.plazosNuevos.length + 1 | 58 | item: $scope.plazosNuevos.length + 1 |
57 | }; | 59 | }; |
58 | } | 60 | } |
59 | }; | 61 | }; |
60 | 62 | ||
61 | $scope.volver = function() { | 63 | $scope.volver = function() { |
62 | $scope.ingreso = false; | 64 | $scope.ingreso = false; |
63 | $scope.plazosNuevos = []; | 65 | $scope.plazosNuevos = []; |
64 | $scope.plazoACargar = | 66 | $scope.plazoACargar = |
65 | { | 67 | { |
66 | item: $scope.plazosNuevos.length + 1 | 68 | item: $scope.plazosNuevos.length + 1 |
67 | }; | 69 | }; |
68 | }; | 70 | }; |
69 | 71 | ||
70 | $scope.quitarPlazo = function(key) { | 72 | $scope.quitarPlazo = function(key) { |
71 | $scope.plazosNuevos.splice(key, 1); | 73 | $scope.plazosNuevos.splice(key, 1); |
72 | $scope.plazoACargar = | 74 | $scope.plazoACargar = |
73 | { | 75 | { |
74 | item: $scope.plazosNuevos.length + 1 | 76 | item: $scope.plazosNuevos.length + 1 |
75 | }; | 77 | }; |
76 | }; | 78 | }; |
77 | 79 | ||
78 | $scope.search = function() { | 80 | $scope.search = function() { |
79 | $scope.filteredPrecioCondicion = $filter('filter')( | 81 | $scope.filteredPrecioCondicion = $filter('filter')( |
80 | $scope.precioCondicion, | 82 | $scope.precioCondicion, |
81 | {$: $scope.filters} | 83 | {$: $scope.filters} |
82 | ); | 84 | ); |
83 | 85 | ||
84 | $scope.lastPage = Math.ceil( | 86 | $scope.lastPage = Math.ceil( |
85 | $scope.filteredPrecioCondicion.length / $scope.numPerPage | 87 | $scope.filteredPrecioCondicion.length / $scope.numPerPage |
86 | ); | 88 | ); |
87 | 89 | ||
88 | $scope.resetPage(); | 90 | $scope.resetPage(); |
89 | }; | 91 | }; |
90 | 92 | ||
91 | $scope.resetPage = function() { | 93 | $scope.resetPage = function() { |
92 | $scope.currentPage = 1; | 94 | $scope.currentPage = 1; |
93 | $scope.selectPage(1); | 95 | $scope.selectPage(1); |
94 | }; | 96 | }; |
95 | 97 | ||
96 | $scope.selectPage = function(page) { | 98 | $scope.selectPage = function(page) { |
97 | var start = (page - 1) * $scope.numPerPage; | 99 | var start = (page - 1) * $scope.numPerPage; |
98 | var end = start + $scope.numPerPage; | 100 | var end = start + $scope.numPerPage; |
99 | $scope.paginas = []; | 101 | $scope.paginas = []; |
100 | $scope.paginas = calcularPages(page); | 102 | $scope.paginas = calcularPages(page); |
101 | $scope.currentPagePrecioCondicion = | 103 | $scope.currentPagePrecioCondicion = |
102 | $scope.filteredPrecioCondicion.slice(start, end); | 104 | $scope.filteredPrecioCondicion.slice(start, end); |
103 | $scope.currentPage = page; | 105 | $scope.currentPage = page; |
104 | }; | 106 | }; |
105 | 107 | ||
106 | $scope.select = function(precioCondicion) { | 108 | $scope.select = function(precioCondicion) { |
107 | $uibModalInstance.close(precioCondicion); | 109 | $uibModalInstance.close(precioCondicion); |
108 | }; | 110 | }; |
109 | 111 | ||
110 | $scope.cancel = function() { | 112 | $scope.cancel = function() { |
111 | $uibModalInstance.dismiss('cancel'); | 113 | $uibModalInstance.dismiss('cancel'); |
112 | }; | 114 | }; |
113 | 115 | ||
114 | $scope.busquedaDown = function(key) { | 116 | $scope.busquedaDown = function(key) { |
115 | if (key === 40) { | 117 | if (key === 40) { |
116 | primera(key); | 118 | primera(key); |
117 | } | 119 | } |
118 | }; | 120 | }; |
119 | 121 | ||
120 | $scope.busquedaPress = function(key) { | 122 | $scope.busquedaPress = function(key) { |
121 | if (key === 13) { | 123 | if (key === 13) { |
122 | primera(key); | 124 | primera(key); |
123 | } | 125 | } |
124 | }; | 126 | }; |
125 | 127 | ||
126 | $scope.itemProducto = function(key) { | 128 | $scope.itemProducto = function(key) { |
127 | if (key === 38) { | 129 | if (key === 38) { |
128 | anterior(key); | 130 | anterior(key); |
129 | } | 131 | } |
130 | 132 | ||
131 | if (key === 40) { | 133 | if (key === 40) { |
132 | siguiente(key); | 134 | siguiente(key); |
133 | } | 135 | } |
134 | 136 | ||
135 | if (key === 37) { | 137 | if (key === 37) { |
136 | retrocederPagina(); | 138 | retrocederPagina(); |
137 | } | 139 | } |
138 | 140 | ||
139 | if (key === 39) { | 141 | if (key === 39) { |
140 | avanzarPagina(); | 142 | avanzarPagina(); |
141 | } | 143 | } |
142 | }; | 144 | }; |
143 | 145 | ||
144 | function calcularPages(paginaActual) { | 146 | function calcularPages(paginaActual) { |
145 | var paginas = []; | 147 | var paginas = []; |
146 | paginas.push(paginaActual); | 148 | paginas.push(paginaActual); |
147 | 149 | ||
148 | if (paginaActual - 1 > 1) { | 150 | if (paginaActual - 1 > 1) { |
149 | 151 | ||
150 | paginas.unshift(paginaActual - 1); | 152 | paginas.unshift(paginaActual - 1); |
151 | if (paginaActual - 2 > 1) { | 153 | if (paginaActual - 2 > 1) { |
152 | paginas.unshift(paginaActual - 2); | 154 | paginas.unshift(paginaActual - 2); |
153 | } | 155 | } |
154 | } | 156 | } |
155 | 157 | ||
156 | if (paginaActual + 1 < $scope.lastPage) { | 158 | if (paginaActual + 1 < $scope.lastPage) { |
157 | paginas.push(paginaActual + 1); | 159 | paginas.push(paginaActual + 1); |
158 | if (paginaActual + 2 < $scope.lastPage) { | 160 | if (paginaActual + 2 < $scope.lastPage) { |
159 | paginas.push(paginaActual + 2); | 161 | paginas.push(paginaActual + 2); |
160 | } | 162 | } |
161 | } | 163 | } |
162 | 164 | ||
163 | if (paginaActual !== 1) { | 165 | if (paginaActual !== 1) { |
164 | paginas.unshift(1); | 166 | paginas.unshift(1); |
165 | } | 167 | } |
166 | 168 | ||
167 | if (paginaActual !== $scope.lastPage) { | 169 | if (paginaActual !== $scope.lastPage) { |
168 | paginas.push($scope.lastPage); | 170 | paginas.push($scope.lastPage); |
169 | } | 171 | } |
170 | 172 | ||
171 | return paginas; | 173 | return paginas; |
172 | } | 174 | } |
173 | 175 | ||
174 | function primera() { | 176 | function primera() { |
175 | $scope.selectedPrecioCondicion = 0; | 177 | $scope.selectedPrecioCondicion = 0; |
176 | } | 178 | } |
177 | 179 | ||
178 | function anterior() { | 180 | function anterior() { |
179 | if ($scope.selectedPrecioCondicion === 0 && $scope.currentPage > 1) { | 181 | if ($scope.selectedPrecioCondicion === 0 && $scope.currentPage > 1) { |
180 | retrocederPagina(); | 182 | retrocederPagina(); |
181 | } else { | 183 | } else { |
182 | $scope.selectedPrecioCondicion--; | 184 | $scope.selectedPrecioCondicion--; |
183 | } | 185 | } |
184 | } | 186 | } |
185 | 187 | ||
186 | function siguiente() { | 188 | function siguiente() { |
187 | if ($scope.selectedPrecioCondicion < | 189 | if ($scope.selectedPrecioCondicion < |
188 | $scope.currentPagePrecioCondicion.length - 1 ) { | 190 | $scope.currentPagePrecioCondicion.length - 1 ) { |
189 | $scope.selectedPrecioCondicion++; | 191 | $scope.selectedPrecioCondicion++; |
190 | } else { | 192 | } else { |
191 | avanzarPagina(); | 193 | avanzarPagina(); |
192 | } | 194 | } |
193 | } | 195 | } |
194 | 196 | ||
195 | function retrocederPagina() { | 197 | function retrocederPagina() { |
196 | if ($scope.currentPage > 1) { | 198 | if ($scope.currentPage > 1) { |
197 | $scope.selectPage($scope.currentPage - 1); | 199 | $scope.selectPage($scope.currentPage - 1); |
198 | $scope.selectedPrecioCondicion = $scope.numPerPage - 1; | 200 | $scope.selectedPrecioCondicion = $scope.numPerPage - 1; |
199 | } | 201 | } |
200 | } | 202 | } |
201 | 203 | ||
202 | function avanzarPagina() { | 204 | function avanzarPagina() { |
203 | if ($scope.currentPage < $scope.lastPage) { | 205 | if ($scope.currentPage < $scope.lastPage) { |
204 | $scope.selectPage($scope.currentPage + 1); | 206 | $scope.selectPage($scope.currentPage + 1); |
205 | $scope.selectedPrecioCondicion = 0; | 207 | $scope.selectedPrecioCondicion = 0; |
206 | } | 208 | } |
207 | } | 209 | } |
208 | } | 210 | } |
209 | ] | 211 | ] |
210 | ); | 212 | ); |
211 | 213 |