Copied to clipboard

Flag this post as spam?

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


  • Robert Graham 22 posts 90 karma points
    Sep 09, 2015 @ 15:57
    Robert Graham
    0

    Using Legacy Trees and Back Office Sections

    Hi,

    I am looking to create a new back office section in a 7.2.1 version site.

    I played around with the new way and although I got it to work looking at the many different posts scattered around the internet I realised I simply don't have time or budget to take on AngularJS and all the other challenges I will face.

    With that in mind I looked into support for asp.net forms etc and found posts stating that the User sections amongst others still uses forms and a legacy iframe solution still exists.

    I downloaded the source for Umbraco and discovered that the User tree for example still uses the umbraco.businesslogic.tree attrribute. I have made many custom sections so it was not long till I got something running.
    You basically create an application like this:

    [Application("account", "account", "icon-car", 16)]
        public class AccountSectionApplication : IApplication
        {
        }
    

    Then you create a tree like this:

    namespace Maple.Digital.Library.Web { [Tree("account", "AccountTree", "account")] public class LegacyTree : BaseTree, umbraco.interfaces.ITree { public LegacyTree(string application) : base(application) { }

        protected override void CreateRootNode(ref XmlTreeNode rootNode)
        {
            rootNode.Text = "My Root Node";
        }
    
        public override void RenderJS(ref StringBuilder Javascript)
        {
            Javascript.Append(
                @"
                function openUser(id) {
                    UmbClientMgr.contentFrame('users/editUser.aspx?id=' + id);
                }
                ");
        }
    
        protected override void CreateAllowedActions(ref List<IAction> actions)
        {
            actions.Clear();
            actions.Add(ActionDisable.Instance);
        }
    
        public override void Render(ref XmlTree tree)
        {
            var users = new List<User>(User.getAll());
    
            User currUser = UmbracoEnsuredPage.CurrentUser;
    
            bool currUserIsAdmin = currUser.IsAdmin();
            foreach (User u in users.OrderBy(x => x.Disabled))
            {
                if (!UmbracoConfig.For.UmbracoSettings().Security.HideDisabledUsersInBackoffice
                    || (UmbracoConfig.For.UmbracoSettings().Security.HideDisabledUsersInBackoffice && !u.Disabled))
                {
    
                    XmlTreeNode xNode = XmlTreeNode.Create(this);
    
                    // special check for ROOT user
                    if (u.Id == 0)
                    {
                        //if its the administrator, don't create a menu
                        xNode.Menu = null;
                        //if the current user is not the administrator, then don't add this node.
                        if (currUser.Id != 0)
                            continue;
                    }
                    // Special check for admins in general (only show admins to admins)
                    else if (!currUserIsAdmin && u.IsAdmin())
                    {
                        continue;
                    }
    
                    //xNode.IconClass = "umbraco-tree-icon-grey";
    
                    xNode.NodeID = u.Id.ToString();
                    xNode.Text = u.Name;
                    xNode.Action = "javascript:openUser(" + u.Id + ");";
                    xNode.Icon = "icon-user";
                    xNode.OpenIcon = "icon-user";
    
                    if (u.Disabled)
                    {
                        xNode.Style.DimNode();
                    }
    
                    OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty);
                    if (xNode != null)
                    {
                        tree.Add(xNode);
                        OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty);
                    }
                }
            }
        }
    }
    

    }

    You will notice I simply copied the user tree for testing purposes.

    The thing I can't get to happen is the root node has no text value set (It should be My Root Node). No matter what I have tried - the node is their but the anchor tag has no text.

    This is what the html has when I view source

    <h5><!-- ngIf: enablecheckboxes == 'true' --><a href="#/account" ng-click="select(tree.root, $event)" on-right-click="altSelect(tree.root, $event)" class="root-link ng-binding"></a></h5>
    

    Following the new way of creating a section I get a root node without any issues. Like this.

    [PluginController("Reports")]
        [Umbraco.Web.Trees.Tree("Reports", "ReportsTree", "My reports section", iconClosed: "icon-doc")]
        public class ReportTreeController : TreeController
        {
            protected override Umbraco.Web.Models.Trees.TreeNodeCollection GetTreeNodes(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
            {
                var nodes = new TreeNodeCollection();
                var item = this.CreateTreeNode("dashboard", id, queryStrings, "My item", "icon-truck", false);
                nodes.Add(item);
                return nodes;
            }
    
            protected override MenuItemCollection GetMenuForNode(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
            {
                var menu = new MenuItemCollection();
                menu.DefaultMenuAlias = ActionNew.Instance.Alias;
                menu.Items.Add<ActionNew>("Create");
                return menu;
            }
        }
    

    I get a nice root node called My reports section.

    So I have two questions:

    1. Has anyone added in legacy back office sections and got it all to work and if so can they see where I have gone wrong?

    2. Is Umbraco intending on providing a non legacy solution for Iframe based back office systems trees that would in turn support asp.net forms & MVC? I for one would like to see this because there are so many times when asp.net forms is quick, easy and fully featured for custom back office sections. Also helps people move from 6 to 7 etc without incurring extra unnecessary costs. I do not want to have to take on AngularJS to simply extend Umbraco - I don't feel I should have to as the internet supports many frameworks and providing an iframe way of working meets everyone's skills and needs.

    Thanks

    Rob

  • Robert Graham 22 posts 90 karma points
    Nov 12, 2015 @ 10:17
    Robert Graham
    0

    Anyone from the core team looked at this post?

    Starting a new project soon and would like to know what the intention is here.

    Thanks

    Rob

Please Sign in or register to post replies

Write your reply to:

Draft