Copied to clipboard

Flag this post as spam?

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


  • Ron Brouwer 273 posts 768 karma points
    Feb 13, 2010 @ 18:23
    Ron Brouwer
    0

    Adding an IAction to Contextmenu of the User section

    Hi,

    Is it possible to add a custom action to the tree in the users section?
    And if so is it possible using the BaseTree.BeforeNodeRender?

    Thanks,

    Ron

  • Richard Soeteman 3943 posts 12362 karma points MVP
    Feb 13, 2010 @ 20:13
    Richard Soeteman
    0

    Hi Ron,

    Never done that, check if the even gets hit when you open a user tree, if that event gets hit, you can use custom actions in the tree.

    Cheers,

    Richard

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Feb 13, 2010 @ 21:44
    Morten Christensen
    1

    Hi Ron,

    Yeah you should be able to do this with the following code:

        public class YourTreeEvent : ApplicationBase
    {
    public YourTreeEvent() {
    umbraco.cms.presentation.Trees.BaseTree.BeforeNodeRender += new umbraco.cms.presentation.Trees.BaseTree.BeforeNodeRenderEventHandler(BaseTree_BeforeNodeRender);
    }

    void BaseTree_BeforeNodeRender(ref umbraco.cms.presentation.Trees.XmlTree sender, ref umbraco.cms.presentation.Trees.XmlTreeNode node, EventArgs e)
    {
    if (node.NodeType == "users" && node.Menu != null)
    {
    node.Menu.Insert(0, new YourActionHere());
    node.Menu.Insert(1, umbraco.BusinessLogic.Actions.ContextMenuSeperator.Instance);
    }
    }
    }

    YourAction will be inserted as the first action in the context menu within the users-Tree.

    NodeType would/could be "users", "userPermissions" or "userTypes" depending on where you want your action to appear. These are the TreeAlias(es) for the users-app (the Users-section).

    - Morten

  • Ron Brouwer 273 posts 768 karma points
    Feb 14, 2010 @ 11:06
    Ron Brouwer
    0

    Thanks @Richard and @Morten

    I already tried that and the event only gets hit in the content section.
    Any suggestions?

    Ron

  • Stephan Lonntorp 195 posts 212 karma points
    Feb 14, 2010 @ 11:08
    Stephan Lonntorp
    0

    File a bug report at codeplex, the event really should fire on all trees, right?

  • Ron Brouwer 273 posts 768 karma points
    Feb 14, 2010 @ 11:17
    Ron Brouwer
    0

    @Morton

    Have you used that code before or did you assume it would work?

    Ron

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Feb 14, 2010 @ 11:39
    Morten Christensen
    0

    @Ron

    I assumed it worked as I have used in it in the content and media sections. I never used it with:

    node.NodeType == "users"

    but assumed it worked, since it has worked for me with:

    node.NodeType == "media"

    I can do a quick test for the users-section and post my result.
    Otherwise I quess you would have to override the loadUsers-class, which is the class that loads the tree and adds actions.

    - Morten

     

  • Ron Brouwer 273 posts 768 karma points
    Feb 14, 2010 @ 11:54
    Ron Brouwer
    0

    @Morton

    The weard thing is that the loadUsers class inherits from BaseTree, so you would think it has to work.
    Thanks for the quick test, then I'm sure its not just me :)

    Ron

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Feb 14, 2010 @ 12:13
    Morten Christensen
    0

    Yeah, your right. It doesn't hit the Event in the Users section.

    But I think I would out why! If you look in the loadMedia and BaseContent classes, you'll find this piece of code in public override void Render(ref XmlTree Tree):

    base.OnBeforeNodeRender(ref Tree, ref node, EventArgs.Empty);
    if (node != null)
    {
    Tree.Add(node);
    }
    base.OnAfterNodeRender(ref Tree, ref node, EventArgs.Empty);

    So the events are only fired before and after the node has been added to the Tree.

    So if you want it to work right now you have to override the loadUsers class or create a new tree loader for the users section.

    - Morten

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Feb 14, 2010 @ 12:13
    Morten Christensen
    0

    Yeah, your right. It doesn't hit the Event in the Users section.

    But I think I would out why! If you look in the loadMedia and BaseContent classes, you'll find this piece of code in public override void Render(ref XmlTree Tree):

    base.OnBeforeNodeRender(ref Tree, ref node, EventArgs.Empty);
    if (node != null)
    {
    Tree.Add(node);
    }
    base.OnAfterNodeRender(ref Tree, ref node, EventArgs.Empty);

    So the events are only fired before and after the node has been added to the Tree.

    So if you want it to work right now you have to override the loadUsers class or create a new tree loader for the users section.

    - Morten

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Feb 14, 2010 @ 12:13
    Morten Christensen
    0

    Yeah, your right. It doesn't hit the Event in the Users section.

    But I think I would out why! If you look in the loadMedia and BaseContent classes, you'll find this piece of code in public override void Render(ref XmlTree Tree):

    base.OnBeforeNodeRender(ref Tree, ref node, EventArgs.Empty);
    if (node != null)
    {
    Tree.Add(node);
    }
    base.OnAfterNodeRender(ref Tree, ref node, EventArgs.Empty);

    So the events are only fired before and after the node has been added to the Tree.

    So if you want it to work right now you have to override the loadUsers class or create a new tree loader for the users section.

    - Morten

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Feb 14, 2010 @ 12:14
    Morten Christensen
    0

    Damnit! Sorry about the triple posting :-S The post wasn't updating after hitting submit.

    - Morten

  • Ron Brouwer 273 posts 768 karma points
    Feb 14, 2010 @ 12:54
    Ron Brouwer
    0

    But how can I make Umbraco use my new loadUsers after I override the event?
    (Sorry I don't have much experience in that area.)

    Ron

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Feb 14, 2010 @ 13:38
    Morten Christensen
    0

    The easiest thing would probably be to copy the code from the loadUsers.cs and create a new one called i.e. RonsUsersTree and then change the entry in the umbracoAppTree table of your db to use your new class and assembly.

    Currently the entry that loads the users-section tree looks like this:

    treeSilent treeInitialize  treeSortOrder   appAlias    treeAlias   treeTitle   treeIconClosed  treeIconOpen    treeHandlerAssembly treeHandlerType action
    0 1 0 users users Brugere .sprTreeFolder .sprTreeFolder_o umbraco loadUsers NULL

    You just need to update "treeHandlerAssembly" and "treeHandlerType" to your assembly and class.

    If you want to reuse the loadUsers class you could inheirent the class and override the CreateNodeActions etc. (public class RonsUsersTree : loadUsers), but you will still have to update the entry in the db to use your class instead of the original one.

    Hope this makes sense.

    - Morten

  • Ron Brouwer 273 posts 768 karma points
    Feb 14, 2010 @ 13:55
    Ron Brouwer
    0

    Yes it makes sence.

    Don't like it tho. It's a shame that I need to change the core in order to get it working.
    However it seems to be the only way to go.

    Thanks a lot!

    Ron

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Feb 14, 2010 @ 21:29
    Morten Christensen
    0

    I agree, and maybe we should ask some of the core developers if there is any particular reason why the Users-section tree isn't firing the event.
    ...Or simply add it as an issue on Codeplex.

    - Morten

  • Richard Soeteman 3943 posts 12362 karma points MVP
    Feb 15, 2010 @ 09:23
    Richard Soeteman
    0

    HI Ron,

    Great that it worked for you. There is a package Action that helps you update the apptree values when you need to create a package out of this. Check out http://packageactioncontrib.codeplex.com/ and http://www.prolificnotion.co.uk/update-application-tree-package-action-for-umbraco

    Cheers,

    Richard

  • Ron Brouwer 273 posts 768 karma points
    Feb 27, 2010 @ 12:56
    Ron Brouwer
    0

    Thanks Richard,

    I choose not to change the tree. I just added an additional one.
    That way I don't need to change Umbraco.

    Ron

Please Sign in or register to post replies

Write your reply to:

Draft