Commit 8cc9a9728d9daf14e6f5cf5862a1b65ee84778cd

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

See merge request !16
src/js/controller.js
1 angular.module('focaModal') 1 angular.module('focaModal')
2 .controller('focaModalConfirmController', [ 2 .controller('focaModalConfirmController', [
3 '$uibModalInstance', '$scope', 'textoModal', 3 '$uibModalInstance', '$scope', 'textoModal',
4 function($uibModalInstance, $scope, textoModal) { 4 function($uibModalInstance, $scope, textoModal) {
5 $scope.textoModal = textoModal; 5 $scope.textoModal = textoModal;
6 $scope.cancelar = function() { 6 $scope.cancelar = function() {
7 $uibModalInstance.dismiss(false); 7 $uibModalInstance.dismiss(false);
8 }; 8 };
9 $scope.aceptar = function() { 9 $scope.aceptar = function() {
10 $uibModalInstance.close(true); 10 $uibModalInstance.close(true);
11 }; 11 };
12 } 12 }
13 ]) 13 ])
14 .controller('focaModalAlertController', [ 14 .controller('focaModalAlertController', [
15 '$uibModalInstance', '$scope', 'textoModal', 15 '$uibModalInstance', '$scope', 'textoModal',
16 function($uibModalInstance, $scope, textoModal) { 16 function($uibModalInstance, $scope, textoModal) {
17 $scope.textoModal = textoModal; 17 $scope.textoModal = textoModal;
18 $scope.aceptar = function() { 18 $scope.aceptar = function() {
19 $uibModalInstance.close(true); 19 $uibModalInstance.close(true);
20 }; 20 };
21 } 21 }
22 ]) 22 ])
23 .controller('focaModalFechaController', [ 23 .controller('focaModalFechaController', [
24 '$uibModalInstance', '$scope', 'titulo', 24 '$uibModalInstance', '$scope', 'titulo',
25 function($uibModalInstance, $scope, titulo) { 25 function($uibModalInstance, $scope, titulo) {
26 $scope.titulo = titulo; 26 $scope.titulo = titulo;
27 $scope.fecha = new Date(); 27 $scope.fecha = new Date();
28 $scope.cancelar = function() { 28 $scope.cancelar = function() {
29 $uibModalInstance.dismiss(); 29 $uibModalInstance.dismiss();
30 }; 30 };
31 $scope.aceptar = function() { 31 $scope.aceptar = function() {
32 $uibModalInstance.close($scope.fecha); 32 $uibModalInstance.close($scope.fecha);
33 }; 33 };
34 } 34 }
35 ]) 35 ])
36 .controller('focaModalPromptController', [ 36 .controller('focaModalPromptController', [
37 '$uibModalInstance', '$scope', 'titulo', 'initValue', 'textarea', 'readonly', 37 '$uibModalInstance', '$scope', 'options', 'focaModalService',
38 function($uibModalInstance, $scope, titulo, initValue, textarea, readonly) { 38 function($uibModalInstance, $scope, options, focaModalService) {
39 $scope.readonly = readonly; 39
40 $scope.textarea = textarea; 40 $scope.options = options;
41 $scope.titulo = titulo;
42 $scope.value = initValue;
43 $scope.cancelar = function() { 41 $scope.cancelar = function() {
44 $uibModalInstance.dismiss(); 42 $uibModalInstance.dismiss();
45 }; 43 };
46 $scope.aceptar = function() { 44 $scope.aceptar = function(key) {
47 $uibModalInstance.close($scope.value); 45 if (key === 13) {
46 if (options.email && !validateEmails($scope.options.value)) {
47 focaModalService.alert('Ingrese email/s válido/s');
48 return;
49 }
50
51 $uibModalInstance.close($scope.options.value);
52 }
48 }; 53 };
54
55 function validateEmails(emails) {
56 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
57 var arr = emails.split(',');
58 var result = true;
59
60 arr.forEach(function(email) {
61 var val = String(email).trim().toLowerCase();
62
63 if(!re.test(val)) result = false;
64 });
65
66 return result;
67 }
49 } 68 }
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 if (parametrosModal.query) { 26 if (parametrosModal.query) {
27 focaModalService.getEntidad( 27 focaModalService.getEntidad(
28 $scope.filters, 28 $scope.filters,
29 parametrosModal.query, 29 parametrosModal.query,
30 parametrosModal.tipo, 30 parametrosModal.tipo,
31 parametrosModal.json 31 parametrosModal.json
32 ).then( 32 ).then(
33 function(res) { 33 function(res) {
34 $scope.searchLoading = false; 34 $scope.searchLoading = false;
35 $scope.primerBusqueda = true; 35 $scope.primerBusqueda = true;
36 $scope.entidades = res.data; 36 $scope.entidades = res.data;
37 filtros($scope.entidades); 37 filtros($scope.entidades);
38 $scope.search(true); 38 $scope.search(true);
39 } 39 }
40 ); 40 );
41 } else { 41 } else {
42 $scope.searchLoading = false; 42 $scope.searchLoading = false;
43 $scope.primerBusqueda = true; 43 $scope.primerBusqueda = true;
44 $scope.entidades = parametrosModal.data; 44 $scope.entidades = parametrosModal.data;
45 filtros($scope.entidades); 45 filtros($scope.entidades);
46 $scope.search(true); 46 $scope.search(true);
47 } 47 }
48 } 48 }
49 }; 49 };
50 function filtros(entidades) { 50 function filtros(entidades) {
51 for (var i = 0; i < $scope.parametrosModal.columnas.length; i++) { 51 for (var i = 0; i < $scope.parametrosModal.columnas.length; i++) {
52 var filtro = $scope.parametrosModal.columnas[i].filtro; 52 var filtro = $scope.parametrosModal.columnas[i].filtro;
53 if (filtro) { 53 if (filtro) {
54 if (filtro.nombre === 'comprobante') { 54 if (filtro.nombre === 'comprobante') {
55 for (var j = 0; j < entidades.length; j++) { 55 for (var j = 0; j < entidades.length; j++) {
56 var array = []; 56 var array = [];
57 $scope.parametrosModal.columnas[i].propiedad 57 $scope.parametrosModal.columnas[i].propiedad
58 .forEach(function(prop) { 58 .forEach(function(prop) {
59 array.push(entidades[j][prop]); 59 array.push(entidades[j][prop]);
60 }); 60 });
61 entidades[j][$scope.parametrosModal.columnas[i].propiedad] = 61 entidades[j][$scope.parametrosModal.columnas[i].propiedad] =
62 $filter('comprobante')(array); 62 $filter('comprobante')(array);
63 } 63 }
64 } else { 64 } else {
65 for (var j = 0; j < entidades.length; j++) { 65 for (var j = 0; j < entidades.length; j++) {
66 entidades[j][$scope.parametrosModal.columnas[i].propiedad] = 66 entidades[j][$scope.parametrosModal.columnas[i].propiedad] =
67 $filter(filtro.nombre)(entidades[j][$scope 67 $filter(filtro.nombre)(entidades[j][$scope
68 .parametrosModal.columnas[i].propiedad], filtro.parametro); 68 .parametrosModal.columnas[i].propiedad], filtro.parametro);
69 } 69 }
70 } 70 }
71 } 71 }
72 } 72 }
73 } 73 }
74 $scope.search = function(pressed) { 74 $scope.search = function(pressed) {
75 if($scope.entidades.length > 0) { 75 if($scope.entidades.length > 0) {
76 $scope.filteredEntidades = $filter('filter')( 76 $scope.filteredEntidades = $filter('filter')(
77 $scope.entidades, { $: $scope.filters } 77 $scope.entidades, { $: $scope.filters }
78 ); 78 );
79 $scope.lastPage = Math.ceil( 79 $scope.lastPage = Math.ceil(
80 $scope.filteredEntidades.length / $scope.numPerPage 80 $scope.filteredEntidades.length / $scope.numPerPage
81 ); 81 );
82 $scope.resetPage(); 82 $scope.resetPage();
83 }else if(pressed) { 83 }else if(pressed) {
84 $timeout(function() { 84 $timeout(function() {
85 angular.element('#search')[0].focus(); 85 angular.element('#search')[0].focus();
86 $scope.filters = ''; 86 $scope.filters = '';
87 }); 87 });
88 } 88 }
89 }; 89 };
90 90
91 $scope.resetPage = function() { 91 $scope.resetPage = function() {
92 $scope.currentPage = 1; 92 $scope.currentPage = 1;
93 $scope.selectPage(1); 93 $scope.selectPage(1);
94 }; 94 };
95 95
96 $scope.selectPage = function(page) { 96 $scope.selectPage = function(page) {
97 var start = (page - 1) * $scope.numPerPage; 97 var start = (page - 1) * $scope.numPerPage;
98 var end = start + $scope.numPerPage; 98 var end = start + $scope.numPerPage;
99 $scope.paginas = []; 99 $scope.paginas = [];
100 $scope.paginas = calcularPages(page); 100 $scope.paginas = calcularPages(page);
101 $scope.currentPageEntidades = $scope.filteredEntidades.slice(start, end); 101 $scope.currentPageEntidades = $scope.filteredEntidades.slice(start, end);
102 $scope.currentPage = page; 102 $scope.currentPage = page;
103 }; 103 };
104 104
105 $scope.select = function(vendedor) { 105 $scope.select = function(vendedor) {
106 $uibModalInstance.close(vendedor); 106 $uibModalInstance.close(vendedor);
107 }; 107 };
108 108
109 $scope.cancel = function() { 109 $scope.cancel = function() {
110 $uibModalInstance.dismiss('cancel'); 110 $uibModalInstance.dismiss('cancel');
111 }; 111 };
112 112
113 $scope.busquedaDown = function(key) { 113 $scope.busquedaDown = function(key) {
114 if (key === 40) { 114 if (key === 40) {
115 primera(key); 115 primera(key);
116 } 116 }
117 }; 117 };
118 118
119 $scope.itemEntidad = function(key) { 119 $scope.itemEntidad = function(key) {
120 if (key === 38) { 120 if (key === 38) {
121 anterior(key); 121 anterior(key);
122 } 122 }
123 if (key === 40) { 123 if (key === 40) {
124 siguiente(key); 124 siguiente(key);
125 } 125 }
126 if (key === 37) { 126 if (key === 37) {
127 retrocederPagina(); 127 retrocederPagina();
128 } 128 }
129 if (key === 39) { 129 if (key === 39) {
130 avanzarPagina(); 130 avanzarPagina();
131 } 131 }
132 }; 132 };
133 $scope.esFecha = function(fecha) { 133 $scope.esFecha = function(fecha) {
134 if(fecha.includes('fecha')) { 134 if(fecha.includes('fecha')) {
135 return true; 135 return true;
136 } 136 }
137 return false; 137 return false;
138 } 138 };
139 139
140 function calcularPages(paginaActual) { 140 function calcularPages(paginaActual) {
141 var paginas = []; 141 var paginas = [];
142 paginas.push(paginaActual); 142 paginas.push(paginaActual);
143 143
144 if (paginaActual - 1 > 1) { 144 if (paginaActual - 1 > 1) {
145 145
146 paginas.unshift(paginaActual - 1); 146 paginas.unshift(paginaActual - 1);
147 if (paginaActual - 2 > 1) { 147 if (paginaActual - 2 > 1) {
148 paginas.unshift(paginaActual - 2); 148 paginas.unshift(paginaActual - 2);
149 } 149 }
150 } 150 }
151 if (paginaActual + 1 < $scope.lastPage) { 151 if (paginaActual + 1 < $scope.lastPage) {
152 paginas.push(paginaActual + 1); 152 paginas.push(paginaActual + 1);
153 if (paginaActual + 2 < $scope.lastPage) { 153 if (paginaActual + 2 < $scope.lastPage) {
154 paginas.push(paginaActual + 2); 154 paginas.push(paginaActual + 2);
155 } 155 }
156 } 156 }
157 if (paginaActual !== 1) { 157 if (paginaActual !== 1) {
158 paginas.unshift(1); 158 paginas.unshift(1);
159 } 159 }
160 if (paginaActual !== $scope.lastPage) { 160 if (paginaActual !== $scope.lastPage) {
161 paginas.push($scope.lastPage); 161 paginas.push($scope.lastPage);
162 } 162 }
163 return paginas; 163 return paginas;
164 } 164 }
165 165
166 function primera() { 166 function primera() {
167 $scope.selectedEntidad = 0; 167 $scope.selectedEntidad = 0;
168 } 168 }
169 169
170 function anterior() { 170 function anterior() {
171 if($scope.selectedEntidad === 0 && $scope.currentPage > 1) { 171 if($scope.selectedEntidad === 0 && $scope.currentPage > 1) {
172 retrocederPagina(); 172 retrocederPagina();
173 } else { 173 } else {
174 $scope.selectedEntidad--; 174 $scope.selectedEntidad--;
175 } 175 }
176 } 176 }
177 177
178 function siguiente() { 178 function siguiente() {
179 if($scope.selectedEntidad < $scope.currentPageEntidades.length - 1) { 179 if($scope.selectedEntidad < $scope.currentPageEntidades.length - 1) {
180 $scope.selectedEntidad++; 180 $scope.selectedEntidad++;
181 } else { 181 } else {
182 avanzarPagina(); 182 avanzarPagina();
183 } 183 }
184 } 184 }
185 185
186 function retrocederPagina() { 186 function retrocederPagina() {
187 if ($scope.currentPage > 1) { 187 if ($scope.currentPage > 1) {
188 $scope.selectPage($scope.currentPage - 1); 188 $scope.selectPage($scope.currentPage - 1);
189 $scope.selectedEntidad = $scope.numPerPage - 1; 189 $scope.selectedEntidad = $scope.numPerPage - 1;
190 } 190 }
191 } 191 }
192 192
193 function avanzarPagina() { 193 function avanzarPagina() {
194 if($scope.currentPage < $scope.lastPage) { 194 if($scope.currentPage < $scope.lastPage) {
195 $scope.selectPage($scope.currentPage + 1); 195 $scope.selectPage($scope.currentPage + 1);
196 $scope.selectedEntidad = 0; 196 $scope.selectedEntidad = 0;
197 } 197 }
198 } 198 }
199 $scope.busquedaPress(13); 199 $scope.busquedaPress(13);
200 }] 200 }]
201 ); 201 );
202 202
1 angular.module('focaModal') 1 angular.module('focaModal')
2 .factory('focaModalService', [ 2 .factory('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(parametrosModal) { 34 modal: function(parametrosModal) {
35 parametrosModal.size = (typeof parametrosModal.size === 'undefined') ? 35 parametrosModal.size = (typeof parametrosModal.size === 'undefined') ?
36 'lg' : parametrosModal.size; 36 'lg' : parametrosModal.size;
37 37
38 return $uibModal.open({ 38 return $uibModal.open({
39 templateUrl: 'foca-modal.html', 39 templateUrl: 'foca-modal.html',
40 controller: 'focaModalController', 40 controller: 'focaModalController',
41 size: parametrosModal.size, 41 size: parametrosModal.size,
42 resolve: { 42 resolve: {
43 parametrosModal: function() { return parametrosModal; } 43 parametrosModal: function() { return parametrosModal; }
44 } 44 }
45 }) 45 })
46 .result.then( 46 .result.then(
47 function(resultado) { 47 function(resultado) {
48 return resultado; 48 return resultado;
49 } 49 }
50 ); 50 );
51 }, 51 },
52 getEntidad: function(filters, query, tipo, json) { 52 getEntidad: function(filters, query, tipo, json) {
53 if (tipo === 'POST') { 53 if (tipo === 'POST') {
54 return $http.post(API_ENDPOINT.URL + query, json); 54 return $http.post(API_ENDPOINT.URL + query, json);
55 } else { 55 } else {
56 return $http.get(API_ENDPOINT.URL + query, {nombre: filters}); 56 return $http.get(API_ENDPOINT.URL + query, {nombre: filters});
57 } 57 }
58 }, 58 },
59 modalFecha: function(titulo) { 59 modalFecha: function(titulo) {
60 return $uibModal.open({ 60 return $uibModal.open({
61 templateUrl: 'foca-fecha.html', 61 templateUrl: 'foca-fecha.html',
62 controller: 'focaModalFechaController', 62 controller: 'focaModalFechaController',
63 size: 'md', 63 size: 'md',
64 resolve: { 64 resolve: {
65 titulo: function() {return titulo;} 65 titulo: function() {return titulo;}
66 } 66 }
67 }) 67 })
68 .result.then( 68 .result.then(
69 function(resultado) { 69 function(resultado) {
70 return resultado; 70 return resultado;
71 } 71 }
72 ); 72 );
73 }, 73 },
74 prompt: function(titulo, initValue, textarea, readonly){ 74 prompt: function(options) {
75 textarea = textarea ? true : false;
76 readonly = readonly ? true : false;
77 return $uibModal.open({ 75 return $uibModal.open({
78 templateUrl: 'modal-prompt.html', 76 templateUrl: 'modal-prompt.html',
79 controller: 'focaModalPromptController', 77 controller: 'focaModalPromptController',
80 size: 'md', 78 size: 'md',
81 resolve: { 79 resolve: {
82 titulo: function() {return titulo;}, 80 options: function() {return options;},
83 initValue: function() {return initValue;},
84 textarea: function() {return textarea;},
85 readonly: function() {return readonly;}
86 } 81 }
87 }) 82 })
88 .result.then( 83 .result.then(
89 function(resultado) { 84 function(resultado) {
90 return resultado; 85 return resultado;
91 } 86 }
92 ); 87 );
93 } 88 }
94 }; 89 };
95 } 90 }
96 ]); 91 ]);
97 92
src/views/modal-prompt.html
1 <div class="modal-header"> 1 <div class="modal-header">
2 <h4 ng-bind="titulo"></h4> 2 <h4 ng-bind="options.titulo"></h4>
3 </div> 3 </div>
4 <div class="modal-body"> 4 <div class="modal-body">
5 <input 5 <input
6 type="text" 6 type="text"
7 class="form-control" 7 class="form-control"
8 ng-model="value" 8 ng-model="options.value"
9 ng-show="!textarea" 9 ng-show="!options.textarea"
10 ng-readonly="readonly"> 10 ng-readonly="options.readonly"
11 ng-keypress="aceptar($event.keyCode)">
11 12
12 <textarea 13 <textarea
13 rows="5" 14 rows="5"
14 class="form-control text-uppercase" 15 class="form-control text-uppercase"
15 ng-model="value" 16 ng-model="options.value"
16 ng-show="textarea" 17 ng-show="options.textarea"
17 ng-readonly="readonly"></textarea> 18 ng-readonly="options.readonly"
19 ng-keypress="aceptar($event.keyCode)"></textarea>
18 </div> 20 </div>
19 <div class="modal-footer"> 21 <div class="modal-footer">
20 <button class="btn btn-primary" ng-click="aceptar()" foca-focus="true">Aceptar</button> 22 <button class="btn btn-primary" ng-click="aceptar(13)" foca-focus="true">Aceptar</button>
21 <button class="btn btn-default" ng-click="cancelar()">Cancelar</button> 23 <button class="btn btn-default" ng-click="cancelar()">Cancelar</button>
22 </div> 24 </div>
23 25