by slothy » Wed Sep 06, 2006 11:23 pm
Hi DirtyHarry
(see bottom for better solution)
i know this may sound silly, but have you thought about just calling the same function that was called on the onload relevant to the drawing of the tree?
Just delete descendants of the top treeNode and redraw the tree with a fresh call.
This would be wasteful but I cant imagine having to call it many times per page visit....would be a bit consuming of course if you had very large trees...
Alex
NB. An afterthought: It may be a good idea to have a database table, say treestates, that contains pertinent info of trees: treeName(this could be Primary Index but could have extra treeID field if you fussy) and lastupdated fields .
So if you have 5 trees say in the database each will have a correspnding row in treestates.
So everytime you update a tree (as you have called the functions to update, add or delete nodes) you simultaneously update the lastupdated field of corresponding tree entry in treestates with the current timestamp.
Now when user comes back to page it polls the treestates table (very simple AJAX call) . And if the lastupdated field is greater than a lasttested [that contains a timestamp that it last invoked the call) , say, variable THEN you KNOW it has changed and go through the call of the function to reload.....
This is less stressful on the server..only one simple call
Someting like "SELECT IF (lastupdated > {$_GET['lastchecked']},1,0) FROM treestates WHERE tree.id = {$_GET['treeid']} "
if it returns 1 you have to redraw else there is no change