dojo.provide("parus.catalogTreeModel");dojo.require("dijit.tree.TreeStoreModel");dojo.require("parus.parus8");dojo.require("parus.database");dojo.declare("parus.treeModel",null,{constructor:function(a){if(a){dojo.mixin(this,a)}},isItem:function(a){return true},fetchItemByIdentity:function(a){parus.parus8.unimplemented(this,"fetchItemByIdentity",arguments)},newItem:function(c,b,a){parus.parus8.unimplemented(this,"newItem",arguments)},pasteItem:function(c,b,a,d){parus.parus8.unimplemented(this,"pasteItem",arguments)},onChange:function(a){},onChildrenChange:function(b,a){},hasAction:function(a,b){return b?false:true},checkAccess:function(){return false},isValid:function(a){return true},refresh:function(){},getIdentity:function(a){return null},getItem:function(a){return null}});dojo.declare("parus.catalogTreeModel",[parus.treeModel],{queryid:null,identityFieldName:"ID",labelFieldName:"NAME",parentLinkFieldName:"PARENT",hasChildrenFieldName:"HASCHILDREN",onGetConditions:function(b,a){},_rootNodes:null,_childrenSet:null,_hasChildren:null,_allFetched:false,getConditions:function(a){return this.onGetConditions(this,a)},getIdentity:function(a){return parus.parus8.nodeField(a,this.identityFieldName)||null},getLabel:function(a){return parus.parus8.nodeField(a,this.labelFieldName)},getParentLink:function(a){return parus.parus8.nodeField(a,this.parentLinkFieldName)},getValue:function(a,c,b){return parus.parus8.nodeField(a,c)||b||null},destroy:function(){this._rootNodes=null;this._childrenSet=null;this._hasChildren=null;this._allFetched=false},getRoot:function(a){if(a){if(!this._rootNodes){parus.database.query(this.queryid,this.getConditions(null),dojo.hitch(this,function(b){this._rootNodes=parus.parus8.rowNodes(b);dojo.forEach(this._rootNodes,a)}))}else{dojo.forEach(this._rootNodes,a)}}},mayHaveChildren:function(c){if(!this._hasChildren){this._hasChildren=[]}var a=this.getIdentity(c);if(dojo.indexOf(this._hasChildren,a)>=0){return true}var b=(parus.parus8.nodeField(c,this.hasChildrenFieldName).toString()=="1");if(b){this._hasChildren.push(a)}return b},getChildren:function(a,c){if(c){if(!this.mayHaveChildren(a)){c([]);return}var b;if(this._childrenSet){b=this._childrenSet[this.getIdentity(a)]}else{this._childrenSet={}}if(!b){return parus.database.query(this.queryid,this.getConditions(a),dojo.hitch(this,function(d){b=parus.parus8.rowNodes(d);this._childrenSet[this.getIdentity(a)]=b;c(b)}))}else{c(b)}}},refresh:function(){this._rootNodes=null;this._childrenSet=null;this._hasChildren=null;this._allFetched=false},newItemCreated:function(c,b){if(!this._hasChildren){this._hasChildren=[]}if(!this._childrenSet){this._childrenSet={}}var a=this.getIdentity(c);this._hasChildren.push(a);this._childrenSet[a]=null;this.getChildren(c,function(){if(b){b()}})},isValid:function(a){return parus.parus8.nodeField(a,"ISVALID")=="1"},checkAccess:function(){return this._rootNodes?parus.parus8.nodeField(this._rootNodes[0],"CHECKACCESS")=="1":false},hasAction:function(f,a){if(!a){return true}if(!f){return false}if(dojo.isIE<=9){return(f.selectSingleNode("XMLFUNCTIONS/ROWSET/ROW[FUNC='"+a+"']"))?true:false}if(f.children){var o=f.children;for(var d=0,n=o.length;d<n;d++){if(o[d].nodeName=="XMLFUNCTIONS"){if(o[d].firstChild){for(var c=0,m=o[d].firstChild.children.length;c<m;c++){if(o[d].firstChild.children[c].nodeName=="ROW"){for(var b=0,l=o[d].firstChild.children[c].children.length;b<l;b++){if(o[d].firstChild.children[c].children[b].firstChild.nodeValue==a){return true}}}}}}}}else{var h=f.firstElementChild;while(h){if(h.nodeName=="XMLFUNCTIONS"){var g=h.firstElementChild?h.firstElementChild.firstElementChild:null;while(g){var e=g.firstElementChild;while(e){if(e.firstChild.nodeValue==a){return true}e=e.nextElementSibling}g=g.nextElementSibling}}h=h.nextElementSibling}}return false},fetchAll:function(b){var a=null;if(!this._allFetched){var d=this.getConditions(null);d.CRN=null;a=parus.database.query(this.queryid,d);var c=parus.parus8.rowNodes(a);this._childrenSet={};dojo.forEach(c,dojo.hitch(this,function(f){var e=this.getParentLink(f);if(!this._childrenSet[e]){this._childrenSet[e]=[]}this._childrenSet[e].push(f)}));this._allFetched=true}if(b){b(this,a)}},getItem:function(d){var b=null;if(this._rootNodes){dojo.forEach(this._rootNodes,dojo.hitch(this,function(f){if(!b&&(this.getIdentity(f)==d)){b=f}}))}if(!b&&this._childrenSet){for(var a in this._childrenSet){if(!b){dojo.forEach(this._childrenSet[a],dojo.hitch(this,function(f){if(!b&&(this.getIdentity(f)==d)){b=f}}))}}}if(!b){var e={};e[this.identityFieldName]=d;response=parus.database.query(this.queryid,e);if(response){var c=parus.parus8.rowNodes(response);if(c.length){b=c[0]}}}return b}});dojo.declare("parus.emptyTreeModel",[parus.treeModel],{destroy:function(){},getRoot:function(a){},mayHaveChildren:function(a){return false},getChildren:function(b,a){},getIdentity:function(a){},getLabel:function(a){}});dojo.mixin(parus.parus8,{emptyTreeModel:function(){return new parus.emptyTreeModel()}});