Copied to clipboard

Flag this post as spam?

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


  • Bas 3 posts 23 karma points
    Mar 17, 2010 @ 09:24
    Bas
    0

    Unable to add custom actions to childnodes in custom tree

    Hi,

    I have added a custom section to Umbraco to enable the productmanagement.

    For this I have created a custom tree with custom actions, all works fine so far.

    The custom tree looks like this:

    ProductManagement

    • Collections
      • Fall Collection 2011
    • ProductModels
    • ProductTypes

    I have added custom actions to the 'Collection', 'ProductModels' and 'ProductTypes' nodes using the following code"

            XmlTreeNode oCollectionNode = addRootNode("Collecties", "docPic.gif");
            oCollectionNode.Menu.AddRange(new List<IAction> { ActionCreateCollection.Instance });
            Tree.Add(oCollectionNode);

            XmlTreeNode oTypeNode = addRootNode("ProductTypes", "docPic.gif");
            oTypeNode.Menu.AddRange(new List<IAction> { ActionCreateProductType.Instance });
            Tree.Add(oTypeNode);

            XmlTreeNode oModelNode = addRootNode("Modellen", "docPic.gif");
            oModelNode.Menu.AddRange(new List<IAction> { ActionCreateModel.Instance });
            Tree.Add(oModelNode);

    This all works fine.

    The childnode 'Fall Collection 2011' is an actual records from the database which i can edit by clicking on it.

    The problem arises when i want to add a custom action to nodes on this level (childnodes under ProductModels also do not appear), see the code below:

          using (SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DSN"].ConnectionString))
          {
            oConn.Open();
            using (SqlCommand oCommand = new SqlCommand("spProductCollection_G", oConn))
            {
              oCommand.CommandType = CommandType.StoredProcedure;
              SqlDataReader oReader = oCommand.ExecuteReader();

              while (oReader.Read())
              {
                var nodeProductCollection = XmlTreeNode.Create(this);
                nodeProductCollection.Text = oReader["ProductCollection"].ToString();
                nodeProductCollection.Icon = "docPic.gif";
                nodeProductCollection.Action = "javascript:editProductCollection(" + oReader["ID"].ToString() + ")";
                nodeProductCollection.Menu.AddRange(new List<IAction> { ActionCreateProduct.Instance });
               
                TreeService treeService = new TreeService(-1, TreeAlias, true, false, DialogMode, app, string.Format("Collection_{0}", oReader["ID"].ToString()));
                nodeProductCollection.Source = treeService.GetServiceUrl();

                Tree.Add(nodeProductCollection);

              }

              oReader.Close();
            }
            oConn.Close();
          }

     

    I can see the childnodes, the collections, appear but the actions do not appear. The same thing for productmodels and other items on the same level.

    Can somebody tell me what im doing wrong?

    Thanks in advance.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 17, 2010 @ 10:28
    Dirk De Grave
    0

    Can't see what's wrong from the code, looks pretty fine to me. Only difference i can see from some code I've been using for csmMailer, is the fact that I'm explicitely clearing the menu actions before adding the custom actions (me thinks I was experiencing the same issue...)

    Can you check if the following does work in your case:

    nodeProductCollection.Menu.Clear();
    nodeProductCollection.Menu.AddRange(new List<IAction> { ActionCreateProduct.Instance });

     

    Cheers,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft