/* 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.AndOrReadStore"]){dojo._hasResource["dojox.data.AndOrReadStore"]=true;dojo.provide("dojox.data.AndOrReadStore");dojo.require("dojo.data.util.filter");dojo.require("dojo.data.util.simpleFetch");dojo.require("dojo.date.stamp");dojo.declare("dojox.data.AndOrReadStore",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;}},url:"",_ccUrl:"",data:null,typeMap:null,clearOnClose:false,urlPreventCache:false,hierarchical:true,_assertIsItem:function(_3){if(!this.isItem(_3)){throw new Error("dojox.data.AndOrReadStore: Invalid item argument.");}},_assertIsAttribute:function(_4){if(typeof _4!=="string"){throw new Error("dojox.data.AndOrReadStore: 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]||[];},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;var _22=function(_23,_24){var _25=[];if(_23.query){var _26=dojo.fromJson(dojo.toJson(_23.query));if(typeof _26=="object"){var _27=0;var p;for(p in _26){_27++;}if(_27>1&&_26.complexQuery){var cq=_26.complexQuery;var _28=false;for(p in _26){if(p!=="complexQuery"){if(!_28){cq="( "+cq+" )";_28=true;}var v=_23.query[p];if(dojo.isString(v)){v="'"+v+"'";}cq+=" AND "+p+":"+v;delete _26[p];}}_26.complexQuery=cq;}}var _29=_23.queryOptions?_23.queryOptions.ignoreCase:false;if(typeof _26!="string"){_26=dojo.toJson(_26);_26=_26.replace(/\\\\/g,"\\");}_26=_26.replace(/\\"/g,"\"");var _2a=dojo.trim(_26.replace(/{|}/g,""));var _2b,i;if(_2a.match(/"? *complexQuery *"?:/)){_2a=dojo.trim(_2a.replace(/"?\s*complexQuery\s*"?:/,""));var _2c=["'","\""];var _2d,_2e;var _2f=false;for(i=0;i<_2c.length;i++){_2d=_2a.indexOf(_2c[i]);_2b=_2a.indexOf(_2c[i],1);_2e=_2a.indexOf(":",1);if(_2d===0&&_2b!=-1&&_2e<_2b){_2f=true;break;}}if(_2f){_2a=_2a.replace(/^\"|^\'|\"$|\'$/g,"");}}var _30=_2a;var _31=/^,|^NOT |^AND |^OR |^\(|^\)|^!|^&&|^\|\|/i;var _32="";var op="";var val="";var pos=-1;var err=false;var key="";var _33="";var tok="";_2b=-1;for(i=0;i<_24.length;++i){var _34=true;var _35=_24[i];if(_35===null){_34=false;}else{_2a=_30;_32="";while(_2a.length>0&&!err){op=_2a.match(_31);while(op&&!err){_2a=dojo.trim(_2a.replace(op[0],""));op=dojo.trim(op[0]).toUpperCase();op=op=="NOT"?"!":op=="AND"||op==","?"&&":op=="OR"?"||":op;op=" "+op+" ";_32+=op;op=_2a.match(_31);}if(_2a.length>0){pos=_2a.indexOf(":");if(pos==-1){err=true;break;}else{key=dojo.trim(_2a.substring(0,pos).replace(/\"|\'/g,""));_2a=dojo.trim(_2a.substring(pos+1));tok=_2a.match(/^\'|^\"/);if(tok){tok=tok[0];pos=_2a.indexOf(tok);_2b=_2a.indexOf(tok,pos+1);if(_2b==-1){err=true;break;}_33=_2a.substring(pos+1,_2b);if(_2b==_2a.length-1){_2a="";}else{_2a=dojo.trim(_2a.substring(_2b+1));}_32+=_21._containsValue(_35,key,_33,dojo.data.util.filter.patternToRegExp(_33,_29));}else{tok=_2a.match(/\s|\)|,/);if(tok){var _36=new Array(tok.length);for(var j=0;j1){for(var j=1;j<_36.length;j++){pos=Math.min(pos,_36[j]);}}_33=dojo.trim(_2a.substring(0,pos));_2a=dojo.trim(_2a.substring(pos));}else{_33=dojo.trim(_2a);_2a="";}_32+=_21._containsValue(_35,key,_33,dojo.data.util.filter.patternToRegExp(_33,_29));}}}}_34=eval(_32);}if(_34){_25.push(_35);}}if(err){_25=[];}_1f(_25,_23);}else{for(var i=0;i<_24.length;++i){var _37=_24[i];if(_37!==null){_25.push(_37);}}_1f(_25,_23);}};if(this._loadFinished){_22(_1e,this._getItemsArray(_1e.queryOptions));}else{if(this._jsonFileUrl!==this._ccUrl){dojo.deprecated("dojox.data.AndOrReadStore: ","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 _38={url:_21._jsonFileUrl,handleAs:"json-comment-optional",preventCache:this.urlPreventCache};var _39=dojo.xhrGet(_38);_39.addCallback(function(_3a){try{_21._getItemsFromLoadedData(_3a);_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);}});_39.addErrback(function(_3b){_21._loadInProgress=false;_20(_3b,_1e);});var _3c=null;if(_1e.abort){_3c=_1e.abort;}_1e.abort=function(){var df=_39;if(df&&df.fired===-1){df.cancel();df=null;}if(_3c){_3c.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("dojox.data.AndOrReadStore: 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