forked from wilsoncx/clientes1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
74 lines (69 loc) · 2.45 KB
/
app.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
app = new angular.module('app',['ngRoute' , 'angularUtils.directives.dirPagination', 'ngResource']);
app.config(['$routeProvider',function($routeProvider){
$routeProvider.
when('/',{controller:'mainController',
templateUrl:'templates/main.html'}).
when('/usuarios',{controller:'userController',
templateUrl:'templates/user.html'}).
when('/cliente',
{controller:'clienteController',
templateUrl:'templates/cliente.html'
})
.when('/cliente/novo',{controller:'addclienteController',
templateUrl:'templates/addCliente.html'})
.when('/cliente/:index',{
controller:'CtrlEditar',
templateUrl:'templates/editCliente.html'
}).
when('/grupos',{controller:'grupoController',
templateUrl:'templates/grupo.html'}).
when('/mensagens',{controller:'mensagemController',
templateUrl:'templates/grupo.html'}).
when('/grupo_usuarios',{controller:'grupo_usuarioController',
templateUrl:'templates/grupo_usuario.html'}).
when('/login',{controller:'loginController',
templateUrl:'templates/login.html'}).
otherwise({redirectTo:'/'});
}]);
app.controller('mainController',function ($scope) {
$scope.userName="Open";
})
app.controller('clienteController',function ($scope,$http) {
$scope.clientes = [];
$scope.$on('$viewContentLoaded', function(){
$http.get("api/cliente").then(function(response){
console.log(response);
$scope.clientes = response.data;
$scope.viewby = 5;
$scope.pageSize = 10;
$scope.totalItems = $scope.clientes.length / $scope.viewby;
$scope.currentPage = 1;
$scope.itemsPerPage = $scope.viewby;
$scope.maxSize = 5; //Number of pager buttons to show
$scope.setPage = function (pageNo) {
$scope.currentPage = pageNo;
};
$scope.setItemsPerPage = function(num) {
$scope.itemsPerPage = num;
$scope.currentPage = 1; //reset to first paghe
};
},function(response){
console.warn(response);
});
});
})
.controller('addclienteController',function ($scope,$http){
///adicionar o cliente
$scope.addCliente = function() {
$http.post('api/cliente',$scope.cliente)
.success(function(data, status, headers, config){
$('#sucessModal').modal('show');
$scope.cliente="";
}).error(function(data) {
$('#erroModal').modal('show');
});
};
})
.controller('CtrlEditar', function($scope, $routeParams) {
$scope.cliente = $scope.clientes[$routeParams.index];
});