Commit e32e0a7aca4800b3545bb3316803fc8bc66814d0
1 parent
46cd6923c4
Exists in
master
primera version
Showing
10 changed files
with
403 additions
and
0 deletions
Show diff stats
.gitignore
.jshintrc
... | ... | @@ -0,0 +1,64 @@ |
1 | +{ | |
2 | + /* | |
3 | + * ENVIRONMENTS | |
4 | + * ================= | |
5 | + */ | |
6 | + | |
7 | + // Define globals exposed by modern browsers. | |
8 | + "browser": true, | |
9 | + | |
10 | + // Define globals exposed by jQuery. | |
11 | + "jquery": true, | |
12 | + | |
13 | + // Define globals exposed by Node.js. | |
14 | + "node": true, | |
15 | + | |
16 | + // Allow ES6. | |
17 | + "esversion": 6, | |
18 | + | |
19 | + /* | |
20 | + * ENFORCING OPTIONS | |
21 | + * ================= | |
22 | + */ | |
23 | + | |
24 | + // Force all variable names to use either camelCase style or UPPER_CASE | |
25 | + // with underscores. | |
26 | + "camelcase": true, | |
27 | + | |
28 | + // Prohibit use of == and != in favor of === and !==. | |
29 | + "eqeqeq": true, | |
30 | + | |
31 | + // Enforce tab width of 2 spaces. | |
32 | + "indent": 4, | |
33 | + | |
34 | + // Prohibit use of a variable before it is defined. | |
35 | + "latedef": false, | |
36 | + | |
37 | + // Enforce line length to 100 characters | |
38 | + "maxlen": 100, | |
39 | + | |
40 | + // Require capitalized names for constructor functions. | |
41 | + "newcap": true, | |
42 | + | |
43 | + // Enforce use of single quotation marks for strings. | |
44 | + "quotmark": "single", | |
45 | + | |
46 | + // Enforce placing 'use strict' at the top function scope | |
47 | + "strict": false, | |
48 | + | |
49 | + // Prohibit use of explicitly undeclared variables. | |
50 | + "undef": true, | |
51 | + | |
52 | + // Warn when variables are defined but never used. | |
53 | + "unused": true, | |
54 | + | |
55 | + // Para que funcione en angular | |
56 | + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], | |
57 | + /* | |
58 | + * RELAXING OPTIONS | |
59 | + * ================= | |
60 | + */ | |
61 | + | |
62 | + // Suppress warnings about == null comparisons. | |
63 | + "eqnull": true | |
64 | +} |
gulpfile.js
... | ... | @@ -0,0 +1,81 @@ |
1 | +const templateCache = require('gulp-angular-templatecache'); | |
2 | +const concat = require('gulp-concat'); | |
3 | +const htmlmin = require('gulp-htmlmin'); | |
4 | +const rename = require('gulp-rename'); | |
5 | +const uglify = require('gulp-uglify'); | |
6 | +const gulp = require('gulp'); | |
7 | +const pump = require('pump'); | |
8 | +const jshint = require('gulp-jshint'); | |
9 | +const replace = require('gulp-replace'); | |
10 | +const connect = require('gulp-connect'); | |
11 | +const clean = require('gulp-clean'); | |
12 | + | |
13 | +var paths = { | |
14 | + srcJS: 'src/js/*.js', | |
15 | + srcViews: 'src/views/*.html', | |
16 | + tmp: 'tmp', | |
17 | + dist: 'dist/' | |
18 | +}; | |
19 | + | |
20 | +gulp.task('templates', function() { | |
21 | + return pump( | |
22 | + [ | |
23 | + gulp.src(paths.srcViews), | |
24 | + replace('views/', ''), | |
25 | + htmlmin(), | |
26 | + templateCache('views.js', { | |
27 | + module: 'focaModalEnviarMail', | |
28 | + root: '' | |
29 | + }), | |
30 | + gulp.dest(paths.tmp) | |
31 | + ] | |
32 | + ); | |
33 | +}); | |
34 | + | |
35 | +gulp.task('uglify', ['templates'], function() { | |
36 | + return pump( | |
37 | + [ | |
38 | + gulp.src([ | |
39 | + paths.srcJS, | |
40 | + 'tmp/views.js' | |
41 | + ]), | |
42 | + concat('foca-modal-enviar-mail.js'), | |
43 | + replace('src/views/', ''), | |
44 | + gulp.dest(paths.tmp), | |
45 | + rename('foca-modal-enviar-mail.min.js'), | |
46 | + uglify(), | |
47 | + gulp.dest(paths.dist) | |
48 | + ] | |
49 | + ); | |
50 | +}); | |
51 | + | |
52 | +gulp.task('pre-commit', function() { | |
53 | + return pump( | |
54 | + [ | |
55 | + gulp.src(paths.srcJS), | |
56 | + jshint('.jshintrc'), | |
57 | + jshint.reporter('default'), | |
58 | + jshint.reporter('fail') | |
59 | + ] | |
60 | + ); | |
61 | + | |
62 | + gulp.start('uglify'); | |
63 | +}); | |
64 | + | |
65 | +gulp.task('webserver', function() { | |
66 | + pump [ | |
67 | + connect.server({port: 3000}) | |
68 | + ] | |
69 | +}); | |
70 | + | |
71 | +gulp.task('clean-post-install', function() { | |
72 | + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | |
73 | + 'index.html'], {read: false}) | |
74 | + .pipe(clean()); | |
75 | +}); | |
76 | + | |
77 | +gulp.task('default', ['webserver']); | |
78 | + | |
79 | +gulp.task('watch', function() { | |
80 | + gulp.watch([paths.srcJS, paths.srcViews], ['uglify']) | |
81 | +}); |
index.html
... | ... | @@ -0,0 +1,34 @@ |
1 | +<html ng-app="focaModalEnviarMail"> | |
2 | + | |
3 | +<head> | |
4 | + <meta charset="UTF-8" /> | |
5 | + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
6 | + | |
7 | + <!--CSS--> | |
8 | + <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" /> | |
9 | + <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet" /> | |
10 | + <link href="node_modules/ladda/dist/ladda-themeless.min.css" rel="stylesheet"> | |
11 | + | |
12 | + <!--VENDOR JS--> | |
13 | + <script src="node_modules/jquery/dist/jquery.min.js"></script> | |
14 | + <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> | |
15 | + <script src="node_modules/angular/angular.min.js"></script> | |
16 | + <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script> | |
17 | + <script src="node_modules/foca-directivas/dist/foca-directivas.min.js"></script> | |
18 | + <script src="node_modules/ladda/dist/spin.min.js"></script> | |
19 | + <script src="node_modules/ladda/dist/ladda.min.js"></script> | |
20 | + <script src="node_modules/angular-ladda/dist/angular-ladda.min.js"></script> | |
21 | + | |
22 | + <!-- BUILD --> | |
23 | + <script src="src/js/app.js"></script> | |
24 | + <script src="src/js/controller.js"></script> | |
25 | + <script src="src/js/service.js"></script> | |
26 | + | |
27 | + <!-- /BUILD --> | |
28 | + <script src="src/etc/develop.js"></script> | |
29 | +</head> | |
30 | + | |
31 | +<body ng-controller="controller"> | |
32 | +</body> | |
33 | + | |
34 | +</html> | |
0 | 35 | \ No newline at end of file |
package.json
... | ... | @@ -0,0 +1,63 @@ |
1 | +{ | |
2 | + "name": "foca-modal-enviar-mail", | |
3 | + "version": "0.0.1", | |
4 | + "description": "Modal para enviar comprobantes por mail", | |
5 | + "main": "index.js", | |
6 | + "scripts": { | |
7 | + "test": "echo \"Error: no test specified\" && exit 1", | |
8 | + "gulp-pre-commit": "gulp pre-commit", | |
9 | + "compile": "gulp uglify", | |
10 | + "postinstall": "npm run compile && gulp clean-post-install", | |
11 | + "install-dev": "npm install --ignore-scripts" | |
12 | + }, | |
13 | + "pre-commit": [ | |
14 | + "gulp-pre-commit" | |
15 | + ], | |
16 | + "repository": { | |
17 | + "type": "git", | |
18 | + "url": "http://git.focasoftware.com/npm/foca-modal-enviar-mail" | |
19 | + }, | |
20 | + "author": "Foca Software", | |
21 | + "license": "ISC", | |
22 | + "peerDependencies": { | |
23 | + "angular": "^1.7.4", | |
24 | + "bootstrap": "^4.1.3", | |
25 | + "font-awesome": "^4.7.0", | |
26 | + "ui-bootstrap4": "^3.0.4", | |
27 | + "gulp": "^3.9.1", | |
28 | + "gulp-angular-templatecache": "^2.2.1", | |
29 | + "gulp-concat": "^2.6.1", | |
30 | + "gulp-connect": "^5.6.1", | |
31 | + "gulp-htmlmin": "^5.0.1", | |
32 | + "gulp-rename": "^1.4.0", | |
33 | + "gulp-replace": "^1.0.0", | |
34 | + "gulp-uglify": "^3.0.1", | |
35 | + "jquery": "^3.3.1", | |
36 | + "pump": "^3.0.0", | |
37 | + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git" | |
38 | + }, | |
39 | + "devDependencies": { | |
40 | + "angular": "^1.7.5", | |
41 | + "angular-ladda": "^0.4.3", | |
42 | + "bootstrap": "^4.1.3", | |
43 | + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", | |
44 | + "font-awesome": "^4.7.0", | |
45 | + "gulp": "^3.9.1", | |
46 | + "gulp-angular-templatecache": "^2.2.5", | |
47 | + "gulp-clean": "^0.4.0", | |
48 | + "gulp-concat": "^2.6.1", | |
49 | + "gulp-connect": "^5.6.1", | |
50 | + "gulp-htmlmin": "^5.0.1", | |
51 | + "gulp-jshint": "^2.1.0", | |
52 | + "gulp-rename": "^1.4.0", | |
53 | + "gulp-replace": "^1.0.0", | |
54 | + "gulp-uglify": "^3.0.1", | |
55 | + "jasmine-core": "^3.3.0", | |
56 | + "jquery": "^3.3.1", | |
57 | + "jshint": "^2.9.6", | |
58 | + "ladda": "^1.0.6", | |
59 | + "pre-commit": "^1.2.2", | |
60 | + "pump": "^3.0.0", | |
61 | + "ui-bootstrap4": "^3.0.5" | |
62 | + } | |
63 | +} |
src/etc/develop.js.ejemplo
src/js/app.js
... | ... | @@ -0,0 +1 @@ |
1 | +angular.module('focaModalEnviarMail', []); |
src/js/controller.js
... | ... | @@ -0,0 +1,81 @@ |
1 | +angular.module('focaModalEnviarMail') | |
2 | + .controller('focaModalEnviarMailController', [ | |
3 | + '$timeout', | |
4 | + '$filter', | |
5 | + '$scope', | |
6 | + '$uibModalInstance', | |
7 | + 'FileSaver', | |
8 | + 'Blob', | |
9 | + 'focaModalEnviarMailService', | |
10 | + 'focaModalService', | |
11 | + 'parametros', | |
12 | + function($timeout, $filter, $scope, $uibModalInstance, FileSaver, Blob, | |
13 | + focaModalEnviarMailService, focaModalService, parametros) { | |
14 | + | |
15 | + 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,}))$/; | |
16 | + $scope.descargado = false; | |
17 | + $scope.correoEnviado = false; | |
18 | + $scope.correoNoEnviado = false; | |
19 | + $scope.esperando = false; | |
20 | + $scope.titulo = parametros.titulo; | |
21 | + $scope.mailCliente = parametros.mailCliente; | |
22 | + | |
23 | + $scope.aceptar = function() { | |
24 | + $uibModalInstance.close(); | |
25 | + }; | |
26 | + | |
27 | + $scope.salir = function() { | |
28 | + $uibModalInstance.close($scope.descargado); | |
29 | + }; | |
30 | + | |
31 | + $scope.imprimir = function () { | |
32 | + $scope.descargado = true; | |
33 | + $scope.esperando = true; | |
34 | + focaModalEnviarMailService | |
35 | + .imprimirComprobanteById(parametros.urlImprimir, parametros.idComprobante) | |
36 | + .then(function(res) { | |
37 | + var data = new Blob([res.data], {type: 'application/pdf'}); | |
38 | + | |
39 | + FileSaver.saveAs( | |
40 | + data, | |
41 | + parametros.nombrePdf | |
42 | + ); | |
43 | + $scope.esperando = false; | |
44 | + }); | |
45 | + }; | |
46 | + | |
47 | + $scope.enviarCorreo = function(key) { | |
48 | + if (key === 13) { | |
49 | + if (!validarMail()) { | |
50 | + focaModalService.alert('Ingrese email/s válido/s'); | |
51 | + return; | |
52 | + } | |
53 | + $scope.descargado = true; | |
54 | + $scope.esperando = true; | |
55 | + var options = { | |
56 | + para: parametros.mailCliente, | |
57 | + idComprobante: parametros.idComprobante | |
58 | + }; | |
59 | + | |
60 | + focaModalEnviarMailService | |
61 | + .enviarCorreo(parametros.urlMail, options) | |
62 | + .then(function() { | |
63 | + $scope.correoEnviado = true; | |
64 | + $scope.esperando = false; | |
65 | + }, function() { | |
66 | + $scope.esperando = false; | |
67 | + $scope.correoNoEnviado = true; | |
68 | + }); | |
69 | + } | |
70 | + }; | |
71 | + | |
72 | + function validarMail() { | |
73 | + var emails = $scope.mailCliente.split(','); | |
74 | + var result = true; | |
75 | + emails.forEach(function(email) { | |
76 | + if (!regexMail.test(email.trim())) result = false; | |
77 | + }); | |
78 | + return result; | |
79 | + } | |
80 | + }] | |
81 | + ); |
src/js/service.js
... | ... | @@ -0,0 +1,17 @@ |
1 | +angular.module('focaModalEnviarMail') | |
2 | + .factory('focaModalEnviarMailService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | |
3 | + return { | |
4 | + getBancos: function() { | |
5 | + //TODO: Pasar filtro | |
6 | + return $http.get(API_ENDPOINT.URL + '/banco'); | |
7 | + }, | |
8 | + imprimirComprobanteById: function(url, idComprobante) { | |
9 | + return $http.get(API_ENDPOINT.URL + url + idComprobante , { | |
10 | + responseType: 'arraybuffer' | |
11 | + }); | |
12 | + }, | |
13 | + enviarCorreo: function(url, options) { | |
14 | + return $http.post(API_ENDPOINT.URL + url, options); | |
15 | + }, | |
16 | + }; | |
17 | + }]); |
src/views/modal-enviar-mail.html
... | ... | @@ -0,0 +1,52 @@ |
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> | |
52 | + | |
0 | 53 | \ No newline at end of file |