Copied to clipboard

Flag this post as spam?

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


  • Jason Evans 50 posts 71 karma points
    Sep 14, 2012 @ 17:28
    Jason Evans
    0

    Have added tree event class, now Umbraco UI is empty!

    Hi there.

    I've followed the instructions for creating custom context menu items in this video: http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco/events/add-items-to-the-context-menu

    Here is my code:

    public class TreeEvent : ApplicationBase
    {
        public TreeEvent()
        {
            BaseTree.BeforeNodeRender += OnBeforeNodeRenderEvent;
        }
        private static void OnBeforeNodeRenderEvent(ref XmlTree sender, ref XmlTreeNode node, EventArgs e)
        {
            if (node.NodeType.Equals("memberGroup", StringComparison.OrdinalIgnoreCase))
            {
                AddSiteMappingMenuItem(node);
            }
        }
        private static void AddSiteMappingMenuItem(XmlTreeNode node)
        {
            node.Menu.Add(new SiteMappingAction());
        }

    public class SiteMappingAction : IAction
    {
        public string Alias
        {
            get
            {
                return "SiteMemberGroupMapping";
            }
        }
        public bool CanBePermissionAssigned
        {
            get
            {
                return true;
            }
        }
        public string Icon
        {
            get
            {
                return string.Empty;
            }
        }
        public string JsFunctionName
        {
            get
            {
                return "alert('Hello');";
            }
        }
        public string JsSource
        {
            get
            {
                return string.Empty;
            }
        }
        public char Letter
        {
            get
            {
                return 'S';
            }
        }
        public bool ShowInNotifier
        {
            get
            {
                return false;
            }
        }
    }

    After I compile the above code and place it in my Umbraco site; when I navigate to the Umraco admin area, all of the content is blank - the left hand navigation, the sections area, the right side content, they are all empty. Other UI items such as the help button and search are still appear.

    Now when I remove my custom tree event class from the site, and refresh the page, then all the content appears without fail.

    My question is : I must be doing something wrong in either the TreeEvent or SiteMappingAction classes, but I don't know what it could be.

    Can someone help please?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 14, 2012 @ 19:27
    Tom Fulton
    0

    Hi Jason,

    The video has some outdated code that breaks post-4.5.  Here's the fix:  http://our.umbraco.org/forum/developers/extending-umbraco/15025-Content-Tree-Will-Not-render-after-creating-new-Context-Menu-Item

    Hope this helps,
    Tom 

  • Jason Evans 50 posts 71 karma points
    Sep 14, 2012 @ 21:45
    Jason Evans
    0

    Hi Tom.

    Thanks for your reply. I've made changes to my action class like so:

     

    public class SiteMappingAction : IAction

    {

    #pragma warning disable 612,618

            private static readonly SiteMappingAction instance = new SiteMappingAction();

    #pragma warning restore 612,618

     

    [Obsolete("Use the singleton instantiation instead of a constructor")]

    public SiteMappingAction()

    {

    }

     

    public static SiteMappingAction Instance

    {

    get

    {

    return instance;

    }

    }

     

    public string Alias

    {

    get

    {

    return "Site Mappings";

    }

    }

     

    public bool CanBePermissionAssigned

    {

    get

    {

    return false;

    }

    }

     

    public string Icon

    {

    get

    {

    return string.Empty;

    }

    }

     

    public string JsFunctionName

    {

    get

    {

    return "Testing()";

    }

    }

     

    public string JsSource

    {

    get

    {

    return "function Testing() { alert('hello') };";

    }

    }

     

    public char Letter

    {

    get

    {

    return 'S';

    }

    }

     

    public bool ShowInNotifier

    {

    get

    {

    return false;

    }

    }

    }

     

    Now when I navigate to Umbraco, and right-click on the target tree node, instead of my action item appearing in the context menu, a new item named "Sort" appears?!?!? Very weird. It says the word "Sort" and has an icon.

    My action class does not mention sort, nor does it mention that icon, so I've no idea why Umbraco is showing this item.

    Can you assist me with this please?

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 14, 2012 @ 21:48
    Tom Fulton
    0

    Hi,

    Just a wild guess, the Letter property of your menu item needs to be unique.  Maybe the Sort action is already using that.

    Usually what I do to pick a letter is push ALT+(random chars on numpad), for ex ALT+4578 gives you Γ - and hope noone else is using that :)

    -Tom

  • Jason Evans 50 posts 71 karma points
    Sep 14, 2012 @ 22:13
    Jason Evans
    0

    Hi Tom.

    I gave that a shot by changing letter to:

    public char Letter

            {

                get

                {

                    return 'Ô';

                }

            }

    I've tried various other characters via the ALT+ random number technique, but I still get the same result : when I right-click now, my context menu item does not appear, but at least the "Sort" item has also vanished now.

    Still stuck on how to get my item to appear.

  • Jason Evans 50 posts 71 karma points
    Sep 17, 2012 @ 12:41
    Jason Evans
    0

    Hi there.

    It looks like the Alias property was at fault. I change it from returning "Site Mappings" to "siteMappings" and (after adding a new row in umbracoAppTree) my custom menu item does appear.

    I do have a new issue regarding the text that appears in the menu item (it says [siteMappings] rather then "Site Mappings", but that's a different issue.

    Thanks for your help with this.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 17, 2012 @ 17:09
    Tom Fulton
    0

    Awesome, glad you fixed it!  The [siteMappings] issue is because you need to add a key to the language file with the actual text you want to use.  Check /umbraco/config/lang/en.xml and add a new key for siteMappings.

Please Sign in or register to post replies

Write your reply to:

Draft