-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathforumservice.js
More file actions
35 lines (31 loc) · 1.15 KB
/
forumservice.js
File metadata and controls
35 lines (31 loc) · 1.15 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
forumplugin.service('$forumService', ['$http', function ($http) {
var RESTAPI = AJS.contextPath() + '/rest/forum/latest/threads';
this.getCurrentUser = function (callback) {
$http.get(AJS.contextPath() + '/rest/gadget/1.0/currentUser').success(function (data) {
if (data) {
callback(data.username);
}
});
}
this.getForums = function (callback) {
$http.get(RESTAPI).success(function (data) {
if (data) {
callback(data);
}
});
};
this.saveForum = function (forum, callback) {
// Preserve the this pointer so we can refer to the service from within the callback-function.
var that = this;
$http.post(RESTAPI, forum).success(function () {
that.getForums(callback);
});
}
this.deleteForum = function (forumId, callback) {
// Preserve the this pointer so we can refer to the service from within the callback-function.
var that = this;
$http({method: 'DELETE', url: RESTAPI + forumId}).success(function (data) {
that.getForums(callback);
});
};
}]);