2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo._hasResource["dijit.tree.TreeStoreModel"]){
9 dojo._hasResource["dijit.tree.TreeStoreModel"]=true;
10 dojo.provide("dijit.tree.TreeStoreModel");
11 dojo.declare("dijit.tree.TreeStoreModel",null,{store:null,childrenAttrs:["children"],newItemIdAttr:"id",labelAttr:"",root:null,query:null,deferItemLoadingUntilExpand:false,constructor:function(_1){
15 if(!_2.getFeatures()["dojo.data.api.Identity"]){
16 throw new Error("dijit.Tree: store must support dojo.data.Identity");
18 if(_2.getFeatures()["dojo.data.api.Notification"]){
19 this.connects=this.connects.concat([dojo.connect(_2,"onNew",this,"onNewItem"),dojo.connect(_2,"onDelete",this,"onDeleteItem"),dojo.connect(_2,"onSet",this,"onSetItem")]);
22 dojo.forEach(this.connects,dojo.disconnect);
23 },getRoot:function(_3,_4){
27 this.store.fetch({query:this.query,onComplete:dojo.hitch(this,function(_5){
29 throw new Error(this.declaredClass+": query "+dojo.toJson(this.query)+" returned "+_5.length+" items, but must return exactly one item");
35 },mayHaveChildren:function(_6){
36 return dojo.some(this.childrenAttrs,function(_7){
37 return this.store.hasAttribute(_6,_7);
39 },getChildren:function(_8,_9,_a){
41 if(!_b.isItemLoaded(_8)){
42 var _c=dojo.hitch(this,arguments.callee);
43 _b.loadItem({item:_8,onItem:function(_d){
49 for(var i=0;i<this.childrenAttrs.length;i++){
50 var _f=_b.getValues(_8,this.childrenAttrs[i]);
54 if(!this.deferItemLoadingUntilExpand){
55 dojo.forEach(_e,function(_11){
56 if(!_b.isItemLoaded(_11)){
64 dojo.forEach(_e,function(_12,idx){
65 if(!_b.isItemLoaded(_12)){
66 _b.loadItem({item:_12,onItem:function(_13){
75 },isItem:function(_14){
76 return this.store.isItem(_14);
77 },fetchItemByIdentity:function(_15){
78 this.store.fetchItemByIdentity(_15);
79 },getIdentity:function(_16){
80 return this.store.getIdentity(_16);
81 },getLabel:function(_17){
83 return this.store.getValue(_17,this.labelAttr);
85 return this.store.getLabel(_17);
87 },newItem:function(_18,_19,_1a){
88 var _1b={parent:_19,attribute:this.childrenAttrs[0],insertIndex:_1a};
89 if(this.newItemIdAttr&&_18[this.newItemIdAttr]){
90 this.fetchItemByIdentity({identity:_18[this.newItemIdAttr],scope:this,onItem:function(_1c){
92 this.pasteItem(_1c,null,_19,true,_1a);
94 this.store.newItem(_18,_1b);
98 this.store.newItem(_18,_1b);
100 },pasteItem:function(_1d,_1e,_1f,_20,_21){
101 var _22=this.store,_23=this.childrenAttrs[0];
103 dojo.forEach(this.childrenAttrs,function(_24){
104 if(_22.containsValue(_1e,_24,_1d)){
106 var _25=dojo.filter(_22.getValues(_1e,_24),function(x){
109 _22.setValues(_1e,_24,_25);
116 if(typeof _21=="number"){
117 var _26=_22.getValues(_1f,_23).slice();
118 _26.splice(_21,0,_1d);
119 _22.setValues(_1f,_23,_26);
121 _22.setValues(_1f,_23,_22.getValues(_1f,_23).concat(_1d));
124 },onChange:function(_27){
125 },onChildrenChange:function(_28,_29){
126 },onDelete:function(_2a,_2b){
127 },onNewItem:function(_2c,_2d){
131 this.getChildren(_2d.item,dojo.hitch(this,function(_2e){
132 this.onChildrenChange(_2d.item,_2e);
134 },onDeleteItem:function(_2f){
136 },onSetItem:function(_30,_31,_32,_33){
137 if(dojo.indexOf(this.childrenAttrs,_31)!=-1){
138 this.getChildren(_30,dojo.hitch(this,function(_34){
139 this.onChildrenChange(_30,_34);