Commit 4a6f50c9b0d793b8ff2e956dc8e43ba094d0a3a2

Authored by Jose Pinto
1 parent 8a6681554e
Exists in master

service a factory, fuera default values, ok validacion mail

Showing 2 changed files with 7 additions and 13 deletions   Show diff stats
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', 'options', 'focaModalService', 37 '$uibModalInstance', '$scope', 'options', 'focaModalService',
38 function($uibModalInstance, $scope, options, focaModalService) { 38 function($uibModalInstance, $scope, options, focaModalService) {
39 39
40 $scope.options = options; 40 $scope.options = options;
41 $scope.cancelar = function() { 41 $scope.cancelar = function() {
42 $uibModalInstance.dismiss(); 42 $uibModalInstance.dismiss();
43 }; 43 };
44 $scope.aceptar = function(key) { 44 $scope.aceptar = function(key) {
45 if (key === 13) { 45 if (key === 13) {
46 if(options.email && !validateEmails($scope.options.value)) { 46 if(options.email && !validateEmails($scope.options.value)) {
47 focaModalService.alert('Ingrese email/s válido/s'); 47 focaModalService.alert('Ingrese email/s válido/s');
48 return; 48 return;
49 } 49 }
50 50
51 $uibModalInstance.close($scope.options.value); 51 $uibModalInstance.close($scope.options.value);
52 } 52 }
53 }; 53 };
54 54
55 function validateEmails(emails) { 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,}))$/; 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(','); 57 var arr = emails.split(',');
58 var result = true;
58 59
59 arr.forEach(function(email) { 60 arr.forEach(function(email) {
60 if(!re.test(String(email).trim().toLowerCase())) return false; 61 var val = String(email).trim().toLowerCase();
62
63 if(!re.test(val)) result = false;
61 }); 64 });
62 return true; 65
66 return result;
63 } 67 }
64 } 68 }
65 ]); 69 ]);
66 70
1 angular.module('focaModal') 1 angular.module('focaModal')
2 .service('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(options) { 74 prompt: function(options) {
75 //DEFAULT VALUES
76 var defaultValues = {
77 titulo: '',
78 value: '',
79 textarea: false,
80 readonly: false,
81 email: false
82 };
83 options = Object.assign(defaultValues, options);
84
85 return $uibModal.open({ 75 return $uibModal.open({
86 templateUrl: 'modal-prompt.html', 76 templateUrl: 'modal-prompt.html',
87 controller: 'focaModalPromptController', 77 controller: 'focaModalPromptController',
88 size: 'md', 78 size: 'md',
89 resolve: { 79 resolve: {
90 options: function() {return options;}, 80 options: function() {return options;},
91 } 81 }
92 }) 82 })
93 .result.then( 83 .result.then(
94 function(resultado) { 84 function(resultado) {
95 return resultado; 85 return resultado;
96 } 86 }
97 ); 87 );
98 } 88 }
99 }; 89 };
100 } 90 }
101 ]); 91 ]);
102 92