//>>built
define("dojox/rpc/Rest",["dojo","dojox"],function(m,h){function p(d,f,a,n){d.addCallback(function(g){d.ioArgs.xhr&&a&&(a=d.ioArgs.xhr.getResponseHeader("Content-Range"),d.fullLength=a&&(a=a.match(/\/(.*)/))&&parseInt(a[1]));return g});return d}m.getObject("rpc.Rest",!0,h);h.rpc&&h.rpc.transportRegistry&&h.rpc.transportRegistry.register("REST",function(d){return"REST"==d},{getExecutor:function(d,f,a){return new h.rpc.Rest(f.name,(f.contentType||a._smd.contentType||"").match(/json|javascript/),null,
function(n,g){var b=a._getRequest(f,[n]);b.url=b.target+(b.data?"?"+b.data:"");g&&(0<=g.start||0<=g.count)&&(b.headers=b.headers||{},b.headers.Range="items\x3d"+(g.start||"0")+"-"+("count"in g&&Infinity!=g.count?g.count+(g.start||0)-1:""));return b})}});var l=h.rpc.Rest=function(d,f,a,n){function g(c){b[c]=function(e,k){return l._change(c,b,e,k)}}var b=function(c,e){return l._get(b,c,e)};b.isJson=f;b._schema=a;b.cache={serialize:f?(h.json&&h.json.ref||m).toJson:function(c){return c}};b._getRequest=
n||function(c,e){m.isObject(c)&&(c=(c=m.objectToQuery(c))?"?"+c:"");if(e&&e.sort&&!e.queryStr){c+=(c?"\x26":"?")+"sort(";for(var k=0;k<e.sort.length;k++){var q=e.sort[k];c+=(0<k?",":"")+(q.descending?"-":"+")+encodeURIComponent(q.attribute)}c+=")"}k={url:d+(null==c?"":c),handleAs:f?"json":"text",contentType:f?"application/json":"text/plain",sync:h.rpc._sync,headers:{Accept:f?"application/json,application/javascript":"*/*"}};e&&(0<=e.start||0<=e.count)&&(k.headers.Range="items\x3d"+(e.start||"0")+
"-"+("count"in e&&Infinity!=e.count?e.count+(e.start||0)-1:""));h.rpc._sync=!1;return k};g("put");g("post");g("delete");b.servicePath=d;return b};l._index={};l._timeStamps={};l._change=function(d,f,a,n){a=f._getRequest(a);a[d+"Data"]=n;return p(m.xhr(d.toUpperCase(),a,!0),f)};l._get=function(d,f,a){a=a||{};return p(m.xhrGet(d._getRequest(f,a)),d,0<=a.start||0<=a.count,f)};return l});