Commit 8272c62be876244bb6f3950840801b6702165bc8
1 parent
e99531c001
Exists in
master
and in
1 other branch
Codigo indentado.
Showing
1 changed file
with
46 additions
and
46 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 | '$timeout', | 4 | '$timeout', |
5 | '$filter', | 5 | '$filter', |
6 | '$scope', | 6 | '$scope', |
7 | '$uibModal', | 7 | '$uibModal', |
8 | '$uibModalInstance', | 8 | '$uibModalInstance', |
9 | 'focaModalService', | 9 | 'focaModalService', |
10 | 'focaModalPrecioCondicionService', | 10 | 'focaModalPrecioCondicionService', |
11 | 'idListaPrecio', | 11 | 'idListaPrecio', |
12 | function( | 12 | function ( |
13 | $timeout, $filter, $scope, $uibModal, $uibModalInstance, | 13 | $timeout, $filter, $scope, $uibModal, $uibModalInstance, |
14 | focaModalService, focaModalPrecioCondicionService, idListaPrecio | 14 | focaModalService, focaModalPrecioCondicionService, idListaPrecio |
15 | ) { | 15 | ) { |
16 | 16 | ||
17 | $scope.filters = ''; | 17 | $scope.filters = ''; |
18 | $scope.ingreso = false; | 18 | $scope.ingreso = false; |
19 | $scope.plazosNuevos = []; | 19 | $scope.plazosNuevos = []; |
20 | $scope.plazoACargar = | 20 | $scope.plazoACargar = |
21 | { | 21 | { |
22 | item: 1 | 22 | item: 1 |
23 | }; | 23 | }; |
24 | // pagination | 24 | // pagination |
25 | $scope.numPerPage = 10; | 25 | $scope.numPerPage = 10; |
26 | $scope.currentPage = 1; | 26 | $scope.currentPage = 1; |
27 | $scope.filteredPrecioCondicion = []; | 27 | $scope.filteredPrecioCondicion = []; |
28 | $scope.currentPagePrecioCondicion = []; | 28 | $scope.currentPagePrecioCondicion = []; |
29 | $scope.selectedPrecioCondicion = -1; | 29 | $scope.selectedPrecioCondicion = -1; |
30 | 30 | ||
31 | var funcionGet = idListaPrecio ? 'getPreciosCondicionesByIdListaPrecio' : | 31 | var funcionGet = idListaPrecio ? 'getPreciosCondicionesByIdListaPrecio' : |
32 | 'getPreciosCondiciones'; | 32 | 'getPreciosCondiciones'; |
33 | 33 | ||
34 | focaModalPrecioCondicionService | 34 | focaModalPrecioCondicionService |
35 | [funcionGet](idListaPrecio) | 35 | [funcionGet](idListaPrecio) |
36 | .then(function(res) { | 36 | .then(function (res) { |
37 | for (var i = 0; i < res.data.length; i++) { | 37 | for (var i = 0; i < res.data.length; i++) { |
38 | var plazosTemp = ''; | 38 | var plazosTemp = ''; |
39 | res.data[i].plazoPago.sort(function(a, b) { | 39 | res.data[i].plazoPago.sort(function (a, b) { |
40 | return a.dias - b.dias; | 40 | return a.dias - b.dias; |
41 | }); | 41 | }); |
42 | for (var j = 0; j < res.data[i].plazoPago.length; j++) { | 42 | for (var j = 0; j < res.data[i].plazoPago.length; j++) { |
43 | if (j + 1 === res.data[i].plazoPago.length) { | 43 | if (j + 1 === res.data[i].plazoPago.length) { |
44 | plazosTemp += res.data[i].plazoPago[j].dias; | 44 | plazosTemp += res.data[i].plazoPago[j].dias; |
45 | } else { | 45 | } else { |
46 | plazosTemp += res.data[i].plazoPago[j].dias + ', '; | 46 | plazosTemp += res.data[i].plazoPago[j].dias + ', '; |
47 | } | 47 | } |
48 | } | 48 | } |
49 | res.data[i].plazos = plazosTemp.trim(); | 49 | res.data[i].plazos = plazosTemp.trim(); |
50 | } | 50 | } |
51 | $scope.precioCondicion = res.data; | 51 | $scope.precioCondicion = res.data; |
52 | $scope.search(); | 52 | $scope.search(); |
53 | }); | 53 | }); |
54 | 54 | ||
55 | //METODOS | 55 | //METODOS |
56 | $scope.agregarPlazo = function(key) { | 56 | $scope.agregarPlazo = function (key) { |
57 | if(key === 13) { | 57 | if (key === 13) { |
58 | if(!$scope.plazoACargar.dias) { | 58 | if (!$scope.plazoACargar.dias) { |
59 | focaModalService.alert('Ingrese cantidad de días'); | 59 | focaModalService.alert('Ingrese cantidad de días'); |
60 | return; | 60 | return; |
61 | } | 61 | } |
62 | var tieneEseDia = $scope.plazosNuevos.filter(function(a) { | 62 | var tieneEseDia = $scope.plazosNuevos.filter(function (a) { |
63 | return a.dias === $scope.plazoACargar.dias; | 63 | return a.dias === $scope.plazoACargar.dias; |
64 | }); | 64 | }); |
65 | if(tieneEseDia.length > 0) { | 65 | if (tieneEseDia.length > 0) { |
66 | focaModalService.alert('Ya ha ingresado un plazo con esos días'); | 66 | focaModalService.alert('Ya ha ingresado un plazo con esos días'); |
67 | return; | 67 | return; |
68 | } | 68 | } |
69 | $scope.plazosNuevos.push($scope.plazoACargar); | 69 | $scope.plazosNuevos.push($scope.plazoACargar); |
70 | $scope.plazoACargar = | 70 | $scope.plazoACargar = |
71 | { | 71 | { |
72 | item: $scope.plazosNuevos.length + 1 | 72 | item: $scope.plazosNuevos.length + 1 |
73 | }; | 73 | }; |
74 | } | 74 | } |
75 | }; | 75 | }; |
76 | 76 | ||
77 | $scope.volver = function() { | 77 | $scope.volver = function () { |
78 | $scope.ingreso = false; | 78 | $scope.ingreso = false; |
79 | $scope.plazosNuevos = []; | 79 | $scope.plazosNuevos = []; |
80 | $scope.plazoACargar = | 80 | $scope.plazoACargar = |
81 | { | 81 | { |
82 | item: $scope.plazosNuevos.length + 1 | 82 | item: $scope.plazosNuevos.length + 1 |
83 | }; | 83 | }; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | $scope.quitarPlazo = function(key) { | 86 | $scope.quitarPlazo = function (key) { |
87 | $scope.plazosNuevos.splice(key, 1); | 87 | $scope.plazosNuevos.splice(key, 1); |
88 | $scope.plazoACargar = | 88 | $scope.plazoACargar = |
89 | { | 89 | { |
90 | item: $scope.plazosNuevos.length + 1 | 90 | item: $scope.plazosNuevos.length + 1 |
91 | }; | 91 | }; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | $scope.search = function(pressed) { | 94 | $scope.search = function (pressed) { |
95 | $scope.filteredPrecioCondicion = $filter('filter')( | 95 | $scope.filteredPrecioCondicion = $filter('filter')( |
96 | $scope.precioCondicion, | 96 | $scope.precioCondicion, |
97 | {$: $scope.filters} | 97 | { $: $scope.filters } |
98 | ); | 98 | ); |
99 | 99 | ||
100 | if(pressed) { | 100 | if (pressed) { |
101 | if($scope.filteredPrecioCondicion.length === 0) { | 101 | if ($scope.filteredPrecioCondicion.length === 0) { |
102 | $timeout(function() { | 102 | $timeout(function () { |
103 | angular.element('#search')[0].focus(); | 103 | angular.element('#search')[0].focus(); |
104 | $scope.filters = ''; | 104 | $scope.filters = ''; |
105 | }); | 105 | }); |
106 | }else { | 106 | } else { |
107 | primera(); | 107 | primera(); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | $scope.lastPage = Math.ceil( | 111 | $scope.lastPage = Math.ceil( |
112 | $scope.filteredPrecioCondicion.length / $scope.numPerPage | 112 | $scope.filteredPrecioCondicion.length / $scope.numPerPage |
113 | ); | 113 | ); |
114 | 114 | ||
115 | $scope.resetPage(); | 115 | $scope.resetPage(); |
116 | }; | 116 | }; |
117 | 117 | ||
118 | $scope.resetPage = function() { | 118 | $scope.resetPage = function () { |
119 | $scope.currentPage = 1; | 119 | $scope.currentPage = 1; |
120 | $scope.selectPage(1); | 120 | $scope.selectPage(1); |
121 | }; | 121 | }; |
122 | 122 | ||
123 | $scope.selectPage = function(page) { | 123 | $scope.selectPage = function (page) { |
124 | var start = (page - 1) * $scope.numPerPage; | 124 | var start = (page - 1) * $scope.numPerPage; |
125 | var end = start + $scope.numPerPage; | 125 | var end = start + $scope.numPerPage; |
126 | $scope.paginas = []; | 126 | $scope.paginas = []; |
127 | $scope.paginas = calcularPages(page); | 127 | $scope.paginas = calcularPages(page); |
128 | $scope.currentPagePrecioCondicion = | 128 | $scope.currentPagePrecioCondicion = |
129 | $scope.filteredPrecioCondicion.slice(start, end); | 129 | $scope.filteredPrecioCondicion.slice(start, end); |
130 | $scope.currentPage = page; | 130 | $scope.currentPage = page; |
131 | }; | 131 | }; |
132 | 132 | ||
133 | $scope.select = function(precioCondicion) { | 133 | $scope.select = function (precioCondicion) { |
134 | $uibModalInstance.close(precioCondicion); | 134 | $uibModalInstance.close(precioCondicion); |
135 | }; | 135 | }; |
136 | 136 | ||
137 | $scope.cancel = function() { | 137 | $scope.cancel = function () { |
138 | $uibModalInstance.dismiss('cancel'); | 138 | $uibModalInstance.dismiss('cancel'); |
139 | }; | 139 | }; |
140 | 140 | ||
141 | $scope.busquedaDown = function(key) { | 141 | $scope.busquedaDown = function (key) { |
142 | if (key === 40) { | 142 | if (key === 40) { |
143 | primera(key); | 143 | primera(key); |
144 | } | 144 | } |
145 | }; | 145 | }; |
146 | 146 | ||
147 | $scope.busquedaPress = function(key) { | 147 | $scope.busquedaPress = function (key) { |
148 | if (key === 13) { | 148 | if (key === 13) { |
149 | $scope.search(true); | 149 | $scope.search(true); |
150 | } | 150 | } |
151 | }; | 151 | }; |
152 | 152 | ||
153 | $scope.itemProducto = function(key) { | 153 | $scope.itemProducto = function (key) { |
154 | if (key === 38) { | 154 | if (key === 38) { |
155 | anterior(key); | 155 | anterior(key); |
156 | } | 156 | } |
157 | 157 | ||
158 | if (key === 40) { | 158 | if (key === 40) { |
159 | siguiente(key); | 159 | siguiente(key); |
160 | } | 160 | } |
161 | 161 | ||
162 | if (key === 37) { | 162 | if (key === 37) { |
163 | retrocederPagina(); | 163 | retrocederPagina(); |
164 | } | 164 | } |
165 | 165 | ||
166 | if (key === 39) { | 166 | if (key === 39) { |
167 | avanzarPagina(); | 167 | avanzarPagina(); |
168 | } | 168 | } |
169 | }; | 169 | }; |
170 | 170 | ||
171 | $scope.verListaPrecio = function(id) { | 171 | $scope.verListaPrecio = function (id) { |
172 | $uibModal.open( | 172 | $uibModal.open( |
173 | { | 173 | { |
174 | ariaLabelledBy: 'Busqueda de Productos', | 174 | ariaLabelledBy: 'Busqueda de Productos', |
175 | templateUrl: 'modal-busqueda-productos.html', | 175 | templateUrl: 'modal-busqueda-productos.html', |
176 | controller: 'modalBusquedaProductosCtrl', | 176 | controller: 'modalBusquedaProductosCtrl', |
177 | resolve: { | 177 | resolve: { |
178 | parametroProducto: { | 178 | parametroProducto: { |
179 | idLista: id, | 179 | idLista: id, |
180 | cotizacion: 1, | 180 | cotizacion: 1, |
181 | simbolo: '$', | 181 | simbolo: '$', |
182 | soloMostrar: true | 182 | soloMostrar: true |
183 | } | 183 | } |
184 | }, | 184 | }, |
185 | size: 'md' | 185 | size: 'md' |
186 | } | 186 | } |
187 | ); | 187 | ); |
188 | }; | 188 | }; |
189 | 189 | ||
190 | function calcularPages(paginaActual) { | 190 | function calcularPages(paginaActual) { |
191 | var paginas = []; | 191 | var paginas = []; |
192 | paginas.push(paginaActual); | 192 | paginas.push(paginaActual); |
193 | 193 | ||
194 | if (paginaActual - 1 > 1) { | 194 | if (paginaActual - 1 > 1) { |
195 | 195 | ||
196 | paginas.unshift(paginaActual - 1); | 196 | paginas.unshift(paginaActual - 1); |
197 | if (paginaActual - 2 > 1) { | 197 | if (paginaActual - 2 > 1) { |
198 | paginas.unshift(paginaActual - 2); | 198 | paginas.unshift(paginaActual - 2); |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | if (paginaActual + 1 < $scope.lastPage) { | 202 | if (paginaActual + 1 < $scope.lastPage) { |
203 | paginas.push(paginaActual + 1); | 203 | paginas.push(paginaActual + 1); |
204 | if (paginaActual + 2 < $scope.lastPage) { | 204 | if (paginaActual + 2 < $scope.lastPage) { |
205 | paginas.push(paginaActual + 2); | 205 | paginas.push(paginaActual + 2); |
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | if (paginaActual !== 1) { | 209 | if (paginaActual !== 1) { |
210 | paginas.unshift(1); | 210 | paginas.unshift(1); |
211 | } | 211 | } |
212 | 212 | ||
213 | if (paginaActual !== $scope.lastPage) { | 213 | if (paginaActual !== $scope.lastPage) { |
214 | paginas.push($scope.lastPage); | 214 | paginas.push($scope.lastPage); |
215 | } | 215 | } |
216 | 216 | ||
217 | return paginas; | 217 | return paginas; |
218 | } | 218 | } |
219 | 219 | ||
220 | function primera() { | 220 | function primera() { |
221 | $scope.selectedPrecioCondicion = 0; | 221 | $scope.selectedPrecioCondicion = 0; |
222 | } | 222 | } |
223 | 223 | ||
224 | function anterior() { | 224 | function anterior() { |
225 | if ($scope.selectedPrecioCondicion === 0 && $scope.currentPage > 1) { | 225 | if ($scope.selectedPrecioCondicion === 0 && $scope.currentPage > 1) { |
226 | retrocederPagina(); | 226 | retrocederPagina(); |
227 | } else { | 227 | } else { |
228 | $scope.selectedPrecioCondicion--; | 228 | $scope.selectedPrecioCondicion--; |
229 | } | 229 | } |
230 | } | 230 | } |
231 | 231 | ||
232 | function siguiente() { | 232 | function siguiente() { |
233 | if ($scope.selectedPrecioCondicion < | 233 | if ($scope.selectedPrecioCondicion < |
234 | $scope.currentPagePrecioCondicion.length ) { | 234 | $scope.currentPagePrecioCondicion.length) { |
235 | $scope.selectedPrecioCondicion++; | 235 | $scope.selectedPrecioCondicion++; |
236 | } else { | 236 | } else { |
237 | avanzarPagina(); | 237 | avanzarPagina(); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
241 | function retrocederPagina() { | 241 | function retrocederPagina() { |
242 | if ($scope.currentPage > 1) { | 242 | if ($scope.currentPage > 1) { |
243 | $scope.selectPage($scope.currentPage - 1); | 243 | $scope.selectPage($scope.currentPage - 1); |
244 | $scope.selectedPrecioCondicion = $scope.numPerPage - 1; | 244 | $scope.selectedPrecioCondicion = $scope.numPerPage - 1; |
245 | } | 245 | } |
246 | } | 246 | } |
247 | 247 | ||
248 | function avanzarPagina() { | 248 | function avanzarPagina() { |
249 | if ($scope.currentPage < $scope.lastPage) { | 249 | if ($scope.currentPage < $scope.lastPage) { |
250 | $scope.selectPage($scope.currentPage + 1); | 250 | $scope.selectPage($scope.currentPage + 1); |
251 | $scope.selectedPrecioCondicion = 0; | 251 | $scope.selectedPrecioCondicion = 0; |
252 | } | 252 | } |
253 | } | 253 | } |
254 | } | 254 | } |
255 | ] | 255 | ] |
256 | ); | 256 | ); |
257 | 257 |