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 4x admin c-trib
    Jul 21, 2009 @ 12:17
    Jeroen Breuer
    0

    Add child nodes to custom Umbraco section

    Hello,

    I created my own custom Umbraco section. In this section are some nodes, but now I would like to add childnodes to these nodes. Currently I have the following source code:

    public

     

    override void RenderJS(ref StringBuilder javascript)

    {

    javascript.Append(

     

    @"

    function openEmailOverzicht(type, naam, emailSoort) {

    parent.right.document.location.href = '/umbraco/sections/EmailOverzicht.aspx?type=' + type + '&naam=' + naam + '&EmailSoort=' + emailSoort;

    }

    "

     

    );

    }

     

    public override void Render(ref XmlTree tree)

    {

     

    XmlTreeNode xNode;

     

    TribalEmailTreeParentCollection tribalEmailTreeParentCollection = TribalEmailTreeParentController.GetEmailTreeParentItems();

     

    int nodeId = 0;

     

    foreach (TribalEmailTreeParent tribalEmailTreeParent in tribalEmailTreeParentCollection)

    {

     

    //Loop door alle TribalEmailTree items heen en maak voor elke rij een node aan.

    xNode =

    XmlTreeNode.Create(this);

    xNode.NodeID = nodeId.ToString();

    xNode.Text = tribalEmailTreeParent.Naam;

    xNode.Action =

    string.Format("javascript:openEmailOverzicht('{0}','{1}','{2}');", tribalEmailTree.EmailTreeId, tribalEmailTree.Naam, tribalEmailTree.Soort);

    xNode.Icon =

    "folder.gif";

    xNode.OpenIcon =

    "folder_o.gif";

    tree.Add(xNode);

     

    //Verhoog de nodeId met 1 voor de volgende node.

    nodeId++;

    }

    }

     

     

    Now I would like to add childnodes to one of the XmlTreeNode objects. How can I do this? A screenshot of my custom section can be found at: http://img32.imageshack.us/img32/5607/section.jpg.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 21, 2009 @ 12:30
    Jeroen Breuer
    0

    Wow the code doens't look good. We really need an edit button and adding images would also be nice. Here is an example about how I would like to have my custom tree. I would like it to be the same as the pacakge node in the developer section. Here is a screenshot: http://img199.imageshack.us/img199/5683/packagef.jpg

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jul 21, 2009 @ 15:23
    Morten Christensen
    100

    Hi Jeroen,

    You should take a look at the following WIKI page:
    http://our.umbraco.org/wiki/reference/api-cheatsheet/tree-api---to-create-custom-treesapplications

    and also, Aaron wrote an article about creating a custom tree dataprovider which I myself have used as inspiration for creating a custom tree with child nodes and everything else that you would expect from an umbraco tree.

    http://www.aaron-powell.com/blog/july-2009/creating-custom-dataproviders-for-linq-to-umbraco.aspx

    From the WIKI page here is how to create multiple child node levels (main difference from creating a single level is highlighted in bold):

    public override void Render(ref XmlTree tree)
    {
               
                Dictionary.DictionaryItem[] tmp;
            //this.id is set when the tree.aspx creates this object.
            //It is the nodeID that is passed in via the tree service parameters (i.e. the query string)
            //this checks if the id is the StartNodeID (root node), if it’s not then this will
            //look up the child nodes for the current dictionary item.
                if (this.id == this.StartNodeID)
                    tmp = Dictionary.getTopMostItems;
                else
                    tmp = new Dictionary.DictionaryItem(this.id).Children;

                foreach (Dictionary.DictionaryItem di in tmp)
                {
                 XmlTreeNode xNode = XmlTreeNode.Create(this);
                 xNode.NodeID = di.id.ToString();
                 xNode.Text = di.key;
                 xNode.Action = string.Format("javascript:openDictionaryItem({0});", di.id);
                 xNode.Icon = "settingDataType.gif";
                 xNode.OpenIcon = "settingDataType.gif";
                 //if there is no children, then set the source to an empty string
    //this will ensure that there is no expand button for this node when it is
    //rendered. Otherwise, set the source to the tree service url by using
    //the BaseTree’s GetTreeServiceUrl method
                 xNode.Source = di.hasChildren ? this.GetTreeServiceUrl(di.id) : "";
                 tree.Add(xNode);
                }
    }

     

    - Morten

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 21, 2009 @ 15:41
    Jeroen Breuer
    0

    Thank your Morten! This is just what I needed.

  • seanrock 240 posts 461 karma points
    Aug 21, 2009 @ 17:18
    seanrock
    0

    Hi

    I'm trying to do this same thing however i'm not having much luck. The wiki page doesn't exist however i did come across the code sample on another url. But then that isn't really clear. I understand that assigning 'something' to the Source property will add the dropdown arrow to the tree node however i can't seem to find where i render the child nodes. Also, i get a null reference exception when i try to call this.GetTreeServiceUrl() (with or with a parameter).

    Regards

    Sean

  • Chris Koiak 700 posts 2626 karma points
    Aug 21, 2009 @ 17:21
  • seanrock 240 posts 461 karma points
    Aug 21, 2009 @ 17:23
    seanrock
    0

    forget my last post - its been a long day! :)

    i understand how it works now.

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 16, 2009 @ 11:40
    Jeroen Breuer
    0

    I've got another question related to child nodes in a custom section. I've succeeded in adding child nodes, but now I would like the child nodes to expand immediately when the page is first loaded. Is this even possible because none of the other umbraco sections expand their childs when the page is loaded.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Oct 17, 2009 @ 04:19
    Aaron Powell
    0

    I don't know if it is possible, you'd need to inject some JavaScript into the page which automatically calls the function to expand the tree.

    It'd probably require quite a bit of hacking the core of Umbraco.

  • Sa 118 posts 152 karma points
    Oct 19, 2009 @ 09:44
    Sa
    0

    if you can tell about Dictionary.DictionaryItem[] tmp;

    what values are stored in tmp?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 20, 2009 @ 09:27
    Jeroen Breuer
    0

    Thanks for reply slace! If I need to implement some javascript to expand the trees do I really need to modify the core of Umbraco? It's about a custom section with custom pages. Can't I place the javascript inside the custom pages? Does anybody know which function I need to call to expand the trees?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 20, 2009 @ 09:43
    Jeroen Breuer
    0

    @ sas7: As you can see in the example it says foreach (Dictionary.DictionaryItem di in tmp). This means tmp probably contains an array of DictionaryItems.  

  • Sa 118 posts 152 karma points
    Oct 21, 2009 @ 09:12
    Sa
    0

    hi jeroen.,

    how to load values into DictionaryItems..

    is it default values or users can load the values?

  • jernej 7 posts 28 karma points
    Oct 21, 2009 @ 13:57
    jernej
    0

    Hello,

    What about Custom menu actions?

    I have my own section with a custom tree inside it. I want to manually add menu actions with this code:

     

    XmlTreeNode

     

    customer = XmlTreeNode.Create(this);

    customer .NodeID =

    "0";

    customer .Text =

    "Customer";

    customer .Icon = FolderIcon;

    customer .Source = GetTreeServiceUrl(

    "Customer");

    customer .Menu.Add(

    ActionNew.Instance);

    customer .Menu.Add(

    ActionDelete.Instance);

     

     This node has child nodes which are set via customer.source.

    But I dont want to have these menu actions (that are set in the last two lines of my code) on child nodes of the customer node.

    How can I prevent the child nodes having the same menu items as their parent?

     

    Thanks!

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 21, 2009 @ 14:24
    Jeroen Breuer
    0

    @sas7 the tmp is filled by the next piece of code:

    if (this.id == this.StartNodeID)
                    tmp = Dictionary.getTopMostItems;
                else
                    tmp = new Dictionary.DictionaryItem(this.id).Children;

     

    the 'this.id' is the id given at this code:

    xNode.Source = di.hasChildren ? this.GetTreeServiceUrl(di.id) : "";

    This way the user can load the values depending on what id he passes.

     

    @jernej I used the following code to give the child nodes different actions:

            public override void Render(ref XmlTree tree)
            {
                XmlTreeNode xNode;
                if (this.id == this.StartNodeID)
                {
                    xNode = XmlTreeNode.Create(this);
                    xNode.NodeID = "NederlandsId";
                    xNode.Text = "Nederlands";
                    xNode.Icon = "folder.gif";
                    xNode.OpenIcon = "folder_o.gif";
                    xNode.Source = this.GetTreeServiceUrl(Convert.ToInt32(NieuwsbriefTaal.Nederlands));
                    tree.Add(xNode);
                    xNode = XmlTreeNode.Create(this);
                    xNode.NodeID = "EngelsId";
                    xNode.Text = "Engels";
                    xNode.Icon = "folder.gif";
                    xNode.OpenIcon = "folder_o.gif";
                    xNode.Source = this.GetTreeServiceUrl(Convert.ToInt32(NieuwsbriefTaal.Engels));
                    tree.Add(xNode);
                }
                else
                {

                    NieuwsbriefTaal nieuwsbriefTaal = GeneralUtilities.IntToEnum<NieuwsbriefTaal>(this.id);

                    TribalNieuwsbriefCollection tribalNieuwsbriefCollection = TribalNieuwsbriefController.GetNieuwsbrieven(nieuwsbriefTaal);
                    foreach (TribalNieuwsbrief tribalNieuwsbrief in tribalNieuwsbriefCollection)
                    {

                        xNode = XmlTreeNode.Create(this);
                        xNode.NodeID = tribalNieuwsbrief.TreeNodeId.ToString();
                        xNode.Text = tribalNieuwsbrief.Naam;
                        xNode.Action = string.Format("javascript:openNieuwsbriefOverzicht('{0}');", tribalNieuwsbrief.NieuwsbriefId);
                        xNode.Icon = "folder.gif";
                        xNode.OpenIcon = "folder_o.gif";
                        tree.Add(xNode);
                    }
                }
            }
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 21, 2009 @ 14:26
    Jeroen Breuer
    0

    This forum needs some updates or at least an edit button! The code above should be one single code block....

  • Sa 118 posts 152 karma points
    Oct 22, 2009 @ 14:33
    Sa
    0

    hi folks.,

    i tried to create  tree nodes here.. but its getting repeated

     XmlTreeNode
                   xnode= XmlTreeNode.Create(this);
                    //node.NodeID = "1";//in remote db(umbracoUser2app)
                     xnode.Text = "custom services";
                    xnode.Action = "javascript:openBoard('Custom');";
                    xnode.OpenIcon = "folder_o.gif";
                    xnode.Icon = "folder.gif";
                    xnode.NodeType = "Custom";

      xnode.Source = this.GetTreeServiceUrl();

     

    here the node get repeated? any pointers?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 28, 2009 @ 13:53
    Jeroen Breuer
    0

    It's currently impossible to expand child nodes immediately, but will this be possible in Umbraco 4.1 since the entire tree will be replaced?

  • Sa 118 posts 152 karma points
    Oct 30, 2009 @ 06:36
    Sa
    0

    hi folks.,

    if you can post the example code of adding childnodes here as i still have difficulty in creating childnode

    Thank you

Please Sign in or register to post replies

Write your reply to:

Draft