summaryrefslogtreecommitdiff
path: root/lib/dojo/rpc/JsonpService.js.uncompressed.js
blob: bc1d7108d4e9e6d219a0840db8684f2387ed6173 (plain)
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
define("dojo/rpc/JsonpService", ["../main", "./RpcService", "../io/script"], function(dojo) {
	// module:
	//		dojo/rpc/JsonpService
	// summary:
	//		TODOC


dojo.declare("dojo.rpc.JsonpService", dojo.rpc.RpcService, {
	// summary:
	//	Generic JSONP service.  Minimally extends RpcService to allow
	//	easy definition of nearly any JSONP style service. Example
	//	SMD files exist in dojox.data

	constructor: function(args, requiredArgs){
		if(this.required) {
			if(requiredArgs){
				dojo.mixin(this.required, requiredArgs);
			}

			dojo.forEach(this.required, function(req){
				if(req=="" || req==undefined){
					throw new Error("Required Service Argument not found: "+req);
				}
			});
		}
	},

	strictArgChecks: false,

	bind: function(method, parameters, deferredRequestHandler, url){
		//summary:
		//              JSONP bind method. Takes remote method, parameters,
		//              deferred, and a url, calls createRequest to make a JSON-RPC
		//              envelope and passes that off with bind.
		//      method: string
		//              The name of the method we are calling
		//      parameters: array
		//              The parameters we are passing off to the method
		//      deferredRequestHandler: deferred
		//              The Deferred object for this particular request

		var def = dojo.io.script.get({
			url: url||this.serviceUrl,
			callbackParamName: this.callbackParamName||"callback",
			content: this.createRequest(parameters),
			timeout: this.timeout,
			handleAs: "json",
			preventCache: true
		});
		def.addCallbacks(this.resultCallback(deferredRequestHandler), this.errorCallback(deferredRequestHandler));
	},

	createRequest: function(parameters){
		// summary:
		//      create a JSONP req
		//      params: array
		//              The array of parameters for this request;

		var params = (dojo.isArrayLike(parameters) && parameters.length==1) ?
				parameters[0] : {};
		dojo.mixin(params,this.required);
		return params;
	}
});

return dojo.rpc.JsonpService;
});