controller.js
1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
angular.module('focaBusquedaProductos')
.controller('modalBusquedaProductosCtrl',
[
'$filter',
'$scope',
'$uibModalInstance',
'focaBusquedaProductosService',
function($filter, $scope, $uibModalInstance, focaBusquedaProductosService) {
focaBusquedaProductosService.getProductos().then(
function(res) {
$scope.productos = res;
$scope.search();
}
);
// pagination
$scope.numPerPage = 10;
$scope.currentPage = 1;
$scope.filteredProductos = [];
$scope.currentPageProductos = [];
$scope.selectProducto = 0;
//METODOS
$scope.search = function() {
$scope.filteredProductos = $filter('filter')($scope.productos, {$: $scope.filters});
$scope.resetPage();
}
$scope.resetPage = function() {
$scope.currentPage = 1;
$scope.selectPage(1);
}
$scope.selectPage = function(page) {
var start = (page - 1) * $scope.numPerPage;
var end = start + $scope.numPerPage;
$scope.currentPageProductos = $scope.filteredProductos.slice(start, end);
}
$scope.select = function(producto) {
$uibModalInstance.close(producto);
}
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
}
$scope.enter = function(key) {
if (key === 13) {
console.table($scope.currentPageProductos);
}
}
}
]
)