PDA

View Full Version : ContextMenu on Ext.menu.Menu



aLe
27 Apr 2009, 6:18 AM
Hi all,
I just finished to activate a ContextMenu on existing Menu for a customer.
I had some difficult to get the underlying menu.item text.
I don't know if it's the best way but it works.



// Extended Ext.menu.Menu
var saveFilterMenu = new GenericMenu({
id: "saveFilterMenu",
url:"menus/filtri.jsp",
//remoteReload: true,
clickHandler: function (menuItem){
alert(" my ID: " + menuItem.id);
}
});
// ContextualMenu on Menu
var menuContextMenu = new Ext.menu.Menu({
id:'filterContextMenu',
items: [{
text: 'Delete ...',
handler: function(item){
var text = item.parentMenu.parentMenu.activeItem.id; // get the underlying item text
alert("my ID is: " + text );
}
}]
});
//TODO incapsulate into GenericMenu
saveFilterMenu.on("show", function(e){
// Menu already rendered
if (this.menuCreated){
// Loop on menu
this.items.each(function(item){
try{
// Handle subMenu
if (typeof( item.menu) !== "undefined" ){
// Loop on all subMenu
var collection = item.menu.items;
for(var i=0;i<collection.getCount();i++){
var myItem = collection.get(i);
// Set contextmenu event on subMenu item
Ext.getCmp(myItem.id).getEl().on('contextmenu', function(e) {
var xy = e.getXY();
e.stopEvent();
menuContextMenu.showAt(xy, item.menu);
});
}
}
}catch(e){
alert("MainView.js exception: " + e);
}
});
}
});