Commit cb25bbd6d677c85587516850e1d40dd3ba72d4ae
1 parent
89b0e837f4
Exists in
master
agrego parametro size a modal y busca cuando inicia
Showing
2 changed files
with
5 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 | 'columnas', | 8 | 'columnas', |
| 9 | 'query', | 9 | 'query', |
| 10 | 'titulo', | 10 | 'titulo', |
| 11 | function($timeout, $filter, $scope, $uibModalInstance, focaModalService, | 11 | function($timeout, $filter, $scope, $uibModalInstance, focaModalService, |
| 12 | columnas, query, titulo) { | 12 | columnas, query, titulo) { |
| 13 | 13 | ||
| 14 | $scope.filters = ''; | 14 | $scope.filters = ''; |
| 15 | $scope.columnas = columnas; | 15 | $scope.columnas = columnas; |
| 16 | $scope.titulo = titulo; | 16 | $scope.titulo = titulo; |
| 17 | $scope.entidades = []; | 17 | $scope.entidades = []; |
| 18 | $scope.primerBusqueda = false; | 18 | $scope.primerBusqueda = false; |
| 19 | $scope.searchLoading = false; | 19 | $scope.searchLoading = false; |
| 20 | // pagination | 20 | // pagination |
| 21 | $scope.numPerPage = 10; | 21 | $scope.numPerPage = 10; |
| 22 | $scope.currentPage = 1; | 22 | $scope.currentPage = 1; |
| 23 | $scope.filteredEntidades = []; | 23 | $scope.filteredEntidades = []; |
| 24 | $scope.currentPageEntidades = []; | 24 | $scope.currentPageEntidades = []; |
| 25 | $scope.selectedEntidad = -1; | 25 | $scope.selectedEntidad = -1; |
| 26 | 26 | ||
| 27 | $scope.busquedaPress = function(key) { | 27 | $scope.busquedaPress = function(key) { |
| 28 | if(key === 13) { | 28 | if(key === 13) { |
| 29 | $scope.searchLoading = true; | 29 | $scope.searchLoading = true; |
| 30 | focaModalService.getEntidad($scope.filters, query).then( | 30 | focaModalService.getEntidad($scope.filters, query).then( |
| 31 | function(res) { | 31 | function(res) { |
| 32 | $scope.searchLoading = false; | 32 | $scope.searchLoading = false; |
| 33 | $scope.primerBusqueda = true; | 33 | $scope.primerBusqueda = true; |
| 34 | $scope.entidades = res.data; | 34 | $scope.entidades = res.data; |
| 35 | $scope.search(true); | 35 | $scope.search(true); |
| 36 | primera(); | 36 | primera(); |
| 37 | } | 37 | } |
| 38 | ); | 38 | ); |
| 39 | } | 39 | } |
| 40 | }; | 40 | }; |
| 41 | $scope.busquedaPress(13); | ||
| 41 | 42 | ||
| 42 | $scope.search = function(pressed) { | 43 | $scope.search = function(pressed) { |
| 43 | if($scope.entidades.length > 0) { | 44 | if($scope.entidades.length > 0) { |
| 44 | $scope.filteredEntidades = $filter('filter')( | 45 | $scope.filteredEntidades = $filter('filter')( |
| 45 | $scope.entidades, { $: $scope.filters } | 46 | $scope.entidades, { $: $scope.filters } |
| 46 | ); | 47 | ); |
| 47 | $scope.lastPage = Math.ceil( | 48 | $scope.lastPage = Math.ceil( |
| 48 | $scope.filteredEntidades.length / $scope.numPerPage | 49 | $scope.filteredEntidades.length / $scope.numPerPage |
| 49 | ); | 50 | ); |
| 50 | $scope.resetPage(); | 51 | $scope.resetPage(); |
| 51 | }else if(pressed) { | 52 | }else if(pressed) { |
| 52 | $timeout(function() { | 53 | $timeout(function() { |
| 53 | angular.element('#search')[0].focus(); | 54 | angular.element('#search')[0].focus(); |
| 54 | $scope.filters = ''; | 55 | $scope.filters = ''; |
| 55 | }); | 56 | }); |
| 56 | } | 57 | } |
| 57 | }; | 58 | }; |
| 58 | 59 | ||
| 59 | $scope.resetPage = function() { | 60 | $scope.resetPage = function() { |
| 60 | $scope.currentPage = 1; | 61 | $scope.currentPage = 1; |
| 61 | $scope.selectPage(1); | 62 | $scope.selectPage(1); |
| 62 | }; | 63 | }; |
| 63 | 64 | ||
| 64 | $scope.selectPage = function(page) { | 65 | $scope.selectPage = function(page) { |
| 65 | var start = (page - 1) * $scope.numPerPage; | 66 | var start = (page - 1) * $scope.numPerPage; |
| 66 | var end = start + $scope.numPerPage; | 67 | var end = start + $scope.numPerPage; |
| 67 | $scope.paginas = []; | 68 | $scope.paginas = []; |
| 68 | $scope.paginas = calcularPages(page); | 69 | $scope.paginas = calcularPages(page); |
| 69 | $scope.currentPageEntidades = $scope.filteredEntidades.slice(start, end); | 70 | $scope.currentPageEntidades = $scope.filteredEntidades.slice(start, end); |
| 70 | $scope.currentPage = page; | 71 | $scope.currentPage = page; |
| 71 | }; | 72 | }; |
| 72 | 73 | ||
| 73 | $scope.select = function(vendedor) { | 74 | $scope.select = function(vendedor) { |
| 74 | $uibModalInstance.close(vendedor); | 75 | $uibModalInstance.close(vendedor); |
| 75 | }; | 76 | }; |
| 76 | 77 | ||
| 77 | $scope.cancel = function() { | 78 | $scope.cancel = function() { |
| 78 | $uibModalInstance.dismiss('cancel'); | 79 | $uibModalInstance.dismiss('cancel'); |
| 79 | }; | 80 | }; |
| 80 | 81 | ||
| 81 | $scope.busquedaDown = function(key) { | 82 | $scope.busquedaDown = function(key) { |
| 82 | if (key === 40) { | 83 | if (key === 40) { |
| 83 | primera(key); | 84 | primera(key); |
| 84 | } | 85 | } |
| 85 | }; | 86 | }; |
| 86 | 87 | ||
| 87 | $scope.itemEntidad = function(key) { | 88 | $scope.itemEntidad = function(key) { |
| 88 | if (key === 38) { | 89 | if (key === 38) { |
| 89 | anterior(key); | 90 | anterior(key); |
| 90 | } | 91 | } |
| 91 | if (key === 40) { | 92 | if (key === 40) { |
| 92 | siguiente(key); | 93 | siguiente(key); |
| 93 | } | 94 | } |
| 94 | if (key === 37) { | 95 | if (key === 37) { |
| 95 | retrocederPagina(); | 96 | retrocederPagina(); |
| 96 | } | 97 | } |
| 97 | if (key === 39) { | 98 | if (key === 39) { |
| 98 | avanzarPagina(); | 99 | avanzarPagina(); |
| 99 | } | 100 | } |
| 100 | }; | 101 | }; |
| 101 | $scope.esFecha = function(fecha) { | 102 | $scope.esFecha = function(fecha) { |
| 102 | if(fecha.includes('fecha')) { | 103 | if(fecha.includes('fecha')) { |
| 103 | return true; | 104 | return true; |
| 104 | } | 105 | } |
| 105 | return false; | 106 | return false; |
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | function calcularPages(paginaActual) { | 109 | function calcularPages(paginaActual) { |
| 109 | var paginas = []; | 110 | var paginas = []; |
| 110 | paginas.push(paginaActual); | 111 | paginas.push(paginaActual); |
| 111 | 112 | ||
| 112 | if (paginaActual - 1 > 1) { | 113 | if (paginaActual - 1 > 1) { |
| 113 | 114 | ||
| 114 | paginas.unshift(paginaActual - 1); | 115 | paginas.unshift(paginaActual - 1); |
| 115 | if (paginaActual - 2 > 1) { | 116 | if (paginaActual - 2 > 1) { |
| 116 | paginas.unshift(paginaActual - 2); | 117 | paginas.unshift(paginaActual - 2); |
| 117 | } | 118 | } |
| 118 | } | 119 | } |
| 119 | if (paginaActual + 1 < $scope.lastPage) { | 120 | if (paginaActual + 1 < $scope.lastPage) { |
| 120 | paginas.push(paginaActual + 1); | 121 | paginas.push(paginaActual + 1); |
| 121 | if (paginaActual + 2 < $scope.lastPage) { | 122 | if (paginaActual + 2 < $scope.lastPage) { |
| 122 | paginas.push(paginaActual + 2); | 123 | paginas.push(paginaActual + 2); |
| 123 | } | 124 | } |
| 124 | } | 125 | } |
| 125 | if (paginaActual !== 1) { | 126 | if (paginaActual !== 1) { |
| 126 | paginas.unshift(1); | 127 | paginas.unshift(1); |
| 127 | } | 128 | } |
| 128 | if (paginaActual !== $scope.lastPage) { | 129 | if (paginaActual !== $scope.lastPage) { |
| 129 | paginas.push($scope.lastPage); | 130 | paginas.push($scope.lastPage); |
| 130 | } | 131 | } |
| 131 | return paginas; | 132 | return paginas; |
| 132 | } | 133 | } |
| 133 | 134 | ||
| 134 | function primera() { | 135 | function primera() { |
| 135 | $scope.selectedEntidad = 0; | 136 | $scope.selectedEntidad = 0; |
| 136 | } | 137 | } |
| 137 | 138 | ||
| 138 | function anterior() { | 139 | function anterior() { |
| 139 | if($scope.selectedEntidad === 0 && $scope.currentPage > 1) { | 140 | if($scope.selectedEntidad === 0 && $scope.currentPage > 1) { |
| 140 | retrocederPagina(); | 141 | retrocederPagina(); |
| 141 | } else { | 142 | } else { |
| 142 | $scope.selectedEntidad--; | 143 | $scope.selectedEntidad--; |
| 143 | } | 144 | } |
| 144 | } | 145 | } |
| 145 | 146 | ||
| 146 | function siguiente() { | 147 | function siguiente() { |
| 147 | if($scope.selectedEntidad < $scope.currentPageEntidades.length - 1) { | 148 | if($scope.selectedEntidad < $scope.currentPageEntidades.length - 1) { |
| 148 | $scope.selectedEntidad++; | 149 | $scope.selectedEntidad++; |
| 149 | } else { | 150 | } else { |
| 150 | avanzarPagina(); | 151 | avanzarPagina(); |
| 151 | } | 152 | } |
| 152 | } | 153 | } |
| 153 | 154 | ||
| 154 | function retrocederPagina() { | 155 | function retrocederPagina() { |
| 155 | if ($scope.currentPage > 1) { | 156 | if ($scope.currentPage > 1) { |
| 156 | $scope.selectPage($scope.currentPage - 1); | 157 | $scope.selectPage($scope.currentPage - 1); |
| 157 | $scope.selectedEntidad = $scope.numPerPage - 1; | 158 | $scope.selectedEntidad = $scope.numPerPage - 1; |
| 158 | } | 159 | } |
| 159 | } | 160 | } |
| 160 | 161 | ||
| 161 | function avanzarPagina() { | 162 | function avanzarPagina() { |
| 162 | if($scope.currentPage < $scope.lastPage) { | 163 | if($scope.currentPage < $scope.lastPage) { |
| 163 | $scope.selectPage($scope.currentPage + 1); | 164 | $scope.selectPage($scope.currentPage + 1); |
| 164 | $scope.selectedEntidad = 0; | 165 | $scope.selectedEntidad = 0; |
| 165 | } | 166 | } |
| 166 | } | 167 | } |
| 167 | }] | 168 | }] |
| 168 | ); | 169 | ); |
| 169 | 170 |
src/js/service.js
| 1 | angular.module('focaModal') | 1 | angular.module('focaModal') |
| 2 | .service('focaModalService', [ | 2 | .service('focaModalService', [ |
| 3 | '$uibModal', 'API_ENDPOINT', '$http', | 3 | '$uibModal', 'API_ENDPOINT', '$http', |
| 4 | function($uibModal, API_ENDPOINT, $http) { | 4 | function($uibModal, API_ENDPOINT, $http) { |
| 5 | return { | 5 | return { |
| 6 | confirm: function(textoModal) { | 6 | confirm: function(textoModal) { |
| 7 | return $uibModal.open({ | 7 | return $uibModal.open({ |
| 8 | templateUrl: 'modal-confirm.html', | 8 | templateUrl: 'modal-confirm.html', |
| 9 | controller: 'focaModalConfirmController', | 9 | controller: 'focaModalConfirmController', |
| 10 | animation: false, | 10 | animation: false, |
| 11 | backdrop: false, | 11 | backdrop: false, |
| 12 | resolve: { textoModal: function() { return textoModal; } } | 12 | resolve: { textoModal: function() { return textoModal; } } |
| 13 | }) | 13 | }) |
| 14 | .result.then( | 14 | .result.then( |
| 15 | function(resultado) { | 15 | function(resultado) { |
| 16 | return resultado; | 16 | return resultado; |
| 17 | } | 17 | } |
| 18 | ); | 18 | ); |
| 19 | }, | 19 | }, |
| 20 | alert: function(textoModal) { | 20 | alert: function(textoModal) { |
| 21 | return $uibModal.open({ | 21 | return $uibModal.open({ |
| 22 | templateUrl: 'modal-alert.html', | 22 | templateUrl: 'modal-alert.html', |
| 23 | controller: 'focaModalAlertController', | 23 | controller: 'focaModalAlertController', |
| 24 | animation: false, | 24 | animation: false, |
| 25 | backdrop: false, | 25 | backdrop: false, |
| 26 | resolve: { textoModal: function() { return textoModal; } } | 26 | resolve: { textoModal: function() { return textoModal; } } |
| 27 | }) | 27 | }) |
| 28 | .result.then( | 28 | .result.then( |
| 29 | function(resultado) { | 29 | function(resultado) { |
| 30 | return resultado; | 30 | return resultado; |
| 31 | } | 31 | } |
| 32 | ); | 32 | ); |
| 33 | }, | 33 | }, |
| 34 | modal: function(columnas, query, titulo) { | 34 | modal: function(columnas, query, titulo, size) { |
| 35 | size = (typeof size === 'undefined') ? 'lg' : size; | ||
| 36 | |||
| 35 | return $uibModal.open({ | 37 | return $uibModal.open({ |
| 36 | templateUrl: 'foca-modal.html', | 38 | templateUrl: 'foca-modal.html', |
| 37 | controller: 'focaModalController', | 39 | controller: 'focaModalController', |
| 38 | size: 'lg', | 40 | size: size, |
| 39 | resolve: { | 41 | resolve: { |
| 40 | columnas: function() { return columnas; }, | 42 | columnas: function() { return columnas; }, |
| 41 | query: function() { return query; }, | 43 | query: function() { return query; }, |
| 42 | titulo: function() {return titulo;} | 44 | titulo: function() {return titulo;} |
| 43 | } | 45 | } |
| 44 | }) | 46 | }) |
| 45 | .result.then( | 47 | .result.then( |
| 46 | function(resultado) { | 48 | function(resultado) { |
| 47 | return resultado; | 49 | return resultado; |
| 48 | } | 50 | } |
| 49 | ); | 51 | ); |
| 50 | }, | 52 | }, |
| 51 | getEntidad: function(filters, query) { | 53 | getEntidad: function(filters, query) { |
| 52 | return $http.get(API_ENDPOINT.URL + query, {nombre: filters}); | 54 | return $http.get(API_ENDPOINT.URL + query, {nombre: filters}); |
| 53 | }, | 55 | }, |
| 54 | modalFecha: function(titulo) { | 56 | modalFecha: function(titulo) { |
| 55 | return $uibModal.open({ | 57 | return $uibModal.open({ |
| 56 | templateUrl: 'foca-fecha.html', | 58 | templateUrl: 'foca-fecha.html', |
| 57 | controller: 'focaModalFechaController', | 59 | controller: 'focaModalFechaController', |
| 58 | size: 'md', | 60 | size: 'md', |
| 59 | resolve: { | 61 | resolve: { |
| 60 | titulo: function() {return titulo;} | 62 | titulo: function() {return titulo;} |
| 61 | } | 63 | } |
| 62 | }) | 64 | }) |
| 63 | .result.then( | 65 | .result.then( |
| 64 | function(resultado) { | 66 | function(resultado) { |
| 65 | return resultado; | 67 | return resultado; |
| 66 | } | 68 | } |
| 67 | ); | 69 | ); |
| 68 | }, | 70 | }, |
| 69 | prompt: function(titulo, initValue){ | 71 | prompt: function(titulo, initValue){ |
| 70 | return $uibModal.open({ | 72 | return $uibModal.open({ |
| 71 | templateUrl: 'modal-prompt.html', | 73 | templateUrl: 'modal-prompt.html', |
| 72 | controller: 'focaModalPromptController', | 74 | controller: 'focaModalPromptController', |
| 73 | size: 'md', | 75 | size: 'md', |
| 74 | resolve: { | 76 | resolve: { |
| 75 | titulo: function() {return titulo;}, | 77 | titulo: function() {return titulo;}, |
| 76 | initValue: function() {return initValue;} | 78 | initValue: function() {return initValue;} |
| 77 | } | 79 | } |
| 78 | }) | 80 | }) |
| 79 | .result.then( | 81 | .result.then( |
| 80 | function(resultado) { | 82 | function(resultado) { |
| 81 | return resultado; | 83 | return resultado; |
| 82 | } | 84 | } |
| 83 | ); | 85 | ); |
| 84 | } | 86 | } |
| 85 | }; | 87 | }; |
| 86 | } | 88 | } |
| 87 | ]); | 89 | ]); |
| 88 | 90 |