Commit 255d797e8d8efd9fa8fd6d54f5d7aafcf02ffcb7

Authored by Jose Pinto
1 parent f0bb186662
Exists in master and in 1 other branch develop

reemplazo alert por modal

1 const templateCache = require('gulp-angular-templatecache'); 1 const templateCache = require('gulp-angular-templatecache');
2 const concat = require('gulp-concat'); 2 const concat = require('gulp-concat');
3 const htmlmin = require('gulp-htmlmin'); 3 const htmlmin = require('gulp-htmlmin');
4 const rename = require('gulp-rename'); 4 const rename = require('gulp-rename');
5 const uglify = require('gulp-uglify'); 5 const uglify = require('gulp-uglify');
6 const gulp = require('gulp'); 6 const gulp = require('gulp');
7 const pump = require('pump'); 7 const pump = require('pump');
8 const jshint = require('gulp-jshint'); 8 const jshint = require('gulp-jshint');
9 const replace = require('gulp-replace'); 9 const replace = require('gulp-replace');
10 const connect = require('gulp-connect'); 10 const connect = require('gulp-connect');
11 const clean = require('gulp-clean'); 11 const clean = require('gulp-clean');
12 12
13 var paths = { 13 var paths = {
14 srcJS: 'src/js/*.js', 14 srcJS: 'src/js/*.js',
15 srcViews: 'src/views/*.html', 15 srcViews: 'src/views/*.html',
16 tmp: 'tmp', 16 tmp: 'tmp',
17 dist: 'dist/' 17 dist: 'dist/'
18 }; 18 };
19 19
20 gulp.task('clean', function() { 20 gulp.task('clean', function() {
21 return gulp.src(['tmp', 'dist'], {read: false}) 21 return gulp.src(['tmp', 'dist'], {read: false})
22 .pipe(clean()); 22 .pipe(clean());
23 }); 23 });
24 24
25 gulp.task('templates', ['clean'], function() { 25 gulp.task('templates', ['clean'], function() {
26 return pump( 26 return pump(
27 [ 27 [
28 gulp.src(paths.srcViews), 28 gulp.src(paths.srcViews),
29 htmlmin(), 29 htmlmin(),
30 templateCache('views.js', { 30 templateCache('views.js', {
31 module: 'focaModalCobranza', 31 module: 'focaModalCobranza',
32 root: '' 32 root: ''
33 }), 33 }),
34 gulp.dest(paths.tmp) 34 gulp.dest(paths.tmp)
35 ] 35 ]
36 ); 36 );
37 }); 37 });
38 38
39 gulp.task('uglify', ['templates'], function() { 39 gulp.task('uglify', ['templates'], function() {
40 return pump( 40 return pump(
41 [ 41 [
42 gulp.src([ 42 gulp.src([
43 paths.srcJS, 43 paths.srcJS,
44 'tmp/views.js' 44 'tmp/views.js'
45 ]), 45 ]),
46 concat('foca-modal-cobranza.js'), 46 concat('foca-modal-cobranza.js'),
47 replace('src/views/', ''), 47 replace('src/views/', ''),
48 replace("['ui.bootstrap', 'focaDirectivas', 'angular-ladda']", '[]'), 48 replace("['ui.bootstrap', 'focaDirectivas', 'focaFiltros, 'angular-ladda', 'focaModal']", '[]'),
49 gulp.dest(paths.tmp), 49 gulp.dest(paths.tmp),
50 rename('foca-modal-cobranza.min.js'), 50 rename('foca-modal-cobranza.min.js'),
51 uglify(), 51 uglify(),
52 gulp.dest(paths.dist) 52 gulp.dest(paths.dist)
53 ] 53 ]
54 ); 54 );
55 }); 55 });
56 56
57 gulp.task('pre-commit', function() { 57 gulp.task('pre-commit', function() {
58 return pump( 58 return pump(
59 [ 59 [
60 gulp.src(paths.srcJS), 60 gulp.src(paths.srcJS),
61 jshint('.jshintrc'), 61 jshint('.jshintrc'),
62 jshint.reporter('default'), 62 jshint.reporter('default'),
63 jshint.reporter('fail') 63 jshint.reporter('fail')
64 ] 64 ]
65 ); 65 );
66 66
67 gulp.start('uglify'); 67 gulp.start('uglify');
68 }); 68 });
69 69
70 gulp.task('webserver', function() { 70 gulp.task('webserver', function() {
71 pump [ 71 pump [
72 connect.server({port: 3000}) 72 connect.server({port: 3000})
73 ] 73 ]
74 }); 74 });
75 75
76 gulp.task('clean-post-install', function(){ 76 gulp.task('clean-post-install', function(){
77 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 77 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
78 'index.html'], {read: false}) 78 'index.html'], {read: false})
79 .pipe(clean()); 79 .pipe(clean());
80 }); 80 });
81 81
82 gulp.task('default', ['webserver']); 82 gulp.task('default', ['webserver']);
83 83
84 gulp.task('watch', function() { 84 gulp.task('watch', function() {
85 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']) 85 gulp.watch([paths.srcJS, paths.srcViews], ['uglify'])
86 }); 86 });
87 87
88 gulp.task('copy', ['uglify'], function(){ 88 gulp.task('copy', ['uglify'], function(){
89 gulp.src('dist/*.js') 89 gulp.src('dist/*.js')
90 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-modal-cobranza/dist')); 90 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-modal-cobranza/dist'));
91 }); 91 });
92 92
93 gulp.task('watchAndCopy', function() { 93 gulp.task('watchAndCopy', function() {
94 gulp.watch([paths.srcJS, paths.srcViews], ['copy']) 94 gulp.watch([paths.srcJS, paths.srcViews], ['copy'])
95 }); 95 });
96 96
1 angular.module('focaModalCobranza', [ 1 angular.module('focaModalCobranza', [
2 'ui.bootstrap', 2 'ui.bootstrap',
3 'focaDirectivas', 3 'focaDirectivas',
4 'focaFiltros', 4 'focaFiltros',
5 'angular-ladda' 5 'angular-ladda',
6 'focaModal'
6 ]); 7 ]);
7 8
src/js/controller.js
1 angular.module('focaModalCobranza') 1 angular.module('focaModalCobranza')
2 .controller('focaModalCobranzaController', 2 .controller('focaModalCobranzaController',
3 [ 3 [
4 '$timeout', 4 '$timeout',
5 '$filter', 5 '$filter',
6 '$scope', 6 '$scope',
7 '$uibModalInstance', 7 '$uibModalInstance',
8 'focaModalCobranzaService', 8 'focaModalCobranzaService',
9 function($timeout, $filter, $scope, $uibModalInstance, focaModalCobranzaService) { 9 'focaModalService',
10 function($timeout, $filter, $scope, $uibModalInstance,
11 focaModalCobranzaService, focaModalService) {
10 var fecha = new Date(); 12 var fecha = new Date();
11 $scope.fechaHasta = new Date(); 13 $scope.fechaHasta = new Date();
12 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); 14 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1));
13 $scope.filters = ''; 15 $scope.filters = '';
14 $scope.cobranzas = []; 16 $scope.cobranzas = [];
15 $scope.primerBusqueda = false; 17 $scope.primerBusqueda = false;
16 $scope.searchLoading = false; 18 $scope.searchLoading = false;
17 // pagination 19 // pagination
18 $scope.numPerPage = 10; 20 $scope.numPerPage = 10;
19 $scope.currentPage = 1; 21 $scope.currentPage = 1;
20 $scope.filteredCobranzas = []; 22 $scope.filteredCobranzas = [];
21 $scope.currentPageCobranzas = []; 23 $scope.currentPageCobranzas = [];
22 $scope.selectedCobranza = -1; 24 $scope.selectedCobranza = -1;
23 25
24 //METODOS 26 //METODOS
25 $scope.busquedaPress = function(key) { 27 $scope.busquedaPress = function(key) {
26 if (key === 13) { 28 if (key === 13) {
27 //TODO Validaciones con alertas de foca
28 if(!$scope.fechaDesde) { 29 if(!$scope.fechaDesde) {
29 alert('INGRESE FECHA DESDE'); 30 focaModalService.alert('INGRESE FECHA DESDE');
30 return; 31 return;
31 } 32 }
32 if(!$scope.fechaHasta) { 33 if(!$scope.fechaHasta) {
33 alert('INGRESE FECHA HASTA'); 34 focaModalService.alert('INGRESE FECHA HASTA');
34 return; 35 return;
35 } 36 }
36 if($scope.fechaDesde > $scope.fechaHasta) { 37 if($scope.fechaDesde > $scope.fechaHasta) {
37 alert('La fecha desde no puede ser mayor a la fecha hasta'); 38 focaModalService
39 .alert('La fecha desde no puede ser mayor a la fecha hasta');
38 return; 40 return;
39 } 41 }
40 $scope.searchLoading = true; 42 $scope.searchLoading = true;
41 //TODO: usar filtros en vez de toISOString 43 //TODO: usar filtros en vez de toISOString
42 focaModalCobranzaService 44 focaModalCobranzaService
43 .getCobranzas($scope.fechaDesde.toISOString().split('.')[0], 45 .getCobranzas($scope.fechaDesde.toISOString().split('.')[0],
44 $scope.fechaHasta.toISOString().split('.')[0]) 46 $scope.fechaHasta.toISOString().split('.')[0])
45 .then(llenarDatos); 47 .then(llenarDatos);
46 } 48 }
47 }; 49 };
48 function llenarDatos(res) { 50 function llenarDatos(res) {
49 $scope.cobranzas = []; 51 $scope.cobranzas = [];
50 $scope.filteredCobranzas = []; 52 $scope.filteredCobranzas = [];
51 $scope.currentPageCobranzas = []; 53 $scope.currentPageCobranzas = [];
52 $scope.selectedCobranza = -1; 54 $scope.selectedCobranza = -1;
53 $scope.searchLoading = false; 55 $scope.searchLoading = false;
54 $scope.primerBusqueda = true; 56 $scope.primerBusqueda = true;
55 $scope.cobranzas = res.data; 57 $scope.cobranzas = res.data;
56 $scope.search(true); 58 $scope.search(true);
57 primera(); 59 primera();
58 } 60 }
59 $scope.search = function(pressed) { 61 $scope.search = function(pressed) {
60 if($scope.cobranzas.length > 0) { 62 if($scope.cobranzas.length > 0) {
61 $scope.filteredCobranzas = $filter('filter')( 63 $scope.filteredCobranzas = $filter('filter')(
62 $scope.cobranzas, 64 $scope.cobranzas,
63 {$: $scope.filters} 65 {$: $scope.filters}
64 ); 66 );
65 67
66 if(pressed && $scope.filteredCobranzas.length === 0){ 68 if(pressed && $scope.filteredCobranzas.length === 0){
67 $timeout(function() { 69 $timeout(function() {
68 angular.element('#search')[0].focus(); 70 angular.element('#search')[0].focus();
69 $scope.filters = ''; 71 $scope.filters = '';
70 }); 72 });
71 } 73 }
72 74
73 $scope.lastPage = Math.ceil( 75 $scope.lastPage = Math.ceil(
74 $scope.filteredCobranzas.length / $scope.numPerPage 76 $scope.filteredCobranzas.length / $scope.numPerPage
75 ); 77 );
76 78
77 $scope.resetPage(); 79 $scope.resetPage();
78 } 80 }
79 }; 81 };
80 82
81 $scope.resetPage = function() { 83 $scope.resetPage = function() {
82 $scope.currentPage = 1; 84 $scope.currentPage = 1;
83 $scope.selectPage(1); 85 $scope.selectPage(1);
84 }; 86 };
85 87
86 $scope.selectPage = function(page) { 88 $scope.selectPage = function(page) {
87 var start = (page - 1) * $scope.numPerPage; 89 var start = (page - 1) * $scope.numPerPage;
88 var end = start + $scope.numPerPage; 90 var end = start + $scope.numPerPage;
89 $scope.paginas = []; 91 $scope.paginas = [];
90 $scope.paginas = calcularPages(page); 92 $scope.paginas = calcularPages(page);
91 $scope.currentPageCobranzas = $scope.filteredCobranzas.slice(start, end); 93 $scope.currentPageCobranzas = $scope.filteredCobranzas.slice(start, end);
92 $scope.currentPage = page; 94 $scope.currentPage = page;
93 }; 95 };
94 96
95 $scope.select = function(cobranza) { 97 $scope.select = function(cobranza) {
96 $uibModalInstance.close(cobranza); 98 $uibModalInstance.close(cobranza);
97 }; 99 };
98 100
99 $scope.cancel = function() { 101 $scope.cancel = function() {
100 $uibModalInstance.dismiss('cancel'); 102 $uibModalInstance.dismiss('cancel');
101 }; 103 };
102 104
103 $scope.busquedaDown = function(key) { 105 $scope.busquedaDown = function(key) {
104 if (key === 40) { 106 if (key === 40) {
105 primera(key); 107 primera(key);
106 } 108 }
107 }; 109 };
108 110
109 $scope.itemCobranza = function(key) { 111 $scope.itemCobranza = function(key) {
110 if (key === 38) { 112 if (key === 38) {
111 anterior(key); 113 anterior(key);
112 } 114 }
113 115
114 if (key === 40) { 116 if (key === 40) {
115 siguiente(key); 117 siguiente(key);
116 } 118 }
117 119
118 if (key === 37) { 120 if (key === 37) {
119 retrocederPagina(); 121 retrocederPagina();
120 } 122 }
121 123
122 if (key === 39) { 124 if (key === 39) {
123 avanzarPagina(); 125 avanzarPagina();
124 } 126 }
125 }; 127 };
126 128
127 $scope.getTotalCobrado = function(cobros) { 129 $scope.getTotalCobrado = function(cobros) {
128 var total = 0; 130 var total = 0;
129 for (var i = 0; i < cobros.length; i++) { 131 for (var i = 0; i < cobros.length; i++) {
130 total += cobros[i].importe; 132 total += cobros[i].importe;
131 } 133 }
132 return parseFloat(total.toFixed(2)); 134 return parseFloat(total.toFixed(2));
133 }; 135 };
134 136
135 function calcularPages(paginaActual) { 137 function calcularPages(paginaActual) {
136 var paginas = []; 138 var paginas = [];
137 paginas.push(paginaActual); 139 paginas.push(paginaActual);
138 140
139 if (paginaActual - 1 > 1) { 141 if (paginaActual - 1 > 1) {
140 142
141 paginas.unshift(paginaActual - 1); 143 paginas.unshift(paginaActual - 1);
142 if (paginaActual - 2 > 1) { 144 if (paginaActual - 2 > 1) {
143 paginas.unshift(paginaActual - 2); 145 paginas.unshift(paginaActual - 2);
144 } 146 }
145 } 147 }
146 148
147 if (paginaActual + 1 < $scope.lastPage) { 149 if (paginaActual + 1 < $scope.lastPage) {
148 paginas.push(paginaActual + 1); 150 paginas.push(paginaActual + 1);
149 if (paginaActual + 2 < $scope.lastPage) { 151 if (paginaActual + 2 < $scope.lastPage) {
150 paginas.push(paginaActual + 2); 152 paginas.push(paginaActual + 2);
151 } 153 }
152 } 154 }
153 155
154 if (paginaActual !== 1) { 156 if (paginaActual !== 1) {
155 paginas.unshift(1); 157 paginas.unshift(1);
156 } 158 }
157 159
158 if (paginaActual !== $scope.lastPage) { 160 if (paginaActual !== $scope.lastPage) {
159 paginas.push($scope.lastPage); 161 paginas.push($scope.lastPage);
160 } 162 }
161 163
162 return paginas; 164 return paginas;
163 } 165 }
164 166
165 function primera() { 167 function primera() {
166 $scope.selectedCobranza = 0; 168 $scope.selectedCobranza = 0;
167 } 169 }
168 170
169 function anterior() { 171 function anterior() {
170 if ($scope.selectedCobranza === 0 && $scope.currentPage > 1) { 172 if ($scope.selectedCobranza === 0 && $scope.currentPage > 1) {
171 retrocederPagina(); 173 retrocederPagina();
172 } else { 174 } else {
173 $scope.selectedCobranza--; 175 $scope.selectedCobranza--;
174 } 176 }
175 } 177 }
176 178
177 function siguiente() { 179 function siguiente() {
178 if ($scope.selectedCobranza < $scope.currentPageCobranzas.length - 1 ) { 180 if ($scope.selectedCobranza < $scope.currentPageCobranzas.length - 1 ) {
179 $scope.selectedCobranza++; 181 $scope.selectedCobranza++;
180 } else { 182 } else {
181 avanzarPagina(); 183 avanzarPagina();
182 } 184 }
183 } 185 }
184 186
185 function retrocederPagina() { 187 function retrocederPagina() {
186 if ($scope.currentPage > 1) { 188 if ($scope.currentPage > 1) {
187 $scope.selectPage($scope.currentPage - 1); 189 $scope.selectPage($scope.currentPage - 1);
188 $scope.selectedCobranza = $scope.numPerPage - 1; 190 $scope.selectedCobranza = $scope.numPerPage - 1;
189 } 191 }
190 } 192 }
191 193
192 function avanzarPagina() { 194 function avanzarPagina() {
193 if ($scope.currentPage < $scope.lastPage) { 195 if ($scope.currentPage < $scope.lastPage) {
194 $scope.selectPage($scope.currentPage + 1); 196 $scope.selectPage($scope.currentPage + 1);
195 $scope.selectedCobranza = 0; 197 $scope.selectedCobranza = 0;
196 } 198 }
197 } 199 }
198 } 200 }
199 ] 201 ]
200 ); 202 );