forked from geding/uam-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.html
More file actions
127 lines (111 loc) · 3.06 KB
/
test_api.html
File metadata and controls
127 lines (111 loc) · 3.06 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!doctype html>
<html lang="en" ng-app="app">
<head>
<meta charset="utf-8">
<title>Email Client</title>
<meta name="author" content="Damian Sosnowski">
<style>
body > div {
margin: 20px;
border: 1px solid black;
}
textarea {
display: block;
width: 90%;
height: 300px;
}
</style>
<script src="lib/angular.js"></script>
<script type="text/javascript">
angular.module('app', []).controller('TestCtrl', function ($scope, $http) {
$scope.getEmails = function () {
$http.get('/emails').success(function (res) {
$scope.emailsRes = res;
});
};
$scope.getEmail = function () {
$http.get('/emails/'+$scope.emailId).success(function (res) {
$scope.emailRes = res;
}).error(function (res) {
$scope.emailRes = 'ERROR: ' + res;
});
};
$scope.updateEmail = function () {
$http.put('/emails/'+$scope.emailId, {
title: $scope.newEmailTitle,
read: true
// random: Math.random()
}).success(function (res) {
$scope.udateEmailRes = res;
})
};
$scope.deleteEmail = function () {
$http.delete('/emails/'+$scope.emailId, {
title: $scope.newEmailTitle,
random: Math.random()
}).success(function (res) {
$scope.deleteEmailRes = res;
})
};
$scope.getSent = function () {
$http.get('/sent').success(function (res) {
$scope.sentRes = res;
})
};
$scope.createSent = function () {
$http.post('/sent', {
id: Date.now(),
title: $scope.sentTitle,
content: 'Cos tam',
receivers: ['sosnowski@outlook.com'],
sent: Date.now()
}).success(function (res) {
$scope.createSentRes = res;
})
};
});
</script>
</head>
<body ng-controller="TestCtrl">
<div>
<button ng-click="getEmails()">Get Emails</button>
<textarea>
{{emailsRes}}
</textarea>
</div>
<div>
<input type="text" ng-model="emailId"/>
<button ng-click="getEmail()">Get Email by Id</button>
<textarea>
{{emailRes}}
</textarea>
</div>
<div>
New title <input type="text" ng-model="newEmailTitle"/>
<button ng-click="updateEmail()">UpdateEmail</button>
<textarea>
{{udateEmailRes}}
</textarea>
</div>
<div>
<button ng-click="deleteEmail()">Delete email</button>
<textarea>
{{deleteEmailRes}}
</textarea>
</div>
<h1>SENT</h1>
<div>
<button ng-click="getSent()">GET Sent</button>
<textarea>
{{sentRes}}
</textarea>
</div>
<div>
New title <input type="text" ng-model="sentTitle"/>
<button ng-click="createSent()">Create Sent</button>
<textarea>
{{createSentRes}}
</textarea>
</div>
</body>
</html>