source: Dev/branches/rest-dojo-ui/client/rft/api.js @ 257

Last change on this file since 257 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.7 KB
RevLine 
[256]1define(['dojo/_base/xhr','dojo/_base/json','dojo/_base/Deferred','./auth'],function(xhr,json,Deferred){
2    return {
3        post: function(path,args) {
4            return xhr.post({
5                url: "../server/api.php/"+path,
6                handleAs: "json",
7                headers: {
8                    "Content-Type": "application/json"
9                },
10                rawBody: json.toJson(args)
11            });
12        },
13        createObject: function(type, args) {
14            var d = new Deferred();
15            this.post("createObject",
16            {
17                type: type,
18                values: args
19            })
20            .then(function(data) {
21                d.resolve(data.uid);
22            },function(){
23                d.reject();
24            });
25            return d.promise;
26        },
27        getObject: function(type, uid) {
28            var d = new Deferred();
29            this.post("getObject",
30            {
31                type: type,
32                uid: uid
33            })
34            .then(function(data) {
35                d.resolve(data.object);
36            },function(){
37                d.reject();
38            });
39            return d.promise;
40        },
41        getObjects: function(type, predicates) {
42            var d = new Deferred();
43            this.post("getObjects",
44            {
45                type: type,
46                predicates: predicates
47            })
48            .then(function(data) {
49                d.resolve(data.objects);
50            },function(){
51                d.reject();
52            });
53            return d.promise;
54        },
55        deleteObject: function(type, uid) {
56            var d = new Deferred();
57            d.reject();
58            return d.promise;
59        }
60    }
61});
Note: See TracBrowser for help on using the repository browser.