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