Commit ae792d6f27991f4c568a8fc497214b05d76650aa

Authored by Jose Pinto
1 parent 7d19d80579
Exists in master

ok servicios modal mail

Showing 2 changed files with 13 additions and 4 deletions   Show diff stats
src/js/controllerMail.js
1 angular.module('focaModal') 1 angular.module('focaModal')
2 .controller('focaModalMailController', [ 2 .controller('focaModalMailController', [
3 '$scope', 3 '$scope',
4 '$uibModalInstance', 4 '$uibModalInstance',
5 'FileSaver', 5 'FileSaver',
6 'Blob', 6 'Blob',
7 'focaModalEnviarMailService',
8 'focaModalService', 7 'focaModalService',
9 'options', 8 'options',
10 function($scope, $uibModalInstance, FileSaver, Blob, 9 function($scope, $uibModalInstance, FileSaver, Blob,
11 focaModalEnviarMailService, focaModalService, options) { 10 focaModalService, options) {
12 11
13 var regexMail = /^(([^<>()\[\]\\.,;:\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,}))$/; 12 var regexMail = /^(([^<>()\[\]\\.,;:\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,}))$/;
14 $scope.descargado = false; 13 $scope.descargado = false;
15 $scope.correoEnviado = false; 14 $scope.correoEnviado = false;
16 $scope.correoNoEnviado = false; 15 $scope.correoNoEnviado = false;
17 $scope.esperando = false; 16 $scope.esperando = false;
18 $scope.titulo = options.titulo; 17 $scope.titulo = options.titulo;
19 $scope.mailCliente = options.envio.mailCliente; 18 $scope.mailCliente = options.envio.mailCliente;
20 19
21 $scope.aceptar = function() { 20 $scope.aceptar = function() {
22 $uibModalInstance.close(); 21 $uibModalInstance.close();
23 }; 22 };
24 $scope.salir = function() { 23 $scope.salir = function() {
25 $uibModalInstance.close($scope.descargado); 24 $uibModalInstance.close($scope.descargado);
26 }; 25 };
27 $scope.imprimir = function () { 26 $scope.imprimir = function () {
28 $scope.descargado = true; 27 $scope.descargado = true;
29 $scope.esperando = true; 28 $scope.esperando = true;
30 focaModalEnviarMailService 29 focaModalService
31 .imprimirComprobante(options.descarga.url, options.options) 30 .imprimirComprobante(options.descarga.url, options.options)
32 .then(function(res) { 31 .then(function(res) {
33 var data = new Blob([res.data], {type: 'application/pdf'}); 32 var data = new Blob([res.data], {type: 'application/pdf'});
34 33
35 FileSaver.saveAs( 34 FileSaver.saveAs(
36 data, 35 data,
37 options.descarga.nombre 36 options.descarga.nombre
38 ); 37 );
39 $scope.esperando = false; 38 $scope.esperando = false;
40 }); 39 });
41 }; 40 };
42 $scope.enviarCorreo = function(key) { 41 $scope.enviarCorreo = function(key) {
43 if (key === 13) { 42 if (key === 13) {
44 if (!validarMail()) { 43 if (!validarMail()) {
45 focaModalService.alert('Ingrese email/s válido/s'); 44 focaModalService.alert('Ingrese email/s válido/s');
46 return; 45 return;
47 } 46 }
48 $scope.descargado = true; 47 $scope.descargado = true;
49 $scope.esperando = true; 48 $scope.esperando = true;
50 Object.assign(options.options, {receiver: $scope.mailCliente}); 49 Object.assign(options.options, {receiver: $scope.mailCliente});
51 50
52 focaModalEnviarMailService 51 focaModalService
53 .enviarCorreo(options.envio.url, options.options) 52 .enviarCorreo(options.envio.url, options.options)
54 .then(function() { 53 .then(function() {
55 $scope.correoEnviado = true; 54 $scope.correoEnviado = true;
56 $scope.esperando = false; 55 $scope.esperando = false;
57 }, function() { 56 }, function() {
58 $scope.esperando = false; 57 $scope.esperando = false;
59 $scope.correoNoEnviado = true; 58 $scope.correoNoEnviado = true;
60 }); 59 });
61 } 60 }
62 }; 61 };
63 function validarMail() { 62 function validarMail() {
64 var emails = $scope.mailCliente.split(','); 63 var emails = $scope.mailCliente.split(',');
65 var result = true; 64 var result = true;
66 emails.forEach(function(email) { 65 emails.forEach(function(email) {
67 if (!regexMail.test(email.trim())) result = false; 66 if (!regexMail.test(email.trim())) result = false;
68 }); 67 });
69 return result; 68 return result;
70 } 69 }
71 } 70 }
72 ]); 71 ]);
73 72
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(parametros) { 59 modalFecha: function(parametros) {
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 parametros: function() { return parametros; } 65 parametros: function() { return parametros; }
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 return $uibModal.open({ 75 return $uibModal.open({
76 templateUrl: 'modal-prompt.html', 76 templateUrl: 'modal-prompt.html',
77 controller: 'focaModalPromptController', 77 controller: 'focaModalPromptController',
78 size: 'md', 78 size: 'md',
79 resolve: { 79 resolve: {
80 options: function() {return options;}, 80 options: function() {return options;},
81 } 81 }
82 }) 82 })
83 .result.then( 83 .result.then(
84 function(resultado) { 84 function(resultado) {
85 return resultado; 85 return resultado;
86 } 86 }
87 ); 87 );
88 }, 88 },
89 mail: function(options) { 89 mail: function(options) {
90 return $uibModal.open({ 90 return $uibModal.open({
91 templateUrl: 'modal-mail.html', 91 templateUrl: 'modal-mail.html',
92 controller: 'focaModalMailController', 92 controller: 'focaModalMailController',
93 size: 'md', 93 size: 'md',
94 resolve: { 94 resolve: {
95 options: function() {return options;}, 95 options: function() {return options;},
96 } 96 }
97 }) 97 })
98 .result.then( 98 .result.then(
99 function(resultado) { 99 function(resultado) {
100 return resultado; 100 return resultado;
101 } 101 }
102 ); 102 );
103 },
104 imprimirComprobante: function(url, options) {
105 return $http.post(
106 API_ENDPOINT.URL + url,
107 options,
108 {responseType: 'arraybuffer'}
109 );
110 },
111 enviarCorreo: function(url, options) {
112 return $http.post(API_ENDPOINT.URL + url, options);
103 } 113 }
104 }; 114 };
105 } 115 }
106 ]); 116 ]);
107 117