Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / docs / js / ClassTree.js
1 /**
2  * Class tree.
3  */
4 Ext.define('Docs.ClassTree', {
5     extend: 'Ext.tree.Panel',
6
7     id: 'treePanelCmp',
8     cls: 'iScroll',
9     renderTo: 'treePanel',
10     folderSort: true,
11     useArrows: true,
12     rootVisible: false,
13
14     height: Ext.core.Element.getViewportHeight() - 170,
15     border: false,
16     bodyBorder: false,
17     padding: '0 0 0 20',
18
19     listeners: {
20         itemclick: function(view, node) {
21             var clsName = node.raw ? node.raw.clsName : node.data.clsName;
22
23             if (clsName) {
24                 Docs.ClassLoader.load(clsName);
25             } else if (!node.isLeaf()) {
26                 if (node.isExpanded()) {
27                     node.collapse(false);
28                 } else {
29                     node.expand(false);
30                 }
31             }
32         }
33     },
34
35     initComponent: function() {
36         // Expand the main tree
37         this.root.expanded = true;
38         this.root.children[0].expanded = true;
39         // Add links for favoriting classes
40         this.addFavIcons(this.root);
41
42         this.callParent();
43     },
44
45     addFavIcons: function(node) {
46         if (node.isClass) {
47             node.text += '<a rel="'+node.id+'" class="fav"></a>';
48         }
49         if (node.children) {
50             Ext.Array.forEach(node.children, this.addFavIcons, this);
51         }
52     },
53
54     /**
55      * Selects class node in tree by name.
56      *
57      * @param {String} className
58      */
59     selectClass: function(className) {
60         var classNode = this.getRootNode().findChildBy(function(n) {
61             return className === n.raw.clsName;
62         }, null, true);
63
64         if (classNode) {
65             this.getSelectionModel().select(classNode);
66             classNode.bubble(function(n) {
67                 n.expand();
68             });
69         }
70     }
71 });