Opened 13 years ago
Closed 13 years ago
#4833 closed defect (wontfix)
No way to programmatically identify a menuItem
Reported by: | guest | Owned by: | |
---|---|---|---|
Priority: | high | Milestone: | 1.1 |
Component: | Dijit | Version: | 0.9 |
Keywords: | menu | Cc: | [email protected]… |
Blocked By: | Blocking: |
Description
In one of my widget's template I create a context menu as follows:
<ul dojoType="dijit.Menu" dojoAttachPoint="contextMenu" style="display: none;">
<li dojoType="dijit.MenuItem?" iconClass="new"
onClick="onCreate">Create</li>
<li dojoType="dijit.MenuItem?" iconClass="mailFoldersActionRename"
onClick="onRename">Rename</li>
</ul>
I want to be able to enable/disable a menuItem at popup depending on which node the popup menu was triggered on. I could use the menuItem's label to identify the menu item but this is not a clean solution.
Here is the patch I propose:
Index: Menu.js =================================================================== --- Menu.js (revision 11056) +++ Menu.js (working copy) @@ -344,6 +344,9 @@
if false, the menu item is enabled disabled: false,
+ action identifier for this menu item + action: "", +
postCreate: function(){
dojo.setSelectable(this.domNode, false); this.setDisabled(this.disabled);
<<<<<<<<<<<<<<<<<<<
This way when defining the menu in my widget's template I can give an action identifier as follows:
<ul dojoType="dijit.Menu" dojoAttachPoint="contextMenu" style="display: none;">
<li dojoType="dijit.MenuItem?" iconClass="new"
action="CREATE" onClick="onCreate">Create</li>
<li dojoType="dijit.MenuItem?" iconClass="mailFoldersActionRename"
action="RENAME" onClick="onRename">Rename</li>
</ul>
Attachments (1)
Change History (6)
Changed 13 years ago by
Attachment: | 4833.patch added |
---|
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
I have a dijit.Tree to which the Menu is bound. In the store that feeds the Tree, each item has an member array disabledActions containing the actions that don't apply to that specific item. When the context menu is shown, it it then very easy to disable the MenuItem? corresponding to the disabled action for the item on which the context menu was triggered.
Does it make a little more sense?
comment:3 Changed 13 years ago by
Here is the code to handle what I was just talking about:
enable menu items depending on the selected node menu.getChildren().forEach(
function(menuItem){
menuItem.setDisabled((dojo.indexOf(disabledActions, menuItem.action) != -1));
}
);
comment:4 Changed 13 years ago by
Milestone: | → 1.1 |
---|
I see. This reminds me of how TreeNodes? etc. have an item (a dojo.data item) which can have any attributes you want.
Note that you can add an attribute to a widget on your own, without modifying dojo, just by doing
dijit.MenuItem.prototype.action="";
in your own js file.
Also note that to make this more general you might want to make the action an object, rather than a string, by adding this to MenuItem?.js:
action: null,
and then in your HTML file do
<div dojoType=dijit.MenuItem action="{foo: 1, bar: 'zaz'}">
Anyway, marking for consideration in 1.1
comment:5 Changed 13 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I don't understand how simply adding an attribute to MenuItem? will let you enable/disable a menuItem at popup depending on which node the popup menu was triggered on. How do you know which node the popup menu was triggered on? And how do you control the enabling/disabling?