public/javascripts/Rwiki/TreePanel.js in rwiki-0.2.4 vs public/javascripts/Rwiki/TreePanel.js in rwiki-0.2.5

- old
+ new

@@ -1,83 +1,74 @@ Ext.ns('Rwiki'); Rwiki.TreePanel = Ext.extend(Ext.tree.TreePanel, { - constructor: function() { - var toolbar = new Rwiki.TreePanel.Toolbar(); + constructor: function() { Ext.apply(this, { id: 'tree', + title: 'Navigation panel', region: 'center', + height: 400, + minSize: 150, autoScroll: true, animate: true, useArrows: true, rootVisible: true, - loader: new Rwiki.TreePanel.Loader(), + loader: new Rwiki.Tree.Loader(), enableDD: true, dropConfig: { appendOnly: true }, - root: new Rwiki.TreePanel.Node({ + root: new Rwiki.Tree.Node({ nodeType: 'async', text: Rwiki.rootFolderName, draggable: false, - baseName: '.' - }), - - tbar: toolbar + children: Rwiki.nodes + }) }); Rwiki.TreePanel.superclass.constructor.apply(this, arguments); - this.contextMenu = new Rwiki.TreePanel.Menu(); - this.on('contextmenu', this.onContextMenu, this); - - this.filter = new Rwiki.TreePanel.Filter(this); - this.root.expand(); - + this.loader.load(this.root); new Ext.tree.TreeSorter(this, { - folderSort: true + folderSort: false }); - var self = this; + this.contextMenu = new Rwiki.Tree.Menu(); + this.on('contextmenu', this.onContextMenu, this); - toolbar.on('expandAll', function() { - self.root.expandChildNodes(true); - }); + this.addEvents('rwiki:pageSelected'); - toolbar.on('collapseAll', function() { - self.root.collapseChildNodes(true); - }); + this.on('nodedragover', function(e) { + var newParent = e.target; + var node = e.dropNode; - toolbar.on('filterFieldChanged', function(text) { - self.filter.filterTree(text); + // do not allow to move a node to the same parent + return node.parentNode != newParent; }); - - this.addEvents('rwiki:pageSelected'); }, initEvents: function() { Rwiki.TreePanel.superclass.initEvents.apply(this, arguments); this.on('click', this.onClick); this.on('rwiki:pageLoaded', this.onPageLoaded); - this.on('rwiki:folderCreated', this.onFolderCreated); this.on('rwiki:pageCreated', this.onPageCreated); - this.on('rwiki:nodeRenamed', this.onNodeRenamed); - this.on('rwiki:nodeDeleted', this.onNodeDeleted); + this.on('rwiki:pageRenamed', this.onPageRenamed); + this.on('rwiki:pageDeleted', this.onPageDeleted); this.on('beforemovenode', this.onBeforeMoveNode); - this.relayEvents(Rwiki.NodeManager.getInstance(), [ + this.relayEvents(Rwiki.Data.PageManager.getInstance(), [ 'rwiki:pageLoaded', - 'rwiki:folderCreated', 'rwiki:pageCreated', - 'rwiki:nodeRenamed', - 'rwiki:nodeDeleted']); + 'rwiki:pageRenamed', + 'rwiki:pageDeleted' + ]); }, onContextMenu: function(node, e) { if (!this.contextMenu) return; @@ -87,90 +78,63 @@ this.contextMenu.show(node, e.getXY()); }, onClick: function(node) { - if (!node.isLeaf()) return; - var page = new Rwiki.Node({ path: node.getPath() }); - this.fireEvent('rwiki:pageSelected', page); + Rwiki.openPage(node.getPath()); }, onPageLoaded: function(page) { var node = this.findNodeByPath(page.getPath()); if (node) { + node.expandAllParents(); node.select(); } }, - onFolderCreated: function(data) { - var node = new Rwiki.TreePanel.Node({ - baseName: data.baseName, - text: data.baseName, - cls: 'folder', - expandable: true, - leaf: false - }); - - var parentNode = this.findNodeByPath(data.parentPath); - parentNode.expand(); - parentNode.appendChild(node); - }, - onPageCreated: function(page) { - var treeNode = new Rwiki.TreePanel.Node({ + var treeNode = new Rwiki.Tree.Node({ baseName: page.getBaseName(), text: page.getTitle(), - cls: 'page', expandable: false, leaf: true }); var parentNode = this.findNodeByPath(page.getParentPath()); parentNode.expand(); parentNode.appendChild(treeNode); treeNode.select(); }, - onNodeRenamed: function(page) { + onPageRenamed: function(page) { var treeNode = this.findNodeByPath(page.getData().oldPath); - treeNode.setBaseName(page.getBaseName()); treeNode.setText(page.getTitle()); }, - onNodeDeleted: function(data) { - var path = data.path; - var node = this.findNodeByPath(path); + onPageDeleted: function(page) { + var node = this.findNodeByPath(page.getPath()); node.remove(); }, onBeforeMoveNode: function(tree, node, oldParent, newParent, index) { var path = node.getPath(); var newParentPath = newParent.getPath(); - var result = Rwiki.NodeManager.getInstance().moveNode(path, newParentPath); + var result = Rwiki.Data.PageManager.getInstance().moveNode(path, newParentPath); return result.success; }, findNodeByPath: function(path) { var node = null; - this.root.cascadeAll(function(curretNode) { - if (curretNode.getPath() == path) { - node = curretNode; + this.root.cascadeAll(function(currentNode) { + if (currentNode.getPath() == path) { + node = currentNode; return false; + } else { + return true; } }); return node; - }, - - openNodeFromLocationHash: function() { - if (!location.hash) return; - - var path = location.hash.replace(new RegExp('^#'), ''); - var node = this.findNodeByPath(path); - if (node) { - node.expandAll(); - this.onClick(node); - } } });