Commit 926a6adb4b6f6ee486eaffe48abf9ca24cc5a4fb
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master See merge request !11
Showing
1 changed file
Show diff stats
src/js/controller.js
1 | angular.module('focaBusquedaCliente') | 1 | angular.module('focaBusquedaCliente') |
2 | .controller('focaBusquedaClienteModalController', [ | 2 | .controller('focaBusquedaClienteModalController', [ |
3 | '$uibModalInstance', 'focaBusquedaClienteService', '$scope', '$filter', | 3 | '$uibModalInstance', 'focaBusquedaClienteService', '$scope', '$filter', |
4 | '$uibModal', 'focaModalService', '$timeout', | 4 | '$uibModal', 'focaModalService', '$timeout', |
5 | function($uibModalInstance, focaBusquedaClienteService, $scope, $filter, | 5 | function($uibModalInstance, focaBusquedaClienteService, $scope, $filter, |
6 | $uibModal, focaModalService, $timeout) { | 6 | $uibModal, focaModalService, $timeout) { |
7 | 7 | ||
8 | $scope.filters = ''; | 8 | $scope.filters = ''; |
9 | $scope.primerBusqueda = false; | 9 | $scope.primerBusqueda = false; |
10 | // pagination | 10 | // pagination |
11 | $scope.numPerPage = 10; | 11 | $scope.numPerPage = 10; |
12 | $scope.currentPage = 1; | 12 | $scope.currentPage = 1; |
13 | $scope.filteredClientes = []; | 13 | $scope.filteredClientes = []; |
14 | $scope.currentPageClientes = []; | 14 | $scope.currentPageClientes = []; |
15 | $scope.selectedClientes = -1; | 15 | $scope.selectedClientes = -1; |
16 | $scope.ingreso = false; | 16 | $scope.ingreso = false; |
17 | $scope.regexCuit = new RegExp(/\b(20|23|24|27|30|33|34)(\D)?[0-9]{8}(\D)?[0-9]/g); | 17 | $scope.regexCuit = new RegExp(/\b(20|23|24|27|30|33|34)(\D)?[0-9]{8}(\D)?[0-9]/g); |
18 | $scope.focused = 1; | 18 | $scope.focused = 1; |
19 | 19 | ||
20 | $scope.cliente = { | 20 | $scope.cliente = { |
21 | COD: 0, | 21 | COD: 0, |
22 | ES_MAY: true, | 22 | ES_MAY: true, |
23 | provincia: { | 23 | provincia: { |
24 | NOMBRE: '' | 24 | NOMBRE: '' |
25 | }, | 25 | }, |
26 | localidad: { | 26 | localidad: { |
27 | NOMBRE: '' | 27 | NOMBRE: '' |
28 | }, | 28 | }, |
29 | iva: { | 29 | iva: { |
30 | NOMBRE: '' | 30 | NOMBRE: '' |
31 | }, | 31 | }, |
32 | actividad: { | 32 | actividad: { |
33 | NOM: '' | 33 | NOM: '' |
34 | }, | 34 | }, |
35 | zona: { | 35 | zona: { |
36 | NOM: '' | 36 | NOM: '' |
37 | }, | 37 | }, |
38 | tipoFactura: { | 38 | tipoFactura: { |
39 | NOMBRE: '' | 39 | NOMBRE: '' |
40 | }, | 40 | }, |
41 | tipoComprobante: { | 41 | tipoComprobante: { |
42 | NOMBRE: '' | 42 | NOMBRE: '' |
43 | }, | 43 | }, |
44 | formaPago: { | 44 | formaPago: { |
45 | NOMBRE: '' | 45 | NOMBRE: '' |
46 | } | 46 | } |
47 | }; | 47 | }; |
48 | 48 | ||
49 | $scope.busquedaPress = function(key) { | 49 | $scope.busquedaPress = function(key) { |
50 | if (key === 13) { | 50 | if (key === 13) { |
51 | $scope.searchLoading = true; | 51 | $scope.searchLoading = true; |
52 | focaBusquedaClienteService.obtenerClientesPorNombreOCuit($scope.filters).then( | 52 | focaBusquedaClienteService.obtenerClientesPorNombreOCuit($scope.filters).then( |
53 | function(res) { | 53 | function(res) { |
54 | $scope.primerBusqueda = true; | 54 | $scope.primerBusqueda = true; |
55 | $scope.clientes = res.data; | 55 | $scope.clientes = res.data; |
56 | $scope.search(true); | 56 | $scope.search(true); |
57 | primera(); | 57 | primera(); |
58 | $scope.searchLoading = false; | 58 | $scope.searchLoading = false; |
59 | }); | 59 | }); |
60 | } | 60 | } |
61 | }; | 61 | }; |
62 | 62 | ||
63 | $scope.search = function (pressed) { | 63 | $scope.search = function (pressed) { |
64 | if($scope.primerBusqueda) { | 64 | if($scope.primerBusqueda) { |
65 | $scope.filteredClientes = $filter('filter')( | 65 | $scope.filteredClientes = $filter('filter')( |
66 | $scope.clientes, {$: $scope.filters} | 66 | $scope.clientes, {$: $scope.filters} |
67 | ); | 67 | ); |
68 | 68 | ||
69 | if(pressed && $scope.filteredClientes.length === 0){ | 69 | if(pressed && $scope.filteredClientes.length === 0){ |
70 | $timeout(function() { | 70 | $timeout(function() { |
71 | angular.element('#search')[0].focus(); | 71 | angular.element('#search')[0].focus(); |
72 | $scope.filters = ''; | 72 | $scope.filters = ''; |
73 | }); | 73 | }); |
74 | } | 74 | } |
75 | 75 | ||
76 | $scope.lastPage = Math.ceil( | 76 | $scope.lastPage = Math.ceil( |
77 | $scope.filteredClientes.length / $scope.numPerPage | 77 | $scope.filteredClientes.length / $scope.numPerPage |
78 | ); | 78 | ); |
79 | 79 | ||
80 | $scope.resetPage(); | 80 | $scope.resetPage(); |
81 | } | 81 | } |
82 | }; | 82 | }; |
83 | 83 | ||
84 | $scope.resetPage = function () { | 84 | $scope.resetPage = function () { |
85 | $scope.currentPage = 1; | 85 | $scope.currentPage = 1; |
86 | $scope.selectPage(1); | 86 | $scope.selectPage(1); |
87 | }; | 87 | }; |
88 | 88 | ||
89 | $scope.selectPage = function (page) { | 89 | $scope.selectPage = function (page) { |
90 | var start = (page - 1) * $scope.numPerPage; | 90 | var start = (page - 1) * $scope.numPerPage; |
91 | var end = start + $scope.numPerPage; | 91 | var end = start + $scope.numPerPage; |
92 | $scope.paginas = []; | 92 | $scope.paginas = []; |
93 | $scope.paginas = calcularPages(page); | 93 | $scope.paginas = calcularPages(page); |
94 | $scope.currentPageClientes = $scope.filteredClientes.slice(start, end); | 94 | $scope.currentPageClientes = $scope.filteredClientes.slice(start, end); |
95 | $scope.currentPage = page; | 95 | $scope.currentPage = page; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | $scope.select = function(cliente, esNuevo = false) { | 98 | $scope.select = function(cliente, esNuevo = false) { |
99 | cliente.esNuevo = esNuevo; | 99 | cliente.esNuevo = esNuevo; |
100 | $uibModalInstance.close(cliente); | 100 | $uibModalInstance.close(cliente); |
101 | }; | 101 | }; |
102 | 102 | ||
103 | $scope.cancel = function() { | 103 | $scope.cancel = function() { |
104 | if($scope.ingreso) { | 104 | if($scope.ingreso) { |
105 | $scope.ingreso = false; | 105 | $scope.ingreso = false; |
106 | }else { | 106 | }else { |
107 | $uibModalInstance.dismiss('cancel'); | 107 | $uibModalInstance.dismiss('cancel'); |
108 | } | 108 | } |
109 | }; | 109 | }; |
110 | 110 | ||
111 | $scope.busquedaDown = function(key) { | 111 | $scope.busquedaDown = function(key) { |
112 | if (key === 40) { | 112 | if (key === 40) { |
113 | primera(key); | 113 | primera(key); |
114 | } | 114 | } |
115 | }; | 115 | }; |
116 | 116 | ||
117 | $scope.itemCliente = function(key) { | 117 | $scope.itemCliente = function(key) { |
118 | if (key === 38) { | 118 | if (key === 38) { |
119 | anterior(key); | 119 | anterior(key); |
120 | } | 120 | } |
121 | 121 | ||
122 | if (key === 40) { | 122 | if (key === 40) { |
123 | siguiente(key); | 123 | siguiente(key); |
124 | } | 124 | } |
125 | 125 | ||
126 | if (key === 37) { | 126 | if (key === 37) { |
127 | retrocederPagina(); | 127 | retrocederPagina(); |
128 | } | 128 | } |
129 | 129 | ||
130 | if (key === 39) { | 130 | if (key === 39) { |
131 | avanzarPagina(); | 131 | avanzarPagina(); |
132 | } | 132 | } |
133 | }; | 133 | }; |
134 | 134 | ||
135 | $scope.focus = function(val) { | 135 | $scope.focus = function(val) { |
136 | $scope.focused = val; | 136 | $scope.focused = val; |
137 | }; | 137 | }; |
138 | 138 | ||
139 | $scope.next = function(key) { | 139 | $scope.next = function(key) { |
140 | if (key === 13) $scope.focused++; | 140 | if (key === 13) $scope.focused++; |
141 | }; | 141 | }; |
142 | 142 | ||
143 | $scope.seleccionarProvincia = function(key) { | 143 | $scope.seleccionarProvincia = function(key) { |
144 | if(key === 13) { | 144 | if(key === 13) { |
145 | var modalInstance = $uibModal.open( | 145 | var modalInstance = $uibModal.open( |
146 | { | 146 | { |
147 | ariaLabelledBy: 'Búsqueda de provincias', | 147 | ariaLabelledBy: 'Búsqueda de provincias', |
148 | templateUrl: 'modal-provincias.html', | 148 | templateUrl: 'modal-provincias.html', |
149 | controller: 'focaModalProvinciaController', | 149 | controller: 'focaModalProvinciaController', |
150 | size: 'md', | 150 | size: 'md', |
151 | resolve: { | 151 | resolve: { |
152 | filters: function() { | 152 | filters: function() { |
153 | return $scope.cliente.provincia.NOMBRE; | 153 | return $scope.cliente.provincia.NOMBRE; |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } | 156 | } |
157 | ); | 157 | ); |
158 | modalInstance.result.then(function(provincia) { | 158 | modalInstance.result.then(function(provincia) { |
159 | $scope.cliente.provincia = provincia; | 159 | $scope.cliente.provincia = provincia; |
160 | $timeout(function() { | 160 | $timeout(function() { |
161 | $scope.focused = 5; | 161 | $scope.focused = 5; |
162 | }); | 162 | }); |
163 | }, function() { | 163 | }, function() { |
164 | //TODO: función llamada cuando cancela el modal | 164 | //TODO: función llamada cuando cancela el modal |
165 | }); | 165 | }); |
166 | } | 166 | } |
167 | }; | 167 | }; |
168 | $scope.seleccionarLocalidad = function(key) { | 168 | $scope.seleccionarLocalidad = function(key) { |
169 | if($scope.cliente.provincia.ID === undefined) { | 169 | if($scope.cliente.provincia.ID === undefined) { |
170 | //TODO: Poner modal alert de foca | 170 | focaModalService.alert('Seleccione una provincia'); |
171 | alert('Seleccione una provincia'); | ||
172 | return; | 171 | return; |
173 | } | 172 | } |
174 | if(key === 13) { | 173 | if(key === 13) { |
175 | var modalInstance = $uibModal.open( | 174 | var modalInstance = $uibModal.open( |
176 | { | 175 | { |
177 | ariaLabelledBy: 'Búsqueda de localidades', | 176 | ariaLabelledBy: 'Búsqueda de localidades', |
178 | templateUrl: 'modal-localidades.html', | 177 | templateUrl: 'modal-localidades.html', |
179 | controller: 'focaModalLocalidadController', | 178 | controller: 'focaModalLocalidadController', |
180 | size: 'md', | 179 | size: 'md', |
181 | resolve: { | 180 | resolve: { |
182 | filters: { | 181 | filters: { |
183 | idProvincia: $scope.cliente.provincia.ID, | 182 | idProvincia: $scope.cliente.provincia.ID, |
184 | busqueda: $scope.cliente.localidad.nombre | 183 | busqueda: $scope.cliente.localidad.nombre |
185 | } | 184 | } |
186 | } | 185 | } |
187 | } | 186 | } |
188 | ); | 187 | ); |
189 | modalInstance.result.then(function(localidad) { | 188 | modalInstance.result.then(function(localidad) { |
190 | $scope.cliente.localidad = localidad; | 189 | $scope.cliente.localidad = localidad; |
191 | $timeout(function() { | 190 | $timeout(function() { |
192 | $scope.focused = 6; | 191 | $scope.focused = 6; |
193 | }); | 192 | }); |
194 | }, function() { | 193 | }, function() { |
195 | //TODO: función llamada cuando cancela el modal | 194 | //TODO: función llamada cuando cancela el modal |
196 | }); | 195 | }); |
197 | } | 196 | } |
198 | }; | 197 | }; |
199 | $scope.seleccionarIva = function(key) { | 198 | $scope.seleccionarIva = function(key) { |
200 | if(key === 13) { | 199 | if(key === 13) { |
201 | var query = '/iva'; | 200 | var query = '/iva'; |
202 | var columnas = { | 201 | var columnas = { |
203 | nombre: ['Código', 'Nombre'], | 202 | nombre: ['Código', 'Nombre'], |
204 | propiedad: ['ID', 'NOM',] | 203 | propiedad: ['ID', 'NOM',] |
205 | }; | 204 | }; |
206 | var titulo = 'Búsqueda de responsabilidad ante el IVA'; | 205 | var titulo = 'Búsqueda de responsabilidad ante el IVA'; |
207 | focaModalService.modal(columnas, query, titulo, 'md').then( | 206 | focaModalService.modal(columnas, query, titulo, 'md').then( |
208 | function(iva) { | 207 | function(iva) { |
209 | $scope.cliente.iva = iva; | 208 | $scope.cliente.iva = iva; |
210 | $timeout(function() { | 209 | $timeout(function() { |
211 | $scope.focused = 9; | 210 | $scope.focused = 9; |
212 | }); | 211 | }); |
213 | }, function() { | 212 | }, function() { |
214 | // funcion ejecutada cuando se cancela el modal | 213 | // funcion ejecutada cuando se cancela el modal |
215 | }); | 214 | }); |
216 | } | 215 | } |
217 | }; | 216 | }; |
218 | $scope.seleccionarActividad = function(key) { | 217 | $scope.seleccionarActividad = function(key) { |
219 | if(key === 13) { | 218 | if(key === 13) { |
220 | var query = '/actividad'; | 219 | var query = '/actividad'; |
221 | var columnas = { | 220 | var columnas = { |
222 | nombre: ['Código', 'Nombre'], | 221 | nombre: ['Código', 'Nombre'], |
223 | propiedad: ['ID', 'NOM',] | 222 | propiedad: ['ID', 'NOM',] |
224 | }; | 223 | }; |
225 | var titulo = 'Búsqueda de actividades'; | 224 | var titulo = 'Búsqueda de actividades'; |
226 | focaModalService.modal(columnas, query, titulo, 'md').then( | 225 | focaModalService.modal(columnas, query, titulo, 'md').then( |
227 | function(actividad) { | 226 | function(actividad) { |
228 | $scope.cliente.actividad = actividad; | 227 | $scope.cliente.actividad = actividad; |
229 | }, function() { | 228 | }, function() { |
230 | // funcion ejecutada cuando se cancela el modal | 229 | // funcion ejecutada cuando se cancela el modal |
231 | }); | 230 | }); |
232 | } | 231 | } |
233 | }; | 232 | }; |
234 | $scope.seleccionarZona = function(key) { | 233 | $scope.seleccionarZona = function(key) { |
235 | if(key === 13) { | 234 | if(key === 13) { |
236 | var query = '/zona'; | 235 | var query = '/zona'; |
237 | var columnas = { | 236 | var columnas = { |
238 | nombre: ['Código', 'Nombre'], | 237 | nombre: ['Código', 'Nombre'], |
239 | propiedad: ['ID', 'NOM',] | 238 | propiedad: ['ID', 'NOM',] |
240 | }; | 239 | }; |
241 | var titulo = 'Búsqueda de zonas'; | 240 | var titulo = 'Búsqueda de zonas'; |
242 | focaModalService.modal(columnas, query, titulo, 'md').then( | 241 | focaModalService.modal(columnas, query, titulo, 'md').then( |
243 | function(zona) { | 242 | function(zona) { |
244 | $scope.cliente.zona = zona; | 243 | $scope.cliente.zona = zona; |
245 | $timeout(function() { | 244 | $timeout(function() { |
246 | $scope.focused = 7; | 245 | $scope.focused = 7; |
247 | }); | 246 | }); |
248 | }, function() { | 247 | }, function() { |
249 | // funcion ejecutada cuando se cancela el modal | 248 | // funcion ejecutada cuando se cancela el modal |
250 | }); | 249 | }); |
251 | } | 250 | } |
252 | }; | 251 | }; |
253 | $scope.seleccionarTipoFactura = function(key) { | 252 | $scope.seleccionarTipoFactura = function(key) { |
254 | if(key === 13) { | 253 | if(key === 13) { |
255 | var query = '/tipo-factura'; | 254 | var query = '/tipo-factura'; |
256 | var columnas = { | 255 | var columnas = { |
257 | nombre: ['Código', 'Nombre'], | 256 | nombre: ['Código', 'Nombre'], |
258 | propiedad: ['ID', 'NOMBRE',] | 257 | propiedad: ['ID', 'NOMBRE',] |
259 | }; | 258 | }; |
260 | var titulo = 'Búsqueda de tipos de factura'; | 259 | var titulo = 'Búsqueda de tipos de factura'; |
261 | focaModalService.modal(columnas, query, titulo, 'md').then( | 260 | focaModalService.modal(columnas, query, titulo, 'md').then( |
262 | function(tipoFactura) { | 261 | function(tipoFactura) { |
263 | $scope.cliente.tipoFactura = tipoFactura; | 262 | $scope.cliente.tipoFactura = tipoFactura; |
264 | $timeout(function() { | 263 | $timeout(function() { |
265 | $scope.focused = 10; | 264 | $scope.focused = 10; |
266 | }); | 265 | }); |
267 | }, function() { | 266 | }, function() { |
268 | // funcion ejecutada cuando se cancela el modal | 267 | // funcion ejecutada cuando se cancela el modal |
269 | }); | 268 | }); |
270 | } | 269 | } |
271 | }; | 270 | }; |
272 | $scope.seleccionarTipoComprobante = function(key) { | 271 | $scope.seleccionarTipoComprobante = function(key) { |
273 | if(key === 13) { | 272 | if(key === 13) { |
274 | var query = '/tipo-comprobante'; | 273 | var query = '/tipo-comprobante'; |
275 | var columnas = { | 274 | var columnas = { |
276 | nombre: ['Código', 'Nombre'], | 275 | nombre: ['Código', 'Nombre'], |
277 | propiedad: ['ID', 'NOMBRE',] | 276 | propiedad: ['ID', 'NOMBRE',] |
278 | }; | 277 | }; |
279 | var titulo = 'Búsqueda de tipos de comprobante'; | 278 | var titulo = 'Búsqueda de tipos de comprobante'; |
280 | focaModalService.modal(columnas, query, titulo, 'md').then( | 279 | focaModalService.modal(columnas, query, titulo, 'md').then( |
281 | function(tipoComprobante) { | 280 | function(tipoComprobante) { |
282 | $scope.cliente.tipoComprobante = tipoComprobante; | 281 | $scope.cliente.tipoComprobante = tipoComprobante; |
283 | $timeout(function() { | 282 | $timeout(function() { |
284 | $scope.focused = 12; | 283 | $scope.focused = 12; |
285 | }); | 284 | }); |
286 | }, function() { | 285 | }, function() { |
287 | // funcion ejecutada cuando se cancela el modal | 286 | // funcion ejecutada cuando se cancela el modal |
288 | }); | 287 | }); |
289 | } | 288 | } |
290 | }; | 289 | }; |
291 | $scope.seleccionarFormaPago = function(key) { | 290 | $scope.seleccionarFormaPago = function(key) { |
292 | if(key === 13) { | 291 | if(key === 13) { |
293 | var query = '/forma-pago'; | 292 | var query = '/forma-pago'; |
294 | var columnas = { | 293 | var columnas = { |
295 | nombre: ['Código', 'Nombre'], | 294 | nombre: ['Código', 'Nombre'], |
296 | propiedad: ['ID', 'NOMBRE',] | 295 | propiedad: ['ID', 'NOMBRE',] |
297 | }; | 296 | }; |
298 | var titulo = 'Búsqueda de formas de pago'; | 297 | var titulo = 'Búsqueda de formas de pago'; |
299 | focaModalService.modal(columnas, query, titulo, 'md').then( | 298 | focaModalService.modal(columnas, query, titulo, 'md').then( |
300 | function(formaPago) { | 299 | function(formaPago) { |
301 | $scope.cliente.formaPago = formaPago; | 300 | $scope.cliente.formaPago = formaPago; |
302 | }, function() { | 301 | }, function() { |
303 | // funcion ejecutada cuando se cancela el modal | 302 | // funcion ejecutada cuando se cancela el modal |
304 | }); | 303 | }); |
305 | } | 304 | } |
306 | }; | 305 | }; |
307 | 306 | ||
308 | $scope.guardar = function() { | 307 | $scope.guardar = function() { |
309 | 308 | ||
310 | $scope.cliente.PCX = $scope.cliente.provincia.ID; | 309 | $scope.cliente.PCX = $scope.cliente.provincia.ID; |
311 | $scope.cliente.LOX = $scope.cliente.localidad.ID; | 310 | $scope.cliente.LOX = $scope.cliente.localidad.ID; |
312 | $scope.cliente.IVA = $scope.cliente.iva.ID; | 311 | $scope.cliente.IVA = $scope.cliente.iva.ID; |
313 | $scope.cliente.ACT = $scope.cliente.actividad.ID; | 312 | $scope.cliente.ACT = $scope.cliente.actividad.ID; |
314 | $scope.cliente.ZON = $scope.cliente.zona.ID; | 313 | $scope.cliente.ZON = $scope.cliente.zona.ID; |
315 | $scope.cliente.TIP = $scope.cliente.tipoFactura.ID; | 314 | $scope.cliente.TIP = $scope.cliente.tipoFactura.ID; |
316 | $scope.cliente.TCO = $scope.cliente.tipoComprobante.ID; | 315 | $scope.cliente.TCO = $scope.cliente.tipoComprobante.ID; |
317 | $scope.cliente.FPA = $scope.cliente.formaPago.ID; | 316 | $scope.cliente.FPA = $scope.cliente.formaPago.ID; |
318 | 317 | ||
319 | delete $scope.cliente.provincia; | 318 | delete $scope.cliente.provincia; |
320 | delete $scope.cliente.localidad; | 319 | delete $scope.cliente.localidad; |
321 | delete $scope.cliente.iva; | 320 | delete $scope.cliente.iva; |
322 | delete $scope.cliente.actividad; | 321 | delete $scope.cliente.actividad; |
323 | delete $scope.cliente.zona; | 322 | delete $scope.cliente.zona; |
324 | delete $scope.cliente.tipoFactura; | 323 | delete $scope.cliente.tipoFactura; |
325 | delete $scope.cliente.tipoComprobante; | 324 | delete $scope.cliente.tipoComprobante; |
326 | delete $scope.cliente.formaPago; | 325 | delete $scope.cliente.formaPago; |
327 | 326 | ||
328 | focaBusquedaClienteService.guardarCliente($scope.cliente).then(function(res) { | 327 | focaBusquedaClienteService.guardarCliente($scope.cliente).then(function(res) { |
329 | var cliente = { | 328 | var cliente = { |
330 | cod: res.data.COD, | 329 | cod: res.data.COD, |
331 | cuit: res.data.CUIT, | 330 | cuit: res.data.CUIT, |
332 | esNuevo: res.data.esNuevo, | 331 | esNuevo: res.data.esNuevo, |
333 | nom: res.data.NOM | 332 | nom: res.data.NOM |
334 | }; | 333 | }; |
335 | $scope.select(cliente, true); | 334 | $scope.select(cliente, true); |
336 | }); | 335 | }); |
337 | }; | 336 | }; |
338 | 337 | ||
339 | function calcularPages(paginaActual) { | 338 | function calcularPages(paginaActual) { |
340 | var paginas = []; | 339 | var paginas = []; |
341 | paginas.push(paginaActual); | 340 | paginas.push(paginaActual); |
342 | 341 | ||
343 | if (paginaActual - 1 > 1) { | 342 | if (paginaActual - 1 > 1) { |
344 | 343 | ||
345 | paginas.unshift(paginaActual - 1); | 344 | paginas.unshift(paginaActual - 1); |
346 | if (paginaActual - 2 > 1) { | 345 | if (paginaActual - 2 > 1) { |
347 | paginas.unshift(paginaActual - 2); | 346 | paginas.unshift(paginaActual - 2); |
348 | } | 347 | } |
349 | } | 348 | } |
350 | 349 | ||
351 | if (paginaActual + 1 < $scope.lastPage) { | 350 | if (paginaActual + 1 < $scope.lastPage) { |
352 | paginas.push(paginaActual + 1); | 351 | paginas.push(paginaActual + 1); |
353 | if (paginaActual + 2 < $scope.lastPage) { | 352 | if (paginaActual + 2 < $scope.lastPage) { |
354 | paginas.push(paginaActual + 2); | 353 | paginas.push(paginaActual + 2); |
355 | } | 354 | } |
356 | } | 355 | } |
357 | 356 | ||
358 | if (paginaActual !== 1) { | 357 | if (paginaActual !== 1) { |
359 | paginas.unshift(1); | 358 | paginas.unshift(1); |
360 | } | 359 | } |
361 | 360 | ||
362 | if (paginaActual !== $scope.lastPage) { | 361 | if (paginaActual !== $scope.lastPage) { |
363 | paginas.push($scope.lastPage); | 362 | paginas.push($scope.lastPage); |
364 | } | 363 | } |
365 | 364 | ||
366 | return paginas; | 365 | return paginas; |
367 | } | 366 | } |
368 | 367 | ||
369 | function primera() { | 368 | function primera() { |
370 | $scope.selectedClientes = 0; | 369 | $scope.selectedClientes = 0; |
371 | } | 370 | } |
372 | 371 | ||
373 | function anterior() { | 372 | function anterior() { |
374 | if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { | 373 | if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { |
375 | retrocederPagina(); | 374 | retrocederPagina(); |
376 | } else { | 375 | } else { |
377 | $scope.selectedClientes--; | 376 | $scope.selectedClientes--; |
378 | } | 377 | } |
379 | } | 378 | } |
380 | 379 | ||
381 | function siguiente() { | 380 | function siguiente() { |
382 | if ($scope.selectedClientes < $scope.currentPageClientes.length - 1 ) { | 381 | if ($scope.selectedClientes < $scope.currentPageClientes.length - 1 ) { |
383 | $scope.selectedClientes++; | 382 | $scope.selectedClientes++; |
384 | } else { | 383 | } else { |
385 | avanzarPagina(); | 384 | avanzarPagina(); |
386 | } | 385 | } |
387 | } | 386 | } |
388 | 387 | ||
389 | function retrocederPagina() { | 388 | function retrocederPagina() { |
390 | if ($scope.currentPage > 1) { | 389 | if ($scope.currentPage > 1) { |
391 | $scope.selectPage($scope.currentPage - 1); | 390 | $scope.selectPage($scope.currentPage - 1); |
392 | $scope.selectedClientes = $scope.numPerPage - 1; | 391 | $scope.selectedClientes = $scope.numPerPage - 1; |
393 | } | 392 | } |
394 | } | 393 | } |
395 | 394 | ||
396 | function avanzarPagina() { | 395 | function avanzarPagina() { |
397 | if ($scope.currentPage < $scope.lastPage) { | 396 | if ($scope.currentPage < $scope.lastPage) { |
398 | $scope.selectPage($scope.currentPage + 1); | 397 | $scope.selectPage($scope.currentPage + 1); |
399 | $scope.selectedClientes = 0; | 398 | $scope.selectedClientes = 0; |
400 | } | 399 | } |
401 | } | 400 | } |
402 | } | 401 | } |
403 | ]); | 402 | ]); |
404 | 403 |