/* Copyright (c) 2004-2010, 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["dojo.data.ItemFileReadStore"]){ dojo._hasResource["dojo.data.ItemFileReadStore"]=true; dojo.provide("dojo.data.ItemFileReadStore"); dojo.require("dojo.data.util.filter"); dojo.require("dojo.data.util.simpleFetch"); dojo.require("dojo.date.stamp"); dojo.declare("dojo.data.ItemFileReadStore",null,{constructor:function(_1){ this._arrayOfAllItems=[]; this._arrayOfTopLevelItems=[]; this._loadFinished=false; this._jsonFileUrl=_1.url; this._ccUrl=_1.url; this.url=_1.url; this._jsonData=_1.data; this.data=null; this._datatypeMap=_1.typeMap||{}; if(!this._datatypeMap["Date"]){ this._datatypeMap["Date"]={type:Date,deserialize:function(_2){ return dojo.date.stamp.fromISOString(_2); }}; } this._features={"dojo.data.api.Read":true,"dojo.data.api.Identity":true}; this._itemsByIdentity=null; this._storeRefPropName="_S"; this._itemNumPropName="_0"; this._rootItemPropName="_RI"; this._reverseRefMap="_RRM"; this._loadInProgress=false; this._queuedFetches=[]; if(_1.urlPreventCache!==undefined){ this.urlPreventCache=_1.urlPreventCache?true:false; } if(_1.hierarchical!==undefined){ this.hierarchical=_1.hierarchical?true:false; } if(_1.clearOnClose){ this.clearOnClose=true; } if("failOk" in _1){ this.failOk=_1.failOk?true:false; } },url:"",_ccUrl:"",data:null,typeMap:null,clearOnClose:false,urlPreventCache:false,failOk:false,hierarchical:true,_assertIsItem:function(_3){ if(!this.isItem(_3)){ throw new Error("dojo.data.ItemFileReadStore: Invalid item argument."); } },_assertIsAttribute:function(_4){ if(typeof _4!=="string"){ throw new Error("dojo.data.ItemFileReadStore: Invalid attribute argument."); } },getValue:function(_5,_6,_7){ var _8=this.getValues(_5,_6); return (_8.length>0)?_8[0]:_7; },getValues:function(_9,_a){ this._assertIsItem(_9); this._assertIsAttribute(_a); return (_9[_a]||[]).slice(0); },getAttributes:function(_b){ this._assertIsItem(_b); var _c=[]; for(var _d in _b){ if((_d!==this._storeRefPropName)&&(_d!==this._itemNumPropName)&&(_d!==this._rootItemPropName)&&(_d!==this._reverseRefMap)){ _c.push(_d); } } return _c; },hasAttribute:function(_e,_f){ this._assertIsItem(_e); this._assertIsAttribute(_f); return (_f in _e); },containsValue:function(_10,_11,_12){ var _13=undefined; if(typeof _12==="string"){ _13=dojo.data.util.filter.patternToRegExp(_12,false); } return this._containsValue(_10,_11,_12,_13); },_containsValue:function(_14,_15,_16,_17){ return dojo.some(this.getValues(_14,_15),function(_18){ if(_18!==null&&!dojo.isObject(_18)&&_17){ if(_18.toString().match(_17)){ return true; } }else{ if(_16===_18){ return true; } } }); },isItem:function(_19){ if(_19&&_19[this._storeRefPropName]===this){ if(this._arrayOfAllItems[_19[this._itemNumPropName]]===_19){ return true; } } return false; },isItemLoaded:function(_1a){ return this.isItem(_1a); },loadItem:function(_1b){ this._assertIsItem(_1b.item); },getFeatures:function(){ return this._features; },getLabel:function(_1c){ if(this._labelAttr&&this.isItem(_1c)){ return this.getValue(_1c,this._labelAttr); } return undefined; },getLabelAttributes:function(_1d){ if(this._labelAttr){ return [this._labelAttr]; } return null; },_fetchItems:function(_1e,_1f,_20){ var _21=this,_22=function(_23,_24){ var _25=[],i,key; if(_23.query){ var _26,_27=_23.queryOptions?_23.queryOptions.ignoreCase:false; var _28={}; for(key in _23.query){ _26=_23.query[key]; if(typeof _26==="string"){ _28[key]=dojo.data.util.filter.patternToRegExp(_26,_27); }else{ if(_26 instanceof RegExp){ _28[key]=_26; } } } for(i=0;i<_24.length;++i){ var _29=true; var _2a=_24[i]; if(_2a===null){ _29=false; }else{ for(key in _23.query){ _26=_23.query[key]; if(!_21._containsValue(_2a,key,_26,_28[key])){ _29=false; } } } if(_29){ _25.push(_2a); } } _1f(_25,_23); }else{ for(i=0;i<_24.length;++i){ var _2b=_24[i]; if(_2b!==null){ _25.push(_2b); } } _1f(_25,_23); } }; if(this._loadFinished){ _22(_1e,this._getItemsArray(_1e.queryOptions)); }else{ if(this._jsonFileUrl!==this._ccUrl){ dojo.deprecated("dojo.data.ItemFileReadStore: ","To change the url, set the url property of the store,"+" not _jsonFileUrl. _jsonFileUrl support will be removed in 2.0"); this._ccUrl=this._jsonFileUrl; this.url=this._jsonFileUrl; }else{ if(this.url!==this._ccUrl){ this._jsonFileUrl=this.url; this._ccUrl=this.url; } } if(this.data!=null&&this._jsonData==null){ this._jsonData=this.data; this.data=null; } if(this._jsonFileUrl){ if(this._loadInProgress){ this._queuedFetches.push({args:_1e,filter:_22}); }else{ this._loadInProgress=true; var _2c={url:_21._jsonFileUrl,handleAs:"json-comment-optional",preventCache:this.urlPreventCache,failOk:this.failOk}; var _2d=dojo.xhrGet(_2c); _2d.addCallback(function(_2e){ try{ _21._getItemsFromLoadedData(_2e); _21._loadFinished=true; _21._loadInProgress=false; _22(_1e,_21._getItemsArray(_1e.queryOptions)); _21._handleQueuedFetches(); } catch(e){ _21._loadFinished=true; _21._loadInProgress=false; _20(e,_1e); } }); _2d.addErrback(function(_2f){ _21._loadInProgress=false; _20(_2f,_1e); }); var _30=null; if(_1e.abort){ _30=_1e.abort; } _1e.abort=function(){ var df=_2d; if(df&&df.fired===-1){ df.cancel(); df=null; } if(_30){ _30.call(_1e); } }; } }else{ if(this._jsonData){ try{ this._loadFinished=true; this._getItemsFromLoadedData(this._jsonData); this._jsonData=null; _22(_1e,this._getItemsArray(_1e.queryOptions)); } catch(e){ _20(e,_1e); } }else{ _20(new Error("dojo.data.ItemFileReadStore: No JSON source data was provided as either URL or a nested Javascript object."),_1e); } } } },_handleQueuedFetches:function(){ if(this._queuedFetches.length>0){ for(var i=0;i