//>>built
define("dojox/data/JsonRestStore","dojo/_base/lang,dojo/_base/declare,dojo/_base/connect,dojox/rpc/Rest,dojox/rpc/JsonRest,dojox/json/schema,dojox/data/ServiceStore".split(","),function(i,o,p,l,c,n,q){var r=i.getObject("dojox.rpc",!0),m=o("dojox.data.JsonRestStore",q,{constructor:function(a){p.connect(l._index,"onUpdate",this,function(a,b,d,s){var c=this.service.servicePath;if(a.__id&&a.__id.substring(0,c.length)==c)this.onSet(a,b,d,s)});this.idAttribute=this.idAttribute||"id";if("string"==typeof a.target&&
(a.target=a.target.match(/\/$/)||this.allowNoTrailingSlash?a.target:a.target+"/",!this.service))this.service=c.services[a.target]||l(a.target,!0);c.registerService(this.service,a.target,this.schema);this.schema=this.service._schema=this.schema||this.service._schema||{};this.service._store=this;this.service.idAsRef=this.idAsRef;this.schema._idAttr=this.idAttribute;var b=c.getConstructor(this.service),d=this;this._constructor=function(a){b.call(this,a);d.onNew(this)};this._constructor.prototype=b.prototype;
this._index=l._index},loadReferencedSchema:!0,idAsRef:!1,referenceIntegrity:!0,target:"",allowNoTrailingSlash:!1,newItem:function(a,b){a=new this._constructor(a);if(b){var d=this.getValue(b.parent,b.attribute,[]),d=d.concat([a]);a.__parent=d;this.setValue(b.parent,b.attribute,d)}return a},deleteItem:function(a){var b=[],d=k._getStoreForItem(a)||this;if(this.referenceIntegrity){c._saveNotNeeded=!0;var j=l._index,e=function(c){var s;var f;b.push(c);c.__checked=1;for(var g in c)if("__"!=g.substring(0,
2)){var h=c[g];h==a?c!=j&&(c instanceof Array?(f=f||[]).push(g):(k._getStoreForItem(c)||d).unsetAttribute(c,g)):"object"==typeof h&&h&&(h.__checked||e(h),"object"==typeof h.__checked&&c!=j&&(k._getStoreForItem(c)||d).setValue(c,g,h.__checked))}if(f){g=f.length;for(s=c.__checked=c.concat(),c=s;g--;)c.splice(f[g],1);return c}return null};e(j);c._saveNotNeeded=!1;for(var f=0;b[f];)delete b[f++].__checked}c.deleteObject(a);d.onDelete(a)},changing:function(a,b){c.changing(a,b)},cancelChanging:function(a){if(a.__id){dirtyObjects=
c.getDirtyObjects();for(var b=0;b<dirtyObjects.length;b++)if(a==dirtyObjects[b].object){dirtyObjects.splice(b,1);break}}},setValue:function(a,b,c){var j=a[b],e=a.__id?k._getStoreForItem(a):this;n&&e.schema&&e.schema.properties&&n.mustBeValid(n.checkPropertyChange(c,e.schema.properties[b]));if(b==e.idAttribute)throw Error("Can not change the identity attribute for an item");e.changing(a);if((a[b]=c)&&!c.__parent)c.__parent=a;e.onSet(a,b,j,c)},setValues:function(a,b,c){if(!i.isArray(c))throw Error("setValues expects to be passed an Array object as its value");
this.setValue(a,b,c)},unsetAttribute:function(a,b){this.changing(a);var c=a[b];delete a[b];this.onSet(a,b,c,void 0)},save:function(a){if(!a||!a.global)(a=a||{}).service=this.service;if("syncMode"in a?a.syncMode:this.syncMode)r._sync=!0;a=c.commit(a);this.serverVersion=this._updates&&this._updates.length;return a},revert:function(a){c.revert(a&&a.global&&this.service)},isDirty:function(a){return c.isDirty(a,this)},isItem:function(a,b){return a&&a.__id&&(b||this.service==c.getServiceAndId(a.__id).service)},
_doQuery:function(a){var b=c.query(this.service,"string"==typeof a.queryStr?a.queryStr:a.query,a),d=this;this.loadReferencedSchema&&b.addCallback(function(a){var e=b.ioArgs&&b.ioArgs.xhr&&b.ioArgs.xhr.getResponseHeader("Content-Type"),f=e&&e.match(/definedby\s*=\s*([^;]*)/);e&&!f&&(f=(f=b.ioArgs.xhr.getResponseHeader("Link"))&&f.match(/<([^>]*)>;\s*rel="?definedby"?/));if(f=f&&f[1])return e=c.getServiceAndId((d.target+f).replace(/^(.*\/)?(\w+:\/\/)|[^\/\.]+\/\.\.\/|^.*\/(\/)/,"$2$3")),e=c.byId(e.service,
e.id),e.addCallbacks(function(b){i.mixin(d.schema,b);return a},function(){return a}),e});return b},_processResults:function(a,b){var c=a.length;return{totalCount:b.fullLength||(b.request.count==c?(b.request.start||0)+2*c:c),items:a}},getConstructor:function(){return this._constructor},getIdentity:function(a){a=a.__clientId||a.__id;if(!a)return a;var b=this.service.servicePath.replace(/[^\/]*$/,"");return a.substring(0,b.length)!=b?a:a.substring(b.length)},fetchItemByIdentity:function(a){var b=a.identity,
d=this;if(b.toString().match(/^(\w*:)?\//))b=c.getServiceAndId(b),d=b.service._store,a.identity=b.id;a._prefix=d.service.servicePath.replace(/[^\/]*$/,"");return d.inherited(arguments)},onSet:function(){},onNew:function(){},onDelete:function(){},getFeatures:function(){var a=this.inherited(arguments);a["dojo.data.api.Write"]=!0;a["dojo.data.api.Notification"]=!0;return a},getParent:function(a){return a&&a.__parent}});m.getStore=function(a,b){if("string"==typeof a.target){a.target=a.target.match(/\/$/)||
a.allowNoTrailingSlash?a.target:a.target+"/";var d=(c.services[a.target]||{})._store;if(d)return d}return new (b||m)(a)};var k=i.getObject("dojox.data",!0);k._getStoreForItem=function(a){if(a.__id){var b=c.getServiceAndId(a.__id);if(b&&b.service._store)return b.service._store;a=a.__id.toString().match(/.*\//)[0];return new m({target:a})}return null};i.getObject("dojox.json.ref",!0)._useRefs=!0;return m});