schmidetzki
02-23-2007, 01:19 PM
The problem:
You have several menus in your application (f. e. a main menu plus a context menu) and need to enable or disable menu items depending on the sate of your application.
If you have a menu item "edit" in the main menu AND the context menu, you habe to disable both.
I implemented this using a observer attribut in all menu items and implemented a central observer modul handling all menu states:
BI={}; // name space
BI.menu={};
BI.menu.main = new Ext.menu.Menu({
{ text: "edit ...",
observer: "edit-page",
}
});
BI.menu.context = new Ext.menu.Menu({
{ text: "edit ...",
observer: "edit-page",
}
})
And implemented a function, to enable/disable ALL menu items with the same observer in one step:
BI.enablemenus=function(observer, enable){
for(m in BI.menu){
var items=BI.menu[m].items;
items.each(function(item){
if(item.observer && item.observer==observer)
enable ? item.enable() : item.disable()
})
}
}
When i finde a situation in my application where edit is not allowed I simply call
BI.enablemenus("edit-page", false)
... and all edit-menu-items in all menus will be disabled.
You have several menus in your application (f. e. a main menu plus a context menu) and need to enable or disable menu items depending on the sate of your application.
If you have a menu item "edit" in the main menu AND the context menu, you habe to disable both.
I implemented this using a observer attribut in all menu items and implemented a central observer modul handling all menu states:
BI={}; // name space
BI.menu={};
BI.menu.main = new Ext.menu.Menu({
{ text: "edit ...",
observer: "edit-page",
}
});
BI.menu.context = new Ext.menu.Menu({
{ text: "edit ...",
observer: "edit-page",
}
})
And implemented a function, to enable/disable ALL menu items with the same observer in one step:
BI.enablemenus=function(observer, enable){
for(m in BI.menu){
var items=BI.menu[m].items;
items.each(function(item){
if(item.observer && item.observer==observer)
enable ? item.enable() : item.disable()
})
}
}
When i finde a situation in my application where edit is not allowed I simply call
BI.enablemenus("edit-page", false)
... and all edit-menu-items in all menus will be disabled.