Commit 9f7ff87cb6d4125954743c1501f1039553ecf517
1 parent
e80493aa58
Exists in
master
and in
1 other branch
modal enviar mail
Showing
3 changed files
with
141 additions
and
0 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -69,4 +69,79 @@ angular.module('focaModal') |
| 69 | 69 | return result; |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | +]) | |
| 73 | +.controller('focaModalMailController', [ | |
| 74 | + '$scope', | |
| 75 | + '$uibModalInstance', | |
| 76 | + 'FileSaver', | |
| 77 | + 'Blob', | |
| 78 | + 'focaModalEnviarMailService', | |
| 79 | + 'focaModalService', | |
| 80 | + 'options', | |
| 81 | + function($scope, $uibModalInstance, FileSaver, Blob, | |
| 82 | + focaModalEnviarMailService, focaModalService, options) { | |
| 83 | + | |
| 84 | + 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,}))$/; | |
| 85 | + $scope.descargado = false; | |
| 86 | + $scope.correoEnviado = false; | |
| 87 | + $scope.correoNoEnviado = false; | |
| 88 | + $scope.esperando = false; | |
| 89 | + $scope.titulo = options.titulo; | |
| 90 | + $scope.mailCliente = options.envio.mailCliente; | |
| 91 | + | |
| 92 | + $scope.aceptar = function() { | |
| 93 | + $uibModalInstance.close(); | |
| 94 | + }; | |
| 95 | + | |
| 96 | + $scope.salir = function() { | |
| 97 | + $uibModalInstance.close($scope.descargado); | |
| 98 | + }; | |
| 99 | + | |
| 100 | + $scope.imprimir = function () { | |
| 101 | + $scope.descargado = true; | |
| 102 | + $scope.esperando = true; | |
| 103 | + focaModalEnviarMailService | |
| 104 | + .imprimirComprobante(options.descarga.url, options.options) | |
| 105 | + .then(function(res) { | |
| 106 | + var data = new Blob([res.data], {type: 'application/pdf'}); | |
| 107 | + | |
| 108 | + FileSaver.saveAs( | |
| 109 | + data, | |
| 110 | + options.descarga.nombre | |
| 111 | + ); | |
| 112 | + $scope.esperando = false; | |
| 113 | + }); | |
| 114 | + }; | |
| 115 | + | |
| 116 | + $scope.enviarCorreo = function(key) { | |
| 117 | + if (key === 13) { | |
| 118 | + if (!validarMail()) { | |
| 119 | + focaModalService.alert('Ingrese email/s válido/s'); | |
| 120 | + return; | |
| 121 | + } | |
| 122 | + $scope.descargado = true; | |
| 123 | + $scope.esperando = true; | |
| 124 | + Object.assign(options.options, {receiver: $scope.mailCliente}); | |
| 125 | + | |
| 126 | + focaModalEnviarMailService | |
| 127 | + .enviarCorreo(options.envio.url, options.options) | |
| 128 | + .then(function() { | |
| 129 | + $scope.correoEnviado = true; | |
| 130 | + $scope.esperando = false; | |
| 131 | + }, function() { | |
| 132 | + $scope.esperando = false; | |
| 133 | + $scope.correoNoEnviado = true; | |
| 134 | + }); | |
| 135 | + } | |
| 136 | + }; | |
| 137 | + | |
| 138 | + function validarMail() { | |
| 139 | + var emails = $scope.mailCliente.split(','); | |
| 140 | + var result = true; | |
| 141 | + emails.forEach(function(email) { | |
| 142 | + if (!regexMail.test(email.trim())) result = false; | |
| 143 | + }); | |
| 144 | + return result; | |
| 145 | + } | |
| 146 | + } | |
| 72 | 147 | ]); |
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> |