]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/rpc/JsonpService.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / rpc / JsonpService.js
1 if(!dojo._hasResource["dojo.rpc.JsonpService"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.rpc.JsonpService"] = true;
3 dojo.provide("dojo.rpc.JsonpService");
4 dojo.require("dojo.rpc.RpcService");
5 dojo.require("dojo.io.script");
6
7 dojo.declare("dojo.rpc.JsonpService", dojo.rpc.RpcService, {
8         // summary:
9         //      Generic JSONP service.  Minimally extends RpcService to allow 
10         //      easy definition of nearly any JSONP style service. Example
11         //      SMD files exist in dojox.data
12
13         constructor: function(args, requiredArgs){
14                 if(this.required) {
15                         if(requiredArgs){
16                                 dojo.mixin(this.required, requiredArgs);
17                         }
18
19                         dojo.forEach(this.required, function(req){
20                                 if(req=="" || req==undefined){
21                                         throw new Error("Required Service Argument not found: "+req); 
22                                 }
23                         });
24                 }               
25         },
26
27         strictArgChecks: false,
28
29         bind: function(method, parameters, deferredRequestHandler, url){
30                 //summary:
31                 //              JSONP bind method. Takes remote method, parameters,
32                 //              deferred, and a url, calls createRequest to make a JSON-RPC
33                 //              envelope and passes that off with bind.
34                 //      method: string
35                 //              The name of the method we are calling
36                 //      parameters: array
37                 //              The parameters we are passing off to the method
38                 //      deferredRequestHandler: deferred
39                 //              The Deferred object for this particular request
40
41                 var def = dojo.io.script.get({
42                         url: url||this.serviceUrl,
43                         callbackParamName: this.callbackParamName||"callback",
44                         content: this.createRequest(parameters),
45                         timeout: this.timeout,
46                         handleAs: "json",       
47                         preventCache: true
48                 });
49                 def.addCallbacks(this.resultCallback(deferredRequestHandler), this.errorCallback(deferredRequestHandler));
50         },
51
52         createRequest: function(parameters){
53                 // summary:
54                 //      create a JSONP req
55                 //      params: array
56                 //              The array of parameters for this request;
57
58                 var params = (dojo.isArrayLike(parameters) && parameters.length==1) ?
59                                 parameters[0] : {};
60                 dojo.mixin(params,this.required);
61                 return params;
62         }
63 });
64
65 }