Commit 6ddbd6a06610b244729fe448fc9cd6e3b3bc0b1b
Exists in
master
Merge branch 'master' into 'master'
incorporación titulo como transportista See merge request modulos-npm/foca-modal-proveedor!10
Showing
2 changed files
Show diff stats
src/js/controller.js
1 | angular.module('focaModalProveedor') | 1 | angular.module('focaModalProveedor') |
2 | .controller('focaModalProveedorCtrl', [ | 2 | .controller('focaModalProveedorCtrl', [ |
3 | '$filter', | 3 | '$filter', |
4 | '$scope', | 4 | '$scope', |
5 | '$uibModalInstance', | 5 | '$uibModalInstance', |
6 | 'focaModalProveedorService', | 6 | 'focaModalProveedorService', |
7 | function ($filter, $scope, $uibModalInstance, focaModalProveedorService) { | 7 | 'transportista', |
8 | function ($filter, $scope, $uibModalInstance, focaModalProveedorService, transportista) { | ||
8 | 9 | ||
9 | $scope.filters = ''; | 10 | $scope.filters = ''; |
10 | $scope.primerBusqueda = false; | 11 | $scope.primerBusqueda = false; |
11 | // pagination | 12 | // pagination |
12 | $scope.numPerPage = 10; | 13 | $scope.numPerPage = 10; |
13 | $scope.currentPage = 1; | 14 | $scope.currentPage = 1; |
14 | $scope.filteredProveedores = []; | 15 | $scope.filteredProveedores = []; |
15 | $scope.currentPageProveedores = []; | 16 | $scope.currentPageProveedores = []; |
16 | $scope.selectedProveedores = -1; | 17 | $scope.selectedProveedores = -1; |
18 | $scope.transportista = transportista | false; | ||
17 | 19 | ||
18 | $scope.busquedaPress = function(key) { | 20 | $scope.busquedaPress = function(key) { |
19 | if (key === 13) { | 21 | if (key === 13) { |
20 | $scope.searchLoading = true; | 22 | $scope.searchLoading = true; |
21 | var json = { | 23 | var json = { |
22 | razonCuitCod: $scope.filters | 24 | razonCuitCod: $scope.filters |
23 | }; | 25 | }; |
24 | focaModalProveedorService.getProveedores(json).then( | 26 | focaModalProveedorService.getProveedores(json).then( |
25 | function(res) { | 27 | function(res) { |
26 | for (var i = res.data.length - 1; i >= 0; i--) { | 28 | for (var i = res.data.length - 1; i >= 0; i--) { |
27 | if (res.data[i].COD === 0) { | 29 | if (res.data[i].COD === 0) { |
28 | delete res.data[i]; | 30 | delete res.data[i]; |
29 | } | 31 | } |
30 | } | 32 | } |
31 | $scope.primerBusqueda = true; | 33 | $scope.primerBusqueda = true; |
32 | $scope.proveedores = res.data; | 34 | $scope.proveedores = res.data; |
33 | $scope.search(); | 35 | $scope.search(); |
34 | primera(); | 36 | primera(); |
35 | $scope.searchLoading = false; | 37 | $scope.searchLoading = false; |
36 | }); | 38 | }); |
37 | } | 39 | } |
38 | }; | 40 | }; |
39 | 41 | ||
40 | $scope.search = function () { | 42 | $scope.search = function () { |
41 | if($scope.primerBusqueda) { | 43 | if($scope.primerBusqueda) { |
42 | $scope.filteredProveedores = $filter('filter')( | 44 | $scope.filteredProveedores = $filter('filter')( |
43 | $scope.proveedores, {$: $scope.filters} | 45 | $scope.proveedores, {$: $scope.filters} |
44 | ); | 46 | ); |
45 | 47 | ||
46 | $scope.lastPage = Math.ceil( | 48 | $scope.lastPage = Math.ceil( |
47 | $scope.filteredProveedores.length / $scope.numPerPage | 49 | $scope.filteredProveedores.length / $scope.numPerPage |
48 | ); | 50 | ); |
49 | 51 | ||
50 | $scope.resetPage(); | 52 | $scope.resetPage(); |
51 | } | 53 | } |
52 | }; | 54 | }; |
53 | 55 | ||
54 | $scope.resetPage = function () { | 56 | $scope.resetPage = function () { |
55 | $scope.currentPage = 1; | 57 | $scope.currentPage = 1; |
56 | $scope.selectPage(1); | 58 | $scope.selectPage(1); |
57 | }; | 59 | }; |
58 | 60 | ||
59 | $scope.selectPage = function (page) { | 61 | $scope.selectPage = function (page) { |
60 | console.info(page); | 62 | console.info(page); |
61 | var start = (page - 1) * $scope.numPerPage; | 63 | var start = (page - 1) * $scope.numPerPage; |
62 | var end = start + $scope.numPerPage; | 64 | var end = start + $scope.numPerPage; |
63 | $scope.paginas = []; | 65 | $scope.paginas = []; |
64 | $scope.paginas = calcularPages(page); | 66 | $scope.paginas = calcularPages(page); |
65 | $scope.currentPageProveedores = $scope.filteredProveedores.slice(start, end); | 67 | $scope.currentPageProveedores = $scope.filteredProveedores.slice(start, end); |
66 | $scope.currentPage = page; | 68 | $scope.currentPage = page; |
67 | }; | 69 | }; |
68 | 70 | ||
69 | $scope.select = function(proveedor) { | 71 | $scope.select = function(proveedor) { |
70 | $uibModalInstance.close(proveedor); | 72 | $uibModalInstance.close(proveedor); |
71 | }; | 73 | }; |
72 | 74 | ||
73 | $scope.cancel = function() { | 75 | $scope.cancel = function() { |
74 | $uibModalInstance.dismiss('cancel'); | 76 | $uibModalInstance.dismiss('cancel'); |
75 | }; | 77 | }; |
76 | 78 | ||
77 | $scope.busquedaDown = function(key) { | 79 | $scope.busquedaDown = function(key) { |
78 | if (key === 40) { | 80 | if (key === 40) { |
79 | primera(key); | 81 | primera(key); |
80 | } | 82 | } |
81 | }; | 83 | }; |
82 | 84 | ||
83 | $scope.itemProveedor = function(key) { | 85 | $scope.itemProveedor = function(key) { |
84 | if (key === 38) { | 86 | if (key === 38) { |
85 | anterior(key); | 87 | anterior(key); |
86 | } | 88 | } |
87 | 89 | ||
88 | if (key === 40) { | 90 | if (key === 40) { |
89 | siguiente(key); | 91 | siguiente(key); |
90 | } | 92 | } |
91 | 93 | ||
92 | if (key === 37) { | 94 | if (key === 37) { |
93 | retrocederPagina(); | 95 | retrocederPagina(); |
94 | } | 96 | } |
95 | 97 | ||
96 | if (key === 39) { | 98 | if (key === 39) { |
97 | avanzarPagina(); | 99 | avanzarPagina(); |
98 | } | 100 | } |
99 | }; | 101 | }; |
100 | 102 | ||
101 | function calcularPages(paginaActual) { | 103 | function calcularPages(paginaActual) { |
102 | var paginas = []; | 104 | var paginas = []; |
103 | paginas.push(paginaActual); | 105 | paginas.push(paginaActual); |
104 | 106 | ||
105 | if (paginaActual - 1 > 1) { | 107 | if (paginaActual - 1 > 1) { |
106 | 108 | ||
107 | paginas.unshift(paginaActual - 1); | 109 | paginas.unshift(paginaActual - 1); |
108 | if (paginaActual - 2 > 1) { | 110 | if (paginaActual - 2 > 1) { |
109 | paginas.unshift(paginaActual - 2); | 111 | paginas.unshift(paginaActual - 2); |
110 | } | 112 | } |
111 | } | 113 | } |
112 | 114 | ||
113 | if (paginaActual + 1 < $scope.lastPage) { | 115 | if (paginaActual + 1 < $scope.lastPage) { |
114 | paginas.push(paginaActual + 1); | 116 | paginas.push(paginaActual + 1); |
115 | if (paginaActual + 2 < $scope.lastPage) { | 117 | if (paginaActual + 2 < $scope.lastPage) { |
116 | paginas.push(paginaActual + 2); | 118 | paginas.push(paginaActual + 2); |
117 | } | 119 | } |
118 | } | 120 | } |
119 | 121 | ||
120 | if (paginaActual !== 1) { | 122 | if (paginaActual !== 1) { |
121 | paginas.unshift(1); | 123 | paginas.unshift(1); |
122 | } | 124 | } |
123 | 125 | ||
124 | if (paginaActual !== $scope.lastPage) { | 126 | if (paginaActual !== $scope.lastPage) { |
125 | paginas.push($scope.lastPage); | 127 | paginas.push($scope.lastPage); |
126 | } | 128 | } |
127 | 129 | ||
128 | return paginas; | 130 | return paginas; |
129 | } | 131 | } |
130 | 132 | ||
131 | function primera() { | 133 | function primera() { |
132 | $scope.selectedProveedores = 0; | 134 | $scope.selectedProveedores = 0; |
133 | } | 135 | } |
134 | 136 | ||
135 | function anterior() { | 137 | function anterior() { |
136 | if ($scope.selectedProveedores === 0 && $scope.currentPage > 1) { | 138 | if ($scope.selectedProveedores === 0 && $scope.currentPage > 1) { |
137 | retrocederPagina(); | 139 | retrocederPagina(); |
138 | } else { | 140 | } else { |
139 | $scope.selectedProveedores--; | 141 | $scope.selectedProveedores--; |
140 | } | 142 | } |
141 | } | 143 | } |
142 | 144 | ||
143 | function siguiente() { | 145 | function siguiente() { |
144 | if ($scope.selectedProveedores < $scope.currentPageProveedores.length - 1 ) { | 146 | if ($scope.selectedProveedores < $scope.currentPageProveedores.length - 1 ) { |
145 | $scope.selectedProveedores++; | 147 | $scope.selectedProveedores++; |
146 | } else { | 148 | } else { |
147 | avanzarPagina(); | 149 | avanzarPagina(); |
148 | } | 150 | } |
149 | } | 151 | } |
150 | 152 | ||
151 | function retrocederPagina() { | 153 | function retrocederPagina() { |
152 | if ($scope.currentPage > 1) { | 154 | if ($scope.currentPage > 1) { |
153 | $scope.selectPage($scope.currentPage - 1); | 155 | $scope.selectPage($scope.currentPage - 1); |
154 | $scope.selectedProveedores = $scope.numPerPage - 1; | 156 | $scope.selectedProveedores = $scope.numPerPage - 1; |
155 | } | 157 | } |
156 | } | 158 | } |
157 | 159 | ||
158 | function avanzarPagina() { | 160 | function avanzarPagina() { |
159 | if ($scope.currentPage < $scope.lastPage) { | 161 | if ($scope.currentPage < $scope.lastPage) { |
160 | $scope.selectPage($scope.currentPage + 1); | 162 | $scope.selectPage($scope.currentPage + 1); |
161 | $scope.selectedProveedores = 0; | 163 | $scope.selectedProveedores = 0; |
162 | } | 164 | } |
163 | } | 165 | } |
164 | }] | 166 | }] |
165 | ); | 167 | ); |
166 | 168 |
src/views/modal-proveedor.html
1 | <div class="modal-header py-1"> | 1 | <div class="modal-header py-1"> |
2 | <h5 class="modal-title">Búsqueda de Proveedor</h5> | 2 | <h5 class="modal-title" ng-hide="transportista">Búsqueda de Proveedor</h5> |
3 | <h5 class="modal-title" ng-show="transportista">Búsqueda de Transportista</h5> | ||
3 | </div> | 4 | </div> |
4 | <div class="modal-body" id="modal-body"> | 5 | <div class="modal-body" id="modal-body"> |
5 | <div class="input-group"> | 6 | <div class="input-group"> |
6 | <input | 7 | <input |
7 | ladda="searchLoading" | 8 | ladda="searchLoading" |
8 | type="text" | 9 | type="text" |
9 | class="form-control" | 10 | class="form-control" |
10 | placeholder="Busqueda" | 11 | placeholder="Busqueda" |
11 | ng-model="filters" | 12 | ng-model="filters" |
12 | ng-change="search()" | 13 | ng-change="search()" |
13 | ng-keydown="busquedaDown($event.keyCode)" | 14 | ng-keydown="busquedaDown($event.keyCode)" |
14 | ng-keypress="busquedaPress($event.keyCode)" | 15 | ng-keypress="busquedaPress($event.keyCode)" |
15 | foca-focus="selectedProveedores == -1" | 16 | foca-focus="selectedProveedores == -1" |
16 | ng-focus="selectedProveedores = -1" | 17 | ng-focus="selectedProveedores = -1" |
17 | teclado-virtual | 18 | teclado-virtual |
18 | > | 19 | > |
19 | <div class="input-group-append"> | 20 | <div class="input-group-append"> |
20 | <button | 21 | <button |
21 | ladda="searchLoading" | 22 | ladda="searchLoading" |
22 | class="btn btn-outline-secondary" | 23 | class="btn btn-outline-secondary" |
23 | type="button" | 24 | type="button" |
24 | ng-click="busquedaPress(13)"> | 25 | ng-click="busquedaPress(13)"> |
25 | <i class="fa fa-search" aria-hidden="true"></i> | 26 | <i class="fa fa-search" aria-hidden="true"></i> |
26 | </button> | 27 | </button> |
27 | </div> | 28 | </div> |
28 | </div> | 29 | </div> |
29 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> | 30 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> |
30 | <thead> | 31 | <thead> |
31 | <tr> | 32 | <tr> |
32 | <th>Código</th> | 33 | <th>Código</th> |
33 | <th>Nombre</th> | 34 | <th>Nombre</th> |
34 | <th>CUIT</th> | 35 | <th>CUIT</th> |
35 | <th></th> | 36 | <th></th> |
36 | </tr> | 37 | </tr> |
37 | </thead> | 38 | </thead> |
38 | <tbody> | 39 | <tbody> |
39 | <tr ng-show="currentPageProveedores.length == 0 && primerBusqueda"> | 40 | <tr ng-show="currentPageProveedores.length == 0 && primerBusqueda"> |
40 | <td colspan="4"> | 41 | <td colspan="4"> |
41 | No se encontraron resultados. | 42 | No se encontraron resultados. |
42 | </td> | 43 | </td> |
43 | </tr> | 44 | </tr> |
44 | <tr | 45 | <tr |
45 | class="selectable" | 46 | class="selectable" |
46 | ng-repeat="(key, proveedor) in currentPageProveedores" | 47 | ng-repeat="(key, proveedor) in currentPageProveedores" |
47 | ng-click="select(proveedor)"> | 48 | ng-click="select(proveedor)"> |
48 | <td ng-bind="proveedor.COD"></td> | 49 | <td ng-bind="proveedor.COD"></td> |
49 | <td ng-bind="proveedor.NOM"></td> | 50 | <td ng-bind="proveedor.NOM"></td> |
50 | <td ng-bind="proveedor.CUIT"></td> | 51 | <td ng-bind="proveedor.CUIT"></td> |
51 | <td> | 52 | <td> |
52 | <button | 53 | <button |
53 | type="button" | 54 | type="button" |
54 | class="btn btn-xs p-1 float-right" | 55 | class="btn btn-xs p-1 float-right" |
55 | ng-class="{ | 56 | ng-class="{ |
56 | 'btn-secondary': selectedProveedores != key, | 57 | 'btn-secondary': selectedProveedores != key, |
57 | 'btn-primary': selectedProveedores == key | 58 | 'btn-primary': selectedProveedores == key |
58 | }" | 59 | }" |
59 | ng-click="select(proveedor)" | 60 | ng-click="select(proveedor)" |
60 | foca-focus="selectedProveedores == {{key}}" | 61 | foca-focus="selectedProveedores == {{key}}" |
61 | ng-keydown="itemProveedor($event.keyCode)" | 62 | ng-keydown="itemProveedor($event.keyCode)" |
62 | > | 63 | > |
63 | <i class="fa fa-arrow-right" aria-hidden="true"></i> | 64 | <i class="fa fa-arrow-right" aria-hidden="true"></i> |
64 | </button> | 65 | </button> |
65 | </td> | 66 | </td> |
66 | </tr> | 67 | </tr> |
67 | </tbody> | 68 | </tbody> |
68 | </table> | 69 | </table> |
69 | <nav ng-show="currentPageProveedores.length > 0 && primerBusqueda"> | 70 | <nav ng-show="currentPageProveedores.length > 0 && primerBusqueda"> |
70 | <ul class="pagination pagination-sm mb-0"> | 71 | <ul class="pagination pagination-sm mb-0"> |
71 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | 72 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> |
72 | <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> | 73 | <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> |
73 | <span aria-hidden="true">«</span> | 74 | <span aria-hidden="true">«</span> |
74 | <span class="sr-only">Anterior</span> | 75 | <span class="sr-only">Anterior</span> |
75 | </a> | 76 | </a> |
76 | </li> | 77 | </li> |
77 | <li | 78 | <li |
78 | class="page-item" | 79 | class="page-item" |
79 | ng-repeat="pagina in paginas" | 80 | ng-repeat="pagina in paginas" |
80 | ng-class="{'active': pagina == currentPage}" | 81 | ng-class="{'active': pagina == currentPage}" |
81 | > | 82 | > |
82 | <a | 83 | <a |
83 | class="page-link" | 84 | class="page-link" |
84 | href="#" | 85 | href="#" |
85 | ng-click="selectPage(pagina)" | 86 | ng-click="selectPage(pagina)" |
86 | ng-bind="pagina" | 87 | ng-bind="pagina" |
87 | ></a> | 88 | ></a> |
88 | </li> | 89 | </li> |
89 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | 90 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> |
90 | <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)"> | 91 | <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)"> |
91 | <span aria-hidden="true">»</span> | 92 | <span aria-hidden="true">»</span> |
92 | <span class="sr-only">Siguiente</span> | 93 | <span class="sr-only">Siguiente</span> |
93 | </a> | 94 | </a> |
94 | </li> | 95 | </li> |
95 | </ul> | 96 | </ul> |
96 | </nav> | 97 | </nav> |
97 | </div> | 98 | </div> |
98 | <div class="modal-footer py-1"> | 99 | <div class="modal-footer py-1"> |
99 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | 100 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> |
100 | </div> | 101 | </div> |
101 | 102 |