source: [view]
if(typeof options.target == 'string' && !options.service){
var target = options.target.replace(/\/$/g, '');
// Special getRequest handler for handling content type negotiation via
// the Rails format extension, as well as properly setting the ID param
// in the URL.
var getRequest = function(id, args){
args = args || {};
var url = target;
var query;
var ident;
if(dojo.isObject(id)){
ident = '';
query = '?' + dojo.objectToQuery(id);
}else if(args.queryStr && args.queryStr.indexOf('?') != -1){
ident = args.queryStr.replace(/\?.*/, '');
query = args.queryStr.replace(/[^?]*\?/g, '?');
}else if(dojo.isString(args.query) && args.query.indexOf('?') != -1){
ident = args.query.replace(/\?.*/, '');
query = args.query.replace(/[^?]*\?/g, '?');
}else{
ident = id ? id.toString() : '';
query = '';
}
if(ident.indexOf('=') != -1){
query = ident;
ident = '';
}
if(ident){
url = url + '/' + ident + '.json' + query;
}else{
url = url + '.json' + query;
}
var isSync = dojox.rpc._sync;
dojox.rpc._sync = false;
return {
url : url,
handleAs : 'json',
contentType : 'application/json',
sync : isSync,
headers : {
Accept : 'application/json,application/javascript',
Range : args && (args.start >= 0 || args.count >= 0)
? "items="
+ (args.start || '0')
+ '-'
+ ((args.count && (args.count
+ (args.start || 0) - 1)) || '')
: undefined
}
};
};
options.service = dojox.rpc.Rest(this.target, true, null,
getRequest);
}