Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.rpc.JsonService");
14
dojo.require("dojo.rpc.RpcService");
15
dojo.require("dojo.io.*");
16
dojo.require("dojo.json");
17
dojo.require("dojo.lang.common");
18
dojo.rpc.JsonService = function (args) {
19
	if (args) {
20
		if (dojo.lang.isString(args)) {
21
			this.connect(args);
22
		} else {
23
			if (args["smdUrl"]) {
24
				this.connect(args.smdUrl);
25
			}
26
			if (args["smdStr"]) {
27
				this.processSmd(dj_eval("(" + args.smdStr + ")"));
28
			}
29
			if (args["smdObj"]) {
30
				this.processSmd(args.smdObj);
31
			}
32
			if (args["serviceUrl"]) {
33
				this.serviceUrl = args.serviceUrl;
34
			}
35
			if (typeof args["strictArgChecks"] != "undefined") {
36
				this.strictArgChecks = args.strictArgChecks;
37
			}
38
		}
39
	}
40
};
41
dojo.inherits(dojo.rpc.JsonService, dojo.rpc.RpcService);
42
dojo.extend(dojo.rpc.JsonService, {bustCache:false, contentType:"application/json-rpc", lastSubmissionId:0, callRemote:function (method, params) {
43
	var deferred = new dojo.Deferred();
44
	this.bind(method, params, deferred);
45
	return deferred;
46
}, bind:function (method, parameters, deferredRequestHandler, url) {
47
	dojo.io.bind({url:url || this.serviceUrl, postContent:this.createRequest(method, parameters), method:"POST", contentType:this.contentType, mimetype:"text/json", load:this.resultCallback(deferredRequestHandler), error:this.errorCallback(deferredRequestHandler), preventCache:this.bustCache});
48
}, createRequest:function (method, params) {
49
	var req = {"params":params, "method":method, "id":++this.lastSubmissionId};
50
	var data = dojo.json.serialize(req);
51
	dojo.debug("JsonService: JSON-RPC Request: " + data);
52
	return data;
53
}, parseResults:function (obj) {
54
	if (!obj) {
55
		return;
56
	}
57
	if (obj["Result"] != null) {
58
		return obj["Result"];
59
	} else {
60
		if (obj["result"] != null) {
61
			return obj["result"];
62
		} else {
63
			if (obj["ResultSet"]) {
64
				return obj["ResultSet"];
65
			} else {
66
				return obj;
67
			}
68
		}
69
	}
70
}});
71