Topic: Reload JSON branch on demand ?

Hello,

I use Mif Tree with Zend Framework / Php5 and Ldap directory.

When I initialize the tree, I feel it with just one level of my Ldap directory.
Clicking on each node  tree loads children nodes on demand

All of this works perfeclty.

The problem is  that I append thing to the Ldap directory  and I need a way to refresh/reload
a particular node with all  his inherited children.

How can I achieve this ?


tree = new Mif.Tree({
                    container: $('mytree'),
                    grid: true,
                    sortable: false,
                    height: 18,
                    forest: true,
                    checkbox: true,
                    initialize: function(){
                    },

                    types: {
                        dhcpGroup:{
                            openIcon: 'mif-tree-open-icon',
                            closeIcon: 'mif-tree-close-icon',
                            middleIcon: 'mif-tree-middle-icon'
                        },
                       
                        dhcpHost: {
                            openIcon: 'mif-tree-open-icon',
                            closeIcon: 'mif-tree-close-icon',
                            middleIcon: 'mif-tree-middle-icon'
                        },
                        loader:{
                            openIcon: 'mif-tree-loader-open-icon',
                            closeIcon: 'mif-tree-loader-close-icon',
                            DDnotAllowed: ['inside','after']
                        },

                    },
                    dfltType:'folder'
                });

               
                tree.load({
                        url: '/catv/customer/treejson'
                });


                tree.loadOptions=function(node){
               
                    if(!node) return;
                    if(node.name=='empty'){
                        return {
                            url: '/share/empty.json'
                        }
                    }
                    return {
                        url: '/catv/customer/treejson/dn/'+node.data.dn+'?search='+ $('keywords').value
                    }
                   
                };


Regards

Re: Reload JSON branch on demand ?

try set node state loaded to false and node children  to empty array, update node and load again:

    node.state.loaded=false;
    node.children=[];
    Tree.Draw.update(node);

i'm think it's will work. If there is some problems i'm create small example.

Re: Reload JSON branch on demand ?

I've try to extend Node Object but it doesn't works for me ?
How can I do this ?
           
----
            Mif.Tree.Node.implement({
                refreshChildren: function() {
                  this.state.loaded=false;
                      this.children=[];
                         Mif.Tree.Draw.update(this);
                     }               
           
            });

Re: Reload JSON branch on demand ?

    Mif.Tree.Node.implement({
        refreshChildren: function() {
            this.state.loaded=false;
            this.state.open=false;
            this.state.loadable=true;
            this.children=[];
            this.$draw=false;
            this.tree.$getIndex();
            this.getDOM('children').innerHTML='';
            Mif.Tree.Draw.update(this);
            return this;
        }       

    });

demo, demo zip archive

i'm use trunk version and found bug in Mif.Tree.Node::toggle when load event addes many times if u reload node children, fix:

if(this.loadable && !this.state.loaded) {
            if(!this.load_event){
                this.load_event=true;
                this.addEvent('load',function(){
                    this.toggle();
                }.bind(this));
            }
            this.load();
            return;
        }

Re: Reload JSON branch on demand ?

better fix:

if(this.loadable && !this.state.loaded) {
            var load=function(){
                this.toggle();
                this.removeEvent('load', load);
            }.bind(this);
            this.addEvent('load',load);
            this.load();
            return;
        }

Re: Reload JSON branch on demand ?

I've put your patch in my Mif.Tree.Node file ...
When I refresh an opened node  it collapse it and refresh ... It should keep the current state and refresh !