Commit 9faff659aa30c8dd5d1b3404550721e2732f177b

Authored by Marcelo Puebla
Exists in develop

Merge branch 'develop' of git.focasoftware.com:npm/foca-modal-domicilio into develop

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('templates', function() { 20 gulp.task('templates', function() {
21 return pump( 21 return pump(
22 [ 22 [
23 gulp.src(paths.srcViews), 23 gulp.src(paths.srcViews),
24 htmlmin(), 24 htmlmin(),
25 templateCache('views.js', { 25 templateCache('views.js', {
26 module: 'focaModalDomicilio', 26 module: 'focaModalDomicilio',
27 root: '' 27 root: ''
28 }), 28 }),
29 gulp.dest(paths.tmp) 29 gulp.dest(paths.tmp)
30 ] 30 ]
31 ); 31 );
32 }); 32 });
33 33
34 gulp.task('uglify', ['templates'], function() { 34 gulp.task('uglify', ['templates'], function() {
35 return pump( 35 return pump(
36 [ 36 [
37 gulp.src([ 37 gulp.src([
38 paths.srcJS, 38 paths.srcJS,
39 'tmp/views.js' 39 'tmp/views.js'
40 ]), 40 ]),
41 concat('foca-modal-domicilios.js'), 41 concat('foca-modal-domicilios.js'),
42 replace('src/views/', ''), 42 replace('src/views/', ''),
43 replace("['ui.bootstrap', 'focaDirectivas', 'focaModal']", '[]'), 43 replace("['ui.bootstrap', 'focaDirectivas', 'focaModal']", '[]'),
44 gulp.dest(paths.tmp), 44 gulp.dest(paths.tmp),
45 rename('foca-modal-domicilios.min.js'), 45 rename('foca-modal-domicilios.min.js'),
46 uglify(), 46 uglify(),
47 gulp.dest(paths.dist) 47 gulp.dest(paths.dist)
48 ] 48 ]
49 ); 49 );
50 }); 50 });
51 51
52 gulp.task('pre-commit', function() { 52 gulp.task('pre-commit', function() {
53 return pump( 53 return pump(
54 [ 54 [
55 gulp.src(paths.srcJS), 55 gulp.src(paths.srcJS),
56 jshint('.jshintrc'), 56 jshint('.jshintrc'),
57 jshint.reporter('default'), 57 jshint.reporter('default'),
58 jshint.reporter('fail') 58 jshint.reporter('fail')
59 ] 59 ]
60 ); 60 );
61 61
62 gulp.start('uglify'); 62 gulp.start('uglify');
63 }); 63 });
64 64
65 gulp.task('webserver', function() { 65 gulp.task('webserver', function() {
66 pump [ 66 pump [
67 connect.server({port: 3000}) 67 connect.server({port: 3000})
68 ] 68 ]
69 }); 69 });
70 70
71 gulp.task('clean-post-install', function(){ 71 gulp.task('clean-post-install', function(){
72 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 72 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
73 'index.html'], {read: false}) 73 'index.html'], {read: false})
74 .pipe(clean()); 74 .pipe(clean());
75 }); 75 });
76 76
77 gulp.task('default', ['webserver']); 77 gulp.task('default', ['webserver']);
78 78
79 gulp.task('watch', function() { 79 gulp.task('watch', function() {
80 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']) 80 gulp.watch([paths.srcJS, paths.srcViews], ['uglify'])
81 }); 81 });
82 82
1 { 1 {
2 "name": "foca-modal-domicilio", 2 "name": "foca-modal-domicilio",
3 "version": "v0.1.2A", 3 "version": "v0.1.2A",
4 "description": "Modal para busqueda de domicilio", 4 "description": "Modal para busqueda de domicilio",
5 "scripts": { 5 "scripts": {
6 "refresh": "gulp uglify && cp tmp/foca-modal-domicilios.js ../wrapper-demo/node_modules/foca-modal-domicilio/dist/foca-modal-domicilios.min.js",
6 "refresh": "gulp uglify && cp tmp/foca-modal-domicilios.js ../wrapper-demo/node_modules/foca-modal-domicilio/dist/foca-modal-domicilios.min.js", 7 "test": "echo \"Error: no test specified\" && exit 1",
7 "test": "echo \"Error: no test specified\" && exit 1", 8 "gulp-pre-commit": "gulp pre-commit",
8 "gulp-pre-commit": "gulp pre-commit", 9 "compile": "gulp uglify",
9 "compile": "gulp uglify", 10 "postinstall": "npm run compile && gulp clean-post-install",
10 "postinstall": "npm run compile && gulp clean-post-install", 11 "install-dev": "npm install -D angular bootstrap font-awesome gulp gulp-angular-templatecache gulp-concat gulp-connect gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify gulp-clean jasmine-core jquery jshint pre-commit pump ui-bootstrap4 && npm i -D git+ssh://git@debonline.dyndns.org:npm/foca-directivas"
11 "install-dev": "npm install -D angular bootstrap font-awesome gulp gulp-angular-templatecache gulp-concat gulp-connect gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify gulp-clean jasmine-core jquery jshint pre-commit pump ui-bootstrap4 && npm i -D git+ssh://git@git.focasoftware.com:npm/foca-directivas" 12 },
12 }, 13 "pre-commit": [
13 "pre-commit": [ 14 "gulp-pre-commit"
14 "gulp-pre-commit" 15 ],
15 ], 16 "repository": {
16 "repository": { 17 "type": "git",
17 "type": "git", 18 "url": "http://git.focasoftware.com/npm/foca-modal-domicilio.git"
18 "url": "http://git.focasoftware.com/npm/foca-modal-domicilio.git" 19 },
19 }, 20 "author": "Foca Software",
20 "author": "Foca Software", 21 "license": "ISC",
21 "license": "ISC", 22 "peerDependencies": {
22 "peerDependencies": { 23 "angular": "^1.7.4",
23 "angular": "^1.7.4", 24 "bootstrap": "^4.1.3",
24 "bootstrap": "^4.1.3", 25 "font-awesome": "^4.7.0",
25 "font-awesome": "^4.7.0", 26 "ui-bootstrap4": "^3.0.4",
26 "ui-bootstrap4": "^3.0.4", 27 "gulp": "^3.9.1",
27 "gulp": "^3.9.1", 28 "gulp-angular-templatecache": "^2.2.1",
28 "gulp-angular-templatecache": "^2.2.1", 29 "gulp-concat": "^2.6.1",
29 "gulp-concat": "^2.6.1", 30 "gulp-connect": "^5.6.1",
30 "gulp-connect": "^5.6.1", 31 "gulp-htmlmin": "^5.0.1",
31 "gulp-htmlmin": "^5.0.1", 32 "gulp-rename": "^1.4.0",
32 "gulp-rename": "^1.4.0", 33 "gulp-replace": "^1.0.0",
33 "gulp-replace": "^1.0.0", 34 "gulp-uglify": "^3.0.1",
34 "gulp-uglify": "^3.0.1", 35 "jquery": "^3.3.1",
35 "jquery": "^3.3.1", 36 "pump": "^3.0.0",
36 "pump": "^3.0.0", 37 "foca-directivas": "git+ssh://git@debonline.dyndns.org:npm/foca-directivas"
37 "foca-directivas": "git+ssh://git@git.focasoftware.com:npm/foca-directivas" 38 },
38 }, 39 "devDependencies": {
39 "devDependencies": { 40 "angular": "^1.7.5",
40 "angular": "^1.7.5", 41 "bootstrap": "^4.1.3",
41 "bootstrap": "^4.1.3", 42 "foca-directivas": "git+ssh://git@debonline.dyndns.org:npm/foca-directivas",
42 "foca-directivas": "git+ssh://git@git.focasoftware.com:npm/foca-directivas", 43 "font-awesome": "^4.7.0",
43 "font-awesome": "^4.7.0", 44 "gulp": "^3.9.1",
44 "gulp": "^3.9.1", 45 "gulp-angular-templatecache": "^2.2.3",
45 "gulp-angular-templatecache": "^2.2.3", 46 "gulp-clean": "^0.4.0",
46 "gulp-clean": "^0.4.0", 47 "gulp-concat": "^2.6.1",
47 "gulp-concat": "^2.6.1", 48 "gulp-connect": "^5.6.1",
48 "gulp-connect": "^5.6.1", 49 "gulp-htmlmin": "^5.0.1",
49 "gulp-htmlmin": "^5.0.1", 50 "gulp-jshint": "^2.1.0",
50 "gulp-jshint": "^2.1.0", 51 "gulp-rename": "^1.4.0",
51 "gulp-rename": "^1.4.0", 52 "gulp-replace": "^1.0.0",
52 "gulp-replace": "^1.0.0", 53 "gulp-uglify": "^3.0.1",
53 "gulp-uglify": "^3.0.1", 54 "jasmine-core": "^3.3.0",
54 "jasmine-core": "^3.3.0", 55 "jquery": "^3.3.1",
55 "jquery": "^3.3.1", 56 "jshint": "^2.9.6",
56 "jshint": "^2.9.6", 57 "pre-commit": "^1.2.2",
57 "pre-commit": "^1.2.2", 58 "pump": "^3.0.0",
58 "pump": "^3.0.0", 59 "ui-bootstrap4": "^3.0.5"
59 "ui-bootstrap4": "^3.0.5" 60 }
60 } 61 }
61 } 62
src/js/controller.js
1 angular.module('focaModalDomicilio') 1 angular.module('focaModalDomicilio')
2 .controller('focaModalDomicilioController', 2 .controller('focaModalDomicilioController',
3 [ 3 [
4 '$timeout', 4 '$timeout',
5 '$filter', 5 '$filter',
6 '$scope', 6 '$scope',
7 '$uibModalInstance', 7 '$uibModalInstance',
8 'focaModalDomicilioService', 8 'focaModalDomicilioService',
9 '$uibModal', 9 '$uibModal',
10 'idCliente', 10 'idCliente',
11 'esNuevo', 11 'esNuevo',
12 'focaModalService', 12 'focaModalService',
13 function($timeout, $filter, $scope, $uibModalInstance, focaModalDomicilioService, 13 function($timeout, $filter, $scope, $uibModalInstance, focaModalDomicilioService,
14 $uibModal, idCliente, esNuevo, focaModalService) { 14 $uibModal, idCliente, esNuevo, focaModalService) {
15 15
16 $scope.buscar = function() { 16 $scope.buscar = function() {
17 focaModalDomicilioService 17 focaModalDomicilioService
18 .getDomiciliosEntregaByIdCliente($scope.idCliente) 18 .getDomiciliosEntregaByIdCliente($scope.idCliente)
19 .then(function(res) { 19 .then(function(res) {
20 $scope.domicilios = res.data; 20 $scope.domicilios = res.data;
21 $scope.search(); 21 $scope.search();
22 $scope.primerBusqueda = true; 22 $scope.primerBusqueda = true;
23 } 23 }
24 ); 24 );
25 }; 25 };
26 $scope.filters = ''; 26 $scope.filters = '';
27 $scope.idCliente = idCliente; 27 $scope.idCliente = idCliente;
28 $scope.buscar(); 28 $scope.buscar();
29 $scope.ingreso = esNuevo; 29 $scope.ingreso = esNuevo;
30 $scope.primerBusqueda = false; 30 $scope.primerBusqueda = false;
31 $scope.contactos = [{}]; 31 $scope.contactos = [{}];
32 // pagination 32 // pagination
33 $scope.numPerPage = 5; 33 $scope.numPerPage = 5;
34 $scope.currentPage = 1; 34 $scope.currentPage = 1;
35 $scope.filteredDomicilios = []; 35 $scope.filteredDomicilios = [];
36 $scope.currentPageDomicilios = []; 36 $scope.currentPageDomicilios = [];
37 $scope.selectedDomicilio = -1; 37 $scope.selectedDomicilio = -1;
38 $scope.focused = 1; 38 $scope.focused = 1;
39 $scope.domicilio = {}; 39 $scope.domicilio = {};
40 40
41 //METODOS 41 //METODOS
42 $scope.search = function(pressed) { 42 $scope.search = function(pressed) {
43 $scope.filteredDomicilios = $filter('filter')( 43 $scope.filteredDomicilios = $filter('filter')(
44 $scope.domicilios, 44 $scope.domicilios,
45 {$: $scope.filters} 45 {$: $scope.filters}
46 ); 46 );
47 47
48 if (pressed) { 48 if (pressed) {
49 if ($scope.filteredDomicilios.length === 0) { 49 if ($scope.filteredDomicilios.length === 0) {
50 $timeout(function() { 50 $timeout(function() {
51 angular.element('#search')[0].focus(); 51 angular.element('#search')[0].focus();
52 $scope.filters = ''; 52 $scope.filters = '';
53 }); 53 });
54 } else { 54 } else {
55 primera(); 55 primera();
56 } 56 }
57 } 57 }
58 58
59 $scope.lastPage = Math.ceil( 59 $scope.lastPage = Math.ceil(
60 $scope.filteredDomicilios.length / $scope.numPerPage 60 $scope.filteredDomicilios.length / $scope.numPerPage
61 ); 61 );
62 62
63 $scope.resetPage(); 63 $scope.resetPage();
64 }; 64 };
65 65
66 $scope.resetPage = function() { 66 $scope.resetPage = function() {
67 $scope.currentPage = 1; 67 $scope.currentPage = 1;
68 $scope.selectPage(1); 68 $scope.selectPage(1);
69 }; 69 };
70 70
71 $scope.selectPage = function(page) { 71 $scope.selectPage = function(page) {
72 var start = (page - 1) * $scope.numPerPage; 72 var start = (page - 1) * $scope.numPerPage;
73 var end = start + $scope.numPerPage; 73 var end = start + $scope.numPerPage;
74 $scope.paginas = []; 74 $scope.paginas = [];
75 $scope.paginas = calcularPages(page); 75 $scope.paginas = calcularPages(page);
76 $scope.currentPageDomicilios = $scope.filteredDomicilios.slice(start, end); 76 $scope.currentPageDomicilios = $scope.filteredDomicilios.slice(start, end);
77 $scope.currentPage = page; 77 $scope.currentPage = page;
78 }; 78 };
79 79
80 $scope.select = function(domicilio) { 80 $scope.select = function(domicilio) {
81 $uibModalInstance.close(domicilio); 81 $uibModalInstance.close(domicilio);
82 }; 82 };
83 83
84 $scope.cancel = function() { 84 $scope.cancel = function() {
85 $uibModalInstance.dismiss('cancel'); 85 $uibModalInstance.dismiss('cancel');
86 }; 86 };
87 87
88 $scope.busquedaDown = function(key) { 88 $scope.busquedaDown = function(key) {
89 if (key === 40) { 89 if (key === 40) {
90 primera(key); 90 primera(key);
91 } 91 }
92 }; 92 };
93 93
94 $scope.busquedaPress = function(key) { 94 $scope.busquedaPress = function(key) {
95 if (key === 13) { 95 if (key === 13) {
96 $scope.search(true); 96 $scope.search(true);
97 } 97 }
98 }; 98 };
99 99
100 $scope.itemDomicilio = function(key) { 100 $scope.itemDomicilio = function(key) {
101 if (key === 38) { 101 if (key === 38) {
102 anterior(key); 102 anterior(key);
103 } 103 }
104 104
105 if (key === 40) { 105 if (key === 40) {
106 siguiente(key); 106 siguiente(key);
107 } 107 }
108 108
109 if (key === 37) { 109 if (key === 37) {
110 retrocederPagina(); 110 retrocederPagina();
111 } 111 }
112 112
113 if (key === 39) { 113 if (key === 39) {
114 avanzarPagina(); 114 avanzarPagina();
115 } 115 }
116 }; 116 };
117 117
118 $scope.agregarDomicilio = function() { 118 $scope.agregarDomicilio = function() {
119 119
120 $scope.domicilio.valores = []; 120 $scope.domicilio.valores = [];
121 $scope.domicilio.idCliente = $scope.idCliente; 121 $scope.domicilio.idCliente = $scope.idCliente;
122 if ($scope.domicilio.calle) { 122 if ($scope.domicilio.calle) {
123 $scope.domicilio.valores.push({ 123 $scope.domicilio.valores.push({
124 ID_ADAC_1: 1, 124 ID_ADAC_1: 1,
125 dato: $scope.domicilio.calle 125 dato: $scope.domicilio.calle
126 }); 126 });
127 } 127 }
128 if ($scope.domicilio.numeroCalle) { 128 if ($scope.domicilio.numeroCalle) {
129 $scope.domicilio.valores.push({ 129 $scope.domicilio.valores.push({
130 ID_ADAC_1: 2, 130 ID_ADAC_1: 2,
131 dato: $scope.domicilio.numeroCalle 131 dato: $scope.domicilio.numeroCalle
132 }); 132 });
133 } 133 }
134 if ($scope.domicilio.localidad) { 134 if ($scope.domicilio.localidad) {
135 $scope.domicilio.valores.push({ 135 $scope.domicilio.valores.push({
136 ID_ADAC_1: 3, 136 ID_ADAC_1: 3,
137 dato: $scope.domicilio.localidad 137 dato: $scope.domicilio.localidad
138 }); 138 });
139 } 139 }
140 if ($scope.domicilio.provincia) { 140 if ($scope.domicilio.provincia) {
141 $scope.domicilio.valores.push({ 141 $scope.domicilio.valores.push({
142 ID_ADAC_1: 4, 142 ID_ADAC_1: 4,
143 dato: $scope.domicilio.provincia 143 dato: $scope.domicilio.provincia
144 }); 144 });
145 } 145 }
146 if ($scope.domicilio.latitud) { 146 if ($scope.domicilio.latitud) {
147 $scope.domicilio.valores.push({ 147 $scope.domicilio.valores.push({
148 ID_ADAC_1: 23, 148 ID_ADAC_1: 23,
149 dato: $scope.domicilio.latitud.toString() 149 dato: $scope.domicilio.latitud.toString()
150 }); 150 });
151 } 151 }
152 if ($scope.domicilio.longitud) { 152 if ($scope.domicilio.longitud) {
153 $scope.domicilio.valores.push({ 153 $scope.domicilio.valores.push({
154 ID_ADAC_1: 24, 154 ID_ADAC_1: 24,
155 dato: $scope.domicilio.longitud.toString() 155 dato: $scope.domicilio.longitud.toString()
156 }); 156 });
157 } 157 }
158 158
159 if (!$scope.domicilio.titulo) { 159 if (!$scope.domicilio.titulo) {
160 focaModalService.alert('Ingrese titulo'); 160 focaModalService.alert('Ingrese titulo');
161 return; 161 return;
162 } else if (!$scope.domicilio.calle) { 162 } else if (!$scope.domicilio.calle) {
163 focaModalService.alert('Ingrese calle'); 163 focaModalService.alert('Ingrese calle');
164 return; 164 return;
165 } else if (!$scope.domicilio.numeroCalle) { 165 } else if (!$scope.domicilio.numeroCalle) {
166 focaModalService.alert('Ingrese numero de calle'); 166 focaModalService.alert('Ingrese numero de calle');
167 return; 167 return;
168 } else if (!$scope.domicilio.localidad) { 168 } else if (!$scope.domicilio.localidad) {
169 focaModalService.alert('Ingrese localidad'); 169 focaModalService.alert('Ingrese localidad');
170 return; 170 return;
171 } else if (!$scope.domicilio.provincia) { 171 } else if (!$scope.domicilio.provincia) {
172 focaModalService.alert('Ingrese provincia'); 172 focaModalService.alert('Ingrese provincia');
173 return; 173 return;
174 } 174 }
175 175
176 //domicilios de entrega corresponden al 1 176 //domicilios de entrega corresponden al 1
177 focaModalDomicilioService 177 focaModalDomicilioService
178 .obtenerUltimoPorNivelPadre(1) 178 .obtenerUltimoPorNivelPadre(1)
179 .then(function(res) { 179 .then(function(res) {
180 $scope.domicilio.nivel1 = 1;//domicilio de entrega corresponde 1 180 $scope.domicilio.nivel1 = 1;//domicilio de entrega corresponde 1
181 $scope.domicilio.nivel2 = res.data[0].ultimo + 1; 181 $scope.domicilio.nivel2 = res.data[0].ultimo + 1;
182 focaModalDomicilioService 182 focaModalDomicilioService
183 .guardarDomicilio($scope.domicilio) 183 .guardarDomicilio($scope.domicilio)
184 .then(function() { 184 .then(function() {
185 $scope.buscar(); 185 $scope.buscar();
186 $scope.ingreso = false; 186 $scope.ingreso = false;
187 $scope.domicilio = {}; 187 $scope.domicilio = {};
188 }) 188 })
189 .catch(function() { 189 .catch(function() {
190 focaModalService.alert('Hubo un error al crear el domicilio'); 190 focaModalService.alert('Hubo un error al crear el domicilio');
191 $scope.ingreso = false; 191 $scope.ingreso = false;
192 }); 192 });
193 }); 193 });
194 }; 194 };
195 195
196 $scope.verPuntosDescarga = function(key) { 196 $scope.verPuntosDescarga = function(key) {
197 197
198 $scope.currentPageDomicilios[key].verPuntos = true; 198 $scope.currentPageDomicilios[key].verPuntos = true;
199 $scope.select($scope.currentPageDomicilios[key]); 199 $scope.select($scope.currentPageDomicilios[key]);
200 }; 200 };
201 201
202 $scope.localizarDomicilio = function(localizar) { 202 $scope.localizarDomicilio = function(localizar) {
203 var direccion = null; 203 var direccion = null;
204 if (localizar) { 204 if (localizar) {
205 direccion = { 205 direccion = {
206 calle: $scope.domicilio.calle, 206 calle: $scope.domicilio.calle,
207 numero: $scope.domicilio.numeroCalle, 207 numero: $scope.domicilio.numeroCalle,
208 localidad: $scope.domicilio.localidad, 208 localidad: $scope.domicilio.localidad,
209 provincia: $scope.domicilio.provincia 209 provincia: $scope.domicilio.provincia
210 }; 210 };
211 } 211 }
212 var modalInstance = $uibModal.open( 212 var modalInstance = $uibModal.open(
213 { 213 {
214 ariaLabelledBy: 'Buscar domicilio', 214 ariaLabelledBy: 'Buscar domicilio',
215 templateUrl: 'modal-localizar.html', 215 templateUrl: 'modal-localizar.html',
216 controller: 'focaModalLocalizarController', 216 controller: 'focaModalLocalizarController',
217 size: 'lg', 217 size: 'lg',
218 resolve: { 218 resolve: {
219 parametros: { 219 parametros: {
220 direccion: direccion,
221 latitud: $scope.domicilio.latitud,
222 longitud: $scope.domicilio.longitud
223 }
220 direccion: direccion, 224 }
221 latitud: $scope.domicilio.latitud, 225 }
222 longitud: $scope.domicilio.longitud 226 );
223 } 227 modalInstance.result.then(function(res) {
224 } 228 $scope.domicilio.latitud = res.latitud;
225 } 229 $scope.domicilio.longitud = res.longitud;
226 ); 230 }, function() {
227 modalInstance.result.then(function(res) { 231 //TODO: función llamada cuando cancela el modal
228 $scope.domicilio.latitud = res.latitud; 232 });
229 $scope.domicilio.longitud = res.longitud; 233 };
230 }, function() { 234
231 //TODO: función llamada cuando cancela el modal 235 $scope.next = function(key) {
232 }); 236 if (key === 13) $scope.focused++;
233 }; 237 };
234 238
235 $scope.next = function(key) { 239 function calcularPages(paginaActual) {
236 if (key === 13) $scope.focused++; 240 var paginas = [];
237 }; 241 paginas.push(paginaActual);
238 242
239 function calcularPages(paginaActual) { 243 if (paginaActual - 1 > 1) {
240 var paginas = []; 244
241 paginas.push(paginaActual); 245 paginas.unshift(paginaActual - 1);
242 246 if (paginaActual - 2 > 1) {
243 if (paginaActual - 1 > 1) { 247 paginas.unshift(paginaActual - 2);
244 248 }
245 paginas.unshift(paginaActual - 1); 249 }
246 if (paginaActual - 2 > 1) { 250
247 paginas.unshift(paginaActual - 2); 251 if (paginaActual + 1 < $scope.lastPage) {
248 } 252 paginas.push(paginaActual + 1);
249 } 253 if (paginaActual + 2 < $scope.lastPage) {
250 254 paginas.push(paginaActual + 2);
251 if (paginaActual + 1 < $scope.lastPage) { 255 }
252 paginas.push(paginaActual + 1); 256 }
253 if (paginaActual + 2 < $scope.lastPage) { 257
254 paginas.push(paginaActual + 2); 258 if (paginaActual !== 1) {
255 } 259 paginas.unshift(1);
256 } 260 }
257 261
258 if (paginaActual !== 1) { 262 if (paginaActual !== $scope.lastPage) {
259 paginas.unshift(1); 263 paginas.push($scope.lastPage);
260 } 264 }
261 265
262 if (paginaActual !== $scope.lastPage) { 266 return paginas;
263 paginas.push($scope.lastPage); 267 }
264 } 268
265 269 function primera() {
266 return paginas; 270 $scope.selectedDomicilio = 0;
267 } 271 }
268 272
269 function primera() { 273 function anterior() {
270 $scope.selectedDomicilio = 0; 274 if ($scope.selectedDomicilio === 0 && $scope.currentPage > 1) {
271 } 275 retrocederPagina();
272 276 } else {
273 function anterior() { 277 $scope.selectedDomicilio--;
274 if ($scope.selectedDomicilio === 0 && $scope.currentPage > 1) { 278 }
275 retrocederPagina(); 279 }
276 } else { 280
277 $scope.selectedDomicilio--; 281 function siguiente() {
278 } 282 if ($scope.selectedDomicilio < $scope.currentPageDomicilios.length ) {
279 } 283 $scope.selectedDomicilio++;
280 284 } else {
281 function siguiente() { 285 avanzarPagina();
282 if ($scope.selectedDomicilio < $scope.currentPageDomicilios.length ) { 286 }
283 $scope.selectedDomicilio++; 287 }
284 } else { 288
285 avanzarPagina(); 289 function retrocederPagina() {
286 } 290 if ($scope.currentPage > 1) {
287 } 291 $scope.selectPage($scope.currentPage - 1);
288 292 $scope.selectedDomicilio = $scope.numPerPage - 1;
289 function retrocederPagina() { 293 }
290 if ($scope.currentPage > 1) { 294 }
291 $scope.selectPage($scope.currentPage - 1); 295
292 $scope.selectedDomicilio = $scope.numPerPage - 1; 296 function avanzarPagina() {
293 } 297 if ($scope.currentPage < $scope.lastPage) {
294 } 298 $scope.selectPage($scope.currentPage + 1);
295 299 $scope.selectedDomicilio = 0;
296 function avanzarPagina() { 300 }
297 if ($scope.currentPage < $scope.lastPage) { 301 }
298 $scope.selectPage($scope.currentPage + 1); 302 }
299 $scope.selectedDomicilio = 0; 303 ]
300 } 304 );
301 } 305
src/views/modal-domicilio.html
1 <div class="modal-header py-1"> 1 <div class="modal-header py-1">
2 <div class="row w-100"> 2 <div class="row w-100 justify-content-between">
3 <div class="col-lg-6"> 3 <div class="col-auto">
4 <h5 class="modal-title my-1" ng-hide="ingreso">Búsqueda de Domicilios</h5> 4 <h5 class="modal-title my-1" ng-hide="ingreso">Búsqueda de Domicilios</h5>
5 <h5 class="modal-title my-1" ng-show="ingreso">Crear domicilios de descarga</h5> 5 <h5 class="modal-title my-1" ng-show="ingreso">Crear domicilios de descarga</h5>
6 </div> 6 </div>
7 <div class="input-group col-lg-6 pr-0 my-2"> 7 <div class="col-auto pr-0 my-2">
8 <button 8 <button
9 class="btn btn-outline-debo mr-2" 9 class="btn btn-outline-debo mr-2"
10 ng-click="ingreso = true" 10 ng-click="ingreso = true"
11 ng-show="!ingreso" 11 ng-show="!ingreso"
12 title="Nuevo"> 12 title="Nuevo">
13 <i class="fa fa-plus" aria-hidden="true"></i> 13 <i class="fa fa-plus" aria-hidden="true"></i>
14 </button> 14 </button>
15 <input
16 type="text"
17 class="form-control form-control-sm"
18 id="search"
19 placeholder="Búsqueda"
20 ng-model="filters"
21 ng-change="search()"
22 ng-keydown="busquedaDown($event.keyCode)"
23 ng-keypress="busquedaPress($event.keyCode)"
24 foca-focus="selectedDomicilio == -1"
25 ng-focus="selectedDomicilio = -1"
26 teclado-virtual
27 >
28 <div class="input-group-append">
29 <button
30 ladda="searchLoading"
31 class="btn btn-outline-secondary"
32 type="button"
33 ng-click="busquedaPress(13)"
34 >
35 <i class="fa fa-search" aria-hidden="true"></i>
36 </button>
37 </div>
38 </div> 15 </div>
39 </div> 16 </div>
40 </div> 17 </div>
41 <div class="modal-body" id="modal-body"> 18 <div class="modal-body" id="modal-body">
42 19
43 <div ng-show="!primerBusqueda"> 20 <div ng-show="!primerBusqueda">
44 Debe realizar una primer búsqueda. 21 Debe realizar una primer búsqueda.
45 </div> 22 </div>
46 23
47 <div ng-show="!ingreso"> 24 <div ng-show="!ingreso">
48 <table ng-show="!ingreso" class="table table-striped table-sm"> 25 <table ng-show="!ingreso" class="table table-striped table-sm">
49 <thead> 26 <thead>
50 <tr> 27 <tr>
51 <th>Titulo</th> 28 <th>Titulo</th>
52 <th>Calle</th> 29 <th>Calle</th>
53 <th>Localidad</th> 30 <th>Localidad</th>
54 <th>Provincia</th> 31 <th>Provincia</th>
55 <th></th> 32 <th></th>
56 <th></th> 33 <th></th>
57 </tr> 34 </tr>
58 </thead> 35 </thead>
59 <tbody> 36 <tbody>
60 <tr ng-show="currentPageDomicilios.length == 0 && primerBusqueda"> 37 <tr ng-show="currentPageDomicilios.length == 0 && primerBusqueda">
61 <td colspan="5"> 38 <td colspan="5">
62 No se encontraron resultados. 39 No se encontraron resultados.
63 </td> 40 </td>
64 </tr> 41 </tr>
65 <tr class="selectable" 42 <tr class="selectable"
66 ng-repeat="(key,domicilio) in currentPageDomicilios"> 43 ng-repeat="(key,domicilio) in currentPageDomicilios">
67 <td 44 <td
68 ng-bind="domicilio.titulo" 45 ng-bind="domicilio.titulo"
69 ng-click="select(domicilio)" 46 ng-click="select(domicilio)"
70 ></td> 47 ></td>
71 <td 48 <td
72 ng-bind="domicilio.Calle + ' ' + domicilio.Numero" 49 ng-bind="domicilio.Calle + ' ' + domicilio.Numero"
73 ng-click="select(domicilio)" 50 ng-click="select(domicilio)"
74 ></td> 51 ></td>
75 <td 52 <td
76 ng-bind="domicilio.Localidad" 53 ng-bind="domicilio.Localidad"
77 ng-click="select(domicilio)" 54 ng-click="select(domicilio)"
78 ></td> 55 ></td>
79 <td 56 <td
80 ng-bind="domicilio.Provincia" 57 ng-bind="domicilio.Provincia"
81 ng-click="select(domicilio)" 58 ng-click="select(domicilio)"
82 ></td> 59 ></td>
83 <td> 60 <td>
84 <button 61 <button
85 type="button" 62 type="button"
86 class="btn btn-sm p-1 float-right btn-secondary" 63 class="btn btn-sm p-1 float-right btn-secondary"
87 ng-click="verPuntosDescarga(key)" 64 ng-click="verPuntosDescarga(key)"
88 title="Puntos de descarga" 65 title="Puntos de descarga"
89 > 66 >
90 <small>PD</small> 67 <small>PD</small>
91 </button> 68 </button>
92 </td> 69 </td>
93 <td> 70 <td>
94 <button 71 <button
95 type="button" 72 type="button"
96 class="btn btn-sm p-1 float-right" 73 class="btn btn-sm p-1 float-right"
97 ng-class="{ 74 ng-class="{
98 'btn-secondary': selectedDomicilio != key + 1, 75 'btn-secondary': selectedDomicilio != key + 1,
99 'btn-primary': selectedDomicilio == key + 1 76 'btn-primary': selectedDomicilio == key + 1
100 }" 77 }"
101 foca-focus="selectedDomicilio == {{key + 1}}" 78 foca-focus="selectedDomicilio == {{key + 1}}"
102 ng-keydown="itemDomicilio($event.keyCode)" 79 ng-keydown="itemDomicilio($event.keyCode)"
103 ng-click="select(domicilio)" 80 ng-click="select(domicilio)"
104 title="Seleccionar" 81 title="Seleccionar"
105 > 82 >
106 <i class="fa fa-circle-thin" aria-hidden="true"></i> 83 <i class="fa fa-circle-thin" aria-hidden="true"></i>
107 </button> 84 </button>
108 </td> 85 </td>
109 </tr> 86 </tr>
110 </tbody> 87 </tbody>
111 </table> 88 </table>
112 </div> 89 </div>
113 <form name="formDomicilio" ng-show="ingreso"> 90 <form name="formDomicilio" ng-show="ingreso">
114 <input 91 <input
115 type="hidden" 92 type="hidden"
116 ng-model="domicilio.latitud" 93 ng-model="domicilio.latitud"
117 ng-required="true"> 94 ng-required="true">
118 <input 95 <input
119 type="hidden" 96 type="hidden"
120 ng-model="domicilio.longitud" 97 ng-model="domicilio.longitud"
121 ng-required="true"> 98 ng-required="true">
122 <div class="row"> 99 <div class="row">
123 <div class="col-4"> 100 <div class="col-4">
124 <label>Tipo</label> 101 <label>Tipo</label>
125 <select 102 <select
126 class="form-control" 103 class="form-control"
127 ng-disabled="true" 104 ng-disabled="true"
128 > 105 >
129 <option ng-value="2">Entrega</option> 106 <option ng-value="2">Entrega</option>
130 </select> 107 </select>
131 </div> 108 </div>
132 <div class="col-8"> 109 <div class="col-8">
133 <label>Titulo</label> 110 <label>Titulo</label>
134 <input 111 <input
135 type="text" 112 type="text"
136 foca-focus="ingreso" 113 foca-focus="ingreso"
137 class="form-control" 114 class="form-control"
138 ng-model="domicilio.titulo" 115 ng-model="domicilio.titulo"
139 placeholder="Ingrese título" 116 placeholder="Ingrese título"
140 ng-required="true" 117 ng-required="true"
141 ng-keypress="next($event.keyCode)" 118 ng-keypress="next($event.keyCode)"
142 ng-focus="focused = 1" 119 ng-focus="focused = 1"
143 foca-focus="focused == 1" 120 foca-focus="focused == 1"
144 teclado-virtual 121 teclado-virtual
145 /> 122 />
146 </div> 123 </div>
147 <div class="col-9"> 124 <div class="col-9">
148 <label>Calle</label> 125 <label>Calle</label>
149 <input 126 <input
150 type="text" 127 type="text"
151 class="form-control" 128 class="form-control"
152 ng-model="domicilio.calle" 129 ng-model="domicilio.calle"
153 placeholder="Ingrese calle" 130 placeholder="Ingrese calle"
154 ng-required="true" 131 ng-required="true"
155 ng-keypress="next($event.keyCode)" 132 ng-keypress="next($event.keyCode)"
156 ng-focus="focused = 2" 133 ng-focus="focused = 2"
157 foca-focus="focused == 2" 134 foca-focus="focused == 2"
158 teclado-virtual 135 teclado-virtual
159 /> 136 />
160 </div> 137 </div>
161 <div class="col-3"> 138 <div class="col-3">
162 <label>Nº</label> 139 <label>Nº</label>
163 <input 140 <input
164 type="text" 141 type="text"
165 class="form-control" 142 class="form-control"
166 ng-model="domicilio.numeroCalle" 143 ng-model="domicilio.numeroCalle"
167 placeholder="Ingrese Numero" 144 placeholder="Ingrese Numero"
168 ng-required="true" 145 ng-required="true"
169 ng-keypress="next($event.keyCode)" 146 ng-keypress="next($event.keyCode)"
170 ng-focus="focused = 3" 147 ng-focus="focused = 3"
171 foca-focus="focused == 3" 148 foca-focus="focused == 3"
172 only-numbers 149 only-numbers
173 teclado-virtual 150 teclado-virtual
174 /> 151 />
175 </div> 152 </div>
176 <div class="col-6"> 153 <div class="col-6">
177 <label>Localidad</label> 154 <label>Localidad</label>
178 <input 155 <input
179 type="text" 156 type="text"
180 class="form-control" 157 class="form-control"
181 ng-model="domicilio.localidad" 158 ng-model="domicilio.localidad"
182 placeholder="Ingrese localidad" 159 placeholder="Ingrese localidad"
183 ng-required="true" 160 ng-required="true"
184 ng-keypress="next($event.keyCode)" 161 ng-keypress="next($event.keyCode)"
185 ng-focus="focused = 4" 162 ng-focus="focused = 4"
186 foca-focus="focused == 4" 163 foca-focus="focused == 4"
187 teclado-virtual 164 teclado-virtual
188 /> 165 />
189 </div> 166 </div>
190 <div class="col-6"> 167 <div class="col-6">
191 <label>Provincia</label> 168 <label>Provincia</label>
192 <input 169 <input
193 type="text" 170 type="text"
194 class="form-control" 171 class="form-control"
195 ng-model="domicilio.provincia" 172 ng-model="domicilio.provincia"
196 placeholder="Ingrese provincia" 173 placeholder="Ingrese provincia"
197 ng-required="true" 174 ng-required="true"
198 ng-keypress="next($event.keyCode)" 175 ng-keypress="next($event.keyCode)"
199 ng-focus="focused = 5" 176 ng-focus="focused = 5"
200 foca-focus="focused == 5" 177 foca-focus="focused == 5"
201 teclado-virtual 178 teclado-virtual
202 /> 179 />
203 </div> 180 </div>
204 </div> 181 </div>
205 <div class="row mt-3"> 182 <div class="row mt-3">
206 <div class="col-12"> 183 <div class="col-12">
207 <button 184 <button
208 type="button" 185 type="button"
209 class="btn btn-primary float-right ml-3" 186 class="btn btn-outline-debo float-right ml-3"
210 ng-click="localizarDomicilio()">Buscar</button> 187 ng-click="localizarDomicilio()">Buscar</button>
211 <button 188 <button
212 type="button" 189 type="button"
213 class="btn btn-primary float-right" 190 class="btn btn-outline-debo float-right"
214 ng-disabled="!domicilio.calle || !domicilio.numeroCalle || !domicilio.localidad || !domicilio.provincia" 191 ng-disabled="!domicilio.calle || !domicilio.numeroCalle || !domicilio.localidad || !domicilio.provincia"
215 ng-click="localizarDomicilio(true)">Localizar</button> 192 ng-click="localizarDomicilio(true)">Localizar</button>
216 </div> 193 </div>
217 </div> 194 </div>
218 </form> 195 </form>
219 </div> 196 </div>
220 <div class="modal-footer"> 197 <div class="modal-footer">
221 <nav ng-show="currentPageDomicilios.length > 0 && !ingreso" class="mr-auto"> 198 <nav ng-show="currentPageDomicilios.length > 0 && !ingreso" class="mr-auto">
222 <ul class="pagination pagination-sm mb-0 justify-content-end"> 199 <ul class="pagination pagination-sm mb-0 justify-content-end">
223 <li class="page-item" ng-class="{'disabled': currentPage == 1}"> 200 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
224 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> 201 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)">
225 <span aria-hidden="true">&laquo;</span> 202 <span aria-hidden="true">&laquo;</span>
226 <span class="sr-only">Anterior</span> 203 <span class="sr-only">Anterior</span>
227 </a> 204 </a>
228 </li> 205 </li>
229 <li 206 <li
230 class="page-item" 207 class="page-item"
231 ng-repeat="pagina in paginas" 208 ng-repeat="pagina in paginas"
232 ng-class="{'active': pagina == currentPage}" 209 ng-class="{'active': pagina == currentPage}"
233 > 210 >
234 <a 211 <a
235 class="page-link" 212 class="page-link"
236 href="javascript:void();" 213 href="javascript:void();"
237 ng-click="selectPage(pagina)" 214 ng-click="selectPage(pagina)"
238 ng-bind="pagina" 215 ng-bind="pagina"
239 ></a> 216 ></a>
240 </li> 217 </li>
241 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> 218 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
242 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> 219 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)">
243 <span aria-hidden="true">&raquo;</span> 220 <span aria-hidden="true">&raquo;</span>
244 <span class="sr-only">Siguiente</span> 221 <span class="sr-only">Siguiente</span>
245 </a> 222 </a>
246 </li> 223 </li>
247 </ul> 224 </ul>
248 </nav> 225 </nav>
249 <button 226 <button
250 ng-show="!ingreso" 227 ng-show="!ingreso"
251 class="btn btn-sm btn-secondary" 228 class="btn btn-sm btn-secondary"
252 type="button" 229 type="button"
253 ng-click="cancel()" 230 ng-click="cancel()"
254 >Volver 231 >Volver
255 </button> 232 </button>
256 <button 233 <button
257 ng-show="ingreso" 234 ng-show="ingreso"
258 class="btn btn-secondary btn-sm" 235 class="btn btn-secondary btn-sm"
259 type="button" 236 type="button"
260 ng-click="ingreso = !ingreso; domicilio = {}; contactos = [{}]" 237 ng-click="ingreso = !ingreso; domicilio = {}; contactos = [{}]"
261 >Cancelar 238 >Cancelar
262 </button> 239 </button>
263 <button 240 <button
264 ng-show="ingreso" 241 ng-show="ingreso"
265 class="btn btn-sm btn-primary" 242 class="btn btn-sm btn-primary"
266 type="button" 243 type="button"
267 ng-click="agregarDomicilio()" 244 ng-click="agregarDomicilio()"
268 >Agregar domicilio 245 >Agregar domicilio
269 </button> 246 </button>
270 </div> 247 </div>
271 248