Board Logo

tree menu pro states
asterix - 5/22/2005 at 06:22 PM

Sorry for my english, I am Italian.
I do not know well javascript.
Is there anybody that can say to me exactly what I have step by syep to do to use the reset_state not to have persistant treeview on reloaded page? It is almost an emergency!!!

Thank you in advance,
Tiziano


rock - 5/23/2005 at 04:45 PM

Edit your tree_tpl.js:

Code:

var tree_tpl = {
...
'beforeInit':'killTreeStates',
'afterInit':'opentoDepth'
// make sure there is no comma after the last key-value pair
};

function killTreeStates(o_tree){
o_tree.o_root.reset_state(); //reset open/close/selected states of the tree
return true;
}

function opentoDepth(o_item){
if(o_item.a_children && o_item.n_depth<0)
//n_depth<0 - open roots; n_depth<1 - open roots and first level nodes, etc.
for(var i=0; i<o_item.a_children.length; i++){
o_item.a_children[ i].open() // open item
opentoDepth(o_item.a_children[ i]) //recursive call
}
}


asterix - 5/24/2005 at 12:07 AM

I appreciate your answer, but there are still problems:
1) I had to eliminate the 'opentoDepth' function becouse it produced a javascript error of 'methos or property non found on the object...' (or something like that)

2) the real big problem is this: I create dinamically a tree menu depending on a choise of the user. I create correctly the tree_items.js but when the user try to switch to another tree dinamically (clicking on a link) it works fine in memory but I must refresh manually the left frame where the treemenu works if I want to see the correct treeview menu.

I hope that you give to me a solution for both points. It is very important for me.

I thank you anyway,
Tiziano


rock - 5/24/2005 at 09:14 AM

1. Please copy&paste opentoDepth function again - due to BBCode reserved tag in previous post some code was missed.
2. You could use several names for your trees so different states will be saved for them. To set tree name use third argument in tree constructor call:

Code:

<script language="JavaScript">
<!-- //
new tree (TREE_ITEMS, TREE_TPL,'MyTree');
// -->
</script>


asterix - 5/24/2005 at 02:54 PM

About your 1) point:
1. Please copy&paste opentoDepth function again - due to BBCode reserved tag in previous post some code was missed.

what do I have to do exactly? copy&paste the previous code or what?

Thank you very much again,
Tiziano


asterix - 5/24/2005 at 02:57 PM

...new tree (TREE_ITEMS, TREE_TPL,'MyTree');

where can I find the 'MyTree' treeview name? Is it the file name? or is it a variable name? I did not touch anything from your original code (except for the items...)

thank again,
Tiziano


rock - 5/24/2005 at 04:08 PM

'MyTree' is value of the tree name and you don't need to seek it or smth
Each named tree will have separate open/closed states. As I said third argument is tree instance name, and you could use any numeric or string value for it ('MyTree', '1232423', 332123, 'myTree1111', etc.). If you created tree with name 'mytree1', and then reload the page but create tree with different name (say 'mytree2') - the states (open/selected) will not be shared, i.e. second time tree will be opened with default view. If you then again reload the page with 'mytree1' named tree - states preserved for the name will be restored.


rock - 5/24/2005 at 04:14 PM

Anyway if you need assistance our specialists are ready to customize/setup the control for your needs for low hourly rates. Please refer to our Customer Care System


asterix - 5/24/2005 at 04:23 PM

fixed then opentoDepth function, now the nodes work ok when the afterinit event in called.
But the big problem still remain:
I have 3 frames, header, menu (on the left side) and work (on the rigth side). I show several links on the work area and when a user click on one of them I create dinamically the treeview. It works fine in memory and it really create the items.js file. the problem is that when somebody click on the link the menu frame on the left side doesnt refresh itself. If I refresh manually I can see the new created treeview.
I hope to be clear.

Thank you in advance again,
Tiziano


rock - 5/25/2005 at 10:31 AM

So the problem is in menu frame not in tree control? What code should fire menu frame refreshing?


asterix - 6/3/2005 at 04:47 PM

Layout with 3 frames, 1 row on top, 2 cols.
I show on the right frame the names of saome directories and when the user click on one of them I create dinamically with php the tree_items.js using the name of the user in this way
<code>
<script type='text/javascript' src='js/<?php print $_SESSION['username'].".js'"; ?>></script>
</code>
It works fine. I find a different file depending of the choise of the user. I create a new user.js every time the user click on one link of the right frame.
The problem is this: when the user click on the right frame over another link representing the name of a directory the new user_tree.js file is really created, I reload the main page with the 3 frames, but the left frame doesn't refresh itself with the new treeview. If I want see the new treeview I must right click over the left frame with the mouse and choise refresh.
The left frame is this:
<code>
<?php
include("init.php");
include("lib/utility.php");
?>

<html>
<head>

<script type='text/javascript' src='js/<?php print $_SESSION['username'].".js'"; ?>></script>
<script type='text/javascript' src='js/tree_tpl.js'></script>
<script type='text/javascript' src='js/tree.js'></script>
</head>

<body bgcolor="#efebde">
<script language="JavaScript">
<!-- //
new tree (TREE_ITEMS, TREE_TPL, 'MyTree');

// -->
</script>
</body>
</html>

</code>

I think that I could do something when the 'afterinit' event is called, but it already call the opentoDepth function that you gave to me.

Sorry for my English, I hope to be clear and I thank you a lot for your answer,
Tiziano


asterix - 6/3/2005 at 04:49 PM

Sorry, I did not use well the BBCode system...


rock - 6/6/2005 at 10:01 AM

I think you should check the point where you refresh the main frame, make sure your menu frame is refreshed with recreated user_tree.js. Don't think the control could cause such refresh problems.


asterix - 6/6/2005 at 02:35 PM

You were rigth...
The problem was a wrong refresh of the menu frame.

Thank you much for all


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/