Commit 18d689890fd986f471088b24062627c710e9768d
1 parent
2f3ef9cc66
Exists in
develop
checkbox funciona para ambas opciones
Showing
3 changed files
with
21 additions
and
22 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.mailCliente = options.envio.mailCliente; | ||
| 19 | $scope.checkboxVar = false; | 18 | $scope.checkboxVar = false; |
| 20 | 19 | ||
| 21 | $scope.aceptar = function () { | 20 | $scope.aceptar = function () { |
| 22 | $uibModalInstance.close(); | 21 | $uibModalInstance.close(); |
| 23 | }; | 22 | }; |
| 24 | $scope.salir = function () { | 23 | $scope.salir = function () { |
| 25 | $uibModalInstance.close($scope.descargado); | 24 | $uibModalInstance.close($scope.descargado); |
| 26 | }; | 25 | }; |
| 27 | $scope.validarImpresion = function () { | 26 | $scope.validarImpresion = function () { |
| 28 | var rutaComprobante; | 27 | var rutaComprobante; |
| 29 | if ($scope.checkboxVar === true) { | 28 | rutaComprobante = $scope.checkboxVar === true ? options.descargaSinValorizar : options.descarga; |
| 30 | rutaComprobante = options.descargaSinValorizar; | ||
| 31 | } else { | ||
| 32 | rutaComprobante = options.descarga; | ||
| 33 | } | ||
| 34 | imprimir(rutaComprobante); | 29 | imprimir(rutaComprobante); |
| 35 | } | 30 | } |
| 36 | imprimir = function (rutaComprobante) { | 31 | imprimir = function (rutaComprobante) { |
| 37 | $scope.descargado = true; | 32 | $scope.descargado = true; |
| 38 | $scope.esperando = true; | 33 | $scope.esperando = true; |
| 39 | focaModalService | 34 | focaModalService |
| 40 | .imprimirComprobante(rutaComprobante.url, options.options) | 35 | .imprimirComprobante(rutaComprobante.url, options.options) |
| 41 | .then(function (res) { | 36 | .then(function (res) { |
| 42 | var data = new Blob([res.data], { type: 'application/pdf' }); | 37 | var data = new Blob([res.data], { type: 'application/pdf' }); |
| 43 | 38 | ||
| 44 | FileSaver.saveAs( | 39 | FileSaver.saveAs( |
| 45 | data, | 40 | data, |
| 46 | rutaComprobante.nombre | 41 | rutaComprobante.nombre |
| 47 | ); | 42 | ); |
| 48 | $scope.esperando = false; | 43 | $scope.esperando = false; |
| 49 | }); | 44 | }); |
| 50 | }; | 45 | }; |
| 51 | $scope.enviarCorreo = function (key) { | 46 | $scope.enviarComprobante = function(){ |
| 47 | var rutaEnvioComprobante; | ||
| 48 | rutaEnvioComprobante = $scope.checkboxVar === true ? options.envioSinValorizar : options.envio; | ||
| 49 | enviarCorreo(rutaEnvioComprobante, 13); | ||
| 50 | } | ||
| 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 | Object.assign(options.options, { receiver: $scope.mailCliente }); | 60 | Object.assign(options.options, { receiver: $scope.mailCliente }); |
| 60 | 61 | ||
| 61 | focaModalService | 62 | focaModalService |
| 62 | .enviarCorreo(options.envio.url, options.options) | 63 | .enviarCorreo(rutaEnvioComprobante.url, options.options) |
| 63 | .then(function () { | 64 | .then(function () { |
| 64 | $scope.correoEnviado = true; | 65 | $scope.correoEnviado = true; |
| 65 | $scope.esperando = false; | 66 | $scope.esperando = false; |
| 66 | }, function () { | 67 | }, function () { |
| 67 | $scope.esperando = false; | 68 | $scope.esperando = false; |
| 68 | $scope.correoNoEnviado = true; | 69 | $scope.correoNoEnviado = true; |
| 69 | }); | 70 | }); |
| 70 | } | 71 | } |
| 71 | }; | 72 | }; |
| 72 | function validarMail() { | 73 | function validarMail() { |
| 73 | var emails = $scope.mailCliente.split(','); | 74 | var emails = $scope.mailCliente.split(','); |
| 74 | var result = true; | 75 | var result = true; |
| 75 | emails.forEach(function (email) { | 76 | emails.forEach(function (email) { |
| 76 | if (!regexMail.test(email.trim())) result = false; | 77 | if (!regexMail.test(email.trim())) result = false; |
| 77 | }); | 78 | }); |
src/js/service.js
| 1 | angular.module('focaModal') | 1 | angular.module('focaModal') |
| 2 | .factory('focaModalService', [ | 2 | .factory('focaModalService', [ |
| 3 | '$uibModal', 'API_ENDPOINT', '$http', | 3 | '$uibModal', 'API_ENDPOINT', '$http', |
| 4 | function($uibModal, API_ENDPOINT, $http) { | 4 | function($uibModal, API_ENDPOINT, $http) { |
| 5 | return { | 5 | return { |
| 6 | confirm: function(textoModal) { | 6 | confirm: function(textoModal) { |
| 7 | return $uibModal.open({ | 7 | return $uibModal.open({ |
| 8 | templateUrl: 'modal-confirm.html', | 8 | templateUrl: 'modal-confirm.html', |
| 9 | controller: 'focaModalConfirmController', | 9 | controller: 'focaModalConfirmController', |
| 10 | animation: false, | 10 | animation: false, |
| 11 | backdrop: false, | 11 | backdrop: false, |
| 12 | resolve: { textoModal: function() { return textoModal; } } | 12 | resolve: { textoModal: function() { return textoModal; } } |
| 13 | }) | 13 | }) |
| 14 | .result.then( | 14 | .result.then( |
| 15 | function(resultado) { | 15 | function(resultado) { |
| 16 | return resultado; | 16 | return resultado; |
| 17 | } | 17 | } |
| 18 | ); | 18 | ); |
| 19 | }, | 19 | }, |
| 20 | info: function(textoModal) { | 20 | info: function(textoModal) { |
| 21 | return $uibModal.open({ | 21 | return $uibModal.open({ |
| 22 | templateUrl: 'modal-info.html', | 22 | templateUrl: 'modal-info.html', |
| 23 | controller: 'focaModalInfoController', | 23 | controller: 'focaModalInfoController', |
| 24 | animation: false, | 24 | animation: false, |
| 25 | backdrop: false, | 25 | backdrop: false, |
| 26 | resolve: { textoModal: function() { return textoModal; } } | 26 | resolve: { textoModal: function() { return textoModal; } } |
| 27 | }) | 27 | }) |
| 28 | .result.then( | 28 | .result.then( |
| 29 | function(resultado) { | 29 | function(resultado) { |
| 30 | return resultado; | 30 | return resultado; |
| 31 | } | 31 | } |
| 32 | ); | 32 | ); |
| 33 | }, | 33 | }, |
| 34 | alert: function(textoModal) { | 34 | alert: function(textoModal) { |
| 35 | return $uibModal.open({ | 35 | return $uibModal.open({ |
| 36 | templateUrl: 'modal-alert.html', | 36 | templateUrl: 'modal-alert.html', |
| 37 | controller: 'focaModalAlertController', | 37 | controller: 'focaModalAlertController', |
| 38 | animation: false, | 38 | animation: false, |
| 39 | backdrop: false, | 39 | backdrop: false, |
| 40 | resolve: { textoModal: function() { return textoModal; } } | 40 | resolve: { textoModal: function() { return textoModal; } } |
| 41 | }) | 41 | }) |
| 42 | .result.then( | 42 | .result.then( |
| 43 | function(resultado) { | 43 | function(resultado) { |
| 44 | return resultado; | 44 | return resultado; |
| 45 | } | 45 | } |
| 46 | ); | 46 | ); |
| 47 | }, | 47 | }, |
| 48 | modal: function(parametrosModal) { | 48 | modal: function(parametrosModal) { |
| 49 | parametrosModal.size = (typeof parametrosModal.size === 'undefined') ? | 49 | parametrosModal.size = (typeof parametrosModal.size === 'undefined') ? |
| 50 | 'lg' : parametrosModal.size; | 50 | 'lg' : parametrosModal.size; |
| 51 | 51 | ||
| 52 | return $uibModal.open({ | 52 | return $uibModal.open({ |
| 53 | templateUrl: 'foca-modal.html', | 53 | templateUrl: 'foca-modal.html', |
| 54 | controller: 'focaModalController', | 54 | controller: 'focaModalController', |
| 55 | size: parametrosModal.size, | 55 | size: parametrosModal.size, |
| 56 | resolve: { | 56 | resolve: { |
| 57 | parametrosModal: function() { return parametrosModal; } | 57 | parametrosModal: function() { return parametrosModal; } |
| 58 | } | 58 | } |
| 59 | }) | 59 | }) |
| 60 | .result.then( | 60 | .result.then( |
| 61 | function(resultado) { | 61 | function(resultado) { |
| 62 | return resultado; | 62 | return resultado; |
| 63 | } | 63 | } |
| 64 | ); | 64 | ); |
| 65 | }, | 65 | }, |
| 66 | getEntidad: function(filters, query, tipo, json) { | 66 | getEntidad: function(filters, query, tipo, json) { |
| 67 | if (tipo === 'POST') { | 67 | if (tipo === 'POST') { |
| 68 | return $http.post(API_ENDPOINT.URL + query, json); | 68 | return $http.post(API_ENDPOINT.URL + query, json); |
| 69 | } else { | 69 | } else { |
| 70 | return $http.get(API_ENDPOINT.URL + query, {nombre: filters}); | 70 | return $http.get(API_ENDPOINT.URL + query, {nombre: filters}); |
| 71 | } | 71 | } |
| 72 | }, | 72 | }, |
| 73 | modalFecha: function(parametros) { | 73 | modalFecha: function(parametros) { |
| 74 | return $uibModal.open({ | 74 | return $uibModal.open({ |
| 75 | templateUrl: 'foca-fecha.html', | 75 | templateUrl: 'foca-fecha.html', |
| 76 | controller: 'focaModalFechaController', | 76 | controller: 'focaModalFechaController', |
| 77 | size: 'md', | 77 | size: 'md', |
| 78 | resolve: { | 78 | resolve: { |
| 79 | parametros: function() { return parametros; } | 79 | parametros: function() { return parametros; } |
| 80 | } | 80 | } |
| 81 | }) | 81 | }) |
| 82 | .result.then( | 82 | .result.then( |
| 83 | function(resultado) { | 83 | function(resultado) { |
| 84 | return resultado; | 84 | return resultado; |
| 85 | } | 85 | } |
| 86 | ); | 86 | ); |
| 87 | }, | 87 | }, |
| 88 | prompt: function(options) { | 88 | prompt: function(options) { |
| 89 | return $uibModal.open({ | 89 | return $uibModal.open({ |
| 90 | templateUrl: 'modal-prompt.html', | 90 | templateUrl: 'modal-prompt.html', |
| 91 | controller: 'focaModalPromptController', | 91 | controller: 'focaModalPromptController', |
| 92 | size: 'md', | 92 | size: 'md', |
| 93 | resolve: { | 93 | resolve: { |
| 94 | options: function() {return options;}, | 94 | options: function() {return options;}, |
| 95 | } | 95 | } |
| 96 | }) | 96 | }) |
| 97 | .result.then( | 97 | .result.then( |
| 98 | function(resultado) { | 98 | function(resultado) { |
| 99 | return resultado; | 99 | return resultado; |
| 100 | } | 100 | } |
| 101 | ); | 101 | ); |
| 102 | }, | 102 | }, |
| 103 | mail: function(options) { | 103 | mail: function(options) { |
| 104 | return $uibModal.open({ | 104 | return $uibModal.open({ |
| 105 | templateUrl: 'modal-mail.html', | 105 | templateUrl: 'modal-mail.html', |
| 106 | controller: 'focaModalMailController', | 106 | controller: 'focaModalMailController', |
| 107 | size: 'md', | 107 | size: 'md', |
| 108 | resolve: { | 108 | resolve: { |
| 109 | options: function() {return options;}, | 109 | options: function() {return options;}, |
| 110 | } | 110 | } |
| 111 | }) | 111 | }) |
| 112 | .result.then( | 112 | .result.then( |
| 113 | function(resultado) { | 113 | function(resultado) { |
| 114 | return resultado; | 114 | return resultado; |
| 115 | } | 115 | } |
| 116 | ); | 116 | ); |
| 117 | }, | 117 | }, |
| 118 | imprimirComprobante: function(url, options) { | 118 | imprimirComprobante: function(url, options) { |
| 119 | console.log('imprimirComprobante', url, options); | ||
| 120 | return $http.post( | 119 | return $http.post( |
| 121 | API_ENDPOINT.URL + url, | 120 | API_ENDPOINT.URL + url, |
| 122 | options, | 121 | options, |
| 123 | {responseType: 'arraybuffer'} | 122 | {responseType: 'arraybuffer'} |
| 124 | ); | 123 | ); |
| 125 | }, | 124 | }, |
| 126 | enviarCorreo: function(url, options) { | 125 | enviarCorreo: function(url, options) { |
| 127 | console.log('enviarCorreo', url, options); | ||
| 128 | return $http.post(API_ENDPOINT.URL + url, options); | 126 | return $http.post(API_ENDPOINT.URL + url, options); |
| 129 | } | 127 | } |
| 130 | }; | 128 | }; |
| 131 | } | 129 | } |
| 132 | ]); | 130 | ]); |
| 133 | 131 |
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 | class="form-control col-9" | 15 | class="form-control col-9" |
| 16 | ng-model="mailCliente" | 16 | ng-model="mailCliente" |
| 17 | ng-keypress="enviarCorreo($event.keyCode)" | 17 | ng-keypress="enviarComprobante($event.keyCode)" |
| 18 | teclado-virtual/> | 18 | teclado-virtual/> |
| 19 | <button | 19 | <button |
| 20 | type="button" | 20 | type="button" |
| 21 | class="btn btn-enviar ml-auto" | 21 | class="btn btn-enviar ml-auto" |
| 22 | ng-click="enviarCorreo(13)" | 22 | ng-click="enviarComprobante(13)" |
| 23 | ladda="esperando" | 23 | ladda="esperando" |
| 24 | >Enviar</button> | 24 | >Enviar</button> |
| 25 | </div> | 25 | </div> |
| 26 | </div> | 26 | </div> |
| 27 | <hr> | 27 | <hr> |
| 28 | <div> | 28 | <div> |
| 29 | <label>Descargar comprobante</label> | 29 | <label>Descargar comprobante</label> |
| 30 | <div class="col my-1 d-flex justify-content-end"> | 30 | <div class="col my-1 d-flex justify-content-end"> |
| 31 | <div class="custom-control custom-checkbox my-auto mr-2"> | ||
| 32 | <input | ||
| 33 | type="checkbox" | ||
| 34 | class="custom-control-input" | ||
| 35 | id="check" | ||
| 36 | ng-click="checkboxVar = !checkboxVar"> | ||
| 37 | <label class="custom-control-label disable-selection" for="check"> | ||
| 38 | Combrobante sin valorizar | ||
| 39 | </label> | ||
| 40 | </div> | ||
| 41 | <button | 31 | <button |
| 42 | class="btn btn-enviar float-right" | 32 | class="btn btn-enviar float-right" |
| 43 | ng-click="validarImpresion()" | 33 | ng-click="validarImpresion()" |
| 44 | ladda="esperando" | 34 | ladda="esperando" |
| 45 | >Descargar</button> | 35 | >Descargar</button> |
| 46 | </div> | 36 | </div> |
| 47 | </div> | 37 | </div> |
| 48 | </div> | 38 | </div> |
| 49 | <div class="modal-footer"> | 39 | <div class="modal-footer"> |
| 40 | <div class="custom-control custom-checkbox my-auto mr-5"> | ||
| 41 | <input | ||
| 42 | type="checkbox" | ||
| 43 | class="custom-control-input mr-5" | ||
| 44 | id="check" | ||
| 45 | ng-click="checkboxVar = !checkboxVar"> | ||
| 46 | <label class="custom-control-label disable-selection" for="check"> | ||
| 47 | Combrobante sin valorizar | ||
| 48 | </label> | ||
| 49 | </div> | ||
| 50 | <button | 50 | <button |
| 51 | type="button" | 51 | type="button" |
| 52 | class="btn btn-secondary" | 52 | class="btn btn-secondary" |
| 53 | ng-click="salir()" | 53 | ng-click="salir()" |
| 54 | ladda="esperando" | 54 | ladda="esperando" |