Commit 859a50a1fdeefc208ee1eab243f15a87b2b6cc25

Authored by Benjamin Rodriguez
1 parent 135163358a
Exists in develop

arreglos

Showing 1 changed file with 0 additions and 3 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 'focaModalService', 7 'focaModalService',
8 'options', 8 'options',
9 function ($scope, $uibModalInstance, FileSaver, Blob, 9 function ($scope, $uibModalInstance, FileSaver, Blob,
10 focaModalService, options) { 10 focaModalService, options) {
11 11
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,}))$/; 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,}))$/;
13 $scope.descargado = false; 13 $scope.descargado = false;
14 $scope.correoEnviado = false; 14 $scope.correoEnviado = false;
15 $scope.correoNoEnviado = false; 15 $scope.correoNoEnviado = false;
16 $scope.esperando = false; 16 $scope.esperando = false;
17 $scope.titulo = options.titulo; 17 $scope.titulo = options.titulo;
18 $scope.checkboxVar = false; 18 $scope.checkboxVar = false;
19 19
20 $scope.aceptar = function () { 20 $scope.aceptar = function () {
21 $uibModalInstance.close(); 21 $uibModalInstance.close();
22 }; 22 };
23 $scope.salir = function () { 23 $scope.salir = function () {
24 $uibModalInstance.close($scope.descargado); 24 $uibModalInstance.close($scope.descargado);
25 }; 25 };
26 $scope.validarImpresion = function () { 26 $scope.validarImpresion = function () {
27 var rutaComprobante; 27 var rutaComprobante;
28 rutaComprobante = $scope.checkboxVar === true ? options.descargaSinValorizar : options.descarga; 28 rutaComprobante = $scope.checkboxVar === true ? options.descargaSinValorizar : options.descarga;
29 imprimir(rutaComprobante); 29 imprimir(rutaComprobante);
30 } 30 }
31 imprimir = function (rutaComprobante) { 31 imprimir = function (rutaComprobante) {
32 $scope.descargado = true; 32 $scope.descargado = true;
33 $scope.esperando = true; 33 $scope.esperando = true;
34 focaModalService 34 focaModalService
35 .imprimirComprobante(rutaComprobante.url, options.options) 35 .imprimirComprobante(rutaComprobante.url, options.options)
36 .then(function (res) { 36 .then(function (res) {
37 var data = new Blob([res.data], { type: 'application/pdf' }); 37 var data = new Blob([res.data], { type: 'application/pdf' });
38 38
39 FileSaver.saveAs( 39 FileSaver.saveAs(
40 data, 40 data,
41 rutaComprobante.nombre 41 rutaComprobante.nombre
42 ); 42 );
43 $scope.esperando = false; 43 $scope.esperando = false;
44 }); 44 });
45 }; 45 };
46 $scope.enviarComprobante = function () { 46 $scope.enviarComprobante = function () {
47 var rutaEnvioComprobante; 47 var rutaEnvioComprobante;
48 rutaEnvioComprobante = $scope.checkboxVar === true ? options.envioSinValorizar : options.envio; 48 rutaEnvioComprobante = $scope.checkboxVar === true ? options.envioSinValorizar : options.envio;
49 enviarCorreo(rutaEnvioComprobante, 13); 49 enviarCorreo(rutaEnvioComprobante, 13);
50 } 50 }
51 enviarCorreo = function (rutaEnvioComprobante, key) { 51 enviarCorreo = function (rutaEnvioComprobante, key) {
52 if (key === 13) { 52 if (key === 13) {
53 if (!validarMail()) { 53 if (!validarMail()) {
54 focaModalService.alert('Ingrese email/s válido/s'); 54 focaModalService.alert('Ingrese email/s válido/s');
55 return; 55 return;
56 } 56 }
57 $scope.descargado = true; 57 $scope.descargado = true;
58 $scope.esperando = true; 58 $scope.esperando = true;
59 rutaEnvioComprobante.mailCliente = $scope.mailCliente; 59 rutaEnvioComprobante.mailCliente = $scope.mailCliente;
60 Object.assign(options.options, { receiver: $scope.mailCliente }); 60 Object.assign(options.options, { receiver: $scope.mailCliente });
61 console.log('ruta',rutaEnvioComprobante)
62 61
63 focaModalService 62 focaModalService
64 .enviarCorreo(rutaEnvioComprobante.url, options.options) 63 .enviarCorreo(rutaEnvioComprobante.url, options.options)
65 .then(function () { 64 .then(function () {
66 $scope.correoEnviado = true; 65 $scope.correoEnviado = true;
67 $scope.esperando = false; 66 $scope.esperando = false;
68 }, function () { 67 }, function () {
69 $scope.esperando = false; 68 $scope.esperando = false;
70 $scope.correoNoEnviado = true; 69 $scope.correoNoEnviado = true;
71 }); 70 });
72 } 71 }
73 }; 72 };
74 function validarMail() { 73 function validarMail() {
75 var emails = $scope.mailCliente.split(','); 74 var emails = $scope.mailCliente.split(',');
76 var result = true; 75 var result = true;
77 emails.forEach(function (email) { 76 emails.forEach(function (email) {
78 if (!regexMail.test(email.trim())) result = false; 77 if (!regexMail.test(email.trim())) result = false;
79 }); 78 });
80 console.log('email:',emails)
81 console.log('result:',result)
82 return result; 79 return result;
83 } 80 }
84 } 81 }
85 ]); 82 ]);
86 83