Commit 6dd4e7a361b71a9c668ae92af0d3392a0bd43810
1 parent
086300190d
Exists in
master
and in
2 other branches
envio id al eliminar
Showing
1 changed file
with
1 additions
and
1 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaAbmVendedorCobrador') | 1 | angular.module('focaAbmVendedorCobrador') |
2 | .controller('focaAbmVendedoresCobradoresController', [ | 2 | .controller('focaAbmVendedoresCobradoresController', [ |
3 | '$scope', 'focaAbmVendedorCobradorService', '$location', '$filter', | 3 | '$scope', 'focaAbmVendedorCobradorService', '$location', '$filter', |
4 | 'focaBotoneraLateralService', 'focaModalService', | 4 | 'focaBotoneraLateralService', 'focaModalService', |
5 | function($scope, focaAbmVendedorCobradorService, $location, $filter, | 5 | function($scope, focaAbmVendedorCobradorService, $location, $filter, |
6 | focaBotoneraLateralService, focaModalService) { | 6 | focaBotoneraLateralService, focaModalService) { |
7 | $scope.now = new Date(); | 7 | $scope.now = new Date(); |
8 | $scope.vendedoresCobradores = []; | 8 | $scope.vendedoresCobradores = []; |
9 | $scope.filters = ''; | 9 | $scope.filters = ''; |
10 | $scope.numPerPage = 10; | 10 | $scope.numPerPage = 10; |
11 | $scope.currentPageVendedoresCobradores = []; | 11 | $scope.currentPageVendedoresCobradores = []; |
12 | $scope.vendedoresCobradores = []; | 12 | $scope.vendedoresCobradores = []; |
13 | 13 | ||
14 | //SETEO BOTONERA LATERAL | 14 | //SETEO BOTONERA LATERAL |
15 | focaBotoneraLateralService.showSalir(true); | 15 | focaBotoneraLateralService.showSalir(true); |
16 | focaBotoneraLateralService.showPausar(false); | 16 | focaBotoneraLateralService.showPausar(false); |
17 | focaBotoneraLateralService.showCancelar(false); | 17 | focaBotoneraLateralService.showCancelar(false); |
18 | focaBotoneraLateralService.showGuardar(false); | 18 | focaBotoneraLateralService.showGuardar(false); |
19 | 19 | ||
20 | $scope.editar = function(id) { | 20 | $scope.editar = function(id) { |
21 | $location.path('/vendedor-cobrador/' + id); | 21 | $location.path('/vendedor-cobrador/' + id); |
22 | }; | 22 | }; |
23 | 23 | ||
24 | $scope.eliminar = function(vendedorCobrador) { | 24 | $scope.eliminar = function(vendedorCobrador) { |
25 | var tipo = !!(vendedorCobrador.rol | 2) ? 'cobrador' : 'vendedor'; | 25 | var tipo = !!(vendedorCobrador.rol | 2) ? 'cobrador' : 'vendedor'; |
26 | focaModalService.confirm('¿Está seguro que desea borrar el ' + tipo + | 26 | focaModalService.confirm('¿Está seguro que desea borrar el ' + tipo + |
27 | ' ' + vendedorCobrador.NOM + '?') | 27 | ' ' + vendedorCobrador.NOM + '?') |
28 | .then(function(data) { | 28 | .then(function(data) { |
29 | if(data) { | 29 | if(data) { |
30 | focaAbmVendedorCobradorService | 30 | focaAbmVendedorCobradorService |
31 | .eliminarVendedorCobrador(vendedorCobrador.NUM) | 31 | .eliminarVendedorCobrador(vendedorCobrador.id) |
32 | .then(function() { | 32 | .then(function() { |
33 | $scope.search(13); | 33 | $scope.search(13); |
34 | }); | 34 | }); |
35 | } | 35 | } |
36 | }); | 36 | }); |
37 | }; | 37 | }; |
38 | 38 | ||
39 | $scope.selectPage = function(page) { | 39 | $scope.selectPage = function(page) { |
40 | var start = (page - 1) * $scope.numPerPage; | 40 | var start = (page - 1) * $scope.numPerPage; |
41 | var end = start + $scope.numPerPage; | 41 | var end = start + $scope.numPerPage; |
42 | $scope.paginas = []; | 42 | $scope.paginas = []; |
43 | $scope.paginas = calcularPages(page); | 43 | $scope.paginas = calcularPages(page); |
44 | $scope.currentPageVendedoresCobradores = | 44 | $scope.currentPageVendedoresCobradores = |
45 | $scope.vendedoresCobradores.slice(start, end); | 45 | $scope.vendedoresCobradores.slice(start, end); |
46 | $scope.currentPage = page; | 46 | $scope.currentPage = page; |
47 | }; | 47 | }; |
48 | 48 | ||
49 | $scope.resetPage = function() { | 49 | $scope.resetPage = function() { |
50 | $scope.currentPage = 1; | 50 | $scope.currentPage = 1; |
51 | $scope.selectPage(1); | 51 | $scope.selectPage(1); |
52 | }; | 52 | }; |
53 | 53 | ||
54 | $scope.search = function(key) { | 54 | $scope.search = function(key) { |
55 | if(key !== 13) return; | 55 | if(key !== 13) return; |
56 | 56 | ||
57 | focaAbmVendedorCobradorService | 57 | focaAbmVendedorCobradorService |
58 | .getVendedoresCobradores($scope.filters) | 58 | .getVendedoresCobradores($scope.filters) |
59 | .then(function(res) { | 59 | .then(function(res) { |
60 | $scope.vendedoresCobradores = res.data; | 60 | $scope.vendedoresCobradores = res.data; |
61 | 61 | ||
62 | $scope.lastPage = Math.ceil( | 62 | $scope.lastPage = Math.ceil( |
63 | $scope.vendedoresCobradores.length / $scope.numPerPage | 63 | $scope.vendedoresCobradores.length / $scope.numPerPage |
64 | ); | 64 | ); |
65 | 65 | ||
66 | $scope.resetPage(); | 66 | $scope.resetPage(); |
67 | }); | 67 | }); |
68 | }; | 68 | }; |
69 | 69 | ||
70 | function calcularPages(paginaActual) { | 70 | function calcularPages(paginaActual) { |
71 | var paginas = []; | 71 | var paginas = []; |
72 | paginas.push(paginaActual); | 72 | paginas.push(paginaActual); |
73 | 73 | ||
74 | if(paginaActual - 1 > 1) { | 74 | if(paginaActual - 1 > 1) { |
75 | 75 | ||
76 | paginas.unshift(paginaActual - 1); | 76 | paginas.unshift(paginaActual - 1); |
77 | if(paginaActual - 2 > 1) { | 77 | if(paginaActual - 2 > 1) { |
78 | paginas.unshift(paginaActual - 2); | 78 | paginas.unshift(paginaActual - 2); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | if(paginaActual + 1 < $scope.lastPage) { | 82 | if(paginaActual + 1 < $scope.lastPage) { |
83 | paginas.push(paginaActual + 1); | 83 | paginas.push(paginaActual + 1); |
84 | if(paginaActual + 2 < $scope.lastPage) { | 84 | if(paginaActual + 2 < $scope.lastPage) { |
85 | paginas.push(paginaActual + 2); | 85 | paginas.push(paginaActual + 2); |
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | if(paginaActual !== 1) { | 89 | if(paginaActual !== 1) { |
90 | paginas.unshift(1); | 90 | paginas.unshift(1); |
91 | } | 91 | } |
92 | 92 | ||
93 | if(paginaActual !== $scope.lastPage) { | 93 | if(paginaActual !== $scope.lastPage) { |
94 | paginas.push($scope.lastPage); | 94 | paginas.push($scope.lastPage); |
95 | } | 95 | } |
96 | 96 | ||
97 | return paginas; | 97 | return paginas; |
98 | } | 98 | } |
99 | // TODO: descomentar cuando se use | 99 | // TODO: descomentar cuando se use |
100 | // function primera() { | 100 | // function primera() { |
101 | // $scope.selectedClientes = 0; | 101 | // $scope.selectedClientes = 0; |
102 | // } | 102 | // } |
103 | 103 | ||
104 | // function anterior() { | 104 | // function anterior() { |
105 | // if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { | 105 | // if ($scope.selectedClientes === 0 && $scope.currentPage > 1) { |
106 | // retrocederPagina(); | 106 | // retrocederPagina(); |
107 | // } else { | 107 | // } else { |
108 | // $scope.selectedClientes--; | 108 | // $scope.selectedClientes--; |
109 | // } | 109 | // } |
110 | // } | 110 | // } |
111 | 111 | ||
112 | // function siguiente() { | 112 | // function siguiente() { |
113 | // if ($scope.selectedClientes < $scope.currentPageVendedoresCobradores.length - 1 ) | 113 | // if ($scope.selectedClientes < $scope.currentPageVendedoresCobradores.length - 1 ) |
114 | //{ | 114 | //{ |
115 | // $scope.selectedClientes++; | 115 | // $scope.selectedClientes++; |
116 | // } else { | 116 | // } else { |
117 | // avanzarPagina(); | 117 | // avanzarPagina(); |
118 | // } | 118 | // } |
119 | // } | 119 | // } |
120 | 120 | ||
121 | // function retrocederPagina() { | 121 | // function retrocederPagina() { |
122 | // if ($scope.currentPage > 1) { | 122 | // if ($scope.currentPage > 1) { |
123 | // $scope.selectPage($scope.currentPage - 1); | 123 | // $scope.selectPage($scope.currentPage - 1); |
124 | // $scope.selectedClientes = $scope.numPerPage - 1; | 124 | // $scope.selectedClientes = $scope.numPerPage - 1; |
125 | // } | 125 | // } |
126 | // } | 126 | // } |
127 | 127 | ||
128 | // function avanzarPagina() { | 128 | // function avanzarPagina() { |
129 | // if ($scope.currentPage < $scope.lastPage) { | 129 | // if ($scope.currentPage < $scope.lastPage) { |
130 | // $scope.selectPage($scope.currentPage + 1); | 130 | // $scope.selectPage($scope.currentPage + 1); |
131 | // $scope.selectedClientes = 0; | 131 | // $scope.selectedClientes = 0; |
132 | // } | 132 | // } |
133 | // } | 133 | // } |
134 | } | 134 | } |
135 | ]); | 135 | ]); |
136 | 136 |