Commit 7d19d80579188fb11995d302a2366bfa5a3e6229
1 parent
9f7ff87cb6
Exists in
master
controller separado, arreglo espacios en blanco
Showing
2 changed files
with
72 additions
and
75 deletions
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('focaModalAlertController', [ | 14 | .controller('focaModalAlertController', [ |
| 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('focaModalFechaController', [ | 23 | .controller('focaModalFechaController', [ |
| 24 | '$uibModalInstance', '$scope', 'parametros', | 24 | '$uibModalInstance', '$scope', 'parametros', |
| 25 | function($uibModalInstance, $scope, parametros) { | 25 | function($uibModalInstance, $scope, parametros) { |
| 26 | $scope.parametros = parametros; | 26 | $scope.parametros = parametros; |
| 27 | $scope.fecha = new Date(); | 27 | $scope.fecha = new Date(); |
| 28 | $scope.options = {}; | 28 | $scope.options = {}; |
| 29 | 29 | ||
| 30 | if (parametros.minDate) $scope.options.minDate = parametros.minDate; | 30 | if (parametros.minDate) $scope.options.minDate = parametros.minDate; |
| 31 | 31 | ||
| 32 | $scope.cancelar = function() { | 32 | $scope.cancelar = function() { |
| 33 | $uibModalInstance.dismiss(); | 33 | $uibModalInstance.dismiss(); |
| 34 | }; | 34 | }; |
| 35 | $scope.aceptar = function() { | 35 | $scope.aceptar = function() { |
| 36 | $uibModalInstance.close($scope.fecha); | 36 | $uibModalInstance.close($scope.fecha); |
| 37 | }; | 37 | }; |
| 38 | } | 38 | } |
| 39 | ]) | 39 | ]) |
| 40 | .controller('focaModalPromptController', [ | 40 | .controller('focaModalPromptController', [ |
| 41 | '$uibModalInstance', '$scope', 'options', 'focaModalService', | 41 | '$uibModalInstance', '$scope', 'options', 'focaModalService', |
| 42 | function($uibModalInstance, $scope, options, focaModalService) { | 42 | function($uibModalInstance, $scope, options, focaModalService) { |
| 43 | 43 | ||
| 44 | $scope.options = options; | 44 | $scope.options = options; |
| 45 | $scope.cancelar = function() { | 45 | $scope.cancelar = function() { |
| 46 | $uibModalInstance.dismiss(); | 46 | $uibModalInstance.dismiss(); |
| 47 | }; | 47 | }; |
| 48 | $scope.aceptar = function(key) { | 48 | $scope.aceptar = function(key) { |
| 49 | if (key === 13) { | 49 | if (key === 13) { |
| 50 | if (options.email && !validateEmails($scope.options.value)) { | 50 | if (options.email && !validateEmails($scope.options.value)) { |
| 51 | focaModalService.alert('Ingrese email/s válido/s'); | 51 | focaModalService.alert('Ingrese email/s válido/s'); |
| 52 | return; | 52 | return; |
| 53 | } | 53 | } |
| 54 | $uibModalInstance.close($scope.options.value); | 54 | $uibModalInstance.close($scope.options.value); |
| 55 | } | 55 | } |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | function validateEmails(emails) { | 58 | function validateEmails(emails) { |
| 59 | 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,}))$/; | 59 | 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,}))$/; |
| 60 | var arr = emails.split(','); | 60 | var arr = emails.split(','); |
| 61 | var result = true; | 61 | var result = true; |
| 62 | 62 | ||
| 63 | arr.forEach(function(email) { | 63 | arr.forEach(function(email) { |
| 64 | var val = String(email).trim().toLowerCase(); | 64 | var val = String(email).trim().toLowerCase(); |
| 65 | 65 | ||
| 66 | if (!re.test(val)) result = false; | 66 | if (!re.test(val)) result = false; |
| 67 | }); | 67 | }); |
| 68 | 68 | ||
| 69 | return result; | 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 | } | ||
| 147 | ]); | 72 | ]); |
| 148 | 73 |
src/js/controllerMail.js
| File was created | 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 | ]); | ||
| 73 |