Commit 9132c32d719e44e81d9760e4b142ceea0eb6f015

Authored by Eric Fernandez
1 parent 4786b133fb
Exists in master

espacios

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