PDA

View Full Version : [SOLVED] Need help with extended component events/listeners



Andrew Peacock
16 Jun 2010, 1:22 AM
Hi,
Sorry if this is a duplicate post - I posted it a few minutes ago, but can't see it in the forum, so I'm not sure whether I did something wrong, or whether it's gone into a moderator queue.

I'm extendeding the menu class as follows, which is part of a process which passes the record from a GridPanel to the grid's context Menu, which will then (hopefully) pass it into the action that the menu triggers. I've got the code passing the record from the GridPanel to the menu, but the menu will only seem to run the default behaviour for the listener. The problem is that I want each instance of the menu to be able to run custom code when the grid is right-clicked, and I can't get the specific instance to run.



MyApp.AccountGridContextMenu = Ext.extend(Ext.menu.Menu, {
parentGrid: null,
contextRecord: null,

initComponent:function() {
var config = {
parentGrid: null // Holds the reference to the grid which the menu works with
}; // eo config object


// Pass the menu to the parent grid
if (this.parentGrid != null) {
this.parentGrid.contextMenu = this;
}

// Add events and listeners
//this.addEvents('contextRecordSet');


// apply config
Ext.apply(this, Ext.apply(this.initialConfig, config));

MyApp.AccountGridContextMenu.superclass.initComponent.apply(this, arguments);
}, // eo function initComponent


setContextRecord: function(contextRecord) {
this.contextRecord = contextRecord;
//this.test(contextRecord);
alert("DEFAULT BEHAVIOUR: Menu has got context record: " + contextRecord.id);
// this.fireEvent('contextRecordSet', contextRecord); // ***** I DON'T THINK THIS IS NECESSARY?
}
});
Ext.reg('accountGridContextMenu', MyApp.AccountGridContextMenu);

The menu is instantiated as follows:



var menuAccountGridContext = new MyApp.AccountGridContextMenu({
items: [
{id: 'pluginActivate', text: 'Activate'},
{id: 'pluginUninstall', text: 'Uninstall'},
{id: 'pluginUpgrade', text: 'Upgrade'},
{id: 'pluginDectivate', text: 'Deactivate'}
],
parentGrid: gridPlugins, // THIS ASSIGNS THE MENU TO A SPECIFIC GRID. THE GRID IS EXTENDED TO SUPPORT THIS, AND THAT FUNCTIONALITY IS WORKING OK

listeners: {
contextRecordSet: function(contextRecord){
alert("CUSTOM BEHAVIOUR: " + contextRecord.plugin_status);
}
}
});


The 'setContextRecord' function is called when the grid is right-clicked, on the 'rowcontextmenu' event.

The connection between the grid and menu is working fine: the menus is assigned to the grid on creation; the default listener function runs fine, and does display the record ID.

But I just can't get the specific instance of the menu to run it's own local routine.

Any advice/tips/hints/alternative solutions/slaps round the head would be GREATLY appreciated, as I spent most of last night trying to get this working!

Thanks in advance,
Andy

Andrew Peacock
16 Jun 2010, 4:53 AM
Somehow, I'd copied and pasted the section



var menuAccountGridContext = new PromotionBot.AccountGridContextMenu({
items: {%$accountGridContextMenuItems%},
...
});


So I had two definitions of the same object, and obviously one of them (without the custom behaviour) redefined the one with the custom behaviour.

Sorry!

Andy