Commit d0c69fa0c812b80052a3174ffa15fe05be20e039

Authored by Eric Fernandez
1 parent e645dcb5a9
Exists in master and in 1 other branch develop

modal recibe cotización para cálculo de precios

Showing 2 changed files with 12 additions and 3 deletions   Show diff stats
1 <html ng-app="focaBusquedaProductos"> 1 <html ng-app="focaBusquedaProductos">
2 <head> 2 <head>
3 <meta charset="UTF-8"/> 3 <meta charset="UTF-8"/>
4 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 4 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
5 5
6 <!--CSS--> 6 <!--CSS-->
7 <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/> 7 <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
8 <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet"/> 8 <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
9 <link href="node_modules/ladda/dist/ladda-themeless.min.css" rel="stylesheet"> 9 <link href="node_modules/ladda/dist/ladda-themeless.min.css" rel="stylesheet">
10 10
11 <!--VENDOR JS--> 11 <!--VENDOR JS-->
12 <script src="node_modules/jquery/dist/jquery.min.js"></script> 12 <script src="node_modules/jquery/dist/jquery.min.js"></script>
13 <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> 13 <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
14 <script src="node_modules/angular/angular.min.js"></script> 14 <script src="node_modules/angular/angular.min.js"></script>
15 <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script> 15 <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script>
16 <script src="node_modules/foca-directivas/dist/foca-directivas.min.js"></script> 16 <script src="node_modules/foca-directivas/dist/foca-directivas.min.js"></script>
17 <script src="node_modules/ladda/dist/spin.min.js"></script> 17 <script src="node_modules/ladda/dist/spin.min.js"></script>
18 <script src="node_modules/ladda/dist/ladda.min.js"></script> 18 <script src="node_modules/ladda/dist/ladda.min.js"></script>
19 <script src="node_modules/angular-ladda/dist/angular-ladda.min.js"></script> 19 <script src="node_modules/angular-ladda/dist/angular-ladda.min.js"></script>
20 20
21 <!-- BUILD --> 21 <!-- BUILD -->
22 <script src="src/js/app.js"></script> 22 <script src="src/js/app.js"></script>
23 <script src="src/js/controller.js"></script> 23 <script src="src/js/controller.js"></script>
24 <script src="src/js/service.js"></script> 24 <script src="src/js/service.js"></script>
25 25
26 <!-- /BUILD --> 26 <!-- /BUILD -->
27 27
28 <!-- CONFIG PARA DEVELOP --> 28 <!-- CONFIG PARA DEVELOP -->
29 <script src="src/etc/develop.js"></script> 29 <script src="src/etc/develop.js"></script>
30 <script type="text/javascript"> 30 <script type="text/javascript">
31 angular.module('focaBusquedaProductos') 31 angular.module('focaBusquedaProductos')
32 .controller('controller', [ 32 .controller('controller', [
33 '$scope', 33 '$scope',
34 '$uibModal', 34 '$uibModal',
35 '$timeout', 35 '$timeout',
36 function($scope, $uibModal, $timeout) { 36 function($scope, $uibModal, $timeout) {
37 openModal(); 37 openModal();
38 38
39 function openModal() { 39 function openModal() {
40 var modalInstance = $uibModal.open( 40 var modalInstance = $uibModal.open(
41 { 41 {
42 ariaLabelledBy: 'Busqueda de Productos', 42 ariaLabelledBy: 'Busqueda de Productos',
43 templateUrl: 'src/views/modal-busqueda-productos.html', 43 templateUrl: 'src/views/modal-busqueda-productos.html',
44 controller: 'modalBusquedaProductosCtrl', 44 controller: 'modalBusquedaProductosCtrl',
45 size: 'lg', 45 size: 'lg',
46 resolve: {idLista : function() { return -1; }} 46 resolve: {idLista : function() { return -1; }, cotizacion: 1}
47 } 47 }
48 ); 48 );
49 49
50 modalInstance.result.then( 50 modalInstance.result.then(
51 function (selectedItem) { 51 function (selectedItem) {
52 console.info(selectedItem); 52 console.info(selectedItem);
53 $timeout(openModal, 500); 53 $timeout(openModal, 500);
54 }, function () { 54 }, function () {
55 console.info('modal-component dismissed at: ' + new Date()); 55 console.info('modal-component dismissed at: ' + new Date());
56 $timeout(openModal, 500); 56 $timeout(openModal, 500);
57 } 57 }
58 ); 58 );
59 } 59 }
60 } 60 }
61 ]); 61 ]);
62 </script> 62 </script>
63 </head> 63 </head>
64 <body ng-controller="controller"> 64 <body ng-controller="controller">
65 </body> 65 </body>
66 </html> 66 </html>
67 67
src/js/controller.js
1 angular.module('focaBusquedaProductos') 1 angular.module('focaBusquedaProductos')
2 .controller('modalBusquedaProductosCtrl', 2 .controller('modalBusquedaProductosCtrl',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'idLista', 7 'idLista',
8 'cotizacion',
8 'focaBusquedaProductosService', 9 'focaBusquedaProductosService',
9 function($filter, $scope, $uibModalInstance, idLista, focaBusquedaProductosService) { 10 function($filter, $scope, $uibModalInstance, idLista,
11 cotizacion, focaBusquedaProductosService
12 ) {
10 13
11 $scope.filters = ''; 14 $scope.filters = '';
12 $scope.productos = []; 15 $scope.productos = [];
13 $scope.primerBusqueda = false; 16 $scope.primerBusqueda = false;
14 $scope.searchLoading = false; 17 $scope.searchLoading = false;
15 // pagination 18 // pagination
16 $scope.numPerPage = 10; 19 $scope.numPerPage = 10;
17 $scope.currentPage = 1; 20 $scope.currentPage = 1;
18 $scope.filteredProductos = []; 21 $scope.filteredProductos = [];
19 $scope.currentPageProductos = []; 22 $scope.currentPageProductos = [];
20 $scope.selectedProducto = -1; 23 $scope.selectedProducto = -1;
21 24
22 //METODOS 25 //METODOS
23 $scope.busquedaPress = function(key) { 26 $scope.busquedaPress = function(key) {
24 if (key === 13) { 27 if (key === 13) {
25 $scope.searchLoading = true; 28 $scope.searchLoading = true;
26 if(idLista > 0) { 29 if(idLista > 0) {
27 focaBusquedaProductosService 30 focaBusquedaProductosService
28 .getProductosByIdLista(idLista, $scope.filters) 31 .getProductosByIdLista(idLista, $scope.filters)
29 .then( 32 .then(
30 function(res) { 33 function(res) {
34 for(var i = 0; i < res.data.length; i++) {
35 res.data[i].precio = res.data[i].precio / cotizacion;
36 }
31 $scope.searchLoading = false; 37 $scope.searchLoading = false;
32 $scope.primerBusqueda = true; 38 $scope.primerBusqueda = true;
33 $scope.productos = res.data; 39 $scope.productos = res.data;
34 $scope.search(); 40 $scope.search();
35 primera(); 41 primera();
36 } 42 }
37 ); 43 );
38 } else if(idLista === -1) { 44 } else if(idLista === -1) {
39 focaBusquedaProductosService.getProductos().then( 45 focaBusquedaProductosService.getProductos().then(
40 function(res) { 46 function(res) {
47 for(var i = 0; i < res.data.length; i++) {
48 res.data[i].precio = res.data[i].precio / cotizacion;
49 }
41 $scope.searchLoading = false; 50 $scope.searchLoading = false;
42 $scope.primerBusqueda = true; 51 $scope.primerBusqueda = true;
43 $scope.productos = res.data; 52 $scope.productos = res.data;
44 $scope.search(); 53 $scope.search();
45 primera(); 54 primera();
46 } 55 }
47 ); 56 );
48 } 57 }
49 } 58 }
50 }; 59 };
51 60
52 $scope.search = function() { 61 $scope.search = function() {
53 if($scope.productos.length > 0) { 62 if($scope.productos.length > 0) {
54 $scope.filteredProductos = $filter('filter')( 63 $scope.filteredProductos = $filter('filter')(
55 $scope.productos, 64 $scope.productos,
56 {$: $scope.filters} 65 {$: $scope.filters}
57 ); 66 );
58 67
59 $scope.lastPage = Math.ceil( 68 $scope.lastPage = Math.ceil(
60 $scope.filteredProductos.length / $scope.numPerPage 69 $scope.filteredProductos.length / $scope.numPerPage
61 ); 70 );
62 71
63 $scope.resetPage(); 72 $scope.resetPage();
64 } 73 }
65 }; 74 };
66 75
67 $scope.resetPage = function() { 76 $scope.resetPage = function() {
68 $scope.currentPage = 1; 77 $scope.currentPage = 1;
69 $scope.selectPage(1); 78 $scope.selectPage(1);
70 }; 79 };
71 80
72 $scope.selectPage = function(page) { 81 $scope.selectPage = function(page) {
73 var start = (page - 1) * $scope.numPerPage; 82 var start = (page - 1) * $scope.numPerPage;
74 var end = start + $scope.numPerPage; 83 var end = start + $scope.numPerPage;
75 $scope.paginas = []; 84 $scope.paginas = [];
76 $scope.paginas = calcularPages(page); 85 $scope.paginas = calcularPages(page);
77 $scope.currentPageProductos = $scope.filteredProductos.slice(start, end); 86 $scope.currentPageProductos = $scope.filteredProductos.slice(start, end);
78 $scope.currentPage = page; 87 $scope.currentPage = page;
79 }; 88 };
80 89
81 $scope.select = function(producto) { 90 $scope.select = function(producto) {
82 $uibModalInstance.close(producto); 91 $uibModalInstance.close(producto);
83 }; 92 };
84 93
85 $scope.cancel = function() { 94 $scope.cancel = function() {
86 $uibModalInstance.dismiss('cancel'); 95 $uibModalInstance.dismiss('cancel');
87 }; 96 };
88 97
89 $scope.busquedaDown = function(key) { 98 $scope.busquedaDown = function(key) {
90 if (key === 40) { 99 if (key === 40) {
91 primera(key); 100 primera(key);
92 } 101 }
93 }; 102 };
94 103
95 $scope.itemProducto = function(key) { 104 $scope.itemProducto = function(key) {
96 if (key === 38) { 105 if (key === 38) {
97 anterior(key); 106 anterior(key);
98 } 107 }
99 108
100 if (key === 40) { 109 if (key === 40) {
101 siguiente(key); 110 siguiente(key);
102 } 111 }
103 112
104 if (key === 37) { 113 if (key === 37) {
105 retrocederPagina(); 114 retrocederPagina();
106 } 115 }
107 116
108 if (key === 39) { 117 if (key === 39) {
109 avanzarPagina(); 118 avanzarPagina();
110 } 119 }
111 }; 120 };
112 121
113 function calcularPages(paginaActual) { 122 function calcularPages(paginaActual) {
114 var paginas = []; 123 var paginas = [];
115 paginas.push(paginaActual); 124 paginas.push(paginaActual);
116 125
117 if (paginaActual - 1 > 1) { 126 if (paginaActual - 1 > 1) {
118 127
119 paginas.unshift(paginaActual - 1); 128 paginas.unshift(paginaActual - 1);
120 if (paginaActual - 2 > 1) { 129 if (paginaActual - 2 > 1) {
121 paginas.unshift(paginaActual - 2); 130 paginas.unshift(paginaActual - 2);
122 } 131 }
123 } 132 }
124 133
125 if (paginaActual + 1 < $scope.lastPage) { 134 if (paginaActual + 1 < $scope.lastPage) {
126 paginas.push(paginaActual + 1); 135 paginas.push(paginaActual + 1);
127 if (paginaActual + 2 < $scope.lastPage) { 136 if (paginaActual + 2 < $scope.lastPage) {
128 paginas.push(paginaActual + 2); 137 paginas.push(paginaActual + 2);
129 } 138 }
130 } 139 }
131 140
132 if (paginaActual !== 1) { 141 if (paginaActual !== 1) {
133 paginas.unshift(1); 142 paginas.unshift(1);
134 } 143 }
135 144
136 if (paginaActual !== $scope.lastPage) { 145 if (paginaActual !== $scope.lastPage) {
137 paginas.push($scope.lastPage); 146 paginas.push($scope.lastPage);
138 } 147 }
139 148
140 return paginas; 149 return paginas;
141 } 150 }
142 151
143 function primera() { 152 function primera() {
144 $scope.selectedProducto = 0; 153 $scope.selectedProducto = 0;
145 } 154 }
146 155
147 function anterior() { 156 function anterior() {
148 if ($scope.selectedProducto === 0 && $scope.currentPage > 1) { 157 if ($scope.selectedProducto === 0 && $scope.currentPage > 1) {
149 retrocederPagina(); 158 retrocederPagina();
150 } else { 159 } else {
151 $scope.selectedProducto--; 160 $scope.selectedProducto--;
152 } 161 }
153 } 162 }
154 163
155 function siguiente() { 164 function siguiente() {
156 if ($scope.selectedProducto < $scope.currentPageProductos.length - 1 ) { 165 if ($scope.selectedProducto < $scope.currentPageProductos.length - 1 ) {
157 $scope.selectedProducto++; 166 $scope.selectedProducto++;
158 } else { 167 } else {
159 avanzarPagina(); 168 avanzarPagina();
160 } 169 }
161 } 170 }
162 171
163 function retrocederPagina() { 172 function retrocederPagina() {
164 if ($scope.currentPage > 1) { 173 if ($scope.currentPage > 1) {
165 $scope.selectPage($scope.currentPage - 1); 174 $scope.selectPage($scope.currentPage - 1);
166 $scope.selectedProducto = $scope.numPerPage - 1; 175 $scope.selectedProducto = $scope.numPerPage - 1;
167 } 176 }
168 } 177 }
169 178
170 function avanzarPagina() { 179 function avanzarPagina() {
171 if ($scope.currentPage < $scope.lastPage) { 180 if ($scope.currentPage < $scope.lastPage) {
172 $scope.selectPage($scope.currentPage + 1); 181 $scope.selectPage($scope.currentPage + 1);
173 $scope.selectedProducto = 0; 182 $scope.selectedProducto = 0;
174 } 183 }
175 } 184 }
176 } 185 }
177 ] 186 ]
178 ); 187 );
179 188