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