Topic: toggle Nodes

Hello,

I don't know why when I use this function :

.addEvent('onLoad', function(){
        this.root.recursive(function(){
            this.toggle(null, false);
        });
    })

I've got this return by firebug :

node is null    -> Mif.Tree.Node.js (ligne 36)
[Break on this error] var wrapper=node.getFirst();

An idea ?


----------------------
My entire function :

function makeTree(_id){
    
    id = _id ? "&id=" + _id : "";
    
    tree = new Mif.Tree({
        container: $('tree_container'),
        forest: true,
        
        initialize: function(){
            new Mif.Tree.Drag(this, {
                onDrag: function(){
                    //
                },
                onStart: function(){
                    //
                },
                onComplete: function(){
                    alert(tree.getNodeOrders());
                }
            });
        },
        
        types: {
            folder:{
                openIcon: 'mif-tree-open-icon',
                closeIcon: 'mif-tree-close-icon',
                loadable: true
            },
            folderFinal:{
                openIcon: 'mif-tree-open-icon',
                closeIcon: 'mif-tree-close-icon',
                loadable: false
            },
            file:{
                openIcon: 'mif-tree-file-open-icon',
                closeIcon: 'mif-tree-file-close-icon'
            },
            loader:{
                openIcon: 'mif-tree-loader-open-icon',
                closeIcon: 'mif-tree-loader-close-icon',
                DDnotAllowed: ['inside','after']
            }
        },
        dfltType:'folder'
    })
    
    .load({
        url: 'modules/geographie3/lieux.ajax.php?ajax=treeRoot' + id
    })
    
    .addEvent('onLoad', function(){
        this.root.recursive(function(){
            this.toggle(null, false);
        });
    })
    
    .addEvent('select',function(node){
        lienAjax('modules/geographie3/lieux.ajax.php?categorie=' + node.data.id);
    })
    
    .loadOptions=function(node){
        if(node.data != undefined){
            return {
                url        : 'modules/geographie3/lieux.ajax.php?ajax=treeChild',
                method    : 'post',
                data    : {'id': node.data.id}
            };
        }
    };
    
    $('tree_btn_rename').addEvent('click', function(){
        var node=tree.selected;
        if(!node) return;
        node.rename();
    });
}

Last edited by alphanono (2008-08-14 17:19:49)

Re: toggle Nodes

because u use forest=true, root node not exist

Re: toggle Nodes

use

this.toggle();// or this.toggle(true)

instead

 this.toggle(null, false);

it's demo mistake

If u want expand tree with forest=true try:

.addEvent('onLoad', function(){
        this.root.recursive(function(){
            if(this.isRoot()) return;
            this.toggle();
        });
    })

Re: toggle Nodes

ok, thanks for your answer !!

But I've got an other problem now ...

With your method, when tree is toggled, all subnodes are loaded with ajax. That I want is to toggle all the nodes already loaded ! Is it possible ?

Re: toggle Nodes

And an other question (thanks!), is it possible to force the selection of one element once the tree is reloaded ?

For exemple, after having toggled all the elements, I whant to place the selector on the element with node.data.id = 123

Re: toggle Nodes

alphanono wrote:

That I want is to toggle all the nodes already loaded ! Is it possible ?

mb add isLoaded check? :-)

 this.root.recursive(function(){
            if(this.isRoot()) return;
            if(this.isLoaded()) this.toggle();
        });
alphanono wrote:

is it possible to force the selection of one element once the tree is reloaded ?

u want just select some node?

yourTree.select(someNode)

Re: toggle Nodes

Thanks Moro ! You're right ! if(this.isLoaded()) seem to be good.

But I don't know how to find a node with his data. In my exemple, the nodes have data like : node.data.id

If I have the id that I want to select, how can I find the ref of the node to give in param at

yourTree.select(param)

?

Re: toggle Nodes

alphanono wrote:

how can I find the ref of the node?

u can use same recursive function:

var someNode;
this.root.recursive(function(){
            if(this.isRoot()) return;
            if(this.data.id=='123') {
                   someNode=this;
                   return false;
            }
        });

Re: toggle Nodes

YES ! That's work fine ! Thanks for your help !

I begin to anderstand better your work ...

But can I go too far with an other question ?? wink

I have make this plugin :

Mif.Tree.implement({
    getNodesOrder: function(){
        var node=this.forest ? this.root.getFirst() : this.root;
        var saveString = '';
        saveString += node.data.id + "-0,";
        node=node.getNextVisible();
        do{
            saveString += node.data.id + "-" + node.getParent().data.id + ",";
        }while(node=node.getNextVisible());
        return saveString;
    }
});

And I try to use it like this :

initialize: function(){
    new Mif.Tree.Drag(this, {
        onComplete: function(){
            alert(tree.getNodesOrder());
        }
    });
}

The plugin is well loaded but firebug say :
tree.getNodesOrder is not a function
[Break on this error] alert(this.getNodesOrder());

That work fine with the old version of MifTree but not with the SVN version.

Re: toggle Nodes

don't know where problem, mb u have test page?

Re: toggle Nodes

I send your an accound by email form.

Have you received it ?

Re: toggle Nodes

alphanono wrote:

Have you received it ?

no, send to magmoro@mail.ru or creavenmoro@gmail.com

P.S. i'm fix e-mail form. It should send mail now.

Re: toggle Nodes

That was post yesterday by mail. Have you received it ?

Re: toggle Nodes

yes, i'm received.

problem is varible tree not a Mif.Tree instance, but function.

replace

tree = new Mif.Tree({
        ...
    })
    
    .load({

     ...

    })

    .loadOptions=function(node){
        if(node.data != undefined){
            return {
                url        : 'modules/geographie3/lieux.ajax.php?ajax=treeChild',
                method    : 'post',
                data    : {'id': node.data.id}
            };
        }
    };//<---- function

with

tree = new Mif.Tree({
        ...
    })
    
    .load({

     ...

    });

    tree.loadOptions=function(node){
        if(node.data != undefined){
            return {
                url        : 'modules/geographie3/lieux.ajax.php?ajax=treeChild',
                method    : 'post',
                data    : {'id': node.data.id}
            };
        }
    };

Re: toggle Nodes

ah yes !! Thanks all is ok now !

(The alert of new post on this forum by mail is now ok too ...)

One last question (for the moment !;) Where are you from ?! wink

Thanks for all

Re: toggle Nodes

alphanono wrote:

Where are you from ?! wink

Russia