Topic: Cookie Storage and refreshChildren method ...

How can I integrate both "Cookie Storage" and refreshChildren method ?

        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;

            },

   

As it seems that Cookie Storage has a bug with multiple loaded on demand nodes ... this is might be it doesn't works ?

Re: Cookie Storage and refreshChildren method ...

Nows the Cookie.Storage works as expected ! Was a problem with my IDs.
Still need a way to integrate it with refreshChildren ...

I've add  a

this.tree.storage.restore(); 

but doesn't do nothing.

Could you take a look ?

Re: Cookie Storage and refreshChildren method ...

since rev83 you can do something like:

storage.restore(storage.read());
//or storage.restore(some_stored_nodes)

Re: Cookie Storage and refreshChildren method ...

This is what I've done and doesn't works properly sad
I mean that If you open various sub nodes of a node and do a refresh all the sub nodes stay closed...

   

    refreshChildren: function() {

            var opened = this.isOpen();
            
            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);
            
            
            if (opened) {
                this.toggle();
                storage.restore( storage.read() );
            
            }
            
        
            return this;

               },    

Last edited by scramatte (2009-04-12 15:00:16)

Re: Cookie Storage and refreshChildren method ...

you should restore states after loading nodes. Something like:

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);
    if(!this.restored_on_load){
        this.addEvent('load', function(){
            this.restored_on_load=true;
            this.tree.storage.restore(this.tree.storage.read());
        }.bind(this))
    }
    
    return this;
}       

Re: Cookie Storage and refreshChildren method ...

Nop ! Doesn't works ...
Nodes states are not restored properly

Re: Cookie Storage and refreshChildren method ...

works for me

Re: Cookie Storage and refreshChildren method ...

I've just send you a demo to your gmail.
Take a look

Thank you

Re: Cookie Storage and refreshChildren method ...

1. add back your code

opened=this.isOpen ...if (opened) { this.toggle(); }

2. try remove ids from reloaded nodes.

Re: Cookie Storage and refreshChildren method ...

and use loadChildren event:

refreshChildren: function() {
    ...
    this.tree.$getIndex();
    this.getDOM('children').innerHTML='';
    Mif.Tree.Draw.update(this);

    var data=this.tree.storage.read();
    this.tree.addEvent('loadChildren', function(){
            this.tree.storage.restore(data);
    }.bind(this))

    ...    

Re: Cookie Storage and refreshChildren method ...

cookie storage still doesn't works properly with on demand json and refresh children ...

refreshChildren: function() {

            var opened = this.isOpen();
            
            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);

            var data=this.tree.storage.read();

            this.tree.addEvent('loadChildren', function(){
                this.tree.storage.restore(data);
            }.bind(this));

            if (opened) {
                this.toggle();
            }
        
            return this;

               },    

You tell me in on of your post to remove ID's ... How can I do this ?
Note that all of my nodes have unique IDs.  I generate and md5  from  LDAP DN (equivalent DB primary key).

The bug is not easy to reproduce ...
For example if  I open various sub nodes on the same level  and I refresh the parent ... only 1 ore 2 subnodes are partially restored ...

Re: Cookie Storage and refreshChildren method ...

cookie storage work.

refreshChildren: function() {

            var opened = this.isOpen();
            
            this.state.loaded=false;
            this.state.open=false;
            this.state.loadable=true;
            this.children=[];
            this.$draw=false;
            ...
            var node=this;
            this.recursive(function(){
                 if(this!=node){
                        var id=this.id;
                        delete Mif.ids[id];
                 }
            })
        
            return this;

}
 

Re: Cookie Storage and refreshChildren method ...

I've just send you an email to your gmail a testcase ... take a look and you will see that cookie storage + refresh children at the same time doesn't do the job properly.

Re: Cookie Storage and refreshChildren method ...

this work

reloadChildren: function() {
        var opened = this.isOpen();

        var node=this;
        this.recursive(function(){
            if(this!=node){
                var id=this.id;
                delete Mif.ids[id];
            }
        });
        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);

        data=this.tree.storage.read();
        
        this.tree.addEvent('loadChildren', function(){
            this.tree.storage.restore(data);
        }.bind(this));
    
        

        if (opened) {
            this.toggle();
        }
        return this;

    } 

Re: Cookie Storage and refreshChildren method ...

thank you Moro.
seems that works now !  what was the problem ?
your code is quite same as mine ...

Re: Cookie Storage and refreshChildren method ...

in your demo missed

 this.tree.addEvent('loadChildren', function(){
            this.tree.storage.restore(data);
        }.bind(this));

and delete ids, after this.children=[], so nothing was removed.