Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Sep 09, 2010 @ 14:51
    Jeroen Breuer
    0

    How to pass id in custom action?

    Hello,

    I created a custom action for my custom tree. Now I want the modalWindow to appear after the action is clicked. In the modalWindow I want to get the id of the node just clicked. How can I do this. I've got the following in my action:

    public string JsFunctionName
    {
        get
        {
            return "ShowCreateCategory()";
        }
    }
    
    /// <summary>
    /// This is a path to a JavaScript file that contains the custom JavaScript to call.
    /// </summary>
    public string JsSource
    {
        get
        {
            //Assign a function.
            //return "function ShowCreateCategory(){ parent.right.document.location.href = '" + VirtualPathUtility.ToAbsolute("/umbraco/sections/articles/CreateCategory.aspx") + "?id=' + UmbClientMgr.mainTree().getActionNode().nodeId ; }";
            return "function ShowCreateCategory(){" + ClientTools.Scripts.OpenModalWindow("/umbraco/sections/articles/CreateCategory.aspx", "test", 750, 550) + "}";
        }
    }

    The first line in comment doens't pop-up but goes directly to a page. That works. The second line opens the pop-up and that also works, but without the id passing. I tried the following to pass the id:

    return "function ShowCreateCategory(){" + ClientTools.Scripts.OpenModalWindow("/umbraco/sections/articles/CreateCategory.aspx?id='UmbClientMgr.mainTree().getActionNode().nodeId;", "test", 750, 550) + "}";

    If I know click on my action nothing happens. I'm doing something wrong but I don't know what. Hope someone can help me :).

    Thanks.

    Jeroen

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Sep 09, 2010 @ 15:14
    Dirk De Grave
    0

    Seems your 

    UmbClientMgr.mainTree().getActionNode().nodeId;

    is part of the string, should be " + UmbClientMgr.mainTree().getActionNode().nodeId + "

     

    Hope this helps.

    Regards,

    /Dirk

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Sep 09, 2010 @ 15:20
    Jeroen Breuer
    0

    That doens't work because it's a javascript function (as you can see in the commentend line) and this is c#. Somehow need to call that javascript function while passing it into the ClientTools.Scripts.OpenModalWindow method. You're probably right and it's a syntax error, but I can't find it.

    Jeroen

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Sep 09, 2010 @ 15:24
    Dirk De Grave
    0

    Here's a sample I use on a site and works perfectly:

     

    public string JsSource {
                get {
                    return "function copyArticle(){"+
                                    "UmbClientMgr.openModalWindow('dialogs/CopyArticleDialog.aspx?articleId='+ UmbClientMgr.mainTree().getActionNode().nodeId + '&languageId=' + "Language.GetLanguageId(umbraco.BusinessLogic.User.GetCurrent().Language) + ", 'Kopieer artikel', true, 600, 550,0,0,'','');"+
                               "}";

                }
            }

     

    So yes, yours will be seen as a string rather than a c# function...

    ClientTools.Scripts.OpenModalWindow("/umbraco/sections/articles/CreateCategory.aspx?id='UmbClientMgr

     

    It's just wrong use of ' and "

    Have to replace the first " by a single ' and make sure you're also closing the string before joining with the UmbClientMgr.mainTree()...

    Cheers,

    /Dirk

     

     

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Sep 09, 2010 @ 15:34
    Jeroen Breuer
    0

    Thank you Dirk I got it solved. Because of your sample I saw what I was doing wrong. Here is the line that works:

    return "function ShowCreateCategory(){" + ClientTools.Scripts.OpenModalWindow("/umbraco/sections/articles/CreateCategory.aspx?id='+UmbClientMgr.mainTree().getActionNode().nodeId+'", "test", 750, 550) + "}";

    I opened the javascript with '+ but because there comes more javascript after my code I should also end it with +'. It was a syntax error after all :).

    Jeroen

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies