PDA

View Full Version : Dynamic Menu



SKapoor
5 Feb 2007, 6:14 AM
Hello,

I have two items in my menu - one is disabled and the other isnot. My form contains two links, one to show the menu and one to enable the second item. Unfortunaly when I try to enable the item, it doesnt really enable it. Here is my simple code:


CreateMenu("test", true);

function removeItemsFromMenu()
{
var ctrl = document.getElementById("s1");
var id = ctrl.id;
var p_oMenu = new YAHOO.widget.ContextMenu("Menu_" + id, { trigger: ctrl } );

var aGroups = p_oMenu.getItemGroups();
var i = aGroups.length - 1;
var aItems;
var item;

do
{
item = p_oMenu.getItem(i);
p_oMenu.removeItem(n, i);
}
while(i--);
}


function CreateMenu(username, bIsDisabled)
{
var ctrl = document.getElementById("s1");
var id = ctrl.id;
var oContextMenu = new YAHOO.widget.ContextMenu("Menu_" + id, { trigger: ctrl } );

if (bIsDisabled)
{
oContextMenu.addItem("Add User");
alert(oContextMenu.getItem(0));
}
else
oContextMenu.addItem("Edit User");

oContextMenu.addItem("Delete User");
alert(oContextMenu.getItemGroups()[0].length);

oContextMenu.getItem(0).clickEvent.subscribe(onAddEditUser, username);
oContextMenu.getItem(1).clickEvent.subscribe(onDeleteUser, username);

oContextMenu.getItem(1).cfg.setProperty("disabled", bIsDisabled);
oContextMenu.render(document.body);

function onAddEditUser(p_sType, p_aArguments, p_oValue)
{
alert("add");
}

function onDeleteUser(p_sType, p_aArguments, p_oValue)
{

var user = p_oValue.split(";")[0];
alert(user);
}
}

Here the two lines from my body tag:


<body>
test ('#')

Show New Menu ('#')
</body>
Can someone please help me? I want to enable the second item when the "Show New Menu" link is clicked.

Thank you,

Animal
5 Feb 2007, 6:18 AM
This is a YUI question, not Ext.

Jack, are you prepared to host another folder on this site:

"YAHOO UI" :?: :roll:

SKapoor
5 Feb 2007, 6:23 AM
Uups, I thought we can ask YUI questions here as well. Sorry about that. I tried the Yahoo YUI usergroups, but have to say that it's really bad. You dont get any response from there at all. I still hope though that someone will be able to help me.



This is a YUI question, not Ext.

Jack, are you prepared to host another folder on this site:

"YAHOO UI" :?: :roll:

Animal
5 Feb 2007, 6:54 AM
In fact, this is just a general programming question. You should try easier stuff first.