Commit f4a501cbc9d624a62a099e9db0c7c1901213f009
Exists in
master
and in
1 other branch
Merge branch 'develop' into 'master'
Develop See merge request !25
Showing
5 changed files
Show diff stats
src/js/controllerMail.js
| ... | ... | @@ -0,0 +1,71 @@ |
| 1 | +angular.module('focaModal') | |
| 2 | + .controller('focaModalMailController', [ | |
| 3 | + '$scope', | |
| 4 | + '$uibModalInstance', | |
| 5 | + 'FileSaver', | |
| 6 | + 'Blob', | |
| 7 | + 'focaModalService', | |
| 8 | + 'options', | |
| 9 | + function($scope, $uibModalInstance, FileSaver, Blob, | |
| 10 | + focaModalService, options) { | |
| 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,}))$/; | |
| 13 | + $scope.descargado = false; | |
| 14 | + $scope.correoEnviado = false; | |
| 15 | + $scope.correoNoEnviado = false; | |
| 16 | + $scope.esperando = false; | |
| 17 | + $scope.titulo = options.titulo; | |
| 18 | + $scope.mailCliente = options.envio.mailCliente; | |
| 19 | + | |
| 20 | + $scope.aceptar = function() { | |
| 21 | + $uibModalInstance.close(); | |
| 22 | + }; | |
| 23 | + $scope.salir = function() { | |
| 24 | + $uibModalInstance.close($scope.descargado); | |
| 25 | + }; | |
| 26 | + $scope.imprimir = function () { | |
| 27 | + $scope.descargado = true; | |
| 28 | + $scope.esperando = true; | |
| 29 | + focaModalService | |
| 30 | + .imprimirComprobante(options.descarga.url, options.options) | |
| 31 | + .then(function(res) { | |
| 32 | + var data = new Blob([res.data], {type: 'application/pdf'}); | |
| 33 | + | |
| 34 | + FileSaver.saveAs( | |
| 35 | + data, | |
| 36 | + options.descarga.nombre | |
| 37 | + ); | |
| 38 | + $scope.esperando = false; | |
| 39 | + }); | |
| 40 | + }; | |
| 41 | + $scope.enviarCorreo = function(key) { | |
| 42 | + if (key === 13) { | |
| 43 | + if (!validarMail()) { | |
| 44 | + focaModalService.alert('Ingrese email/s válido/s'); | |
| 45 | + return; | |
| 46 | + } | |
| 47 | + $scope.descargado = true; | |
| 48 | + $scope.esperando = true; | |
| 49 | + Object.assign(options.options, {receiver: $scope.mailCliente}); | |
| 50 | + | |
| 51 | + focaModalService | |
| 52 | + .enviarCorreo(options.envio.url, options.options) | |
| 53 | + .then(function() { | |
| 54 | + $scope.correoEnviado = true; | |
| 55 | + $scope.esperando = false; | |
| 56 | + }, function() { | |
| 57 | + $scope.esperando = false; | |
| 58 | + $scope.correoNoEnviado = true; | |
| 59 | + }); | |
| 60 | + } | |
| 61 | + }; | |
| 62 | + function validarMail() { | |
| 63 | + var emails = $scope.mailCliente.split(','); | |
| 64 | + var result = true; | |
| 65 | + emails.forEach(function(email) { | |
| 66 | + if (!regexMail.test(email.trim())) result = false; | |
| 67 | + }); | |
| 68 | + return result; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + ]); |
src/js/controllerModal.js
src/js/service.js
| ... | ... | @@ -85,6 +85,31 @@ 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 | + ); | |
| 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); | |
| 88 | 113 | } |
| 89 | 114 | }; |
| 90 | 115 | } |
src/views/foca-modal.html
| ... | ... | @@ -18,6 +18,14 @@ |
| 18 | 18 | ng-focus="selectedEntidad = -1" |
| 19 | 19 | teclado-virtual |
| 20 | 20 | > |
| 21 | + <button | |
| 22 | + ng-show="filters.length >= 1" | |
| 23 | + type="button" | |
| 24 | + class="clear-input" | |
| 25 | + ng-click="clearInput()" | |
| 26 | + > | |
| 27 | + <i class="fa fa-times"></i> | |
| 28 | + </button> | |
| 21 | 29 | <div class="input-group-append"> |
| 22 | 30 | <button |
| 23 | 31 | ladda="searchLoading" |
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> |