Commit 5f57ee0dec18084d582c9960dc86668cdce970f8
Exists in
master
Merge branch 'master' into 'develop'
Master See merge request !22
Showing
3 changed files
Show diff stats
src/js/controllerMail.js
| ... | ... | @@ -0,0 +1,72 @@ |
| 1 | +angular.module('focaModal') | |
| 2 | + .controller('focaModalMailController', [ | |
| 3 | + '$scope', | |
| 4 | + '$uibModalInstance', | |
| 5 | + 'FileSaver', | |
| 6 | + 'Blob', | |
| 7 | + 'focaModalEnviarMailService', | |
| 8 | + 'focaModalService', | |
| 9 | + 'options', | |
| 10 | + function($scope, $uibModalInstance, FileSaver, Blob, | |
| 11 | + focaModalEnviarMailService, focaModalService, options) { | |
| 12 | + | |
| 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,}))$/; | |
| 14 | + $scope.descargado = false; | |
| 15 | + $scope.correoEnviado = false; | |
| 16 | + $scope.correoNoEnviado = false; | |
| 17 | + $scope.esperando = false; | |
| 18 | + $scope.titulo = options.titulo; | |
| 19 | + $scope.mailCliente = options.envio.mailCliente; | |
| 20 | + | |
| 21 | + $scope.aceptar = function() { | |
| 22 | + $uibModalInstance.close(); | |
| 23 | + }; | |
| 24 | + $scope.salir = function() { | |
| 25 | + $uibModalInstance.close($scope.descargado); | |
| 26 | + }; | |
| 27 | + $scope.imprimir = function () { | |
| 28 | + $scope.descargado = true; | |
| 29 | + $scope.esperando = true; | |
| 30 | + focaModalEnviarMailService | |
| 31 | + .imprimirComprobante(options.descarga.url, options.options) | |
| 32 | + .then(function(res) { | |
| 33 | + var data = new Blob([res.data], {type: 'application/pdf'}); | |
| 34 | + | |
| 35 | + FileSaver.saveAs( | |
| 36 | + data, | |
| 37 | + options.descarga.nombre | |
| 38 | + ); | |
| 39 | + $scope.esperando = false; | |
| 40 | + }); | |
| 41 | + }; | |
| 42 | + $scope.enviarCorreo = function(key) { | |
| 43 | + if (key === 13) { | |
| 44 | + if (!validarMail()) { | |
| 45 | + focaModalService.alert('Ingrese email/s válido/s'); | |
| 46 | + return; | |
| 47 | + } | |
| 48 | + $scope.descargado = true; | |
| 49 | + $scope.esperando = true; | |
| 50 | + Object.assign(options.options, {receiver: $scope.mailCliente}); | |
| 51 | + | |
| 52 | + focaModalEnviarMailService | |
| 53 | + .enviarCorreo(options.envio.url, options.options) | |
| 54 | + .then(function() { | |
| 55 | + $scope.correoEnviado = true; | |
| 56 | + $scope.esperando = false; | |
| 57 | + }, function() { | |
| 58 | + $scope.esperando = false; | |
| 59 | + $scope.correoNoEnviado = true; | |
| 60 | + }); | |
| 61 | + } | |
| 62 | + }; | |
| 63 | + function validarMail() { | |
| 64 | + var emails = $scope.mailCliente.split(','); | |
| 65 | + var result = true; | |
| 66 | + emails.forEach(function(email) { | |
| 67 | + if (!regexMail.test(email.trim())) result = false; | |
| 68 | + }); | |
| 69 | + return result; | |
| 70 | + } | |
| 71 | + } | |
| 72 | + ]); |
src/js/service.js
| ... | ... | @@ -85,6 +85,21 @@ angular.module('focaModal') |
| 85 | 85 | return resultado; |
| 86 | 86 | } |
| 87 | 87 | ); |
| 88 | + }, | |
| 89 | + mail: function(options) { | |
| 90 | + return $uibModal.open({ | |
| 91 | + templateUrl: 'modal-mail.html', | |
| 92 | + controller: 'focaModalMailController', | |
| 93 | + size: 'md', | |
| 94 | + resolve: { | |
| 95 | + options: function() {return options;}, | |
| 96 | + } | |
| 97 | + }) | |
| 98 | + .result.then( | |
| 99 | + function(resultado) { | |
| 100 | + return resultado; | |
| 101 | + } | |
| 102 | + ); | |
| 88 | 103 | } |
| 89 | 104 | }; |
| 90 | 105 | } |
src/views/modal-mail.html
| ... | ... | @@ -0,0 +1,51 @@ |
| 1 | +<div class="modal-header"> | |
| 2 | + <h5 ng-bind="titulo"></h5> | |
| 3 | +</div> | |
| 4 | +<div class="modal-body"> | |
| 5 | + <div > | |
| 6 | + <label | |
| 7 | + class="col-12 bg-success text-white" | |
| 8 | + ng-show="correoEnviado">Correo enviado con éxito</label> | |
| 9 | + <label | |
| 10 | + class="col-12 bg-danger text-white" | |
| 11 | + ng-show="correoNoEnviado">Hubo un error al enviar el correo</label> | |
| 12 | + <label>Enviar correo a</label> | |
| 13 | + <div class="d-flex"> | |
| 14 | + <input | |
| 15 | + class="form-control col-9" | |
| 16 | + ng-model="mailCliente" | |
| 17 | + ng-keypress="enviarCorreo($event.keyCode)" | |
| 18 | + teclado-virtual/> | |
| 19 | + <button | |
| 20 | + type="button" | |
| 21 | + class="btn btn-primary ml-auto" | |
| 22 | + ng-click="enviarCorreo(13)" | |
| 23 | + ladda="esperando" | |
| 24 | + >Enviar</button> | |
| 25 | + </div> | |
| 26 | + </div> | |
| 27 | + <hr> | |
| 28 | + <div> | |
| 29 | + <label>Descargar comprobante en este dispositivo</label> | |
| 30 | + <button | |
| 31 | + class="btn btn-primary float-right" | |
| 32 | + ng-click="imprimir()" | |
| 33 | + ladda="esperando" | |
| 34 | + >Descargar</button> | |
| 35 | + </div> | |
| 36 | +</div> | |
| 37 | +<div class="modal-footer"> | |
| 38 | + <button | |
| 39 | + type="button" | |
| 40 | + class="btn btn-secondary" | |
| 41 | + ng-click="salir()" | |
| 42 | + ladda="esperando" | |
| 43 | + >Salir</button> | |
| 44 | + <button | |
| 45 | + type="button" | |
| 46 | + class="btn btn-primary" | |
| 47 | + ng-click="aceptar()" | |
| 48 | + ladda="esperando" | |
| 49 | + ng-disabled="!descargado" | |
| 50 | + >Aceptar</button> | |
| 51 | +</div> |