2010-11-15 07:39:52 +00:00
|
|
|
/*
|
2011-11-08 16:40:44 +00:00
|
|
|
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
|
2010-11-15 07:39:52 +00:00
|
|
|
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
|
|
|
see: http://dojotoolkit.org/license for details
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-03-04 16:02:28 +00:00
|
|
|
if(!dojo._hasResource["dojo.rpc.JsonpService"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
|
dojo._hasResource["dojo.rpc.JsonpService"] = true;
|
2010-11-15 07:39:52 +00:00
|
|
|
dojo.provide("dojo.rpc.JsonpService");
|
|
|
|
dojo.require("dojo.rpc.RpcService");
|
|
|
|
dojo.require("dojo.io.script");
|
2011-03-04 16:02:28 +00:00
|
|
|
|
2011-11-08 16:40:44 +00:00
|
|
|
|
2011-03-04 16:02:28 +00:00
|
|
|
dojo.declare("dojo.rpc.JsonpService", dojo.rpc.RpcService, {
|
|
|
|
// summary:
|
2011-11-08 16:40:44 +00:00
|
|
|
// Generic JSONP service. Minimally extends RpcService to allow
|
2011-03-04 16:02:28 +00:00
|
|
|
// 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){
|
2011-11-08 16:40:44 +00:00
|
|
|
throw new Error("Required Service Argument not found: "+req);
|
2011-03-04 16:02:28 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-08 16:40:44 +00:00
|
|
|
}
|
2011-03-04 16:02:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
2011-11-08 16:40:44 +00:00
|
|
|
handleAs: "json",
|
2011-03-04 16:02:28 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-11-15 07:39:52 +00:00
|
|
|
});
|
2011-03-04 16:02:28 +00:00
|
|
|
|
2010-11-15 07:39:52 +00:00
|
|
|
}
|