Commit a67e491ef513d4716eb8b8b70b54fb236b3ff0b6

Authored by Nicolás Guarnieri
Exists in master

Merge branch 'master' into 'master'

Master

See merge request !5
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
8
9 //METODOS 7 //METODOS
10 function init() { 8 function init() {
9 $scope.numPerPage = 9;
11 $scope.now = new Date(); 10 $scope.now = new Date();
12 $scope.seleccionado = ''; 11 $scope.seleccionado = '';
13 $scope.cuentas = []; 12 $scope.cuentas = [];
14 $scope.$broadcast('removeCabecera', { 13 $scope.$broadcast('removeCabecera', {
15 label: 'Selección:', 14 label: 'Selección:',
16 valor: $scope.seleccionado 15 valor: $scope.seleccionado
17 }); 16 });
18 } 17 }
19 18
20 function config() { 19 function config() {
21 $scope.botonera = [ 20 $scope.botonera = [
22 { 21 {
23 label: 'Transportista', 22 label: 'Transportista',
24 image: 'cliente.png' 23 image: 'cliente.png'
25 }, 24 },
26 { 25 {
27 label: 'Cobrador', 26 label: 'Cobrador',
28 image: 'cliente.png' 27 image: 'cliente.png'
29 }, 28 },
30 { 29 {
31 label: 'Vendedor', 30 label: 'Vendedor',
32 image: 'cliente.png' 31 image: 'cliente.png'
33 } 32 }
34 ]; 33 ];
35 34
36 $timeout(function() { 35 $timeout(function() {
37 focaBotoneraLateralService.showSalir(true); 36 focaBotoneraLateralService.showSalir(true);
38 focaBotoneraLateralService.showPausar(false); 37 focaBotoneraLateralService.showPausar(false);
39 focaBotoneraLateralService.showCancelar(false); 38 focaBotoneraLateralService.showCancelar(false);
40 focaBotoneraLateralService.showGuardar(false); 39 focaBotoneraLateralService.showGuardar(false);
41 }); 40 });
42 41
43 init(); 42 init();
44 } 43 }
45 44
46 $scope.seleccionarTransportista = function() { 45 $scope.seleccionarTransportista = function() {
47 $scope.seleccionado = 'Transportistas'; 46 $scope.seleccionado = 'Transportistas';
48 47
49 focaCrearLoginService.getListaChoferes().then(setearTabla); 48 focaCrearLoginService.getListaChoferes().then(setearTabla);
50 }; 49 };
51 50
52 $scope.seleccionarCobrador = function() { 51 $scope.seleccionarCobrador = function() {
53 $scope.seleccionado = 'Cobradores'; 52 $scope.seleccionado = 'Cobradores';
54 53
55 focaCrearLoginService.getListaCobradores().then(setearTabla); 54 focaCrearLoginService.getListaCobradores().then(setearTabla);
56 }; 55 };
57 56
58 $scope.seleccionarVendedor = function() { 57 $scope.seleccionarVendedor = function() {
59 $scope.seleccionado = 'Vendedores'; 58 $scope.seleccionado = 'Vendedores';
60 59
61 focaCrearLoginService.getListaVendedores().then(setearTabla); 60 focaCrearLoginService.getListaVendedores().then(setearTabla);
62 }; 61 };
63 62
64 $scope.openModalAcceso = function(cuenta) { 63 $scope.openModalAcceso = function(cuenta) {
65 var parametros = { 64 var parametros = {
66 cuenta: cuenta, 65 cuenta: cuenta,
67 tipo: $scope.seleccionado 66 tipo: $scope.seleccionado
68 } 67 };
69 68
70 var modalInstance = $uibModal.open( 69 var modalInstance = $uibModal.open(
71 { 70 {
72 ariaLabelledBy: 'Configuracion de Logueo', 71 ariaLabelledBy: 'Configuracion de Logueo',
73 templateUrl: 'modal-login.html', 72 templateUrl: 'modal-login.html',
74 controller: 'focaModalLoginController', 73 controller: 'focaModalLoginController',
75 size: 'md', 74 size: 'md',
76 resolve: { 75 resolve: {
77 parametros: function() { 76 parametros: function() {
78 return parametros; 77 return parametros;
79 } 78 }
80 } 79 }
81 } 80 }
82 ); 81 );
83 82
84 modalInstance.result.then( 83 modalInstance.result.then(
85 function(result) { 84 function(result) {
86 init(); 85 init();
87 }, function() {} 86 }, function() {}
88 ); 87 );
89 } 88 };
89
90 $scope.selectPage = function(page) {
91 var start = (page - 1) * $scope.numPerPage;
92 var end = start + $scope.numPerPage;
93 $scope.paginas = [];
94 $scope.paginas = calcularPages(page);
95 $scope.currentPageUsuarios =
96 $scope.cuentas.slice(start, end);
97 $scope.currentPage = page;
98 };
99
100 $scope.resetPage = function() {
101 $scope.currentPage = 1;
102 $scope.selectPage(1);
103 };
90 104
91 function setearTabla(datos) { 105 function setearTabla(datos) {
92 $scope.cuentas = datos.data; 106 $scope.cuentas = datos.data;
93 107
108 $scope.lastPage = Math.ceil(
109 $scope.cuentas.length / $scope.numPerPage
110 );
111 $scope.resetPage();
112
94 if ($scope.seleccionado == 'Cobradores' || 113 if ($scope.seleccionado == 'Cobradores' ||
95 $scope.seleccionado == 'Vendedores' 114 $scope.seleccionado == 'Vendedores'
96 ) { 115 ) {
97 for (var i = $scope.cuentas.length - 1; i >= 0; i--) { 116 for (var i = $scope.cuentas.length - 1; i >= 0; i--) {
98 $scope.cuentas[i].id = $scope.cuentas[i].CodVen; 117 $scope.cuentas[i].id = $scope.cuentas[i].CodVen;
99 $scope.cuentas[i].nombre = $scope.cuentas[i].NomVen; 118 $scope.cuentas[i].nombre = $scope.cuentas[i].NomVen;
100 $scope.cuentas[i].dni = $scope.cuentas[i].DNI; 119 $scope.cuentas[i].dni = $scope.cuentas[i].DNI;
101 $scope.cuentas[i].telefono = $scope.cuentas[i].TelVen; 120 $scope.cuentas[i].telefono = $scope.cuentas[i].TelVen;
102 } 121 }
103 } 122 }
104 123
105 $scope.$broadcast('removeCabecera', { 124 $scope.$broadcast('removeCabecera', {
106 label: 'Selección:', 125 label: 'Selección:',
107 valor: $scope.seleccionado 126 valor: $scope.seleccionado
108 }); 127 });
109 } 128 }
129
130 function calcularPages(paginaActual) {
131 var paginas = [];
132 paginas.push(paginaActual);
133
134 if(paginaActual - 1 > 1) {
135
136 paginas.unshift(paginaActual - 1);
137 if(paginaActual - 2 > 1) {
138 paginas.unshift(paginaActual - 2);
139 }
140 }
141
142 if(paginaActual + 1 < $scope.lastPage) {
143 paginas.push(paginaActual + 1);
144 if(paginaActual + 2 < $scope.lastPage) {
145 paginas.push(paginaActual + 2);
146 }
147 }
148
149 if(paginaActual !== 1) {
150 paginas.unshift(1);
151 }
152
153 if(paginaActual !== $scope.lastPage) {
154 paginas.push($scope.lastPage);
155 }
156
157 return paginas;
158 }
159
160 function primera() {
161 $scope.selectedUsuarios = 0;
162 }
163
164 function anterior() {
165 if ($scope.selectedUsuarios === 0 && $scope.currentPage > 1) {
166 retrocederPagina();
167 } else {
168 $scope.selectedUsuarios--;
169 }
170 }
171
172 function siguiente() {
173 if ($scope.selectedUsuarios < $scope.currentPageUsuarios.length - 1 ) {
174 $scope.selectedUsuarios++;
175 } else {
176 avanzarPagina();
177 }
178 }
179
180 function retrocederPagina() {
181 if ($scope.currentPage > 1) {
182 $scope.selectPage($scope.currentPage - 1);
183 $scope.selectedUsuarios = $scope.numPerPage - 1;
184 }
185 }
186
187 function avanzarPagina() {
188 if ($scope.currentPage < $scope.lastPage) {
189 $scope.selectPage($scope.currentPage + 1);
190 $scope.selectedUsuarios = 0;
191 }
192 }
110 } 193 }
src/views/foca-crear-login.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Administración de Ingreso'" 3 titulo="'Administración de Ingreso'"
4 fecha="now" 4 fecha="now"
5 class="mb-0 col-12" 5 class="mb-0 col-12"
6 ></foca-cabecera-facturador> 6 ></foca-cabecera-facturador>
7 </div> 7 </div>
8 <div class="row"> 8 <div class="row">
9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> 9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded">
10 <div class="row px-5 py-2 botonera-secundaria"> 10 <div class="row px-5 py-2 botonera-secundaria">
11 <div class="col-12"> 11 <div class="col-12">
12 <foca-botonera-facturador botones="botonera" extra="3" class="row"></foca-botonera-facturador> 12 <foca-botonera-facturador botones="botonera" max="6" class="row"></foca-botonera-facturador>
13 </div> 13 </div>
14 </div> 14 </div>
15 <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> 15 <table class="table table-default table-hover table-sm table-abm table-striped mb-0">
16 <thead> 16 <thead>
17 <tr> 17 <tr>
18 <th>Código</th> 18 <th>Código</th>
19 <th>Nombre</th> 19 <th>Nombre</th>
20 <th>DNI</th> 20 <th>DNI</th>
21 <th>Teléfono</th> 21 <th>Teléfono</th>
22 <th class="text-center"> 22 <th class="text-center">
23 </th> 23 </th>
24 </tr> 24 </tr>
25 </thead> 25 </thead>
26 <tbody> 26 <tbody>
27 <tr ng-repeat="cuenta in cuentas | filter:filters"> 27 <tr ng-repeat="cuenta in currentPageUsuarios">
28 <td ng-bind="cuenta.id"></td> 28 <td ng-bind="cuenta.id"></td>
29 <td ng-bind="cuenta.nombre"></td> 29 <td ng-bind="cuenta.nombre"></td>
30 <td ng-bind="cuenta.dni"></td> 30 <td ng-bind="cuenta.dni"></td>
31 <td ng-bind="cuenta.telefono"></td> 31 <td ng-bind="cuenta.telefono"></td>
32 <td class="text-center"> 32 <td class="text-center">
33 <button 33 <button
34 class="btn btn-outline-dark boton-accion" 34 class="btn btn-outline-dark boton-accion"
35 title="Editar acceso" 35 title="Editar acceso"
36 ng-click="openModalAcceso(cuenta)" 36 ng-click="openModalAcceso(cuenta)"
37 > 37 >
38 <i class="fa fa-lock"></i> 38 <i class="fa fa-lock"></i>
39 </button> 39 </button>
40 </td> 40 </td>
41 </tr> 41 </tr>
42 </body> 42 </body>
43 </table> 43 </table>
44 </div> 44 </div>
45 </div> 45 </div>
46 <div class="row">
47 <nav ng-show="currentPageUsuarios.length > 0" class="mr-auto">
48 <ul class="pagination pagination-sm mb-0">
49 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
50 <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage - 1)">
51 <span aria-hidden="true">&laquo;</span>
52 <span class="sr-only">Anterior</span>
53 </a>
54 </li>
55 <li
56 class="page-item"
57 ng-repeat="pagina in paginas"
58 ng-class="{'active': pagina == currentPage}"
59 >
60 <a
61 class="page-link"
62 href="javascript:void()"
63 ng-click="selectPage(pagina)"
64 ng-bind="pagina"
65 ></a>
66 </li>
67 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
68 <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage + 1)">
69 <span aria-hidden="true">&raquo;</span>
70 <span class="sr-only">Siguiente</span>
71 </a>
72 </li>
73 </ul>
74 </nav>
75 </div>
46 76