Changeset 12481

Show
Ignore:
Timestamp:
02/17/08 04:13:48 (11 months ago)
Author:
bill
Message:

Specify root item of tree using query parameter (like in v1.0) rather than "root" parameter. But query returning multiple items (rather than a single item) is deprecated; plan to remove in 2.0. Fixes #5879. !strict

Location:
dijit/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/tests/test_Tree.html

    r12417 r12481  
    3737        <p>Clicking a folder node will open/close it (openOnclick==true), and clicking a leaf node will popup an alert.</p> 
    3838        <div dojoType="dijit.Tree" id="mytree" 
    39                 store="continentStoreDecorated" root="continentRoot" labelAttr="name" childrenAttr="children" 
     39                store="continentStoreDecorated" labelAttr="name" childrenAttr="children" 
    4040                openOnClick="true"> 
    4141                <script type="dojo/method" event="onClick" args="item"> 
     
    8282 
    8383        <div dojoType="dijit.Tree" id="tree2" 
    84                 store="continentStoreDecorated" root="continentRoot" labelAttr="name" childrenAttr="children" 
     84                store="continentStoreDecorated" labelAttr="name" childrenAttr="children" 
    8585                showRoot="false" openOnClick="true"> 
    8686 
  • dijit/trunk/tests/tree/test_Tree_v1.html

    r12417 r12481  
    66 
    77        <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"; 
    1010        </style> 
    1111 
    12  
    13         <script type="text/javascript" src="../../../../dojo/dojo.js" 
     12        <script type="text/javascript" src="../../../dojo/dojo.js" 
    1413                djConfig="parseOnLoad: true, isDebug: true"></script> 
    15         <script type="text/javascript" src="_testCommon.js"></script> 
     14        <script type="text/javascript" src="../_testCommon.js"></script> 
    1615 
    1716        <script language="JavaScript" type="text/javascript"> 
  • dijit/trunk/Tree.js

    r12399 r12481  
    215215                // On initial tree show, put focus on either the root node of the tree, 
    216216                // 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) 
    218217                if(!this.parent){ 
    219218                        var fc = this.tree.showRoot ? this : this.getChildren()[0], 
     
    270269        store: null, 
    271270 
    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        // 
    282284        // example: 
    283285        //              {type:'continent'} 
     
    337339 
    338340                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 by 
    358                         // whether or not the user has specified a label 
    359                         this.showRoot = Boolean(this.label); 
    360                 } 
    361341 
    362342                if(!this.store.getFeatures()['dojo.data.api.Identity']){ 
     
    397377 
    398378                // 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({ 
    406408                                        item: item, 
    407                                         tree: _this, 
     409                                        tree: this, 
    408410                                        isExpandable: true, 
    409                                         label: _this.label || _this.getLabel(item) 
     411                                        label: this.label || this.getLabel(item) 
    410412                                }); 
    411                                 if(!_this.showRoot){ 
     413                                if(!this.showRoot){ 
    412414                                        rn.rowNode.style.display="none"; 
    413415                                } 
    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; 
    416418 
    417419                                rn._updateLayout();             // sets "dijitTreeIsRoot" CSS classname 
    418420 
    419421                                // load top level children 
    420                                 _this._expandNode(rn); 
    421                         } 
     422                                this._expandNode(rn); 
     423                        }) 
    422424                }); 
    423425 
  • dijit/trunk/_tree/ForestStoreDecorator.js

    r12417 r12481  
    2626        // rootId: String 
    2727        //      ID of root item 
    28         rootId: "", 
     28        rootId: "$root$", 
    2929 
    3030        // rootLabel: String 
    3131        //      Label of root item 
    32         rootLabel: "", 
     32        rootLabel: "ROOT", 
    3333 
    3434        // childrenAttr: String 
     
    5757                        id: params.rootId, 
    5858                        label: params.rootLabel, 
    59                         children: [] 
     59                        children: params.rootChildren || [] 
    6060                }; 
    6161 
     
    234234 
    235235        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                } 
    237248        }, 
    238249