Copied to clipboard

Flag this post as spam?

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


  • Tom Maton 387 posts 660 karma points
    Nov 04, 2013 @ 10:50
    Tom Maton
    0

    Creating multi-level custom tree in 6.1.6 with mixture of own data and umbraco nodes

    Hi All,

    I've not used Umbraco in a while (shamefully) and now trying to move my custom section and tree from 4.8 to the latest 6.1.6 but it no longer seems to be rendering the tree its just displaying the spinning image.

    One of the things I've noticed is that Document is now deprecated I've looked at the ContentService (which I believe its bee replaced with) but I dont seem to be retrieving any content using this. If anyone has any examples or blog posts they could point my in the correct direction that would be great.

    Thanks in advance.

    Tom

  • Garðar Þorsteinsson 113 posts 534 karma points
    Nov 04, 2013 @ 12:58
    Garðar Þorsteinsson
    0

    Hi Tom, I just had to find a way to create custom section in Umbraco 6.1.6 and boy that took some reading, the documentation is scaddered all over the place.

    I'm going to write a blog post about all the steps for creating the custom application but this should help you until I get to it.

    If anyone can better my code then that would be appreciated.

    You dont need to include anything into the tree config file, it wil be added there automaticly.

    [Tree("Application", "Application", "Application")]

        public class populateTree : BaseTree

        {

            public populateTree(string application)

                : base(application)

            { }

     

            protected override void CreateRootNode(ref XmlTreeNode rootNode)

            {

                rootNode.Icon = FolderIcon;

                rootNode.OpenIcon = FolderIconOpen;

                rootNode.NodeType = "init" + TreeAlias;

                rootNode.NodeID = "init";

                rootNode.Action = "javascript:openCategory(-1);";

            }

     

            public override void Render(ref XmlTree tree)

            {

                // Get the current database object

                var db = ApplicationContext.Current.DatabaseContext.Database;

                // Fetch a collection from the db.

                List<Category> listOfCategories = null;

                int key = -1;

                if (!string.IsNullOrEmpty(this.NodeKey))

                {

                    key = Convert.ToInt32(this.NodeKey);

                }

     

                listOfCategories = db.Fetch<Category>("SELECT * FROM Categories WHERE deleted=@0 ORDER BY name", false);

     

                if (listOfCategories != null)

                {

     

                    foreach (Category category in listOfCategories.Where(x => x.parentId == key))

                    {

                        string id = category.treeId.ToString();

     

                        // Create tree node

                        var node = XmlTreeNode.Create(this);

                        node.NodeID = id;

                        node.Text = category.name;

                        node.Icon = "folder_o.gif";

                        node.Action = "javascript:openCategory(" + node.NodeID + ");";

     

                        // Add child nodes

     

                        bool hasChildren = listOfCategories.Where(x => x.parentId == category.treeId).Any();

     

                        node.Source = hasChildren ? this.GetTreeServiceUrl(node.NodeID) : "";

     

                        // Add the node to the tree

                        tree.Add(node);

     

                    }

     

                }

     

            }

     

            public override void RenderJS(ref StringBuilder Javascript)

            {

                Javascript.Append(@"

                function openCategory(id) {

                    document.getElementById('right').scrolling = 'auto';

                    UmbClientMgr.contentFrame('../App_Plugins/PluginName/Category/List?id=' + id);

                }

                ");

            }

        }

  • Tom Maton 387 posts 660 karma points
    Nov 04, 2013 @ 15:35
    Tom Maton
    0

    Cheers mate,

    I'll take a look tonight and let you know how I get on.

    Thanks, Tom

Please Sign in or register to post replies

Write your reply to:

Draft