PDA

View Full Version : Context menu on pre-configured class



TheDude55
17 Jan 2011, 6:26 AM
Hi all, I've got a TreePanel with a context menu to delete nodes.
I've got it working, but can't get it to work in a pre-configured class:
The 'Delete' menu pops up, but clicking on it gives me this error:

this.getSelectionModel is not a function

Anybody got any ideas ?




Ext.ns("VBS.treepanel");

VBS.treepanel.SiteCodesTree = Ext.extend(Ext.tree.TreePanel, {

title: 'Site Codes',
dataUrl: 'Services/SiteCodes.ashx',
root: 'Codes',
collapsible: true,
flex: 1,

initComponent: function() {

VBS.treepanel.SiteCodesTree.superclass.initComponent.call(this);

this.getRootNode().expand();

this.on('contextmenu', treeContextHandler);

var contextMenu = new Ext.menu.Menu({
items: [
{ text: 'Delete', handler: deleteHandler }
]
});


function treeContextHandler(node) {
node.select();
contextMenu.show(node.ui.getAnchor());
}

function deleteHandler() {
this.getSelectionModel().getSelectedNode().remove();
}

}

});

Ext.reg('SiteCodesTree', VBS.treepanel.SiteCodesTree);




Currently , I've got it working like this:


// shorthand
var Tree = Ext.tree;

var tree = new Tree.TreePanel({
region: 'west',
title: 'Hello',
margins: '0 5 0 0',
height: '100%',
flex:1,
useArrows: true,
autoScroll: true,
animate: true,
enableDD: false,
containerScroll: true,
dataUrl: 'Services/SiteCodes.ashx',

listeners: {

remove: function(tree, parent, node) {
alert('removing from server ' + node.text);
},
click: function(node) {
//alert(node.id); alert(node.attributes.myID); alert(node.isLeaf());
settings_form.getForm().load({
url: 'Services/Test.ashx',
params: '{id : "' + node.id + '"}'

});

}


},

root: {
text: 'Site'
}
});

tree.getRootNode().expand();


tree.on('contextmenu', treeContextHandler);

var contextMenu = new Ext.menu.Menu({
items: [
{ text: 'Delete', handler: deleteHandler }
]
});


function treeContextHandler(node) {
node.select();
contextMenu.show(node.ui.getAnchor());
}

function deleteHandler() {
tree.getSelectionModel().getSelectedNode().remove();
alert('removing from client');
}

Condor
17 Jan 2011, 6:43 AM
{
text: 'Delete',
handler: deleteHandler,
scope: this
}

TheDude55
17 Jan 2011, 7:00 AM
Excellent - that's fixed it! Makes sense. Thank you so much.