Commit 135163358aafba2f16ef6bd5037a0221c9420c90
1 parent
9f2d599dd7
Exists in
develop
arreglos
Showing
2 changed files
with
5 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 | $scope.mailCliente = rutaEnvioComprobante.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) | ||
61 | 62 | ||
62 | focaModalService | 63 | focaModalService |
63 | .enviarCorreo(rutaEnvioComprobante.url, options.options) | 64 | .enviarCorreo(rutaEnvioComprobante.url, options.options) |
64 | .then(function () { | 65 | .then(function () { |
65 | $scope.correoEnviado = true; | 66 | $scope.correoEnviado = true; |
66 | $scope.esperando = false; | 67 | $scope.esperando = false; |
67 | }, function () { | 68 | }, function () { |
68 | $scope.esperando = false; | 69 | $scope.esperando = false; |
69 | $scope.correoNoEnviado = true; | 70 | $scope.correoNoEnviado = true; |
70 | }); | 71 | }); |
71 | } | 72 | } |
72 | }; | 73 | }; |
73 | function validarMail() { | 74 | function validarMail() { |
74 | var emails = $scope.mailCliente.split(','); | 75 | var emails = $scope.mailCliente.split(','); |
75 | var result = true; | 76 | var result = true; |
76 | emails.forEach(function (email) { | 77 | emails.forEach(function (email) { |
77 | if (!regexMail.test(email.trim())) result = false; | 78 | if (!regexMail.test(email.trim())) result = false; |
78 | }); | 79 | }); |
80 | console.log('email:',emails) | ||
81 | console.log('result:',result) | ||
79 | return result; | 82 | return result; |
80 | } | 83 | } |
81 | } | 84 | } |
82 | ]); | 85 | ]); |
83 | 86 |
src/views/modal-mail.html
1 | <div class="modal-header" > | 1 | <div class="modal-header"> |
2 | <h5 ng-bind="titulo"></h5> | 2 | <h5 ng-bind="titulo"></h5> |
3 | </div> | 3 | </div> |
4 | <div class="modal-body"> | 4 | <div class="modal-body"> |
5 | <div > | 5 | <div > |
6 | <label | 6 | <label |
7 | class="col-12 bg-success text-white" | 7 | class="col-12 bg-success text-white" |
8 | ng-show="correoEnviado">Correo enviado con éxito</label> | 8 | ng-show="correoEnviado">Correo enviado con éxito</label> |
9 | <label | 9 | <label |
10 | class="col-12 bg-danger text-white" | 10 | class="col-12 bg-danger text-white" |
11 | ng-show="correoNoEnviado">Hubo un error al enviar el correo</label> | 11 | ng-show="correoNoEnviado">Hubo un error al enviar el correo</label> |
12 | <label>Enviar correo a</label> | 12 | <label>Enviar correo a</label> |
13 | <div class="d-flex"> | 13 | <div class="d-flex"> |
14 | <input | 14 | <input |
15 | type="email" | 15 | type="email" |
16 | class="form-control col-9" | 16 | class="form-control col-9" |
17 | ng-model="mailCliente" | 17 | ng-model="mailCliente" |
18 | ng-keypress="enviarComprobante($event.keyCode)" | 18 | ng-keypress="enviarComprobante($event.keyCode)" |
19 | teclado-virtual/> | 19 | teclado-virtual/> |
20 | <button | 20 | <button |
21 | type="button" | 21 | type="button" |
22 | class="btn btn-enviar ml-auto" | 22 | class="btn btn-enviar ml-auto" |
23 | ng-click="enviarComprobante(13)" | 23 | ng-click="enviarComprobante(13)" |
24 | ladda="esperando" | 24 | ladda="esperando" |
25 | >Enviar</button> | 25 | >Enviar</button> |
26 | </div> | 26 | </div> |
27 | </div> | 27 | </div> |
28 | <hr> | 28 | <hr> |
29 | <div> | 29 | <div> |
30 | <label>Descargar comprobante</label> | 30 | <label>Descargar comprobante</label> |
31 | <div class="col my-1 d-flex justify-content-end"> | 31 | <div class="col my-1 d-flex justify-content-end"> |
32 | <button | 32 | <button |
33 | class="btn btn-enviar float-right" | 33 | class="btn btn-enviar float-right" |
34 | ng-click="validarImpresion()" | 34 | ng-click="validarImpresion()" |
35 | ladda="esperando" | 35 | ladda="esperando" |
36 | >Descargar</button> | 36 | >Descargar</button> |
37 | </div> | 37 | </div> |
38 | </div> | 38 | </div> |
39 | </div> | 39 | </div> |
40 | <div class="modal-footer"> | 40 | <div class="modal-footer"> |
41 | <div class="custom-control custom-checkbox my-auto mr-5"> | 41 | <div class="custom-control custom-checkbox my-auto mr-5"> |
42 | <input | 42 | <input |
43 | type="checkbox" | 43 | type="checkbox" |
44 | class="custom-control-input mr-5" | 44 | class="custom-control-input mr-5" |
45 | id="check" | 45 | id="check" |
46 | ng-click="checkboxVar = !checkboxVar"> | 46 | ng-click="checkboxVar = !checkboxVar"> |
47 | <label class="custom-control-label disable-selection" for="check"> | 47 | <label class="custom-control-label disable-selection" for="check"> |
48 | Combrobante sin valorizar | 48 | Combrobante sin valorizar |
49 | </label> | 49 | </label> |
50 | </div> | 50 | </div> |
51 | <button | 51 | <button |
52 | type="button" | 52 | type="button" |
53 | class="btn btn-secondary" | 53 | class="btn btn-secondary" |
54 | ng-click="salir()" | 54 | ng-click="salir()" |
55 | ladda="esperando" | 55 | ladda="esperando" |
56 | >Salir</button> | 56 | >Salir</button> |
57 | <button | 57 | <button |
58 | type="button" | 58 | type="button" |
59 | class="btn btn-primary" | 59 | class="btn btn-primary" |
60 | ng-click="aceptar()" | 60 | ng-click="aceptar()" |
61 | ladda="esperando" | 61 | ladda="esperando" |
62 | ng-disabled="!descargado" | 62 | ng-disabled="!descargado" |
63 | >Aceptar</button> | 63 | >Aceptar</button> |
64 | </div> | 64 | </div> |
65 | </div> | ||
66 | 65 |