Copied to clipboard

Flag this post as spam?

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


  • Ian Robinson 79 posts 143 karma points
    Mar 13, 2012 @ 10:55
    Ian Robinson
    1

    Getting the node id from in custom tree event / IAction

    I'll get my excuses in first... I have a bit of a cold today so I'm probably missing something really obvious, and I'm sure this question has been asked many times before, but...

    From my custom tree event and the IAction class it calls, how do I pass the node id of the node that's been right-clicked on, to my aspx page?

    I'm using Umbraco 4.7.1.1 and I've followed the umbraco support videos to get this far, but now I'm a bit stuck.

    The menu item appears when I right-click on my node in the umbraco content tree, and if I select the item, a modal window appears displaying my page "packageCaseStudy.aspx?id=1", but I need to replace the 1 with the node id the user right-clicked on.  If anyone can help, that would be great.

    NOTE - in the code below, the class is called "PackageCaseStudy".  This isn't a reference to umbraco packages, it's just what my client calls the action I'm trying to perform.

    public class CaseStudyTreeEventApplicationBase
        {
            public CaseStudyTreeEvent()
            {
                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 =="content" && node.Menu != null && node.Icon == "package.gif")
                {
                    
                    node.Menu.Insert(0, new PackageCaseStudy());
                    node.Menu.Insert(1, umbraco.BusinessLogic.Actions.ContextMenuSeperator.Instance);
                }
            }   
        }

    public class PackageCaseStudy : umbraco.interfaces.IAction     {         private string _alias = "packageCaseStudy";         public string Alias         {             get { return _alias; }         }         public bool CanBePermissionAssigned         {             get { return false; }         }         public string Icon         {             get { return "/umbraco/plugins/eFMGenerator/images/compress.png"; }         }         public string JsFunctionName         {             get             {                 return "OpenPackageWindow();";             }         }         public string JsSource         {             get { return "function OpenPackageWindow(){ UmbClientMgr.openModalWindow('/umbraco/plugins/eFMGenerator/packageCaseStudy.aspx?id=" + 1 + "', 'Package Case Study', true, 350, 380); }"; }         }         public char Letter         {             get { return '2'; }         }         public bool ShowInNotifier         {             get { return false; }         }     }
  • Ian Robinson 79 posts 143 karma points
    Mar 13, 2012 @ 13:38
    Ian Robinson
    0

    Still struggling with this but I'm sure there's a simple answer. 

  • Rodion Novoselov 694 posts 859 karma points
    Mar 13, 2012 @ 15:53
    Rodion Novoselov
    2

    Hi. You can use "UmbClientMgr.mainTree().getActionNode()" inside the javascript that handles your action.

    Update: It returns a javascript object - in order to get the ID just get the "nodeId" property of it: "UmbClientMgr.mainTree().getActionNode().nodeId"

  • Ian Robinson 79 posts 143 karma points
    Mar 13, 2012 @ 16:36
    Ian Robinson
    0

    That worked like a charm.  Absolutely brilliant.

    Thanks Rodion!

Please Sign in or register to post replies

Write your reply to:

Draft