Commit d96c78f743b59c26ab8c97ffbdfb670ab8bc4658
Exists in
master
Merge branch 'master' into 'master'
Master(efernandez) See merge request !8
Showing
2 changed files
Show diff stats
src/js/controllerModal.js
| 1 | angular.module('focaModal') | 1 | angular.module('focaModal') |
| 2 | .controller('focaModalController', [ | 2 | .controller('focaModalController', [ |
| 3 | '$timeout', | 3 | '$timeout', |
| 4 | '$filter', | 4 | '$filter', |
| 5 | '$scope', | 5 | '$scope', |
| 6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
| 7 | 'focaModalService', | 7 | 'focaModalService', |
| 8 | 'parametrosModal', | 8 | 'parametrosModal', |
| 9 | function($timeout, $filter, $scope, $uibModalInstance, focaModalService, parametrosModal) { | 9 | function($timeout, $filter, $scope, $uibModalInstance, focaModalService, parametrosModal) { |
| 10 | 10 | ||
| 11 | $scope.parametrosModal = parametrosModal; | 11 | $scope.parametrosModal = parametrosModal; |
| 12 | $scope.filters = ''; | 12 | $scope.filters = ''; |
| 13 | $scope.entidades = []; | 13 | $scope.entidades = []; |
| 14 | $scope.primerBusqueda = false; | 14 | $scope.primerBusqueda = false; |
| 15 | $scope.searchLoading = false; | 15 | $scope.searchLoading = false; |
| 16 | // pagination | 16 | // pagination |
| 17 | $scope.numPerPage = 10; | 17 | $scope.numPerPage = 10; |
| 18 | $scope.currentPage = 1; | 18 | $scope.currentPage = 1; |
| 19 | $scope.filteredEntidades = []; | 19 | $scope.filteredEntidades = []; |
| 20 | $scope.currentPageEntidades = []; | 20 | $scope.currentPageEntidades = []; |
| 21 | $scope.selectedEntidad = -1; | 21 | $scope.selectedEntidad = -1; |
| 22 | 22 | ||
| 23 | $scope.busquedaPress = function(key) { | 23 | $scope.busquedaPress = function(key) { |
| 24 | if(key === 13) { | 24 | if(key === 13) { |
| 25 | $scope.searchLoading = true; | 25 | $scope.searchLoading = true; |
| 26 | focaModalService.getEntidad($scope.filters, parametrosModal.query).then( | 26 | focaModalService.getEntidad($scope.filters, parametrosModal.query).then( |
| 27 | function(res) { | 27 | function(res) { |
| 28 | $scope.searchLoading = false; | 28 | $scope.searchLoading = false; |
| 29 | $scope.primerBusqueda = true; | 29 | $scope.primerBusqueda = true; |
| 30 | $scope.entidades = res.data; | 30 | $scope.entidades = res.data; |
| 31 | filtros($scope.entidades); | ||
| 31 | $scope.search(true); | 32 | $scope.search(true); |
| 32 | primera(); | 33 | primera(); |
| 33 | } | 34 | } |
| 34 | ); | 35 | ); |
| 35 | } | 36 | } |
| 36 | }; | 37 | }; |
| 37 | $scope.busquedaPress(13); | 38 | $scope.busquedaPress(13); |
| 38 | 39 | function filtros(entidades) { | |
| 40 | for (var i = 0; i < $scope.parametrosModal.columnas.length; i++) { | ||
| 41 | var filtro = $scope.parametrosModal.columnas[i].filtro; | ||
| 42 | if (filtro) { | ||
| 43 | for (var j = 0; j < entidades.length; j++) { | ||
| 44 | entidades[j][$scope.parametrosModal.columnas[i].propiedad] = | ||
| 45 | $filter(filtro.nombre)(entidades[j][$scope | ||
| 46 | .parametrosModal.columnas[i].propiedad], filtro.parametro); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 39 | $scope.search = function(pressed) { | 51 | $scope.search = function(pressed) { |
| 40 | if($scope.entidades.length > 0) { | 52 | if($scope.entidades.length > 0) { |
| 41 | $scope.filteredEntidades = $filter('filter')( | 53 | $scope.filteredEntidades = $filter('filter')( |
| 42 | $scope.entidades, { $: $scope.filters } | 54 | $scope.entidades, { $: $scope.filters } |
| 43 | ); | 55 | ); |
| 44 | $scope.lastPage = Math.ceil( | 56 | $scope.lastPage = Math.ceil( |
| 45 | $scope.filteredEntidades.length / $scope.numPerPage | 57 | $scope.filteredEntidades.length / $scope.numPerPage |
| 46 | ); | 58 | ); |
| 47 | $scope.resetPage(); | 59 | $scope.resetPage(); |
| 48 | }else if(pressed) { | 60 | }else if(pressed) { |
| 49 | $timeout(function() { | 61 | $timeout(function() { |
| 50 | angular.element('#search')[0].focus(); | 62 | angular.element('#search')[0].focus(); |
| 51 | $scope.filters = ''; | 63 | $scope.filters = ''; |
| 52 | }); | 64 | }); |
| 53 | } | 65 | } |
| 54 | }; | 66 | }; |
| 55 | 67 | ||
| 56 | $scope.resetPage = function() { | 68 | $scope.resetPage = function() { |
| 57 | $scope.currentPage = 1; | 69 | $scope.currentPage = 1; |
| 58 | $scope.selectPage(1); | 70 | $scope.selectPage(1); |
| 59 | }; | 71 | }; |
| 60 | 72 | ||
| 61 | $scope.selectPage = function(page) { | 73 | $scope.selectPage = function(page) { |
| 62 | var start = (page - 1) * $scope.numPerPage; | 74 | var start = (page - 1) * $scope.numPerPage; |
| 63 | var end = start + $scope.numPerPage; | 75 | var end = start + $scope.numPerPage; |
| 64 | $scope.paginas = []; | 76 | $scope.paginas = []; |
| 65 | $scope.paginas = calcularPages(page); | 77 | $scope.paginas = calcularPages(page); |
| 66 | $scope.currentPageEntidades = $scope.filteredEntidades.slice(start, end); | 78 | $scope.currentPageEntidades = $scope.filteredEntidades.slice(start, end); |
| 67 | $scope.currentPage = page; | 79 | $scope.currentPage = page; |
| 68 | }; | 80 | }; |
| 69 | 81 | ||
| 70 | $scope.select = function(vendedor) { | 82 | $scope.select = function(vendedor) { |
| 71 | $uibModalInstance.close(vendedor); | 83 | $uibModalInstance.close(vendedor); |
| 72 | }; | 84 | }; |
| 73 | 85 | ||
| 74 | $scope.cancel = function() { | 86 | $scope.cancel = function() { |
| 75 | $uibModalInstance.dismiss('cancel'); | 87 | $uibModalInstance.dismiss('cancel'); |
| 76 | }; | 88 | }; |
| 77 | 89 | ||
| 78 | $scope.busquedaDown = function(key) { | 90 | $scope.busquedaDown = function(key) { |
| 79 | if (key === 40) { | 91 | if (key === 40) { |
| 80 | primera(key); | 92 | primera(key); |
| 81 | } | 93 | } |
| 82 | }; | 94 | }; |
| 83 | 95 | ||
| 84 | $scope.itemEntidad = function(key) { | 96 | $scope.itemEntidad = function(key) { |
| 85 | if (key === 38) { | 97 | if (key === 38) { |
| 86 | anterior(key); | 98 | anterior(key); |
| 87 | } | 99 | } |
| 88 | if (key === 40) { | 100 | if (key === 40) { |
| 89 | siguiente(key); | 101 | siguiente(key); |
| 90 | } | 102 | } |
| 91 | if (key === 37) { | 103 | if (key === 37) { |
| 92 | retrocederPagina(); | 104 | retrocederPagina(); |
| 93 | } | 105 | } |
| 94 | if (key === 39) { | 106 | if (key === 39) { |
| 95 | avanzarPagina(); | 107 | avanzarPagina(); |
| 96 | } | 108 | } |
| 97 | }; | 109 | }; |
| 98 | $scope.esFecha = function(fecha) { | 110 | $scope.esFecha = function(fecha) { |
| 99 | if(fecha.includes('fecha')) { | 111 | if(fecha.includes('fecha')) { |
| 100 | return true; | 112 | return true; |
| 101 | } | 113 | } |
| 102 | return false; | 114 | return false; |
| 103 | } | 115 | } |
| 104 | 116 | ||
| 105 | function calcularPages(paginaActual) { | 117 | function calcularPages(paginaActual) { |
| 106 | var paginas = []; | 118 | var paginas = []; |
| 107 | paginas.push(paginaActual); | 119 | paginas.push(paginaActual); |
| 108 | 120 | ||
| 109 | if (paginaActual - 1 > 1) { | 121 | if (paginaActual - 1 > 1) { |
| 110 | 122 | ||
| 111 | paginas.unshift(paginaActual - 1); | 123 | paginas.unshift(paginaActual - 1); |
| 112 | if (paginaActual - 2 > 1) { | 124 | if (paginaActual - 2 > 1) { |
| 113 | paginas.unshift(paginaActual - 2); | 125 | paginas.unshift(paginaActual - 2); |
| 114 | } | 126 | } |
| 115 | } | 127 | } |
| 116 | if (paginaActual + 1 < $scope.lastPage) { | 128 | if (paginaActual + 1 < $scope.lastPage) { |
| 117 | paginas.push(paginaActual + 1); | 129 | paginas.push(paginaActual + 1); |
| 118 | if (paginaActual + 2 < $scope.lastPage) { | 130 | if (paginaActual + 2 < $scope.lastPage) { |
| 119 | paginas.push(paginaActual + 2); | 131 | paginas.push(paginaActual + 2); |
| 120 | } | 132 | } |
| 121 | } | 133 | } |
| 122 | if (paginaActual !== 1) { | 134 | if (paginaActual !== 1) { |
| 123 | paginas.unshift(1); | 135 | paginas.unshift(1); |
| 124 | } | 136 | } |
| 125 | if (paginaActual !== $scope.lastPage) { | 137 | if (paginaActual !== $scope.lastPage) { |
| 126 | paginas.push($scope.lastPage); | 138 | paginas.push($scope.lastPage); |
| 127 | } | 139 | } |
| 128 | return paginas; | 140 | return paginas; |
| 129 | } | 141 | } |
| 130 | 142 | ||
| 131 | function primera() { | 143 | function primera() { |
| 132 | $scope.selectedEntidad = 0; | 144 | $scope.selectedEntidad = 0; |
| 133 | } | 145 | } |
| 134 | 146 | ||
| 135 | function anterior() { | 147 | function anterior() { |
| 136 | if($scope.selectedEntidad === 0 && $scope.currentPage > 1) { | 148 | if($scope.selectedEntidad === 0 && $scope.currentPage > 1) { |
| 137 | retrocederPagina(); | 149 | retrocederPagina(); |
| 138 | } else { | 150 | } else { |
| 139 | $scope.selectedEntidad--; | 151 | $scope.selectedEntidad--; |
| 140 | } | 152 | } |
| 141 | } | 153 | } |
| 142 | 154 | ||
| 143 | function siguiente() { | 155 | function siguiente() { |
| 144 | if($scope.selectedEntidad < $scope.currentPageEntidades.length - 1) { | 156 | if($scope.selectedEntidad < $scope.currentPageEntidades.length - 1) { |
| 145 | $scope.selectedEntidad++; | 157 | $scope.selectedEntidad++; |
| 146 | } else { | 158 | } else { |
| 147 | avanzarPagina(); | 159 | avanzarPagina(); |
| 148 | } | 160 | } |
| 149 | } | 161 | } |
| 150 | 162 | ||
| 151 | function retrocederPagina() { | 163 | function retrocederPagina() { |
| 152 | if ($scope.currentPage > 1) { | 164 | if ($scope.currentPage > 1) { |
| 153 | $scope.selectPage($scope.currentPage - 1); | 165 | $scope.selectPage($scope.currentPage - 1); |
| 154 | $scope.selectedEntidad = $scope.numPerPage - 1; | 166 | $scope.selectedEntidad = $scope.numPerPage - 1; |
| 155 | } | 167 | } |
| 156 | } | 168 | } |
| 157 | 169 | ||
| 158 | function avanzarPagina() { | 170 | function avanzarPagina() { |
| 159 | if($scope.currentPage < $scope.lastPage) { | 171 | if($scope.currentPage < $scope.lastPage) { |
| 160 | $scope.selectPage($scope.currentPage + 1); | 172 | $scope.selectPage($scope.currentPage + 1); |
| 161 | $scope.selectedEntidad = 0; | 173 | $scope.selectedEntidad = 0; |
| 162 | } | 174 | } |
| 163 | } | 175 | } |
| 164 | }] | 176 | }] |
| 165 | ); | 177 | ); |
| 166 | 178 |
src/views/foca-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 ng-class="(parametrosModal.size == 'md') ? 'col-lg-12' : 'col-lg-6'"> | 3 | <div ng-class="(parametrosModal.size == 'md') ? 'col-lg-12' : 'col-lg-6'"> |
| 4 | <h5 class="modal-title my-1">{{parametrosModal.titulo}}</h5> | 4 | <h5 class="modal-title my-1">{{parametrosModal.titulo}}</h5> |
| 5 | <h6 ng-if="parametrosModal.subTitulo">{{parametrosModal.subTitulo}}</h6> | 5 | <h6 ng-if="parametrosModal.subTitulo">{{parametrosModal.subTitulo}}</h6> |
| 6 | </div> | 6 | </div> |
| 7 | <div class="input-group pr-0 my-2" ng-class="(parametrosModal.size == 'md') ? 'col-lg-12' : 'col-lg-6'"> | 7 | <div class="input-group pr-0 my-2" ng-class="(parametrosModal.size == 'md') ? 'col-lg-12' : 'col-lg-6'"> |
| 8 | <input | 8 | <input |
| 9 | ladda="searchLoading" | 9 | ladda="searchLoading" |
| 10 | type="text" | 10 | type="text" |
| 11 | class="form-control form-control-sm" | 11 | class="form-control form-control-sm" |
| 12 | id="search" | 12 | id="search" |
| 13 | placeholder="Busqueda" | 13 | placeholder="Busqueda" |
| 14 | ng-model="filters" | 14 | ng-model="filters" |
| 15 | ng-change="search()" | 15 | ng-change="search()" |
| 16 | ng-keydown="busquedaDown($event.keyCode)" | 16 | ng-keydown="busquedaDown($event.keyCode)" |
| 17 | ng-keypress="busquedaPress($event.keyCode)" | 17 | ng-keypress="busquedaPress($event.keyCode)" |
| 18 | foca-focus="selectedEntidad == -1" | 18 | foca-focus="selectedEntidad == -1" |
| 19 | ng-focus="selectedEntidad = -1" | 19 | ng-focus="selectedEntidad = -1" |
| 20 | teclado-virtual | 20 | teclado-virtual |
| 21 | > | 21 | > |
| 22 | <div class="input-group-append"> | 22 | <div class="input-group-append"> |
| 23 | <button | 23 | <button |
| 24 | ladda="searchLoading" | 24 | ladda="searchLoading" |
| 25 | data-spinner-color="#FF0000" | 25 | data-spinner-color="#FF0000" |
| 26 | class="btn btn-outline-secondary" | 26 | class="btn btn-outline-secondary" |
| 27 | type="button" | 27 | type="button" |
| 28 | ng-click="busquedaPress(13)" | 28 | ng-click="busquedaPress(13)" |
| 29 | > | 29 | > |
| 30 | <i class="fa fa-search" aria-hidden="true"></i> | 30 | <i class="fa fa-search" aria-hidden="true"></i> |
| 31 | </button> | 31 | </button> |
| 32 | </div> | 32 | </div> |
| 33 | </div> | 33 | </div> |
| 34 | </div> | 34 | </div> |
| 35 | </div> | 35 | </div> |
| 36 | <div class="modal-body" id="modal-body"> | 36 | <div class="modal-body" id="modal-body"> |
| 37 | 37 | ||
| 38 | <div ng-show="!primerBusqueda"> | 38 | <div ng-show="!primerBusqueda"> |
| 39 | Debe realizar una primer búsqueda. | 39 | Debe realizar una primer búsqueda. |
| 40 | </div> | 40 | </div> |
| 41 | 41 | ||
| 42 | <table ng-show="primerBusqueda" class="table table-striped table-sm col-12"> | 42 | <table ng-show="primerBusqueda" class="table table-striped table-sm col-12"> |
| 43 | <thead> | 43 | <thead> |
| 44 | <tr> | 44 | <tr> |
| 45 | <th ng-repeat="nombre in parametrosModal.columnas.nombre" ng-bind="nombre"></th> | 45 | <th ng-repeat="columna in parametrosModal.columnas" ng-bind="columna.nombre"></th> |
| 46 | <th></th> | 46 | <th></th> |
| 47 | </tr> | 47 | </tr> |
| 48 | </thead> | 48 | </thead> |
| 49 | <tbody> | 49 | <tbody> |
| 50 | <tr ng-show="currentPageEntidades.length == 0 && primerBusqueda"> | 50 | <tr ng-show="currentPageEntidades.length == 0 && primerBusqueda"> |
| 51 | <td colspan="3"> | 51 | <td colspan="3"> |
| 52 | No se encontraron resultados. | 52 | No se encontraron resultados. |
| 53 | </td> | 53 | </td> |
| 54 | </tr> | 54 | </tr> |
| 55 | <tr class="selected" | 55 | <tr class="selected" |
| 56 | ng-repeat="(key, entidad) in currentPageEntidades" | 56 | ng-repeat="(key, entidad) in currentPageEntidades" |
| 57 | ng-click="select(entidad)" | 57 | ng-click="select(entidad)" |
| 58 | > | 58 | > |
| 59 | <td | 59 | <td |
| 60 | ng-repeat="propiedad in parametrosModal.columnas.propiedad" | 60 | ng-repeat="columna in parametrosModal.columnas" |
| 61 | ng-bind="entidad[propiedad]"></td> | 61 | ng-bind="entidad[columna.propiedad]"></td> |
| 62 | <td class="d-md-none text-primary"> | 62 | <td class="d-md-none text-primary"> |
| 63 | <i class="fa fa-circle-thin" aria-hidden="true"></i> | 63 | <i class="fa fa-circle-thin" aria-hidden="true"></i> |
| 64 | </td> | 64 | </td> |
| 65 | <td class="d-none d-md-table-cell"> | 65 | <td class="d-none d-md-table-cell"> |
| 66 | <button | 66 | <button |
| 67 | type="button" | 67 | type="button" |
| 68 | class="btn btn-xs p-1 float-right" | 68 | class="btn btn-xs p-1 float-right" |
| 69 | ng-class="{ | 69 | ng-class="{ |
| 70 | 'btn-secondary': selectedEntidad != key, | 70 | 'btn-secondary': selectedEntidad != key, |
| 71 | 'btn-primary': selectedEntidad == key | 71 | 'btn-primary': selectedEntidad == key |
| 72 | }" | 72 | }" |
| 73 | foca-focus="selectedEntidad == {{key}}" | 73 | foca-focus="selectedEntidad == {{key}}" |
| 74 | ng-keydown="itemEntidad($event.keyCode)"> | 74 | ng-keydown="itemEntidad($event.keyCode)"> |
| 75 | <i class="fa fa-circle-thin" aria-hidden="true"></i> | 75 | <i class="fa fa-circle-thin" aria-hidden="true"></i> |
| 76 | </button> | 76 | </button> |
| 77 | </td> | 77 | </td> |
| 78 | </tr> | 78 | </tr> |
| 79 | </tbody> | 79 | </tbody> |
| 80 | </table> | 80 | </table> |
| 81 | </div> | 81 | </div> |
| 82 | <div class="modal-footer py-1"> | 82 | <div class="modal-footer py-1"> |
| 83 | <nav ng-show="currentPageEntidades.length > 0 && primerBusqueda" class="mr-auto"> | 83 | <nav ng-show="currentPageEntidades.length > 0 && primerBusqueda" class="mr-auto"> |
| 84 | <ul class="pagination pagination-sm justify-content mb-0"> | 84 | <ul class="pagination pagination-sm justify-content mb-0"> |
| 85 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | 85 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> |
| 86 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> | 86 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> |
| 87 | <span aria-hidden="true">«</span> | 87 | <span aria-hidden="true">«</span> |
| 88 | <span class="sr-only">Anterior</span> | 88 | <span class="sr-only">Anterior</span> |
| 89 | </a> | 89 | </a> |
| 90 | </li> | 90 | </li> |
| 91 | <li | 91 | <li |
| 92 | class="page-item" | 92 | class="page-item" |
| 93 | ng-repeat="pagina in paginas" | 93 | ng-repeat="pagina in paginas" |
| 94 | ng-class="{'active': pagina == currentPage}" | 94 | ng-class="{'active': pagina == currentPage}" |
| 95 | > | 95 | > |
| 96 | <a | 96 | <a |
| 97 | class="page-link" | 97 | class="page-link" |
| 98 | href="javascript:void();" | 98 | href="javascript:void();" |
| 99 | ng-click="selectPage(pagina)" | 99 | ng-click="selectPage(pagina)" |
| 100 | ng-bind="pagina" | 100 | ng-bind="pagina" |
| 101 | ></a> | 101 | ></a> |
| 102 | </li> | 102 | </li> |
| 103 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | 103 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> |
| 104 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> | 104 | <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> |
| 105 | <span aria-hidden="true">»</span> | 105 | <span aria-hidden="true">»</span> |
| 106 | <span class="sr-only">Siguiente</span> | 106 | <span class="sr-only">Siguiente</span> |
| 107 | </a> | 107 | </a> |
| 108 | </li> | 108 | </li> |
| 109 | </ul> | 109 | </ul> |
| 110 | </nav> | 110 | </nav> |
| 111 | <button class="btn btn-sm btn-secondary my-1" type="button" ng-click="cancel()">Cancelar</button> | 111 | <button class="btn btn-sm btn-secondary my-1" type="button" ng-click="cancel()">Cancelar</button> |
| 112 | </div> | 112 | </div> |
| 113 | 113 |