Changeset 12481
- Timestamp:
- 02/17/08 04:13:48 (11 months ago)
- Location:
- dijit/trunk
- Files:
-
- 4 modified
-
tests/test_Tree.html (modified) (2 diffs)
-
tests/tree/test_Tree_v1.html (modified) (1 diff)
-
Tree.js (modified) (4 diffs)
-
_tree/ForestStoreDecorator.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dijit/trunk/tests/test_Tree.html
r12417 r12481 37 37 <p>Clicking a folder node will open/close it (openOnclick==true), and clicking a leaf node will popup an alert.</p> 38 38 <div dojoType="dijit.Tree" id="mytree" 39 store="continentStoreDecorated" root="continentRoot"labelAttr="name" childrenAttr="children"39 store="continentStoreDecorated" labelAttr="name" childrenAttr="children" 40 40 openOnClick="true"> 41 41 <script type="dojo/method" event="onClick" args="item"> … … 82 82 83 83 <div dojoType="dijit.Tree" id="tree2" 84 store="continentStoreDecorated" root="continentRoot"labelAttr="name" childrenAttr="children"84 store="continentStoreDecorated" labelAttr="name" childrenAttr="children" 85 85 showRoot="false" openOnClick="true"> 86 86 -
dijit/trunk/tests/tree/test_Tree_v1.html
r12417 r12481 6 6 7 7 <style type="text/css"> 8 @import "../../../ ../dojo/resources/dojo.css";9 @import " css/dijitTests.css";8 @import "../../../dojo/resources/dojo.css"; 9 @import "../css/dijitTests.css"; 10 10 </style> 11 11 12 13 <script type="text/javascript" src="../../../../dojo/dojo.js" 12 <script type="text/javascript" src="../../../dojo/dojo.js" 14 13 djConfig="parseOnLoad: true, isDebug: true"></script> 15 <script type="text/javascript" src=" _testCommon.js"></script>14 <script type="text/javascript" src="../_testCommon.js"></script> 16 15 17 16 <script language="JavaScript" type="text/javascript"> -
dijit/trunk/Tree.js
r12399 r12481 215 215 // On initial tree show, put focus on either the root node of the tree, 216 216 // or the first child, if the root node is hidden 217 // TODO: move to Tree.postCreate? (but can't execute until root node and child nodes finish loading)218 217 if(!this.parent){ 219 218 var fc = this.tree.showRoot ? this : this.getChildren()[0], … … 270 269 store: null, 271 270 272 // root: String 273 // id of item in store corresponding to root of tree 274 root: "", 275 276 // query: String 277 // Deprecated. Use dijit._tree.ForestStoreDecorator directly instead. 278 // Specifies a set of "top level" items for the tree, rather than just a single item. 279 // If a label is also specified, the tree is given a fake root node (not corresponding to an item in 280 // the data store), whose children are the items that match this query. 281 // 271 // query: anything 272 // Specifies datastore query to return the root item for the tree. 273 // 274 // Deprecated functionality: if the query returns multiple items, the tree is given 275 // a fake root node (not corresponding to any item in the data store), 276 // whose children are the items that match this query. 277 // 278 // The root node is shown or hidden based on whether a label is specified. 279 // 280 // Having a query return multiple items is deprecated. 281 // If your store doesn't have a root item, wrap the store with 282 // dijit._tree.ForestStoreDecorator, and specify store=myDecoratedStore query="$root$". 283 // 282 284 // example: 283 285 // {type:'continent'} … … 337 339 338 340 this._itemNodeMap={}; 339 340 if(!this.root){341 // 1.0 compatible behavior.342 // Provide (possibly hidden) fake root node not corresponding to any data store item,343 // which fathers all the items returned by fetch({query: this.query})344 dojo.deprecated("Tree: from version 2.0, must specify root item id (using root parameter) rather than query/label parameters when constructing a dijit.Tree; use dijit._tree.ForestStoreDecorator if your data store has no root item.");345 this._v10Compat = true;346 this.underlyingStore = this.store;347 this.root = "$root$";348 this.store = new dijit._tree.ForestStoreDecorator({349 id: this.id + "_ForestStoreDecorator",350 store: this.underlyingStore,351 query: this.query,352 childrenAttr: this.childrenAttr[0],353 rootId: this.root,354 rootLabel: this.label||"ROOT"355 });356 357 // For backwards compatibility, the visibility of the root node is controlled by358 // whether or not the user has specified a label359 this.showRoot = Boolean(this.label);360 }361 341 362 342 if(!this.store.getFeatures()['dojo.data.api.Identity']){ … … 397 377 398 378 // load root node (possibly hidden) and it's children 399 var _this = this; 400 this.store.fetchItemByIdentity({ 401 identity: this.root, 402 onItem: function(item){ 403 _this.rootItem = item; 404 405 var rn = _this.rootNode = new dijit._TreeNode({ 379 this.store.fetch({ 380 query: this.query, 381 onComplete: dojo.hitch(this, function(items){ 382 if(items.length > 1){ 383 // 1.0 compatible behavior. 384 // Provide (possibly hidden) fake root node not corresponding to any data store item, 385 // which fathers all the items returned by fetch({query: this.query}) 386 dojo.deprecated("Tree: from version 2.0, query must return a single root item; use dijit._tree.ForestStoreDecorator if your data store has no root item."); 387 this._v10Compat = true; 388 this.underlyingStore = this.store; 389 this.root = "$root$"; 390 this.store = new dijit._tree.ForestStoreDecorator({ 391 id: this.id + "_ForestStoreDecorator", 392 store: this.underlyingStore, 393 childrenAttr: this.childrenAttr[0], 394 rootId: this.root, 395 rootLabel: this.label||"ROOT", 396 rootChildren: items 397 }); 398 var item = this.store.root; 399 400 // For backwards compatibility, the visibility of the root node is controlled by 401 // whether or not the user has specified a label 402 this.showRoot = Boolean(this.label); 403 }else{ 404 item = items[0]; 405 } 406 407 var rn = this.rootNode = new dijit._TreeNode({ 406 408 item: item, 407 tree: _this,409 tree: this, 408 410 isExpandable: true, 409 label: _this.label || _this.getLabel(item)411 label: this.label || this.getLabel(item) 410 412 }); 411 if(! _this.showRoot){413 if(!this.showRoot){ 412 414 rn.rowNode.style.display="none"; 413 415 } 414 _this.domNode.appendChild(rn.domNode);415 _this._itemNodeMap[_this.root] = rn;416 this.domNode.appendChild(rn.domNode); 417 this._itemNodeMap[this.store.getIdentity(item)] = rn; 416 418 417 419 rn._updateLayout(); // sets "dijitTreeIsRoot" CSS classname 418 420 419 421 // load top level children 420 _this._expandNode(rn);421 } 422 this._expandNode(rn); 423 }) 422 424 }); 423 425 -
dijit/trunk/_tree/ForestStoreDecorator.js
r12417 r12481 26 26 // rootId: String 27 27 // ID of root item 28 rootId: " ",28 rootId: "$root$", 29 29 30 30 // rootLabel: String 31 31 // Label of root item 32 rootLabel: " ",32 rootLabel: "ROOT", 33 33 34 34 // childrenAttr: String … … 57 57 id: params.rootId, 58 58 label: params.rootLabel, 59 children: []59 children: params.rootChildren || [] 60 60 }; 61 61 … … 234 234 235 235 fetch: function(/* Object */ args){ 236 return this.store.fetch(args); 236 if(!args.query){ 237 // No query means to get the (fake) root item 238 return this.fetchItemByIdentity({ 239 identity: this.rootId, 240 onItem: function(item){ args.onComplete([item]); }, 241 onError: args.onError 242 }); 243 }else{ 244 // Not sure if another query should search the items in the underlying store 245 // or just return empty list; I think this code path will never execute anyway. 246 return this.store.fetch(args); 247 } 237 248 }, 238 249