Copied to clipboard

Flag this post as spam?

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


  • Anthony Barsotti 26 posts 66 karma points
    Feb 11, 2014 @ 23:25
    Anthony Barsotti
    0

    Clicking on Section Icon Changes Name of Tree Nodes

    I'm creating a new section and I'm currently working on implementing the Tree for this section. On page load, everything looks fine but if I navigate to another section and then come back to this new section, every node of the tree in this section now has a name combining all five nodes' names into one name. If I navigate to another section again it appends all five names again and again to the point that I might have a string consisting of all five node names repeated five or six times. My trees.cs code is:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Web;

    using umbraco.businesslogic;

    using umbraco.cms.presentation.Trees;

     

        [Tree("howard", "howardTree", "Howard")]

        public class HowardTree : BaseTree

        {

            public HowardTree(string application) : base(application)

            { }

     

            protected override void CreateRootNode(ref XmlTreeNode rootNode)

            {

                rootNode.Icon = FolderIcon;

                rootNode.OpenIcon = FolderIconOpen;

                rootNode.NodeType = "init" + TreeAlias;

                rootNode.NodeID = "init";

            }

     

            public override void Render(ref XmlTree tree)

            {

                var contacts = XmlTreeNode.Create(this);

                contacts.Text = "Contacts";

                contacts.Icon = "docPic.gif";

                contacts.Action = "javascript:openContacts()";

                // Add the node to the tree

                tree.Add(contacts);

     

                var gifts = XmlTreeNode.Create(this);

                gifts.Text = "Gifts";

                gifts.Icon = "docPic.gif";

                gifts.Action = "javascript:openGifts()";

                // Add the node to the tree

                tree.Add(gifts);

     

                var sales = XmlTreeNode.Create(this);

                sales.Text = "Sales";

                sales.Icon = "docPic.gif";

                sales.Action = "javascript:openSales()";

                // Add the node to the tree

                tree.Add(sales);

     

                var campaigns = XmlTreeNode.Create(this);

                campaigns.Text = "Campaigns";

                campaigns.Icon = "docPic.gif";

                campaigns.Action = "javascript:openCampaigns()";

                // Add the node to the tree

                tree.Add(campaigns);

     

                var reports = XmlTreeNode.Create(this);

                reports.Text = "Reports";

                reports.Icon = "docPic.gif";

                reports.Action = "javascript:openReports()";

                // Add the node to the tree

                tree.Add(reports);

            }

     

            public override void RenderJS(ref StringBuilder Javascript)

            {

                Javascript.Append(@"

                function openContacts() {

                parent.right.document.location.href = 'howard/contacts.aspx';

                }

                ");

     

                Javascript.Append(@"

                function openGifts() {

                parent.right.document.location.href = 'howard/gifts.aspx';

                }

                ");

     

                Javascript.Append(@"

                function openSales() {

                parent.right.document.location.href = 'howard/sales.aspx';

                }

                ");

     

                Javascript.Append(@"

                function openCampaigns() {

                parent.right.document.location.href = 'howard/campaigns.aspx';

                }

                ");

     

                Javascript.Append(@"

                function openReports() {

                parent.right.document.location.href = 'howard/reports.aspx';

                }

                ");

            }

        }

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Feb 15, 2014 @ 00:35
    Bjarne Fyrstenborg
    100

    Hi Anthony

    I remember I had a similar issue once .. and from what I can see on my previously code examples you need to add a unique NodeID  ... also you might add  .Menu.Clear(); which I think was not to get the full context menu, but I am not sure..

    So try change you code to this:

    protected override void CreateRootNode(ref XmlTreeNode rootNode)
    {
        rootNode.Icon = FolderIcon;
        rootNode.OpenIcon = FolderIconOpen;
        rootNode.NodeType = "init" + TreeAlias;
        rootNode.NodeID = "init";
    
        // reset rootnode menu actions
        rootNode.Menu.Clear();
    }

    and this for each tree node ... notice the second line with NodeID :

    var contacts = XmlTreeNode.Create(this);
    contacts.NodeID = "uniqueContacts";
    contacts.Text = "Contacts";
    contacts.Icon = "docPic.gif";
    contacts.Action = "javascript:openContacts()";
    contacts.Menu.Clear();
    
    // Add the node to the tree
    tree.Add(contacts);

    and the same for gifts, sales, campaigns and report nodes..

    /Bjarne

  • Anthony Barsotti 26 posts 66 karma points
    Feb 15, 2014 @ 01:01
    Anthony Barsotti
    0

    This fixed it thanks so much this was driving me nuts.

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Feb 15, 2014 @ 01:03
    Bjarne Fyrstenborg
    0

    I'm glad I could help :)

    /Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft