4 Ext.define('Docs.view.tree.Tree', {
5 extend: 'Ext.tree.Panel',
6 alias : 'widget.classtree',
8 'Docs.view.HoverMenuButton',
13 cls: 'class-tree iScroll',
21 initComponent: function() {
25 * Fired when class in tree was clicked on and needs to be loaded.
26 * @param {String} cls name of the class.
31 // Expand the main tree
32 this.root.expanded = true;
33 this.root.children[0].expanded = true;
35 this.on("itemclick", this.onItemClick, this);
45 xtype: 'hovermenubutton',
46 cls: 'icon-fav sidebar',
50 emptyText: 'No favorites',
51 showCloseButtons: true
53 store: Ext.getStore('Favorites'),
55 closeclick: function(cls) {
56 Docs.Favorites.remove(cls);
61 xtype: 'hovermenubutton',
62 cls: 'icon-hist sidebar',
66 emptyText: 'No history',
67 showCloseButtons: true
69 store: Ext.getStore('History'),
71 closeclick: function(cls) {
72 Docs.History.removeClass(cls);
82 // Add links for favoriting classes
84 // We should be able to just listen the "render" event of tee,
85 // but for some reason the tree nodes aren't quite ready when
86 // "render" fires (setting text on node will cause an
87 // exception because the actual dom node seems to be missing,
88 // although setting text on the currently hidden nodes will
89 // work). I found a workaround by listening the "refresh"
90 // event which seems to first fire when all tree nodes are
91 // ready. Most ceartanly a big hack.
93 // Additionally all this is done after callParent, because the
94 // getRootNode() will work after initComponent has run.
95 // Probably not neccessary, because "refresh" should happen
96 // after that anyway, but just to play it safe.
97 Docs.Favorites.setTree(this);
98 Ext.getStore("Favorites").on("load", function() {
99 this.getView().on("refresh", function(){
100 this.getRootNode().cascadeBy(this.addFavIcons, this);
101 }, this, {single: true});
105 addFavIcons: function(node) {
106 if (node.get("leaf")) {
107 var cls = node.raw.clsName;
108 var show = Docs.Favorites.has(cls) ? "show" : "";
109 node.set("text", node.get("text") + Ext.String.format('<a rel="{0}" class="fav {1}"></a>', cls, show));
114 onItemClick: function(view, node, item, index, e) {
115 var clsName = node.raw ? node.raw.clsName : node.data.clsName;
118 if (e.getTarget(".fav")) {
119 var favEl = Ext.get(e.getTarget(".fav"));
120 if (favEl.hasCls('show')) {
121 Docs.Favorites.remove(clsName);
124 Docs.Favorites.add(clsName);
128 this.fireEvent("classclick", clsName);
131 else if (!node.isLeaf()) {
132 if (node.isExpanded()) {
133 node.collapse(false);
142 * Selects class node in tree by name.
144 * @param {String} cls
146 selectClass: function(cls) {
147 var r = this.findRecordByClassName(cls);
149 this.getSelectionModel().select(r);
150 r.bubble(function(n) {
157 * Sets favorite status of class on or off.
159 * @param {String} cls name of the class
160 * @param {Boolean} enable true to mark class as favorite.
162 setFavorite: function(cls, enable) {
163 var r = this.findRecordByClassName(cls);
165 var show = enable ? "show" : "";
166 r.set("text", r.get("text").replace(/class="fav *(show)?"/, 'class="fav '+show+'"'));
171 findRecordByClassName: function(cls) {
172 return this.getRootNode().findChildBy(function(n) {
173 return cls === n.raw.clsName;