/*
	Copyright (c) 2004-2009, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dojox.data.PersevereStore"]){
dojo._hasResource["dojox.data.PersevereStore"]=true;
dojo.provide("dojox.data.PersevereStore");
dojo.require("dojox.data.JsonQueryRestStore");
dojo.require("dojox.rpc.Client");
dojox.json.ref.serializeFunctions=true;
dojo.declare("dojox.data.PersevereStore",dojox.data.JsonQueryRestStore,{useFullIdInQueries:true,jsonQueryPagination:false});
dojox.data.PersevereStore.getStores=function(_1,_2){
_1=(_1&&(_1.match(/\/$/)?_1:(_1+"/")))||"/";
if(_1.match(/^\w*:\/\//)){
dojo.require("dojox.io.xhrScriptPlugin");
dojox.io.xhrScriptPlugin(_1,"callback",dojox.io.xhrPlugins.fullHttpAdapter);
}
var _3=dojo.xhr;
dojo.xhr=function(_4,_5){
(_5.headers=_5.headers||{})["X-Server-Methods"]=false;
return _3.apply(dojo,arguments);
};
var _6=dojox.rpc.Rest(_1,true);
dojox.rpc._sync=_2;
var _7=_6("Class/");
var _8;
var _9={};
var _a=0;
_7.addCallback(function(_b){
for(var i in _b){
if(typeof _b[i]=="object"){
var _d=_b[i];
if(_d.methods){
for(var j in _d.methods){
var _f=_d.methods[j];
if(_f.runAt=="server"&&!_d.prototype[j]){
_d.prototype=_d.prototype||{};
_d.prototype[j]=(function(_10){
return function(){
var _11=dojo.rawXhrPost({url:this.__id,postData:dojo.toJson({method:_10,id:_a++,params:dojo._toArray(arguments)}),handleAs:"json"});
_11.addCallback(function(_12){
return _12.error?new Error(_12.error):_12.result;
});
return _11;
};
})(j);
}
}
}
_9[_b[i].id]=new dojox.data.PersevereStore({target:new dojo._Url(_1,_b[i].id)+"",schema:_d});
}
}
return (_8=_9);
});
dojo.xhr=_3;
return _2?_8:_7;
};
dojox.data.PersevereStore.addProxy=function(){
dojo.require("dojox.io.xhrPlugins");
dojox.io.xhrPlugins.addProxy("/proxy/");
};
}
