Commit f79d0b0f524337fd42fd26346647abd0b0de2c22
Exists in
develop
Merge branch 'master' into 'develop'
Master See merge request !37
Showing
3 changed files
Show diff stats
src/js/controller.js
1 | angular.module('focaModal') | 1 | angular.module('focaModal') |
2 | .controller('focaModalConfirmController', [ | 2 | .controller('focaModalConfirmController', [ |
3 | '$uibModalInstance', '$scope', 'textoModal', | 3 | '$uibModalInstance', '$scope', 'textoModal', |
4 | function($uibModalInstance, $scope, textoModal) { | 4 | function($uibModalInstance, $scope, textoModal) { |
5 | $scope.textoModal = textoModal; | 5 | $scope.textoModal = textoModal; |
6 | $scope.cancelar = function() { | 6 | $scope.cancelar = function() { |
7 | $uibModalInstance.dismiss(false); | 7 | $uibModalInstance.dismiss(false); |
8 | }; | 8 | }; |
9 | $scope.aceptar = function() { | 9 | $scope.aceptar = function() { |
10 | $uibModalInstance.close(true); | 10 | $uibModalInstance.close(true); |
11 | }; | 11 | }; |
12 | } | 12 | } |
13 | ]) | 13 | ]) |
14 | .controller('focaModalInfoController', [ | 14 | .controller('focaModalInfoController', [ |
15 | '$uibModalInstance', '$scope', 'textoModal', | 15 | '$uibModalInstance', '$scope', 'textoModal', |
16 | function($uibModalInstance, $scope, textoModal) { | 16 | function($uibModalInstance, $scope, textoModal) { |
17 | $scope.textoModal = textoModal; | 17 | $scope.textoModal = textoModal; |
18 | $scope.aceptar = function() { | 18 | $scope.aceptar = function() { |
19 | $uibModalInstance.close(true); | 19 | $uibModalInstance.close(true); |
20 | }; | 20 | }; |
21 | } | 21 | } |
22 | ]) | 22 | ]) |
23 | .controller('focaModalAlertController', [ | 23 | .controller('focaModalAlertController', [ |
24 | '$uibModalInstance', '$scope', 'textoModal', | 24 | '$uibModalInstance', '$scope', 'textoModal', |
25 | function($uibModalInstance, $scope, textoModal) { | 25 | function($uibModalInstance, $scope, textoModal) { |
26 | $scope.textoModal = textoModal; | 26 | $scope.textoModal = textoModal; |
27 | $scope.aceptar = function() { | 27 | $scope.aceptar = function() { |
28 | $uibModalInstance.close(true); | 28 | $uibModalInstance.close(true); |
29 | }; | 29 | }; |
30 | } | 30 | } |
31 | ]) | 31 | ]) |
32 | .controller('focaModalFechaController', [ | 32 | .controller('focaModalFechaController', [ |
33 | '$uibModalInstance', '$scope', 'parametros', | 33 | '$uibModalInstance', '$scope', 'parametros', |
34 | function($uibModalInstance, $scope, parametros) { | 34 | function($uibModalInstance, $scope, parametros) { |
35 | $scope.parametros = parametros; | 35 | $scope.parametros = parametros; |
36 | $scope.fecha = new Date(); | 36 | $scope.fecha = new Date(); |
37 | $scope.options = {}; | 37 | $scope.options = {}; |
38 | 38 | ||
39 | if (parametros.minDate) $scope.options.minDate = parametros.minDate; | 39 | if (parametros.minDate) $scope.options.minDate = parametros.minDate; |
40 | 40 | ||
41 | $scope.cancelar = function() { | 41 | $scope.cancelar = function() { |
42 | $uibModalInstance.dismiss(); | 42 | $uibModalInstance.dismiss(); |
43 | }; | 43 | }; |
44 | $scope.aceptar = function() { | 44 | $scope.aceptar = function() { |
45 | $uibModalInstance.close($scope.fecha); | 45 | $uibModalInstance.close($scope.fecha); |
46 | }; | 46 | }; |
47 | } | 47 | } |
48 | ]) | 48 | ]) |
49 | .controller('focaModalPromptController', [ | 49 | .controller('focaModalPromptController', [ |
50 | '$uibModalInstance', '$scope', 'options', 'focaModalService', | 50 | '$uibModalInstance', '$scope', 'options', 'focaModalService', |
51 | function($uibModalInstance, $scope, options, focaModalService) { | 51 | function($uibModalInstance, $scope, options, focaModalService) { |
52 | 52 | ||
53 | $scope.options = options; | 53 | $scope.options = options; |
54 | 54 | ||
55 | if (!$scope.options.tipo) { | 55 | if (!$scope.options.tipo) { |
56 | $scope.options.tipo = 'text' | 56 | $scope.options.tipo = 'text' |
57 | } | 57 | } |
58 | $scope.cancelar = function() { | 58 | $scope.cancelar = function() { |
59 | $uibModalInstance.dismiss(); | 59 | $uibModalInstance.dismiss(); |
60 | }; | 60 | }; |
61 | $scope.aceptar = function(key) { | 61 | $scope.aceptar = function(key) { |
62 | if (key === 13) { | 62 | if (key === 13) { |
63 | if (options.email && !validateEmails($scope.options.value)) { | 63 | if (options.email && !validateEmails($scope.options.value)) { |
64 | focaModalService.alert('Ingrese email/s válido/s'); | 64 | focaModalService.alert('Ingrese email/s válido/s'); |
65 | return; | 65 | return; |
66 | } | 66 | } |
67 | $uibModalInstance.close($scope.options.value); | 67 | $uibModalInstance.close($scope.options.value); |
68 | } | 68 | } |
69 | }; | 69 | }; |
70 | 70 | ||
71 | function validateEmails(emails) { | 71 | function validateEmails(emails) { |
72 | var re = /^(([^<>()\[\]\\.,;:\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,}))$/; | 72 | var re = /^(([^<>()\[\]\\.,;:\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,}))$/; |
73 | var arr = emails.split(','); | 73 | var arr = emails.split(','); |
74 | var result = true; | 74 | var result = true; |
75 | 75 | ||
76 | arr.forEach(function(email) { | 76 | arr.forEach(function(email) { |
77 | var val = String(email).trim().toLowerCase(); | 77 | var val = String(email).trim().toLowerCase(); |
78 | 78 | ||
79 | if (!re.test(val)) result = false; | 79 | if (!re.test(val)) result = false; |
80 | }); | 80 | }); |
81 | 81 | ||
82 | return result; | 82 | return result; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | ]); | 85 | ]); |
86 | 86 |
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; | 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.imprimir = function () { | 26 | $scope.validarImpresion = function () { |
27 | var rutaComprobante; | ||
28 | rutaComprobante = $scope.checkboxVar === true ? options.descargaSinValorizar : options.descarga; | ||
29 | imprimir(rutaComprobante); | ||
30 | } | ||
31 | imprimir = function (rutaComprobante) { | ||
27 | $scope.descargado = true; | 32 | $scope.descargado = true; |
28 | $scope.esperando = true; | 33 | $scope.esperando = true; |
29 | focaModalService | 34 | focaModalService |
30 | .imprimirComprobante(options.descarga.url, options.options) | 35 | .imprimirComprobante(rutaComprobante.url, options.options) |
31 | .then(function(res) { | 36 | .then(function (res) { |
32 | var data = new Blob([res.data], {type: 'application/pdf'}); | 37 | var data = new Blob([res.data], { type: 'application/pdf' }); |
33 | 38 | ||
34 | FileSaver.saveAs( | 39 | FileSaver.saveAs( |
35 | data, | 40 | data, |
36 | options.descarga.nombre | 41 | rutaComprobante.nombre |
37 | ); | 42 | ); |
38 | $scope.esperando = false; | 43 | $scope.esperando = false; |
39 | }); | 44 | }); |
40 | }; | 45 | }; |
41 | $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) { | ||
42 | if (key === 13) { | 52 | if (key === 13) { |
43 | if (!validarMail()) { | 53 | if (!validarMail()) { |
44 | focaModalService.alert('Ingrese email/s válido/s'); | 54 | focaModalService.alert('Ingrese email/s válido/s'); |
45 | return; | 55 | return; |
46 | } | 56 | } |
47 | $scope.descargado = true; | 57 | $scope.descargado = true; |
48 | $scope.esperando = true; | 58 | $scope.esperando = true; |
49 | Object.assign(options.options, {receiver: $scope.mailCliente}); | 59 | $scope.mailCliente = rutaEnvioComprobante.mailCliente; |
60 | Object.assign(options.options, { receiver: $scope.mailCliente }); | ||
50 | 61 | ||
51 | focaModalService | 62 | focaModalService |
52 | .enviarCorreo(options.envio.url, options.options) | 63 | .enviarCorreo(rutaEnvioComprobante.url, options.options) |
53 | .then(function() { | 64 | .then(function () { |
54 | $scope.correoEnviado = true; | 65 | $scope.correoEnviado = true; |
55 | $scope.esperando = false; | 66 | $scope.esperando = false; |
56 | }, function() { | 67 | }, function () { |
57 | $scope.esperando = false; | 68 | $scope.esperando = false; |
58 | $scope.correoNoEnviado = true; | 69 | $scope.correoNoEnviado = true; |
59 | }); | 70 | }); |
60 | } | 71 | } |
61 | }; | 72 | }; |
62 | function validarMail() { | 73 | function validarMail() { |
63 | var emails = $scope.mailCliente.split(','); | 74 | var emails = $scope.mailCliente.split(','); |
64 | var result = true; | 75 | var result = true; |
65 | emails.forEach(function(email) { | 76 | emails.forEach(function (email) { |
66 | if (!regexMail.test(email.trim())) result = false; | 77 | if (!regexMail.test(email.trim())) result = false; |
67 | }); | 78 | }); |
68 | return result; | 79 | return result; |
69 | } | 80 | } |
70 | } | 81 | } |
71 | ]); | 82 | ]); |
72 | 83 |
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 en este dispositivo</label> | 29 | <label>Descargar comprobante</label> |
30 | <button | 30 | <div class="col my-1 d-flex justify-content-end"> |
31 | class="btn btn-enviar float-right" | 31 | <button |
32 | ng-click="imprimir()" | 32 | class="btn btn-enviar float-right" |
33 | ladda="esperando" | 33 | ng-click="validarImpresion()" |
34 | >Descargar</button> | 34 | ladda="esperando" |
35 | >Descargar</button> | ||
36 | </div> | ||
35 | </div> | 37 | </div> |
36 | </div> | 38 | </div> |
37 | <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> | ||
38 | <button | 50 | <button |
39 | type="button" | 51 | type="button" |
40 | class="btn btn-secondary" | 52 | class="btn btn-secondary" |
41 | ng-click="salir()" | 53 | ng-click="salir()" |
42 | ladda="esperando" | 54 | ladda="esperando" |
43 | >Salir</button> | 55 | >Salir</button> |
44 | <button | 56 | <button |
45 | type="button" | 57 | type="button" |
46 | class="btn btn-primary" | 58 | class="btn btn-primary" |
47 | ng-click="aceptar()" | 59 | ng-click="aceptar()" |
48 | ladda="esperando" | 60 | ladda="esperando" |
49 | ng-disabled="!descargado" | 61 | ng-disabled="!descargado" |
50 | >Aceptar</button> | 62 | >Aceptar</button> |
51 | </div> | 63 | </div> |
52 | 64 |