Commit e6e01e595da30860105de9ecdd09102338a0f069
1 parent
8c34b01447
Exists in
master
buscador en header, paginacion en footer, cambio icons
Showing
2 changed files
with
12 additions
and
4 deletions
 
Show diff stats
src/js/controller.js
| 1 | angular.module('focaBusquedaCliente') | 1 | angular.module('focaBusquedaCliente') | 
| 2 | .controller('focaBusquedaClienteModalController', [ | 2 | .controller('focaBusquedaClienteModalController', [ | 
| 3 | '$uibModalInstance', 'focaBusquedaClienteService', '$scope', '$filter', | 3 | '$uibModalInstance', 'focaBusquedaClienteService', '$scope', '$filter', '$timeout', | 
| 4 | function($uibModalInstance, focaBusquedaClienteService, $scope, $filter) { | 4 | function($uibModalInstance, focaBusquedaClienteService, $scope, $filter, $timeout) { | 
| 5 | 5 | ||
| 6 | $scope.filters = ''; | 6 | $scope.filters = ''; | 
| 7 | $scope.primerBusqueda = false; | 7 | $scope.primerBusqueda = false; | 
| 8 | // pagination | 8 | // pagination | 
| 9 | $scope.numPerPage = 10; | 9 | $scope.numPerPage = 10; | 
| 10 | $scope.currentPage = 1; | 10 | $scope.currentPage = 1; | 
| 11 | $scope.filteredClientes = []; | 11 | $scope.filteredClientes = []; | 
| 12 | $scope.currentPageClientes = []; | 12 | $scope.currentPageClientes = []; | 
| 13 | $scope.selectedClientes = -1; | 13 | $scope.selectedClientes = -1; | 
| 14 | 14 | ||
| 15 | $scope.busquedaPress = function(key) { | 15 | $scope.busquedaPress = function(key) { | 
| 16 | if (key === 13) { | 16 | if (key === 13) { | 
| 17 | $scope.searchLoading = true; | 17 | $scope.searchLoading = true; | 
| 18 | focaBusquedaClienteService.obtenerClientesPorNombreOCuit($scope.filters).then( | 18 | focaBusquedaClienteService.obtenerClientesPorNombreOCuit($scope.filters).then( | 
| 19 | function(res) { | 19 | function(res) { | 
| 20 | $scope.primerBusqueda = true; | 20 | $scope.primerBusqueda = true; | 
| 21 | $scope.clientes = res.data; | 21 | $scope.clientes = res.data; | 
| 22 | $scope.search(); | 22 | $scope.search(true); | 
| 23 | primera(); | 23 | primera(); | 
| 24 | $scope.searchLoading = false; | 24 | $scope.searchLoading = false; | 
| 25 | }); | 25 | }); | 
| 26 | } | 26 | } | 
| 27 | }; | 27 | }; | 
| 28 | 28 | ||
| 29 | $scope.search = function () { | 29 | $scope.search = function (pressed) { | 
| 30 | if($scope.primerBusqueda) { | 30 | if($scope.primerBusqueda) { | 
| 31 | $scope.filteredClientes = $filter('filter')( | 31 | $scope.filteredClientes = $filter('filter')( | 
| 32 | $scope.clientes, {$: $scope.filters} | 32 | $scope.clientes, {$: $scope.filters} | 
| 33 | ); | 33 | ); | 
| 34 | 34 | ||
| 35 | if(pressed && $scope.filteredClientes.length === 0){ | ||
| 36 | $timeout(function() { | ||
| 37 | angular.element('#search')[0].focus(); | ||
| 38 | $scope.filters = ''; | ||
| 39 | }); | ||
| 40 | } | ||
| 41 | |||
| 35 | $scope.lastPage = Math.ceil( | 42 | $scope.lastPage = Math.ceil( | 
| 36 | $scope.filteredClientes.length / $scope.numPerPage | 43 | $scope.filteredClientes.length / $scope.numPerPage | 
| 37 | ); | 44 | ); | 
| 38 | 45 | ||
| 39 | $scope.resetPage(); | 46 | $scope.resetPage(); | 
| 40 | } | 47 | } | 
| 41 | }; | 48 | }; | 
| 42 | 49 | ||
| 43 | $scope.resetPage = function () { | 50 | $scope.resetPage = function () { | 
| 44 | $scope.currentPage = 1; | 51 | $scope.currentPage = 1; | 
| 45 | $scope.selectPage(1); | 52 | $scope.selectPage(1); | 
| 46 | }; | 53 | }; | 
| 47 | 54 | ||
| 48 | $scope.selectPage = function (page) { | 55 | $scope.selectPage = function (page) { | 
| 49 | var start = (page - 1) * $scope.numPerPage; | 56 | var start = (page - 1) * $scope.numPerPage; | 
| 50 | var end = start + $scope.numPerPage; | 57 | var end = start + $scope.numPerPage; | 
| 51 | $scope.paginas = []; | 58 | $scope.paginas = []; | 
| 52 | $scope.paginas = calcularPages(page); | 59 | $scope.paginas = calcularPages(page); | 
| 53 | $scope.currentPageClientes = $scope.filteredClientes.slice(start, end); | 60 | $scope.currentPageClientes = $scope.filteredClientes.slice(start, end); | 
| 54 | $scope.currentPage = page; | 61 | $scope.currentPage = page; | 
| 55 | }; | 62 | }; | 
| 56 | 63 | ||
| 57 | $scope.select = function(cliente) { | 64 | $scope.select = function(cliente) { | 
| 58 | $uibModalInstance.close(cliente); | 65 | $uibModalInstance.close(cliente); | 
| 59 | }; | 66 | }; | 
| 60 | 67 | ||
| 61 | $scope.cancel = function() { | 68 | $scope.cancel = function() { | 
| 62 | $uibModalInstance.dismiss('cancel'); | 69 | $uibModalInstance.dismiss('cancel'); | 
| 63 | }; | 70 | }; | 
| 64 | 71 | ||
| 65 | $scope.busquedaDown = function(key) { | 72 | $scope.busquedaDown = function(key) { | 
| 66 | if (key === 40) { | 73 | if (key === 40) { | 
| 67 | primera(key); | 74 | primera(key); | 
| 68 | } | 75 | } | 
| 69 | }; | 76 | }; | 
| 70 | 77 | ||
| 71 | $scope.itemCliente = function(key) { | 78 | $scope.itemCliente = function(key) { | 
| 72 | if (key === 38) { | 79 | if (key === 38) { | 
| 73 | anterior(key); | 80 | anterior(key); | 
| 74 | } | 81 | } | 
| 75 | 82 | ||
| 76 | if (key === 40) { | 83 | if (key === 40) { | 
| 77 | siguiente(key); | 84 | siguiente(key); | 
| 78 | } | 85 | } | 
| 79 | 86 | ||
| 80 | if (key === 37) { | 87 | if (key === 37) { | 
| 81 | retrocederPagina(); | 88 | retrocederPagina(); | 
| 82 | } | 89 | } | 
| 83 | 90 | ||
| 84 | if (key === 39) { | 91 | if (key === 39) { | 
| 85 | avanzarPagina(); | 92 | avanzarPagina(); | 
| 86 | } | 93 | } | 
| 87 | }; | 94 | }; | 
| 88 | 95 | ||
| 89 | function calcularPages(paginaActual) { | 96 | function calcularPages(paginaActual) { | 
| 90 | var paginas = []; | 97 | var paginas = []; | 
| 91 | paginas.push(paginaActual); | 98 | paginas.push(paginaActual); | 
| 92 | 99 | ||
| 93 | if (paginaActual - 1 > 1) { | 100 | if (paginaActual - 1 > 1) { | 
| 94 | 101 | ||
| 95 | paginas.unshift(paginaActual - 1); | 102 | paginas.unshift(paginaActual - 1); | 
| 96 | if (paginaActual - 2 > 1) { | 103 | if (paginaActual - 2 > 1) { | 
| 97 | paginas.unshift(paginaActual - 2); | 104 | paginas.unshift(paginaActual - 2); | 
| 98 | } | 105 | } | 
| 99 | } | 106 | } | 
| 100 | 107 | ||
| 101 | if (paginaActual + 1 < $scope.lastPage) { | 108 | if (paginaActual + 1 < $scope.lastPage) { | 
| 102 | paginas.push(paginaActual + 1); | 109 | paginas.push(paginaActual + 1); | 
| 103 | if (paginaActual + 2 < $scope.lastPage) { | 110 | if (paginaActual + 2 < $scope.lastPage) { | 
| 104 | paginas.push(paginaActual + 2); | 111 | paginas.push(paginaActual + 2); | 
| 105 | } | 112 | } | 
| 106 | } | 113 | } | 
| 107 | 114 | ||
| 108 | if (paginaActual !== 1) { | 115 | if (paginaActual !== 1) { | 
| 109 | paginas.unshift(1); | 116 | paginas.unshift(1); | 
| 110 | } | 117 | } | 
| 111 | 118 | ||
| 112 | if (paginaActual !== $scope.lastPage) { | 119 | if (paginaActual !== $scope.lastPage) { | 
| 113 | paginas.push($scope.lastPage); | 120 | paginas.push($scope.lastPage); | 
| 114 | } | 121 | } | 
| 115 | 122 | ||
| 116 | return paginas; | 123 | return paginas; | 
| 117 | } | 124 | } | 
| 118 | 125 | ||
| 119 | function primera() { | 126 | function primera() { | 
| 120 | $scope.selectedClientes = 0; | 127 | $scope.selectedClientes = 0; | 
| 121 | } | 128 | } | 
| 122 | 129 | ||
| 123 | function anterior() { | 130 | function anterior() { | 
| 124 | if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { | 131 | if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { | 
| 125 | retrocederPagina(); | 132 | retrocederPagina(); | 
| 126 | } else { | 133 | } else { | 
| 127 | $scope.selectedClientes--; | 134 | $scope.selectedClientes--; | 
| 128 | } | 135 | } | 
| 129 | } | 136 | } | 
| 130 | 137 | ||
| 131 | function siguiente() { | 138 | function siguiente() { | 
| 132 | if ($scope.selectedClientes < $scope.currentPageClientes.length - 1 ) { | 139 | if ($scope.selectedClientes < $scope.currentPageClientes.length - 1 ) { | 
| 133 | $scope.selectedClientes++; | 140 | $scope.selectedClientes++; | 
| 134 | } else { | 141 | } else { | 
| 135 | avanzarPagina(); | 142 | avanzarPagina(); | 
| 136 | } | 143 | } | 
| 137 | } | 144 | } | 
| 138 | 145 | ||
| 139 | function retrocederPagina() { | 146 | function retrocederPagina() { | 
| 140 | if ($scope.currentPage > 1) { | 147 | if ($scope.currentPage > 1) { | 
| 141 | $scope.selectPage($scope.currentPage - 1); | 148 | $scope.selectPage($scope.currentPage - 1); | 
| 142 | $scope.selectedClientes = $scope.numPerPage - 1; | 149 | $scope.selectedClientes = $scope.numPerPage - 1; | 
| 143 | } | 150 | } | 
| 144 | } | 151 | } | 
| 145 | 152 | ||
| 146 | function avanzarPagina() { | 153 | function avanzarPagina() { | 
| 147 | if ($scope.currentPage < $scope.lastPage) { | 154 | if ($scope.currentPage < $scope.lastPage) { | 
| 148 | $scope.selectPage($scope.currentPage + 1); | 155 | $scope.selectPage($scope.currentPage + 1); | 
| 149 | $scope.selectedClientes = 0; | 156 | $scope.selectedClientes = 0; | 
| 150 | } | 157 | } | 
| 151 | } | 158 | } | 
| 152 | } | 159 | } | 
| 153 | ]); | 160 | ]); | 
| 154 | 161 | 
src/views/foca-busqueda-cliente-modal.html
| 1 | <div class="modal-header py-1"> | 1 | <div class="modal-header py-1"> | 
| 2 | <div class="row w-100"> | 2 | <div class="row w-100"> | 
| 3 | <div class="col-lg-6"> | 3 | <div class="col-lg-6"> | 
| 4 | <h5 class="modal-title my-1">Búsqueda de Cliente</h5> | 4 | <h5 class="modal-title my-1">Búsqueda de Cliente</h5> | 
| 5 | </div> | 5 | </div> | 
| 6 | <div class="input-group col-lg-6 pr-0 my-2"> | 6 | <div class="input-group col-lg-6 pr-0 my-2"> | 
| 7 | <input | 7 | <input | 
| 8 | ladda="searchLoading" | 8 | ladda="searchLoading" | 
| 9 | type="text" | 9 | type="text" | 
| 10 | class="form-control form-control-sm" | 10 | class="form-control form-control-sm" | 
| 11 | id="search" | ||
| 11 | placeholder="Busqueda" | 12 | placeholder="Busqueda" | 
| 12 | ng-model="filters" | 13 | ng-model="filters" | 
| 13 | ng-change="search()" | 14 | ng-change="search()" | 
| 14 | ng-keydown="busquedaDown($event.keyCode)" | 15 | ng-keydown="busquedaDown($event.keyCode)" | 
| 15 | ng-keypress="busquedaPress($event.keyCode)" | 16 | ng-keypress="busquedaPress($event.keyCode)" | 
| 16 | foca-focus="selectedClientes == -1" | 17 | foca-focus="selectedClientes == -1" | 
| 17 | ng-focus="selectedClientes = -1" | 18 | ng-focus="selectedClientes = -1" | 
| 18 | teclado-virtual | 19 | teclado-virtual | 
| 19 | > | 20 | > | 
| 20 | <div class="input-group-append"> | 21 | <div class="input-group-append"> | 
| 21 | <button | 22 | <button | 
| 22 | ladda="searchLoading" | 23 | ladda="searchLoading" | 
| 23 | class="btn btn-outline-secondary" | 24 | class="btn btn-outline-secondary" | 
| 24 | type="button" | 25 | type="button" | 
| 25 | ng-click="busquedaPress(13)"> | 26 | ng-click="busquedaPress(13)"> | 
| 26 | <i class="fa fa-search" aria-hidden="true"></i> | 27 | <i class="fa fa-search" aria-hidden="true"></i> | 
| 27 | </button> | 28 | </button> | 
| 28 | </div> | 29 | </div> | 
| 29 | </div> | 30 | </div> | 
| 30 | </div> | 31 | </div> | 
| 31 | </div> | 32 | </div> | 
| 32 | <div class="modal-body" id="modal-body"> | 33 | <div class="modal-body" id="modal-body"> | 
| 33 | 34 | ||
| 34 | <div ng-show="!primerBusqueda"> | 35 | <div ng-show="!primerBusqueda"> | 
| 35 | Debe realizar una primer búsqueda. | 36 | Debe realizar una primer búsqueda. | 
| 36 | </div> | 37 | </div> | 
| 37 | 38 | ||
| 38 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> | 39 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> | 
| 39 | <thead> | 40 | <thead> | 
| 40 | <tr> | 41 | <tr> | 
| 41 | <th>Código</th> | 42 | <th>Código</th> | 
| 42 | <th>Nombre</th> | 43 | <th>Nombre</th> | 
| 43 | <th>CUIT</th> | 44 | <th>CUIT</th> | 
| 44 | <th></th> | 45 | <th></th> | 
| 45 | </tr> | 46 | </tr> | 
| 46 | </thead> | 47 | </thead> | 
| 47 | <tbody> | 48 | <tbody> | 
| 48 | <tr ng-show="currentPageClientes.length == 0 && primerBusqueda"> | 49 | <tr ng-show="currentPageClientes.length == 0 && primerBusqueda"> | 
| 49 | <td colspan="4"> | 50 | <td colspan="4"> | 
| 50 | No se encontraron resultados. | 51 | No se encontraron resultados. | 
| 51 | </td> | 52 | </td> | 
| 52 | </tr> | 53 | </tr> | 
| 53 | <tr | 54 | <tr | 
| 54 | class="selectable" | 55 | class="selectable" | 
| 55 | ng-repeat="(key, cliente) in currentPageClientes" | 56 | ng-repeat="(key, cliente) in currentPageClientes" | 
| 56 | ng-click="select(cliente)"> | 57 | ng-click="select(cliente)"> | 
| 57 | <td ng-bind="cliente.cod"></td> | 58 | <td ng-bind="cliente.cod"></td> | 
| 58 | <td ng-bind="cliente.nom"></td> | 59 | <td ng-bind="cliente.nom"></td> | 
| 59 | <td ng-bind="cliente.cuit"></td> | 60 | <td ng-bind="cliente.cuit"></td> | 
| 60 | <td> | 61 | <td> | 
| 61 | <button | 62 | <button | 
| 62 | type="button" | 63 | type="button" | 
| 63 | class="btn btn-xs p-1 float-right" | 64 | class="btn btn-xs p-1 float-right" | 
| 64 | ng-class="{ | 65 | ng-class="{ | 
| 65 | 'btn-secondary': selectedClientes != key, | 66 | 'btn-secondary': selectedClientes != key, | 
| 66 | 'btn-primary': selectedClientes == key | 67 | 'btn-primary': selectedClientes == key | 
| 67 | }" | 68 | }" | 
| 68 | ng-click="select(cliente)" | 69 | ng-click="select(cliente)" | 
| 69 | foca-focus="selectedClientes == {{key}}" | 70 | foca-focus="selectedClientes == {{key}}" | 
| 70 | ng-keydown="itemCliente($event.keyCode)" | 71 | ng-keydown="itemCliente($event.keyCode)" | 
| 71 | > | 72 | > | 
| 72 | <i class="fa fa-circle-thin" aria-hidden="true"></i> | 73 | <i class="fa fa-circle-thin" aria-hidden="true"></i> | 
| 73 | </button> | 74 | </button> | 
| 74 | </td> | 75 | </td> | 
| 75 | </tr> | 76 | </tr> | 
| 76 | </tbody> | 77 | </tbody> | 
| 77 | </table> | 78 | </table> | 
| 78 | 79 | ||
| 79 | </div> | 80 | </div> | 
| 80 | <div class="modal-footer py-1"> | 81 | <div class="modal-footer py-1"> | 
| 81 | <nav ng-show="currentPageClientes.length > 0 && primerBusqueda" class="mr-auto"> | 82 | <nav ng-show="currentPageClientes.length > 0 && primerBusqueda" class="mr-auto"> | 
| 82 | <ul class="pagination pagination-sm mb-0"> | 83 | <ul class="pagination pagination-sm mb-0"> | 
| 83 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | 84 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | 
| 84 | <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage - 1)"> | 85 | <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage - 1)"> | 
| 85 | <span aria-hidden="true">«</span> | 86 | <span aria-hidden="true">«</span> | 
| 86 | <span class="sr-only">Anterior</span> | 87 | <span class="sr-only">Anterior</span> | 
| 87 | </a> | 88 | </a> | 
| 88 | </li> | 89 | </li> | 
| 89 | <li | 90 | <li | 
| 90 | class="page-item" | 91 | class="page-item" | 
| 91 | ng-repeat="pagina in paginas" | 92 | ng-repeat="pagina in paginas" | 
| 92 | ng-class="{'active': pagina == currentPage}" | 93 | ng-class="{'active': pagina == currentPage}" | 
| 93 | > | 94 | > | 
| 94 | <a | 95 | <a | 
| 95 | class="page-link" | 96 | class="page-link" | 
| 96 | href="javascript:void()" | 97 | href="javascript:void()" | 
| 97 | ng-click="selectPage(pagina)" | 98 | ng-click="selectPage(pagina)" | 
| 98 | ng-bind="pagina" | 99 | ng-bind="pagina" | 
| 99 | ></a> | 100 | ></a> | 
| 100 | </li> | 101 | </li> | 
| 101 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | 102 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | 
| 102 | <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage + 1)"> | 103 | <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage + 1)"> | 
| 103 | <span aria-hidden="true">»</span> | 104 | <span aria-hidden="true">»</span> | 
| 104 | <span class="sr-only">Siguiente</span> | 105 | <span class="sr-only">Siguiente</span> | 
| 105 | </a> | 106 | </a> | 
| 106 | </li> | 107 | </li> | 
| 107 | </ul> | 108 | </ul> | 
| 108 | </nav> | 109 | </nav> | 
| 109 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | 110 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | 
| 110 | </div> | 111 | </div> | 
| 111 | 112 |