Commit 8783bb386e97ec60466916c6e8a28cfb137f0943

Authored by Pablo Marco del Pont
1 parent 84ca285bed
Exists in master

linea demasiado larga.

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