2150 |
mathias |
1 |
if(!dojo._hasResource["dojo.rpc.JsonService"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojo.rpc.JsonService"] = true;
|
|
|
3 |
dojo.provide("dojo.rpc.JsonService");
|
|
|
4 |
dojo.require("dojo.rpc.RpcService");
|
|
|
5 |
|
|
|
6 |
dojo.declare("dojo.rpc.JsonService", dojo.rpc.RpcService, {
|
|
|
7 |
bustCache: false,
|
|
|
8 |
contentType: "application/json-rpc",
|
|
|
9 |
lastSubmissionId: 0,
|
|
|
10 |
|
|
|
11 |
callRemote: function(method, params){
|
|
|
12 |
// summary:
|
|
|
13 |
// call an arbitrary remote method without requiring it to be
|
|
|
14 |
// predefined with SMD
|
|
|
15 |
// method: string
|
|
|
16 |
// the name of the remote method you want to call.
|
|
|
17 |
// params: array
|
|
|
18 |
// array of parameters to pass to method
|
|
|
19 |
|
|
|
20 |
var deferred = new dojo.Deferred();
|
|
|
21 |
this.bind(method, params, deferred);
|
|
|
22 |
return deferred;
|
|
|
23 |
},
|
|
|
24 |
|
|
|
25 |
bind: function(method, parameters, deferredRequestHandler, url){
|
|
|
26 |
//summary:
|
|
|
27 |
// JSON-RPC bind method. Takes remote method, parameters,
|
|
|
28 |
// deferred, and a url, calls createRequest to make a JSON-RPC
|
|
|
29 |
// envelope and passes that off with bind.
|
|
|
30 |
// method: string
|
|
|
31 |
// The name of the method we are calling
|
|
|
32 |
// parameters: array
|
|
|
33 |
// The parameters we are passing off to the method
|
|
|
34 |
// deferredRequestHandler: deferred
|
|
|
35 |
// The Deferred object for this particular request
|
|
|
36 |
|
|
|
37 |
var def = dojo.rawXhrPost({
|
|
|
38 |
url: url||this.serviceUrl,
|
|
|
39 |
postData: this.createRequest(method, parameters),
|
|
|
40 |
contentType: this.contentType,
|
|
|
41 |
timeout: this.timeout,
|
|
|
42 |
handleAs: "json-comment-optional"
|
|
|
43 |
});
|
|
|
44 |
def.addCallbacks(this.resultCallback(deferredRequestHandler), this.errorCallback(deferredRequestHandler));
|
|
|
45 |
},
|
|
|
46 |
|
|
|
47 |
createRequest: function(method, params){
|
|
|
48 |
// summary:
|
|
|
49 |
// create a JSON-RPC envelope for the request
|
|
|
50 |
// method: string
|
|
|
51 |
// The name of the method we are creating the requst for
|
|
|
52 |
// params: array
|
|
|
53 |
// The array of parameters for this request;
|
|
|
54 |
|
|
|
55 |
var req = { "params": params, "method": method, "id": ++this.lastSubmissionId };
|
|
|
56 |
var data = dojo.toJson(req);
|
|
|
57 |
return data;
|
|
|
58 |
},
|
|
|
59 |
|
|
|
60 |
parseResults: function(/*anything*/obj){
|
|
|
61 |
//summary:
|
|
|
62 |
// parse the result envelope and pass the results back to
|
|
|
63 |
// the callback function
|
|
|
64 |
// obj: Object
|
|
|
65 |
// Object containing envelope of data we recieve from the server
|
|
|
66 |
|
|
|
67 |
if(dojo.isObject(obj)){
|
|
|
68 |
if("result" in obj){
|
|
|
69 |
return obj.result;
|
|
|
70 |
}
|
|
|
71 |
if("Result" in obj){
|
|
|
72 |
return obj.Result;
|
|
|
73 |
}
|
|
|
74 |
if("ResultSet" in obj){
|
|
|
75 |
return obj.ResultSet;
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
return obj;
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
);
|
|
|
82 |
|
|
|
83 |
}
|