I've created my own custom tree and I want to add a custom action to it. The action works, but only on the root node. All the other nodes don't display the action. Can someone tell me whap I'm doing wrong? Here is the code (I don't use the codeblock because it really makes a mess of the code):
public class LoadFinanceTree : BaseTree { public LoadFinanceTree(string application) : base(application) { }
Thank you Dirk, but I already tried that and it still doesn't work. When I debug and look into the Menu the action actually is there! I just can't click on any of the nodes besides the rootnode. Do I need to do something to make it clickable with the right mouse?
It does work for me, just checked my code. Also wanted override the default actions on the root node, and had to explicitly call .Clear() on the Menu object and add my own actions (and so for other non root nodes), so I'm sure that should work. I've done debugging as well, and have indeed noticed that action was in the list, but got removed once the tree was completely loaded (as said, never got to the bottom of it..)
Ah some extra info, I was after changing the default list of actions for the root node, and it didn't work as you'd expect it to, just by adding an extra action.. I ended up doing the following:
And that works (bit of a hack, altho RootNodeActions is publicly exposed, so I guess it was safe to do so). Doing the same for other nodes (on a lower level - and that seems to work as well, ie clearing the list and adding your own)
Custom umbraco tree actions
Hello,
I've created my own custom tree and I want to add a custom action to it. The action works, but only on the root node. All the other nodes don't display the action. Can someone tell me whap I'm doing wrong? Here is the code (I don't use the codeblock because it really makes a mess of the code):
public class LoadFinanceTree : BaseTree
{
public LoadFinanceTree(string application) : base(application) { }
protected override void CreateRootNodeActions(ref List<IAction> actions)
{
actions.Add(CreateQuoteAction.Instance);
}
protected override void CreateAllowedActions(ref List<IAction> actions)
{
actions.Add(CreateQuoteAction.Instance);
}
protected override void CreateRootNode(ref XmlTreeNode rootNode)
{
rootNode.Icon = FolderIcon;
rootNode.OpenIcon = FolderIconOpen;
rootNode.NodeType = TreeAlias;
rootNode.Text = "Financiƫn";
}
/// <summary>
/// Renders the Javascript.
/// </summary>
/// <param name="javascript">The javascript.</param>
public override void RenderJS(ref StringBuilder javascript)
{
//Opens Orders page.
javascript.Append(
@"
function openOrders() {
parent.right.document.location.href = '/umbraco/sections/finance/Orders.aspx';
}
");
//Opens Budgets page.
javascript.Append(
@"
function openBudgets() {
parent.right.document.location.href = '/umbraco/sections/finance/Budgets.aspx';
}
");
//Opens the edit all page.
javascript.Append(
@"
function openTenders() {
parent.right.document.location.href = '/umbraco/sections/finance/Tenders.aspx';
}
");
}
public override void Render(ref XmlTree tree)
{
XmlTreeNode xNode;
xNode = XmlTreeNode.Create(this);
xNode.Text = "Bestellingen";
xNode.Action = "javascript:openOrders();";
xNode.Icon = "folder.gif";
xNode.OpenIcon = "folder_o.gif";
tree.Add(xNode);
xNode = XmlTreeNode.Create(this);
xNode.Text = "Begrotingen";
xNode.Action = "javascript:openBudgets();";
xNode.Icon = "folder.gif";
xNode.OpenIcon = "folder_o.gif";
tree.Add(xNode);
xNode = XmlTreeNode.Create(this);
xNode.Text = "Offertes";
xNode.Action = "javascript:openTenders();";
xNode.Icon = "folder.gif";
xNode.OpenIcon = "folder_o.gif";
tree.Add(xNode);
}
}
Jeroen,
I have noticed the same (altho didn't go after the issue nor logged it on Codeplex...), ended up using this snippet on each xNode you create:
Hope this helps.
Regards,
/Dirk
Thank you Dirk, but I already tried that and it still doesn't work. When I debug and look into the Menu the action actually is there! I just can't click on any of the nodes besides the rootnode. Do I need to do something to make it clickable with the right mouse?
I fixed the problem! What I forgot to do in my example above is to give each node an id. So after adding the id it works!
It does work for me, just checked my code. Also wanted override the default actions on the root node, and had to explicitly call .Clear() on the Menu object and add my own actions (and so for other non root nodes), so I'm sure that should work. I've done debugging as well, and have indeed noticed that action was in the list, but got removed once the tree was completely loaded (as said, never got to the bottom of it..)
Cheers,
/Dirk
Ah some extra info, I was after changing the default list of actions for the root node, and it didn't work as you'd expect it to, just by adding an extra action.. I ended up doing the following:
And that works (bit of a hack, altho RootNodeActions is publicly exposed, so I guess it was safe to do so). Doing the same for other nodes (on a lower level - and that seems to work as well, ie clearing the list and adding your own)
is working on a reply...