Commit 0066561abd4c03890ee0d36302eb2290bb730aa5
1 parent
3b0b9b622a
Exists in
master
remove console
Showing
1 changed file
with
0 additions
and
1 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearLogin') | 1 | angular.module('focaCrearLogin') |
2 | .controller('focaCrearLoginController', [ | 2 | .controller('focaCrearLoginController', [ |
3 | '$scope', '$timeout', '$uibModal', 'focaCrearLoginService','focaBotoneraLateralService', | 3 | '$scope', '$timeout', '$uibModal', 'focaCrearLoginService','focaBotoneraLateralService', |
4 | function($scope, $timeout, $uibModal, focaCrearLoginService, focaBotoneraLateralService) { | 4 | function($scope, $timeout, $uibModal, focaCrearLoginService, focaBotoneraLateralService) { |
5 | config(); | 5 | config(); |
6 | 6 | ||
7 | //METODOS | 7 | //METODOS |
8 | function init() { | 8 | function init() { |
9 | $scope.numPerPage = 9; | 9 | $scope.numPerPage = 9; |
10 | $scope.now = new Date(); | 10 | $scope.now = new Date(); |
11 | $scope.seleccionado = ''; | 11 | $scope.seleccionado = ''; |
12 | $scope.cuentas = []; | 12 | $scope.cuentas = []; |
13 | $scope.$broadcast('removeCabecera', { | 13 | $scope.$broadcast('removeCabecera', { |
14 | label: 'Selección:', | 14 | label: 'Selección:', |
15 | valor: $scope.seleccionado | 15 | valor: $scope.seleccionado |
16 | }); | 16 | }); |
17 | } | 17 | } |
18 | 18 | ||
19 | function config() { | 19 | function config() { |
20 | $scope.botonera = [ | 20 | $scope.botonera = [ |
21 | { | 21 | { |
22 | label: 'Transportista', | 22 | label: 'Transportista', |
23 | image: 'cliente.png' | 23 | image: 'cliente.png' |
24 | }, | 24 | }, |
25 | { | 25 | { |
26 | label: 'Cobrador', | 26 | label: 'Cobrador', |
27 | image: 'cliente.png' | 27 | image: 'cliente.png' |
28 | }, | 28 | }, |
29 | { | 29 | { |
30 | label: 'Vendedor', | 30 | label: 'Vendedor', |
31 | image: 'cliente.png' | 31 | image: 'cliente.png' |
32 | } | 32 | } |
33 | ]; | 33 | ]; |
34 | 34 | ||
35 | $timeout(function() { | 35 | $timeout(function() { |
36 | focaBotoneraLateralService.showSalir(true); | 36 | focaBotoneraLateralService.showSalir(true); |
37 | focaBotoneraLateralService.showPausar(false); | 37 | focaBotoneraLateralService.showPausar(false); |
38 | focaBotoneraLateralService.showCancelar(false); | 38 | focaBotoneraLateralService.showCancelar(false); |
39 | focaBotoneraLateralService.showGuardar(false); | 39 | focaBotoneraLateralService.showGuardar(false); |
40 | }); | 40 | }); |
41 | 41 | ||
42 | init(); | 42 | init(); |
43 | } | 43 | } |
44 | 44 | ||
45 | $scope.seleccionarTransportista = function() { | 45 | $scope.seleccionarTransportista = function() { |
46 | $scope.seleccionado = 'Transportistas'; | 46 | $scope.seleccionado = 'Transportistas'; |
47 | 47 | ||
48 | focaCrearLoginService.getListaChoferes().then(setearTabla); | 48 | focaCrearLoginService.getListaChoferes().then(setearTabla); |
49 | }; | 49 | }; |
50 | 50 | ||
51 | $scope.seleccionarCobrador = function() { | 51 | $scope.seleccionarCobrador = function() { |
52 | $scope.seleccionado = 'Cobradores'; | 52 | $scope.seleccionado = 'Cobradores'; |
53 | 53 | ||
54 | focaCrearLoginService.getListaCobradores().then(setearTabla); | 54 | focaCrearLoginService.getListaCobradores().then(setearTabla); |
55 | }; | 55 | }; |
56 | 56 | ||
57 | $scope.seleccionarVendedor = function() { | 57 | $scope.seleccionarVendedor = function() { |
58 | $scope.seleccionado = 'Vendedores'; | 58 | $scope.seleccionado = 'Vendedores'; |
59 | 59 | ||
60 | focaCrearLoginService.getListaVendedores().then(setearTabla); | 60 | focaCrearLoginService.getListaVendedores().then(setearTabla); |
61 | }; | 61 | }; |
62 | 62 | ||
63 | $scope.openModalAcceso = function(cuenta) { | 63 | $scope.openModalAcceso = function(cuenta) { |
64 | var parametros = { | 64 | var parametros = { |
65 | cuenta: cuenta, | 65 | cuenta: cuenta, |
66 | tipo: $scope.seleccionado | 66 | tipo: $scope.seleccionado |
67 | }; | 67 | }; |
68 | 68 | ||
69 | var modalInstance = $uibModal.open( | 69 | var modalInstance = $uibModal.open( |
70 | { | 70 | { |
71 | ariaLabelledBy: 'Configuracion de Logueo', | 71 | ariaLabelledBy: 'Configuracion de Logueo', |
72 | templateUrl: 'modal-login.html', | 72 | templateUrl: 'modal-login.html', |
73 | controller: 'focaModalLoginController', | 73 | controller: 'focaModalLoginController', |
74 | size: 'md', | 74 | size: 'md', |
75 | resolve: { | 75 | resolve: { |
76 | parametros: function() { | 76 | parametros: function() { |
77 | return parametros; | 77 | return parametros; |
78 | } | 78 | } |
79 | } | 79 | } |
80 | } | 80 | } |
81 | ); | 81 | ); |
82 | 82 | ||
83 | modalInstance.result.then( | 83 | modalInstance.result.then( |
84 | function(result) { | 84 | function(result) { |
85 | init(); | 85 | init(); |
86 | }, function() {} | 86 | }, function() {} |
87 | ); | 87 | ); |
88 | }; | 88 | }; |
89 | 89 | ||
90 | $scope.selectPage = function(page) { | 90 | $scope.selectPage = function(page) { |
91 | var start = (page - 1) * $scope.numPerPage; | 91 | var start = (page - 1) * $scope.numPerPage; |
92 | var end = start + $scope.numPerPage; | 92 | var end = start + $scope.numPerPage; |
93 | $scope.paginas = []; | 93 | $scope.paginas = []; |
94 | $scope.paginas = calcularPages(page); | 94 | $scope.paginas = calcularPages(page); |
95 | $scope.currentPageUsuarios = | 95 | $scope.currentPageUsuarios = |
96 | $scope.cuentas.slice(start, end); | 96 | $scope.cuentas.slice(start, end); |
97 | $scope.currentPage = page; | 97 | $scope.currentPage = page; |
98 | }; | 98 | }; |
99 | 99 | ||
100 | $scope.resetPage = function() { | 100 | $scope.resetPage = function() { |
101 | $scope.currentPage = 1; | 101 | $scope.currentPage = 1; |
102 | $scope.selectPage(1); | 102 | $scope.selectPage(1); |
103 | }; | 103 | }; |
104 | 104 | ||
105 | function setearTabla(datos) { | 105 | function setearTabla(datos) { |
106 | $scope.cuentas = datos.data; | 106 | $scope.cuentas = datos.data; |
107 | 107 | ||
108 | $scope.lastPage = Math.ceil( | 108 | $scope.lastPage = Math.ceil( |
109 | $scope.cuentas.length / $scope.numPerPage | 109 | $scope.cuentas.length / $scope.numPerPage |
110 | ); | 110 | ); |
111 | $scope.resetPage(); | 111 | $scope.resetPage(); |
112 | 112 | ||
113 | if ($scope.seleccionado == 'Cobradores' || | 113 | if ($scope.seleccionado == 'Cobradores' || |
114 | $scope.seleccionado == 'Vendedores' | 114 | $scope.seleccionado == 'Vendedores' |
115 | ) { | 115 | ) { |
116 | for (var i = $scope.cuentas.length - 1; i >= 0; i--) { | 116 | for (var i = $scope.cuentas.length - 1; i >= 0; i--) { |
117 | console.info($scope.cuentas[i]); | ||
118 | $scope.cuentas[i].codigo = $scope.cuentas[i].NUM; | 117 | $scope.cuentas[i].codigo = $scope.cuentas[i].NUM; |
119 | $scope.cuentas[i].nombre = $scope.cuentas[i].NOM; | 118 | $scope.cuentas[i].nombre = $scope.cuentas[i].NOM; |
120 | $scope.cuentas[i].dni = $scope.cuentas[i].dni; | 119 | $scope.cuentas[i].dni = $scope.cuentas[i].dni; |
121 | } | 120 | } |
122 | } else { | 121 | } else { |
123 | for (var i = $scope.cuentas.length - 1; i >= 0; i--) { | 122 | for (var i = $scope.cuentas.length - 1; i >= 0; i--) { |
124 | $scope.cuentas[i].codigo = $scope.cuentas[i].id; | 123 | $scope.cuentas[i].codigo = $scope.cuentas[i].id; |
125 | } | 124 | } |
126 | } | 125 | } |
127 | 126 | ||
128 | $scope.$broadcast('removeCabecera', { | 127 | $scope.$broadcast('removeCabecera', { |
129 | label: 'Selección:', | 128 | label: 'Selección:', |
130 | valor: $scope.seleccionado | 129 | valor: $scope.seleccionado |
131 | }); | 130 | }); |
132 | } | 131 | } |
133 | 132 | ||
134 | function calcularPages(paginaActual) { | 133 | function calcularPages(paginaActual) { |
135 | var paginas = []; | 134 | var paginas = []; |
136 | paginas.push(paginaActual); | 135 | paginas.push(paginaActual); |
137 | 136 | ||
138 | if(paginaActual - 1 > 1) { | 137 | if(paginaActual - 1 > 1) { |
139 | 138 | ||
140 | paginas.unshift(paginaActual - 1); | 139 | paginas.unshift(paginaActual - 1); |
141 | if(paginaActual - 2 > 1) { | 140 | if(paginaActual - 2 > 1) { |
142 | paginas.unshift(paginaActual - 2); | 141 | paginas.unshift(paginaActual - 2); |
143 | } | 142 | } |
144 | } | 143 | } |
145 | 144 | ||
146 | if(paginaActual + 1 < $scope.lastPage) { | 145 | if(paginaActual + 1 < $scope.lastPage) { |
147 | paginas.push(paginaActual + 1); | 146 | paginas.push(paginaActual + 1); |
148 | if(paginaActual + 2 < $scope.lastPage) { | 147 | if(paginaActual + 2 < $scope.lastPage) { |
149 | paginas.push(paginaActual + 2); | 148 | paginas.push(paginaActual + 2); |
150 | } | 149 | } |
151 | } | 150 | } |
152 | 151 | ||
153 | if(paginaActual !== 1) { | 152 | if(paginaActual !== 1) { |
154 | paginas.unshift(1); | 153 | paginas.unshift(1); |
155 | } | 154 | } |
156 | 155 | ||
157 | if(paginaActual !== $scope.lastPage) { | 156 | if(paginaActual !== $scope.lastPage) { |
158 | paginas.push($scope.lastPage); | 157 | paginas.push($scope.lastPage); |
159 | } | 158 | } |
160 | 159 | ||
161 | return paginas; | 160 | return paginas; |
162 | } | 161 | } |
163 | 162 | ||
164 | function primera() { | 163 | function primera() { |
165 | $scope.selectedUsuarios = 0; | 164 | $scope.selectedUsuarios = 0; |
166 | } | 165 | } |
167 | 166 | ||
168 | function anterior() { | 167 | function anterior() { |
169 | if ($scope.selectedUsuarios === 0 && $scope.currentPage > 1) { | 168 | if ($scope.selectedUsuarios === 0 && $scope.currentPage > 1) { |
170 | retrocederPagina(); | 169 | retrocederPagina(); |
171 | } else { | 170 | } else { |
172 | $scope.selectedUsuarios--; | 171 | $scope.selectedUsuarios--; |
173 | } | 172 | } |
174 | } | 173 | } |
175 | 174 | ||
176 | function siguiente() { | 175 | function siguiente() { |
177 | if ($scope.selectedUsuarios < $scope.currentPageUsuarios.length - 1 ) { | 176 | if ($scope.selectedUsuarios < $scope.currentPageUsuarios.length - 1 ) { |
178 | $scope.selectedUsuarios++; | 177 | $scope.selectedUsuarios++; |
179 | } else { | 178 | } else { |
180 | avanzarPagina(); | 179 | avanzarPagina(); |
181 | } | 180 | } |
182 | } | 181 | } |
183 | 182 | ||
184 | function retrocederPagina() { | 183 | function retrocederPagina() { |
185 | if ($scope.currentPage > 1) { | 184 | if ($scope.currentPage > 1) { |
186 | $scope.selectPage($scope.currentPage - 1); | 185 | $scope.selectPage($scope.currentPage - 1); |
187 | $scope.selectedUsuarios = $scope.numPerPage - 1; | 186 | $scope.selectedUsuarios = $scope.numPerPage - 1; |
188 | } | 187 | } |
189 | } | 188 | } |
190 | 189 | ||
191 | function avanzarPagina() { | 190 | function avanzarPagina() { |
192 | if ($scope.currentPage < $scope.lastPage) { | 191 | if ($scope.currentPage < $scope.lastPage) { |
193 | $scope.selectPage($scope.currentPage + 1); | 192 | $scope.selectPage($scope.currentPage + 1); |
194 | $scope.selectedUsuarios = 0; | 193 | $scope.selectedUsuarios = 0; |
195 | } | 194 | } |
196 | } | 195 | } |
197 | } | 196 | } |
198 | ]); | 197 | ]); |
199 | 198 |