Commit 3add07f9c438980359d5b2d123434bc9ef7ee4f8

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'develop' into 'master'

Develop

See merge request !21
src/js/controller.js
... ... @@ -21,10 +21,14 @@ angular.module('focaModal')
21 21 }
22 22 ])
23 23 .controller('focaModalFechaController', [
24   - '$uibModalInstance', '$scope', 'titulo',
25   - function($uibModalInstance, $scope, titulo) {
26   - $scope.titulo = titulo;
  24 + '$uibModalInstance', '$scope', 'parametros',
  25 + function($uibModalInstance, $scope, parametros) {
  26 + $scope.parametros = parametros;
27 27 $scope.fecha = new Date();
  28 + $scope.options = {};
  29 +
  30 + if (parametros.minDate) $scope.options.minDate = parametros.minDate;
  31 +
28 32 $scope.cancelar = function() {
29 33 $uibModalInstance.dismiss();
30 34 };
... ... @@ -34,17 +38,35 @@ angular.module('focaModal')
34 38 }
35 39 ])
36 40 .controller('focaModalPromptController', [
37   - '$uibModalInstance', '$scope', 'titulo', 'initValue', 'textarea', 'readonly',
38   - function($uibModalInstance, $scope, titulo, initValue, textarea, readonly) {
39   - $scope.readonly = readonly;
40   - $scope.textarea = textarea;
41   - $scope.titulo = titulo;
42   - $scope.value = initValue;
  41 + '$uibModalInstance', '$scope', 'options', 'focaModalService',
  42 + function($uibModalInstance, $scope, options, focaModalService) {
  43 +
  44 + $scope.options = options;
43 45 $scope.cancelar = function() {
44 46 $uibModalInstance.dismiss();
45 47 };
46   - $scope.aceptar = function() {
47   - $uibModalInstance.close($scope.value);
  48 + $scope.aceptar = function(key) {
  49 + if (key === 13) {
  50 + if (options.email && !validateEmails($scope.options.value)) {
  51 + focaModalService.alert('Ingrese email/s válido/s');
  52 + return;
  53 + }
  54 + $uibModalInstance.close($scope.options.value);
  55 + }
48 56 };
  57 +
  58 + function validateEmails(emails) {
  59 + 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,}))$/;
  60 + var arr = emails.split(',');
  61 + var result = true;
  62 +
  63 + arr.forEach(function(email) {
  64 + var val = String(email).trim().toLowerCase();
  65 +
  66 + if (!re.test(val)) result = false;
  67 + });
  68 +
  69 + return result;
  70 + }
49 71 }
50 72 ]);
src/js/controllerModal.js
... ... @@ -9,7 +9,7 @@ angular.module(&#39;focaModal&#39;)
9 9 function($timeout, $filter, $scope, $uibModalInstance, focaModalService, parametrosModal) {
10 10  
11 11 $scope.parametrosModal = parametrosModal;
12   - $scope.filters = '';
  12 + $scope.filters = parametrosModal.searchText || '';
13 13 $scope.entidades = [];
14 14 $scope.primerBusqueda = false;
15 15 $scope.searchLoading = false;
... ... @@ -21,7 +21,7 @@ angular.module(&#39;focaModal&#39;)
21 21 $scope.selectedEntidad = -1;
22 22  
23 23 $scope.busquedaPress = function(key) {
24   - if(key === 13) {
  24 + if (key === 13) {
25 25 $scope.searchLoading = true;
26 26 if (parametrosModal.query) {
27 27 focaModalService.getEntidad(
... ... @@ -72,7 +72,7 @@ angular.module(&#39;focaModal&#39;)
72 72 }
73 73 }
74 74 $scope.search = function(pressed) {
75   - if($scope.entidades.length > 0) {
  75 + if ($scope.entidades.length > 0) {
76 76 $scope.filteredEntidades = $filter('filter')(
77 77 $scope.entidades, { $: $scope.filters }
78 78 );
... ... @@ -80,7 +80,7 @@ angular.module(&#39;focaModal&#39;)
80 80 $scope.filteredEntidades.length / $scope.numPerPage
81 81 );
82 82 $scope.resetPage();
83   - }else if(pressed) {
  83 + } else if (pressed) {
84 84 $timeout(function() {
85 85 angular.element('#search')[0].focus();
86 86 $scope.filters = '';
... ... @@ -131,11 +131,11 @@ angular.module(&#39;focaModal&#39;)
131 131 }
132 132 };
133 133 $scope.esFecha = function(fecha) {
134   - if(fecha.includes('fecha')) {
  134 + if (fecha.includes('fecha')) {
135 135 return true;
136 136 }
137 137 return false;
138   - }
  138 + };
139 139  
140 140 function calcularPages(paginaActual) {
141 141 var paginas = [];
... ... @@ -168,7 +168,7 @@ angular.module(&#39;focaModal&#39;)
168 168 }
169 169  
170 170 function anterior() {
171   - if($scope.selectedEntidad === 0 && $scope.currentPage > 1) {
  171 + if ($scope.selectedEntidad === 0 && $scope.currentPage > 1) {
172 172 retrocederPagina();
173 173 } else {
174 174 $scope.selectedEntidad--;
... ... @@ -191,7 +191,7 @@ angular.module(&#39;focaModal&#39;)
191 191 }
192 192  
193 193 function avanzarPagina() {
194   - if($scope.currentPage < $scope.lastPage) {
  194 + if ($scope.currentPage < $scope.lastPage) {
195 195 $scope.selectPage($scope.currentPage + 1);
196 196 $scope.selectedEntidad = 0;
197 197 }
... ... @@ -56,13 +56,13 @@ angular.module(&#39;focaModal&#39;)
56 56 return $http.get(API_ENDPOINT.URL + query, {nombre: filters});
57 57 }
58 58 },
59   - modalFecha: function(titulo) {
  59 + modalFecha: function(parametros) {
60 60 return $uibModal.open({
61 61 templateUrl: 'foca-fecha.html',
62 62 controller: 'focaModalFechaController',
63 63 size: 'md',
64 64 resolve: {
65   - titulo: function() {return titulo;}
  65 + parametros: function() { return parametros; }
66 66 }
67 67 })
68 68 .result.then(
... ... @@ -71,18 +71,13 @@ angular.module(&#39;focaModal&#39;)
71 71 }
72 72 );
73 73 },
74   - prompt: function(titulo, initValue, textarea, readonly){
75   - textarea = textarea ? true : false;
76   - readonly = readonly ? true : false;
  74 + prompt: function(options) {
77 75 return $uibModal.open({
78 76 templateUrl: 'modal-prompt.html',
79 77 controller: 'focaModalPromptController',
80 78 size: 'md',
81 79 resolve: {
82   - titulo: function() {return titulo;},
83   - initValue: function() {return initValue;},
84   - textarea: function() {return textarea;},
85   - readonly: function() {return readonly;}
  80 + options: function() {return options;},
86 81 }
87 82 })
88 83 .result.then(
src/views/foca-fecha.html
1 1 <div class="modal-header py-1">
2   - <h4 ng-bind="titulo"></h4>
  2 + <h4 ng-bind="parametros.titulo"></h4>
3 3 <strong ng-bind="fecha | date: 'dd/MMMM/yyyy HH:mm'"></strong>
4 4 </div>
5 5 <div class="modal-body">
6 6 <div class="offset-2">
7   - <div uib-datepicker ng-model="fecha"></div>
  7 + <div
  8 + uib-datepicker
  9 + datepicker-options="options"
  10 + ng-model="fecha"></div>
8 11 </div>
9 12 </div>
10 13 <div class="modal-footer">
src/views/modal-prompt.html
1 1 <div class="modal-header">
2   - <h4 ng-bind="titulo"></h4>
  2 + <h4 ng-bind="options.titulo"></h4>
3 3 </div>
4 4 <div class="modal-body">
5 5 <input
6 6 type="text"
7 7 class="form-control"
8   - ng-model="value"
9   - ng-show="!textarea"
10   - ng-readonly="readonly">
  8 + ng-model="options.value"
  9 + ng-show="!options.textarea"
  10 + maxlength="{{options.maxlength}}"
  11 + ng-readonly="options.readonly"
  12 + ng-keypress="aceptar($event.keyCode)"
  13 + teclado-virtual
  14 + >
11 15  
12 16 <textarea
13 17 rows="5"
14 18 class="form-control text-uppercase"
15   - ng-model="value"
16   - ng-show="textarea"
17   - ng-readonly="readonly"></textarea>
  19 + ng-model="options.value"
  20 + ng-show="options.textarea"
  21 + maxlength="{{options.maxlength}}"
  22 + ng-readonly="options.readonly"
  23 + ng-keypress="aceptar($event.keyCode)"
  24 + teclado-virtual
  25 + ></textarea>
18 26 </div>
19 27 <div class="modal-footer">
20   - <button class="btn btn-primary" ng-click="aceptar()" foca-focus="true">Aceptar</button>
  28 + <button class="btn btn-primary" ng-click="aceptar(13)" foca-focus="true">Aceptar</button>
21 29 <button class="btn btn-default" ng-click="cancelar()">Cancelar</button>
22 30 </div>