Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 01, 2010 @ 14:09
    Jeroen Breuer
    0

    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);
            }
        }

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 01, 2010 @ 14:30
    Dirk De Grave
    1

    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:

    xNode.Menu.Clear();
    xNode.Menu.AddRange(new List<IAction>() { CreateQuoteAction.Instance });

     

    Hope this helps.

    Regards,

    /Dirk

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 01, 2010 @ 14:35
    Jeroen Breuer
    0

    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?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 01, 2010 @ 15:08
    Jeroen Breuer
    0

    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!

    xNode.NodeID =

    this.id++.ToString();

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 01, 2010 @ 15:09
    Dirk De Grave
    0

    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

     

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 01, 2010 @ 15:21
    Dirk De Grave
    1

    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:

     

    protected override void CreateRootNode(ref XmlTreeNode rootNode) {
      rootNode.Icon = FolderIcon;
      rootNode.OpenIcon = FolderIconOpen;
      rootNode.NodeType = "NodeType";
      rootNode.NodeID = "-1";
      RootNodeActions.Clear();
      RootNodeActions.AddRange(new List<IAction>() { ActionRefresh.Instance });
    }

     

    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)

     

Please Sign in or register to post replies

Write your reply to:

Draft