garyrgi
21 May 2007, 7:01 AM
Hello all,
I was wondering if someone a tad more familiar with the tree panel and how to interact with it could nudge me in the right direction.
I have a tree panel that is lazy loaded via a remote call, I also have a context menu that is loaded via a remote call as well, it could be static as this point but I was testing...here is the menu, its basically returned every time at the moment:
{menu: [
new Ext.menu.Item({
text: 'Add'
}),
new Ext.menu.Item({
text: 'Edit'
})
,
new Ext.menu.Item({
text: 'Delete',
handler:function(e){Ext.Msg.confirm('Confirm','Are you sure you want to do that?',delItem);}
})
]
}
As you can see i have a function that I want to call when a user clicks on the delete menu option. Here is the code for my tree
<script language="javascript">
Ext.menu.Menu.prototype.load = function( options ){
var loader = new Ext.menu.Item({text: 'Loading...'});
var conn = new Ext.data.Connection();
this.addItem(loader);
conn.on('requestcomplete', function( conn, response ){
this.remove(loader);
response = Ext.decode(response.responseText);
Ext.each( response.menu, function( item ){ this.add( item ) }, this);
}, this);
conn.on('requestexception', function(){
this.remove(loader);
this.add({text: 'Failed to load menu items'});
}, this);
conn.request( options );
}
</script>
<script language="javascript">
var TreeTest = function(){
var Tree = Ext.tree;
return {
init : function(){
var loader = new Tree.TreeLoader({dataUrl:'menu.cfc?method=gettree'});
loader.on('beforeload', function(loader, node){
loader.dataUrl = 'menu.cfc?method=gettree&id='+node.attributes.id;
});
var tree = new Tree.TreePanel('treeView', {
animate:false,
loader: loader,
enableDD:true,
containerScroll: true
});
// set the root node
var root = new Tree.AsyncTreeNode({
text: 'Kategorie',
draggable:false,
id:'0'
});
tree.setRootNode(root);
// render the tree
tree.render();
//enable a context menu
tree.on('contextmenu', this.menuShow, this);
// false for not recursive (the default), false to disable animation
root.expand();
},
menuShow: function( node ){
var ctmenu=new Ext.menu.Menu();
//context menu calls the context menu generator
ctmenu.load({url:'menu.cfc?method=getContextMenu&hasChildren='+!node.isLeaf()});
ctmenu.show(node.ui.getAnchor());
}
};
}();
function delItem (i){
//var r = Tree.getRootNode();
alert("hello");
}
function contextMenu(v){
var ctmenu=new Ext.menu.Menu();
//context menu calls the context menu generator
ctmenu.load({url:'menu.cfc?method=getContextMenu&hasChildren='+!v.isLeaf()});
ctmenu.show(v.ui.getAnchor());
};
Ext.onReady(TreeTest.init, TreeTest, true);
</script>
The problem is I can't seem to reference my tree from my delete function. Ideally when the user clicks the delete option in the context menu I want to delete the selected node.
I have tried to reference it a number of different ways but I can't seem to get to it.
Any pointers or help would be appreciated.
Thanks in advance,
Gary
I was wondering if someone a tad more familiar with the tree panel and how to interact with it could nudge me in the right direction.
I have a tree panel that is lazy loaded via a remote call, I also have a context menu that is loaded via a remote call as well, it could be static as this point but I was testing...here is the menu, its basically returned every time at the moment:
{menu: [
new Ext.menu.Item({
text: 'Add'
}),
new Ext.menu.Item({
text: 'Edit'
})
,
new Ext.menu.Item({
text: 'Delete',
handler:function(e){Ext.Msg.confirm('Confirm','Are you sure you want to do that?',delItem);}
})
]
}
As you can see i have a function that I want to call when a user clicks on the delete menu option. Here is the code for my tree
<script language="javascript">
Ext.menu.Menu.prototype.load = function( options ){
var loader = new Ext.menu.Item({text: 'Loading...'});
var conn = new Ext.data.Connection();
this.addItem(loader);
conn.on('requestcomplete', function( conn, response ){
this.remove(loader);
response = Ext.decode(response.responseText);
Ext.each( response.menu, function( item ){ this.add( item ) }, this);
}, this);
conn.on('requestexception', function(){
this.remove(loader);
this.add({text: 'Failed to load menu items'});
}, this);
conn.request( options );
}
</script>
<script language="javascript">
var TreeTest = function(){
var Tree = Ext.tree;
return {
init : function(){
var loader = new Tree.TreeLoader({dataUrl:'menu.cfc?method=gettree'});
loader.on('beforeload', function(loader, node){
loader.dataUrl = 'menu.cfc?method=gettree&id='+node.attributes.id;
});
var tree = new Tree.TreePanel('treeView', {
animate:false,
loader: loader,
enableDD:true,
containerScroll: true
});
// set the root node
var root = new Tree.AsyncTreeNode({
text: 'Kategorie',
draggable:false,
id:'0'
});
tree.setRootNode(root);
// render the tree
tree.render();
//enable a context menu
tree.on('contextmenu', this.menuShow, this);
// false for not recursive (the default), false to disable animation
root.expand();
},
menuShow: function( node ){
var ctmenu=new Ext.menu.Menu();
//context menu calls the context menu generator
ctmenu.load({url:'menu.cfc?method=getContextMenu&hasChildren='+!node.isLeaf()});
ctmenu.show(node.ui.getAnchor());
}
};
}();
function delItem (i){
//var r = Tree.getRootNode();
alert("hello");
}
function contextMenu(v){
var ctmenu=new Ext.menu.Menu();
//context menu calls the context menu generator
ctmenu.load({url:'menu.cfc?method=getContextMenu&hasChildren='+!v.isLeaf()});
ctmenu.show(v.ui.getAnchor());
};
Ext.onReady(TreeTest.init, TreeTest, true);
</script>
The problem is I can't seem to reference my tree from my delete function. Ideally when the user clicks the delete option in the context menu I want to delete the selected node.
I have tried to reference it a number of different ways but I can't seem to get to it.
Any pointers or help would be appreciated.
Thanks in advance,
Gary