-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainController.js
More file actions
107 lines (92 loc) · 3.08 KB
/
mainController.js
File metadata and controls
107 lines (92 loc) · 3.08 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
angular.module('myApp', []).controller('mainController', function ($scope, $http) {
$scope.title = 'Lista Telefonica';
$scope.contatos = [];
$scope.operadora = [];
$scope.cor = [];
$scope.isContatoSelecionado = function (e) {
e.forEach(element => {
if (element.Selecionado)
deleteContato(element.Selcionado.ID);
return true;
});
}
// operadoras
var getOperadoras = function () {
return $http({
method: 'GET',
url: 'http://localhost/operadoras',
headers: { 'X-Force-Content-Type': 'application/json' }
})
.then(function (response) {
$scope.operadora = response.data;
}).catch(function () {
console.log("Deu Ruim");
});
};
// contatos
var getContatos = function () {
return $http({
method: 'GET',
url: 'http://localhost/contatos',
headers: { 'X-Force-Content-Type': 'application/json' }
}).then(function (response) {
console.log('Json de resposta ==== >>>', response.data);
$scope.contatos = response.data;
}).catch(function () {
console.log("Deu ruim")
});
};
var deleteContato = function (ID) {
return $http({
method: 'DELETE',
url: 'http://localhost/contatos/' + ID,
headers: { 'X-Force-Content-Type': 'application/json' }
}).then(function (response) {
console.log('Json de resposta ==== >>>', response.data)
$scope.contatos = response.data;
}).catch(function () {
console.log("Deu ruim")
});
};
var putContato = function (ID) {
return $http({
method: 'PUT',
url: 'http://localhost/contatos/' + ID,
headers: { 'X-Force-Content-Type': 'application/json' }
}).then(function (response) {
console.log('Json de resposta ==== >>>', response.data)
$scope.contatos = response.data;
}).catch(function () {
console.log("Deu ruim")
});
};
$scope.enviar = function (e) {
console.log(angular.copy(e));
$scope.contatos.push(angular.copy(e));
delete $scope.e;
}
$scope.apagar = function (e) {
$scope.contatos = e.filter(function (contato) {
if (!contato.selecionado) return contato;
});
console.log(contatosSelecionados);
}
// cor
var getCor = function () {
return $http({
method: 'GET',
url: 'http://localhost/cores',
headers: { 'X-Force-Content-Type': 'application/json' }
})
.then(function (response) {
$scope.cor = response.data;
}).catch(function () {
console.log("Deu Ruim");
});
};
getCor();
getOperadoras();
getContatos();
putContato();
debugger;
});