PDA

View Full Version : TreePanel, different Listener per Node?



Symbi0nt
16 Apr 2007, 11:58 PM
Hi there,

I would like to Build a tree with Nodes which shall lead to different subpages load by Ajax. For example:



- Mueller, Peter
- Clients
- Firm A
- Firm B
- Notes
- Note A
- Note B
- Lidelle, Chuck
- Clients
- Client C


etc.

I' loading the Tree at once. Is there a way to tell a leaf right in the json Array/hash the name of the handler?

If that is not the case I have to do it serverside or clientside, be creatin the tree by hand and attaching the right handler in a switch construct or so.

Animal
17 Apr 2007, 1:22 AM
Add a single click handler to the TreePanel and process the Node appropriately:

http://extjs.com/deploy/ext/docs/output/Ext.tree.TreePanel.html#event-click

Symbi0nt
17 Apr 2007, 2:13 AM
That was my second idea to process it on the serverside.

With a Framework like (to name one) CakePHP where you have controllers for each model, it would be better to call the correct controller right from the node.

for my example it would be


index.php?/users/show/1
index.php?/clients/show/50
index.php?/notes/show/33


well I'm already using a double call to process the stuff, so I think I have to life with that result. Just for someone who already has no mod_rewrite on his server and is using CakePHP.

My Treecode:


var UserTree = function(){
// shorthand
var tree;

return {
init : function(){
tree = new Ext.tree.TreePanel('treeUsers', {
animate: false,
loader: new Ext.tree.TreeLoader({
dataUrl: 'http://www.domain.de/app/webroot/_.php',
baseParams: { c: 'users', a: 'tree' } // <-- important, so _.php
}),
enableDD: false,
containerScroll: true,
dropConfig: { appendOnly: true }
});

var root = new Ext.tree.AsyncTreeNode({
text: "Users",
draggable: false
});

tree.setRootNode(root);
tree.on("click", onClickHandler, this);

tree.render();
root.expand(false, false);
},
};

function onClickHandler(e, obj, options) {
alert("You clicked User=" + e.id);
}
}();


The _.php


<?php
print_r($_POST);

define('D_PATH', 'http://www.domain.de/index.php');

if (!isset($_POST['c']) || !isset($_POST['a'])) {
header("Location: ".D_PATH);
exit();
}

$url = "/{$_POST['c']}/{$_POST['a']}/";

unset($_POST['c'], $_POST['a']);

$tmpQuery = array();
foreach ($_POST as $key => $elem) {
$tmpQuery[] = "{$key},{$elem}";
}

$url .= implode(';', $tmpQuery);

// Here codes the redirect (which is the ugly part)
header("Location: http://www.domain.de/index.php?{$url}");
exit();
?>


(This example fit not 100% my initial problem, but I fixed that almost the same)