View Full Version : Tree: Turning a leaf into a folder?

13 Jan 2007, 12:28 PM
I'm loving the tree control so far. Really impressive work, and out of the box dataUrl stuff - awesome.

Now, I'm using the tree to manage a tree-oriented CMS and I would like to allow leafs to be turned into folders by drag/dropping a page on the leaf. Is this possible with the current setup?

15 Jan 2007, 7:43 AM
node.leaf = false;

9 Feb 2007, 4:02 AM
Setting leaf to false in an AsyncTreeNode means that every Node has initially a PLUS-Icon to open even if the Folder has no children.

1. Set the attribute loaded in the JsonString to true if the current Folder has no children.
2 . Change the Code:

YAHOO.ext.tree.AsyncTreeNode = function(config) {
this.loaded=config.loaded===true; // THIS IS THE CHANGED ROW
this.loading = false;
YAHOO.ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
this.events['beforeload'] = true;
this.events['load'] = true;

18 Feb 2007, 5:59 PM
Still trying to get this right. Reloads are going great, but magically converting a leaf to a folder still isn't going too well.

function reloadContentTreeItem(id) {
var myTree = treeRoot.getOwnerTree();
var itemRoot = myTree.getNodeById(id);

if (itemRoot.leaf)
itemRoot.leaf = false;

itemRoot.loaded = false;

the reload works awesomely when i'm adding a new item to something that's already a folder, but when i try to reload a leaf that just got children added to it, i'm still stuck with a leaf. there's a slight blink like it's trying to load children, but nothing happens and apparently no ajax calls are being made (according to firebug).

any ideas?

19 Feb 2007, 3:06 AM
In the latest beta 1 coming out later today there's a reload() function on AsyncTreeNode. It looks like this:

* Trigger a reload for this node
* @param {Function} callback
reload : function(callback){
this.childrenRendered = false;
this.loaded = false;
this.expand(false, false, callback);

Calling renderChildren() directly is not a good idea as it is a private function and in general is unsafe without some checks.

19 Feb 2007, 6:27 AM
Awesome, I'll try that out. I was only using renderChildren() because it was mentioned in another tree related discussion thread... I was running out of ideas. I'm hoping that lifting your reload function until I have a chance to get Beta 1 into place in my project is going to fix things.

Thanks Jack - you do do amazing work.

19 Feb 2007, 2:34 PM
ok, close.

i modified my original code to use

itemRoot.childrenRendered = false;

this does change the leaf into a folder, and it looks expanded... but the children arent showing until i hit the '-' and then '+' the folder again. ...ideas?

19 Feb 2007, 2:47 PM
one more question. sorry, i can't find if this has been addressed elsewhere.

will it be possible to have leafs turn into folders by dragging something onto it? im not sure if there's any built in functionality, or if this will have to be a customization...

19 Feb 2007, 6:48 PM
ok, one more observation. the freaky situation that i'm getting only shows up when i have a folder, that becomes a leaf by deleting the child, then gets another child added to it.

if it starts out as a leaf, and then gains a child, the reload doesnt seem to do anything.