JavaScript.CoolDev.Com Support Forums

Any questions related to JavaScript menu and JavaScript tree menu by Javascript.CoolDev.Com

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Restore state from cookie on recreate?

 
Post new topic   Reply to topic    JavaScript.CoolDev.Com Forum Index -> COOLjsTree
Author Message
richsonn



Joined: 13 Aug 2007
Posts: 5

PostPosted: Mon Aug 13, 2007 10:13 pm    Post subject: Restore state from cookie on recreate? Reply with quote

Hi Anton,

I hope you're having a good summer. I have followed your advice from a previous post and am using the .recreate method to redraw the tree after setting up a new array:

Quote:
var NEW_TREE_NODES = [...];
tree.getRoot().recreate(NEW_TREE_NODES);


My tree is also using your cookies feature to keep track of the state. When the tree is redrawn, it is redrawn fully collapsed, instead of loading the cookie and reseting the state to the cookie code.

How can I get the tree to redraw in a cookie-savvy way following the recreate?

Thanks in advance,

Rich
Back to top
AlexKunin
Developer


Joined: 03 Jan 2003
Posts: 1191

PostPosted: Tue Aug 14, 2007 3:48 am    Post subject: Reply with quote

1. Add ID to every node:
Code:
[{id:123}, 'Caption', 'file.html', null],


2. Then turn alternative cookie mode on (make sure you're using one of the recent versions):
Code:
var tree = new COOLjsTreePRO('tree', TREE_FORMAT, TREE_NODES, true, true);
Back to top
richsonn



Joined: 13 Aug 2007
Posts: 5

PostPosted: Tue Aug 14, 2007 4:22 am    Post subject: Reply with quote

Alex,

Thank you for the quick reply. We already have taken the steps you mention. The cookie state is restored no problem when we first initialize the tree using the 'var = new ...' syntax:

var tree5_project = new COOLjsTreePRO("tree5_project", TREE_NODES, TREE_FORMAT);
tree5_project.init();
RedrawAllTrees();

The problem occurs when we try to use .recreate after updating the nodes. The nodes we introduce are collapsed, but they should be expanded, according to the cookie on the client.

Thanks,

Rich
Back to top
AlexKunin
Developer


Joined: 03 Jan 2003
Posts: 1191

PostPosted: Tue Aug 14, 2007 4:38 am    Post subject: Reply with quote

Oh, I see.

Then there is no way to restore state. And I think it's correct because you're restoring state of newly created tree - it has no state, it's brand new.

But you can add {format:{expanded:true}} to nodes while generating NEW_TREE_NODES structure.
Back to top
richsonn



Joined: 13 Aug 2007
Posts: 5

PostPosted: Tue Aug 14, 2007 5:14 am    Post subject: Reply with quote

Alex,

Ok, so I understand that .recreate will not trigger the internal cookie restore method.

Our original intent was to take an updated tree array structure and apply it to the tree. Previously we've been reloading the entire frame but this is slow and one of the other frames can send the updated tree array structure to the tree frame more quickly than forcing a reload of the tree frame (which requires a round-trip to the server with all the overhead that entails).

We'd like the cookie to still apply, as it does on a full reload of the page. Can we somehow delete the entire tree and start over with a 'var xxx= new COOLjsTreePRO()...init...redraw()' sequence? If that makes sense, what would we delete from the DOM and the javascript stack to accomplish that?

Thanks for hanging with us on this issue!

Rich
Back to top
AlexKunin
Developer


Joined: 03 Jan 2003
Posts: 1191

PostPosted: Tue Aug 14, 2007 5:29 am    Post subject: Reply with quote

Latest yet unreleased version has static create() method which triggers state restoration procedure:
Code:
var tree = COOLjsTreePRO.create('tree', TREE_NODES, TREE_FORMAT, optionalParentDivElementOrId);

Let me know (javascript@cooldev.com) if you'd like to play with this new version.
Back to top
richsonn



Joined: 13 Aug 2007
Posts: 5

PostPosted: Mon Feb 04, 2008 11:11 pm    Post subject: Has this been released yet? Reply with quote

Please let us know if this is still under active development, as we're keen to implement the static create() method. Thanks!
Back to top
AlexKunin
Developer


Joined: 03 Jan 2003
Posts: 1191

PostPosted: Wed Mar 05, 2008 9:42 am    Post subject: Reply with quote

We're going to release version 3.0 soon, it was rewritten from scratch, has many new features and quite extensible architecture. Watch for announces.
Back to top
richsonn



Joined: 13 Aug 2007
Posts: 5

PostPosted: Fri Apr 18, 2008 12:25 am    Post subject: Great news! Reply with quote

Thanks, Alex. I'm glad to hear a new version will be out soon! Very Happy


-Rich
Back to top
Display posts from previous:   
Post new topic   Reply to topic    JavaScript.CoolDev.Com Forum Index -> COOLjsTree All times are GMT
Page 1 of 1