Commit 750bf222048ba2a64543a9142e3568089f8e465e

Authored by Pablo Marco del Pont
1 parent c67cce973e
Exists in master

Cambios para usarse en nota pedido y remito.

1 <html ng-app="focaModalNotaPedido"> 1 <html ng-app="focaModalNotaPedido">
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('focaModalNotaPedido') 31 angular.module('focaModalNotaPedido')
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 Nota de Pedido', 42 ariaLabelledBy: 'Busqueda de Nota de Pedido',
43 templateUrl: 'src/views/foca-modal-nota-pedido.html', 43 templateUrl: 'src/views/foca-modal-nota-pedido.html',
44 controller: 'focaModalNotaPedidoController', 44 controller: 'focaModalNotaPedidoController',
45 size: 'lg', 45 size: 'lg',
46 resolve: { 46 resolve: {
47 usadoPor: 'remito',
47 parametroNotaPedido: { 48 parametroNotaPedido: {
48 idLista: -1, 49 idLista: -1,
49 cotizacion: 1, 50 cotizacion: 1,
50 simbolo:'$' 51 simbolo:'$'
51 } 52 }
52 } 53 }
53 } 54 }
54 ); 55 );
55 56
56 modalInstance.result.then( 57 modalInstance.result.then(
57 function (selectedItem) { 58 function (selectedItem) {
58 console.info(selectedItem); 59 console.info(selectedItem);
59 $timeout(openModal, 500); 60 $timeout(openModal, 500);
60 }, function () { 61 }, function () {
61 console.info('modal-component dismissed at: ' + new Date()); 62 console.info('modal-component dismissed at: ' + new Date());
62 $timeout(openModal, 500); 63 $timeout(openModal, 500);
63 } 64 }
64 ); 65 );
65 } 66 }
66 } 67 }
67 ]); 68 ]);
68 </script> 69 </script>
69 </head> 70 </head>
70 <body ng-controller="controller"> 71 <body ng-controller="controller">
71 </body> 72 </body>
72 </html> 73 </html>
73 74
src/js/controller.js
1 angular.module('focaModalNotaPedido') 1 angular.module('focaModalNotaPedido')
2 .controller('focaModalNotaPedidoController', 2 .controller('focaModalNotaPedidoController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'focaModalNotaPedidoService', 7 'focaModalNotaPedidoService',
8 'usadoPor',
8 function($filter, $scope, $uibModalInstance, 9 function($filter, $scope, $uibModalInstance,
9 focaModalNotaPedidoService 10 focaModalNotaPedidoService, usadoPor
10 ) { 11 ) {
11 12
12 $scope.filters = ''; 13 $scope.filters = '';
13 $scope.notasPedido = []; 14 $scope.notasPedido = [];
14 $scope.primerBusqueda = false; 15 $scope.primerBusqueda = false;
15 $scope.searchLoading = false; 16 $scope.searchLoading = false;
16 // pagination 17 // pagination
17 $scope.numPerPage = 10; 18 $scope.numPerPage = 10;
18 $scope.currentPage = 1; 19 $scope.currentPage = 1;
19 $scope.filteredNotasPedido = []; 20 $scope.filteredNotasPedido = [];
20 $scope.currentPageNotasPedido = []; 21 $scope.currentPageNotasPedido = [];
21 $scope.selectedNotaPedido = -1; 22 $scope.selectedNotaPedido = -1;
22 23
23 //METODOS 24 //METODOS
24 $scope.busquedaPress = function(key) { 25 $scope.busquedaPress = function(key) {
25 if (key === 13) { 26 if (key === 13) {
26 $scope.searchLoading = true; 27 $scope.searchLoading = true;
27 focaModalNotaPedidoService.getNotasPedido().then(llenarDatos); 28 focaModalNotaPedidoService.getNotasPedido(usadoPor).then(llenarDatos);
28 } 29 }
29 }; 30 };
30 function llenarDatos(res) { 31 function llenarDatos(res) {
31 $scope.searchLoading = false; 32 $scope.searchLoading = false;
32 $scope.primerBusqueda = true; 33 $scope.primerBusqueda = true;
33 $scope.notasPedido = res.data; 34 $scope.notasPedido = res.data;
34 $scope.search(); 35 $scope.search();
35 primera(); 36 primera();
36 } 37 }
37 $scope.search = function() { 38 $scope.search = function() {
38 if($scope.notasPedido.length > 0) { 39 if($scope.notasPedido.length > 0) {
39 $scope.filteredNotasPedido = $filter('filter')( 40 $scope.filteredNotasPedido = $filter('filter')(
40 $scope.notasPedido, 41 $scope.notasPedido,
41 {$: $scope.filters} 42 {$: $scope.filters}
42 ); 43 );
43 44
44 $scope.lastPage = Math.ceil( 45 $scope.lastPage = Math.ceil(
45 $scope.filteredNotasPedido.length / $scope.numPerPage 46 $scope.filteredNotasPedido.length / $scope.numPerPage
46 ); 47 );
47 48
48 $scope.resetPage(); 49 $scope.resetPage();
49 } 50 }
50 }; 51 };
51 52
52 $scope.resetPage = function() { 53 $scope.resetPage = function() {
53 $scope.currentPage = 1; 54 $scope.currentPage = 1;
54 $scope.selectPage(1); 55 $scope.selectPage(1);
55 }; 56 };
56 57
57 $scope.selectPage = function(page) { 58 $scope.selectPage = function(page) {
58 var start = (page - 1) * $scope.numPerPage; 59 var start = (page - 1) * $scope.numPerPage;
59 var end = start + $scope.numPerPage; 60 var end = start + $scope.numPerPage;
60 $scope.paginas = []; 61 $scope.paginas = [];
61 $scope.paginas = calcularPages(page); 62 $scope.paginas = calcularPages(page);
62 $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end); 63 $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end);
63 $scope.currentPage = page; 64 $scope.currentPage = page;
64 }; 65 };
65 66
66 $scope.select = function(notaPedido) { 67 $scope.select = function(notaPedido) {
67 $uibModalInstance.close(notaPedido); 68 $uibModalInstance.close(notaPedido);
68 }; 69 };
69 70
70 $scope.cancel = function() { 71 $scope.cancel = function() {
71 $uibModalInstance.dismiss('cancel'); 72 $uibModalInstance.dismiss('cancel');
72 }; 73 };
73 74
74 $scope.busquedaDown = function(key) { 75 $scope.busquedaDown = function(key) {
75 if (key === 40) { 76 if (key === 40) {
76 primera(key); 77 primera(key);
77 } 78 }
78 }; 79 };
79 80
80 $scope.itemNotaPedido = function(key) { 81 $scope.itemNotaPedido = function(key) {
81 if (key === 38) { 82 if (key === 38) {
82 anterior(key); 83 anterior(key);
83 } 84 }
84 85
85 if (key === 40) { 86 if (key === 40) {
86 siguiente(key); 87 siguiente(key);
87 } 88 }
88 89
89 if (key === 37) { 90 if (key === 37) {
90 retrocederPagina(); 91 retrocederPagina();
91 } 92 }
92 93
93 if (key === 39) { 94 if (key === 39) {
94 avanzarPagina(); 95 avanzarPagina();
95 } 96 }
96 }; 97 };
97 98
98 function calcularPages(paginaActual) { 99 function calcularPages(paginaActual) {
99 var paginas = []; 100 var paginas = [];
100 paginas.push(paginaActual); 101 paginas.push(paginaActual);
101 102
102 if (paginaActual - 1 > 1) { 103 if (paginaActual - 1 > 1) {
103 104
104 paginas.unshift(paginaActual - 1); 105 paginas.unshift(paginaActual - 1);
105 if (paginaActual - 2 > 1) { 106 if (paginaActual - 2 > 1) {
106 paginas.unshift(paginaActual - 2); 107 paginas.unshift(paginaActual - 2);
107 } 108 }
108 } 109 }
109 110
110 if (paginaActual + 1 < $scope.lastPage) { 111 if (paginaActual + 1 < $scope.lastPage) {
111 paginas.push(paginaActual + 1); 112 paginas.push(paginaActual + 1);
112 if (paginaActual + 2 < $scope.lastPage) { 113 if (paginaActual + 2 < $scope.lastPage) {
113 paginas.push(paginaActual + 2); 114 paginas.push(paginaActual + 2);
114 } 115 }
115 } 116 }
116 117
117 if (paginaActual !== 1) { 118 if (paginaActual !== 1) {
118 paginas.unshift(1); 119 paginas.unshift(1);
119 } 120 }
120 121
121 if (paginaActual !== $scope.lastPage) { 122 if (paginaActual !== $scope.lastPage) {
122 paginas.push($scope.lastPage); 123 paginas.push($scope.lastPage);
123 } 124 }
124 125
125 return paginas; 126 return paginas;
126 } 127 }
127 128
128 function primera() { 129 function primera() {
129 $scope.selectedNotaPedido = 0; 130 $scope.selectedNotaPedido = 0;
130 } 131 }
131 132
132 function anterior() { 133 function anterior() {
133 if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) { 134 if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) {
134 retrocederPagina(); 135 retrocederPagina();
135 } else { 136 } else {
136 $scope.selectedNotaPedido--; 137 $scope.selectedNotaPedido--;
137 } 138 }
138 } 139 }
139 140
140 function siguiente() { 141 function siguiente() {
141 if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) { 142 if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) {
142 $scope.selectedNotaPedido++; 143 $scope.selectedNotaPedido++;
143 } else { 144 } else {
144 avanzarPagina(); 145 avanzarPagina();
145 } 146 }
146 } 147 }
147 148
148 function retrocederPagina() { 149 function retrocederPagina() {
149 if ($scope.currentPage > 1) { 150 if ($scope.currentPage > 1) {
150 $scope.selectPage($scope.currentPage - 1); 151 $scope.selectPage($scope.currentPage - 1);
151 $scope.selectedNotaPedido = $scope.numPerPage - 1; 152 $scope.selectedNotaPedido = $scope.numPerPage - 1;
152 } 153 }
153 } 154 }
154 155
155 function avanzarPagina() { 156 function avanzarPagina() {
156 if ($scope.currentPage < $scope.lastPage) { 157 if ($scope.currentPage < $scope.lastPage) {
157 $scope.selectPage($scope.currentPage + 1); 158 $scope.selectPage($scope.currentPage + 1);
158 $scope.selectedNotaPedido = 0; 159 $scope.selectedNotaPedido = 0;
159 } 160 }
160 } 161 }
161 } 162 }
162 ] 163 ]
163 ); 164 );
164 165
1 angular.module('focaModalNotaPedido') 1 angular.module('focaModalNotaPedido')
2 .service('focaModalNotaPedidoService', [ 2 .service('focaModalNotaPedidoService', [
3 '$http', 3 '$http',
4 'API_ENDPOINT', 4 'API_ENDPOINT',
5 function($http, API_ENDPOINT) { 5 function($http, API_ENDPOINT) {
6 return { 6 return {
7 getNotasPedido: function() { 7 getNotasPedido: function(usadoPor) {
8 return $http.get(API_ENDPOINT.URL + '/nota-pedido/listar/sin-remito'); 8 sinRemito = usadoPor === 'remito' ? '/sin-remito' : '';
9 return $http.get(API_ENDPOINT.URL + '/nota-pedido/listar' + sinRemito);
9 } 10 }
10 }; 11 };
11 } 12 }
12 ]); 13 ]);
13 14