//>>built
define("dijit/tree/TreeStoreModel",["dojo/_base/array","dojo/aspect","dojo/_base/declare","dojo/_base/lang"],function(l,p,r,g){return r("dijit.tree.TreeStoreModel",null,{store:null,childrenAttrs:["children"],newItemIdAttr:"id",labelAttr:"",root:null,query:null,deferItemLoadingUntilExpand:!1,constructor:function(a){g.mixin(this,a);this.connects=[];a=this.store;if(!a.getFeatures()["dojo.data.api.Identity"])throw Error("dijit.tree.TreeStoreModel: store must support dojo.data.Identity");a.getFeatures()["dojo.data.api.Notification"]&&
(this.connects=this.connects.concat([p.after(a,"onNew",g.hitch(this,"onNewItem"),!0),p.after(a,"onDelete",g.hitch(this,"onDeleteItem"),!0),p.after(a,"onSet",g.hitch(this,"onSetItem"),!0)]))},destroy:function(){for(var a;a=this.connects.pop();)a.remove()},getRoot:function(a,b){this.root?a(this.root):this.store.fetch({query:this.query,onComplete:g.hitch(this,function(c){if(1!=c.length)throw Error("dijit.tree.TreeStoreModel: root query returned "+c.length+" items, but must return exactly one");this.root=
c[0];a(this.root)}),onError:b})},mayHaveChildren:function(a){return l.some(this.childrenAttrs,function(b){return this.store.hasAttribute(a,b)},this)},getChildren:function(a,b,c){var f=this.store;if(f.isItemLoaded(a)){for(var d=[],e=0;e<this.childrenAttrs.length;e++){var k=f.getValues(a,this.childrenAttrs[e]);d=d.concat(k)}var m=0;this.deferItemLoadingUntilExpand||l.forEach(d,function(h){f.isItemLoaded(h)||m++});0==m?b(d):l.forEach(d,function(h,q){f.isItemLoaded(h)||f.loadItem({item:h,onItem:function(t){d[q]=
t;0==--m&&b(d)},onError:c})})}else{var n=g.hitch(this,arguments.callee);f.loadItem({item:a,onItem:function(h){n(h,b,c)},onError:c})}},isItem:function(a){return this.store.isItem(a)},fetchItemByIdentity:function(a){this.store.fetchItemByIdentity(a)},getIdentity:function(a){return this.store.getIdentity(a)},getLabel:function(a){return this.labelAttr?this.store.getValue(a,this.labelAttr):this.store.getLabel(a)},newItem:function(a,b,c){var f={parent:b,attribute:this.childrenAttrs[0]},d;this.newItemIdAttr&&
a[this.newItemIdAttr]?this.fetchItemByIdentity({identity:a[this.newItemIdAttr],scope:this,onItem:function(e){e?this.pasteItem(e,null,b,!0,c):(d=this.store.newItem(a,f))&&void 0!=c&&this.pasteItem(d,b,b,!1,c)}}):(d=this.store.newItem(a,f))&&void 0!=c&&this.pasteItem(d,b,b,!1,c)},pasteItem:function(a,b,c,f,d){var e=this.store,k=this.childrenAttrs[0];b&&l.forEach(this.childrenAttrs,function(n){if(e.containsValue(b,n,a)){if(!f){var h=l.filter(e.getValues(b,n),function(q){return q!=a});e.setValues(b,n,
h)}k=n}});if(c)if("number"==typeof d){var m=e.getValues(c,k).slice();m.splice(d,0,a);e.setValues(c,k,m)}else e.setValues(c,k,e.getValues(c,k).concat(a))},onChange:function(){},onChildrenChange:function(){},onDelete:function(){},onNewItem:function(a,b){b&&this.getChildren(b.item,g.hitch(this,function(c){this.onChildrenChange(b.item,c)}))},onDeleteItem:function(a){this.onDelete(a)},onSetItem:function(a,b){if(-1!=l.indexOf(this.childrenAttrs,b))this.getChildren(a,g.hitch(this,function(c){this.onChildrenChange(a,
c)}));else this.onChange(a)}})});