Commit ecb228f8abb9a9312c3b924f817dbdf673182f68

Authored by Jose Pinto
1 parent e9edcb5b7c
Exists in master

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