Commit 2c9026f2d6381c3326ab92d6a36e1e56ab3cd0ad
1 parent
1f343e7653
Exists in
master
- Saqué lógica y propiedades innecesarias.
Showing
1 changed file
with
1 additions
and
7 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalNotaPedido') | 1 | angular.module('focaModalNotaPedido') |
2 | .controller('focaModalNotaPedidoController', | 2 | .controller('focaModalNotaPedidoController', |
3 | [ | 3 | [ |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'parametroNotaPedido', | ||
8 | 'focaModalNotaPedidoService', | 7 | 'focaModalNotaPedidoService', |
9 | function($filter, $scope, $uibModalInstance, parametroNotaPedido, | 8 | function($filter, $scope, $uibModalInstance, |
10 | focaModalNotaPedidoService | 9 | focaModalNotaPedidoService |
11 | ) { | 10 | ) { |
12 | 11 | ||
13 | $scope.simbolo = parametroNotaPedido.simbolo; | ||
14 | $scope.filters = ''; | 12 | $scope.filters = ''; |
15 | $scope.notasPedido = []; | 13 | $scope.notasPedido = []; |
16 | $scope.primerBusqueda = false; | 14 | $scope.primerBusqueda = false; |
17 | $scope.searchLoading = false; | 15 | $scope.searchLoading = false; |
18 | // pagination | 16 | // pagination |
19 | $scope.numPerPage = 10; | 17 | $scope.numPerPage = 10; |
20 | $scope.currentPage = 1; | 18 | $scope.currentPage = 1; |
21 | $scope.filteredNotasPedido = []; | 19 | $scope.filteredNotasPedido = []; |
22 | $scope.currentPageNotasPedido = []; | 20 | $scope.currentPageNotasPedido = []; |
23 | $scope.selectedNotaPedido = -1; | 21 | $scope.selectedNotaPedido = -1; |
24 | 22 | ||
25 | //METODOS | 23 | //METODOS |
26 | $scope.busquedaPress = function(key) { | 24 | $scope.busquedaPress = function(key) { |
27 | if (key === 13) { | 25 | if (key === 13) { |
28 | $scope.searchLoading = true; | 26 | $scope.searchLoading = true; |
29 | focaModalNotaPedidoService.getNotasPedido().then(llenarDatos); | 27 | focaModalNotaPedidoService.getNotasPedido().then(llenarDatos); |
30 | } | 28 | } |
31 | }; | 29 | }; |
32 | function llenarDatos(res) { | 30 | function llenarDatos(res) { |
33 | for(var i = 0; i < res.data.length; i++) { | ||
34 | res.data[i].precio = | ||
35 | res.data[i].precio / parametroNotaPedido.cotizacion; | ||
36 | } | ||
37 | $scope.searchLoading = false; | 31 | $scope.searchLoading = false; |
38 | $scope.primerBusqueda = true; | 32 | $scope.primerBusqueda = true; |
39 | $scope.notasPedido = res.data; | 33 | $scope.notasPedido = res.data; |
40 | $scope.search(); | 34 | $scope.search(); |
41 | primera(); | 35 | primera(); |
42 | } | 36 | } |
43 | $scope.search = function() { | 37 | $scope.search = function() { |
44 | if($scope.notasPedido.length > 0) { | 38 | if($scope.notasPedido.length > 0) { |
45 | $scope.filteredNotasPedido = $filter('filter')( | 39 | $scope.filteredNotasPedido = $filter('filter')( |
46 | $scope.notasPedido, | 40 | $scope.notasPedido, |
47 | {$: $scope.filters} | 41 | {$: $scope.filters} |
48 | ); | 42 | ); |
49 | 43 | ||
50 | $scope.lastPage = Math.ceil( | 44 | $scope.lastPage = Math.ceil( |
51 | $scope.filteredNotasPedido.length / $scope.numPerPage | 45 | $scope.filteredNotasPedido.length / $scope.numPerPage |
52 | ); | 46 | ); |
53 | 47 | ||
54 | $scope.resetPage(); | 48 | $scope.resetPage(); |
55 | } | 49 | } |
56 | }; | 50 | }; |
57 | 51 | ||
58 | $scope.resetPage = function() { | 52 | $scope.resetPage = function() { |
59 | $scope.currentPage = 1; | 53 | $scope.currentPage = 1; |
60 | $scope.selectPage(1); | 54 | $scope.selectPage(1); |
61 | }; | 55 | }; |
62 | 56 | ||
63 | $scope.selectPage = function(page) { | 57 | $scope.selectPage = function(page) { |
64 | var start = (page - 1) * $scope.numPerPage; | 58 | var start = (page - 1) * $scope.numPerPage; |
65 | var end = start + $scope.numPerPage; | 59 | var end = start + $scope.numPerPage; |
66 | $scope.paginas = []; | 60 | $scope.paginas = []; |
67 | $scope.paginas = calcularPages(page); | 61 | $scope.paginas = calcularPages(page); |
68 | $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end); | 62 | $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end); |
69 | $scope.currentPage = page; | 63 | $scope.currentPage = page; |
70 | }; | 64 | }; |
71 | 65 | ||
72 | $scope.select = function(notaPedido) { | 66 | $scope.select = function(notaPedido) { |
73 | $uibModalInstance.close(notaPedido); | 67 | $uibModalInstance.close(notaPedido); |
74 | }; | 68 | }; |
75 | 69 | ||
76 | $scope.cancel = function() { | 70 | $scope.cancel = function() { |
77 | $uibModalInstance.dismiss('cancel'); | 71 | $uibModalInstance.dismiss('cancel'); |
78 | }; | 72 | }; |
79 | 73 | ||
80 | $scope.busquedaDown = function(key) { | 74 | $scope.busquedaDown = function(key) { |
81 | if (key === 40) { | 75 | if (key === 40) { |
82 | primera(key); | 76 | primera(key); |
83 | } | 77 | } |
84 | }; | 78 | }; |
85 | 79 | ||
86 | $scope.itemNotaPedido = function(key) { | 80 | $scope.itemNotaPedido = function(key) { |
87 | if (key === 38) { | 81 | if (key === 38) { |
88 | anterior(key); | 82 | anterior(key); |
89 | } | 83 | } |
90 | 84 | ||
91 | if (key === 40) { | 85 | if (key === 40) { |
92 | siguiente(key); | 86 | siguiente(key); |
93 | } | 87 | } |
94 | 88 | ||
95 | if (key === 37) { | 89 | if (key === 37) { |
96 | retrocederPagina(); | 90 | retrocederPagina(); |
97 | } | 91 | } |
98 | 92 | ||
99 | if (key === 39) { | 93 | if (key === 39) { |
100 | avanzarPagina(); | 94 | avanzarPagina(); |
101 | } | 95 | } |
102 | }; | 96 | }; |
103 | 97 | ||
104 | function calcularPages(paginaActual) { | 98 | function calcularPages(paginaActual) { |
105 | var paginas = []; | 99 | var paginas = []; |
106 | paginas.push(paginaActual); | 100 | paginas.push(paginaActual); |
107 | 101 | ||
108 | if (paginaActual - 1 > 1) { | 102 | if (paginaActual - 1 > 1) { |
109 | 103 | ||
110 | paginas.unshift(paginaActual - 1); | 104 | paginas.unshift(paginaActual - 1); |
111 | if (paginaActual - 2 > 1) { | 105 | if (paginaActual - 2 > 1) { |
112 | paginas.unshift(paginaActual - 2); | 106 | paginas.unshift(paginaActual - 2); |
113 | } | 107 | } |
114 | } | 108 | } |
115 | 109 | ||
116 | if (paginaActual + 1 < $scope.lastPage) { | 110 | if (paginaActual + 1 < $scope.lastPage) { |
117 | paginas.push(paginaActual + 1); | 111 | paginas.push(paginaActual + 1); |
118 | if (paginaActual + 2 < $scope.lastPage) { | 112 | if (paginaActual + 2 < $scope.lastPage) { |
119 | paginas.push(paginaActual + 2); | 113 | paginas.push(paginaActual + 2); |
120 | } | 114 | } |
121 | } | 115 | } |
122 | 116 | ||
123 | if (paginaActual !== 1) { | 117 | if (paginaActual !== 1) { |
124 | paginas.unshift(1); | 118 | paginas.unshift(1); |
125 | } | 119 | } |
126 | 120 | ||
127 | if (paginaActual !== $scope.lastPage) { | 121 | if (paginaActual !== $scope.lastPage) { |
128 | paginas.push($scope.lastPage); | 122 | paginas.push($scope.lastPage); |
129 | } | 123 | } |
130 | 124 | ||
131 | return paginas; | 125 | return paginas; |
132 | } | 126 | } |
133 | 127 | ||
134 | function primera() { | 128 | function primera() { |
135 | $scope.selectedNotaPedido = 0; | 129 | $scope.selectedNotaPedido = 0; |
136 | } | 130 | } |
137 | 131 | ||
138 | function anterior() { | 132 | function anterior() { |
139 | if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) { | 133 | if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) { |
140 | retrocederPagina(); | 134 | retrocederPagina(); |
141 | } else { | 135 | } else { |
142 | $scope.selectedNotaPedido--; | 136 | $scope.selectedNotaPedido--; |
143 | } | 137 | } |
144 | } | 138 | } |
145 | 139 | ||
146 | function siguiente() { | 140 | function siguiente() { |
147 | if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) { | 141 | if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) { |
148 | $scope.selectedNotaPedido++; | 142 | $scope.selectedNotaPedido++; |
149 | } else { | 143 | } else { |
150 | avanzarPagina(); | 144 | avanzarPagina(); |
151 | } | 145 | } |
152 | } | 146 | } |
153 | 147 | ||
154 | function retrocederPagina() { | 148 | function retrocederPagina() { |
155 | if ($scope.currentPage > 1) { | 149 | if ($scope.currentPage > 1) { |
156 | $scope.selectPage($scope.currentPage - 1); | 150 | $scope.selectPage($scope.currentPage - 1); |
157 | $scope.selectedNotaPedido = $scope.numPerPage - 1; | 151 | $scope.selectedNotaPedido = $scope.numPerPage - 1; |
158 | } | 152 | } |
159 | } | 153 | } |
160 | 154 | ||
161 | function avanzarPagina() { | 155 | function avanzarPagina() { |
162 | if ($scope.currentPage < $scope.lastPage) { | 156 | if ($scope.currentPage < $scope.lastPage) { |
163 | $scope.selectPage($scope.currentPage + 1); | 157 | $scope.selectPage($scope.currentPage + 1); |
164 | $scope.selectedNotaPedido = 0; | 158 | $scope.selectedNotaPedido = 0; |
165 | } | 159 | } |
166 | } | 160 | } |
167 | } | 161 | } |
168 | ] | 162 | ] |
169 | ); | 163 | ); |
170 | 164 |