Copied to clipboard

Flag this post as spam?

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


  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 26, 2010 @ 19:34
    Matt Brailsford
    0

    UmbClientMgr.openModalWindow encoding apostrophies

    Hey Guys,

    I'm trying to create a custom tree in 4.5 and have worked out the following from reflector, but when i use this the apostrophies are getting encoded to \u0027. My JsFunctionName for the action is as follows:

    public string JsFunctionName
    {
        get { return "UmbClientMgr.openModalWindow('theoutfield/doctypeextensions/dialogs/ChangeMasterDocType.aspx?id='+ UmbClientMgr.mainTree().getActionNode().nodeId +'&rnd='+ this._utils.generateRandom(), uiKeys['actions_change_master_doc_type'], true, 500, 480);"; }
    }

    Anyone know why this is?

    Cheers

    Matt

  • jaygreasley 416 posts 403 karma points
    Jun 26, 2010 @ 19:50
    jaygreasley
    0

    Hi Matt,

    \u0027 is the unicode character for an apostrophe (or more specifically a single quote).

    I'd try escaping it along the lines of:

     get { return "UmbClientMgr.openModalWindow(\'t

    That may work or you may need something cleverer :-)

    j

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 26, 2010 @ 20:16
    Matt Brailsford
    0

    Yea, I tried that, but that did't work either

    Matt

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jun 26, 2010 @ 21:21
    Morten Christensen
    0

    Hi Matt,

    Have you tried this:

    public string JsFunctionName
    {
       
    get { return string.format("UmbClientMgr.openModalWindow('theoutfield/doctypeextensions/dialogs/ChangeMasterDocType.aspx?id={0}');", UmbClientMgr.mainTree().getActionNode().nodeId); }
    }

    I cut off some of the parameters, but my suggestion is just to format it as shown. If you look in the source of 4.5 all actions looks like:

    public string JsFunctionName
    {
    get
    {
    return string.Format("{0}.actionPublish()", ClientTools.Scripts.GetAppActions);
    }
    }

    I take it that it is an action that you are trying to create right?

    - Morten

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 26, 2010 @ 21:29
    Matt Brailsford
    0

    It doesn't throw an error, but obviously it doesn't know what my action method is. Only way I can think to solve it at the moment, is go with just a simple method call, and set the JsSource to point to a js file with the method defined in it?

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 26, 2010 @ 21:39
    Matt Brailsford
    0

    Thought I might have found something then, but nope. Just tried:

    return ClientTools.Scripts.OpenModalWindow(
     "theoutfield/doctypeextensions/dialogs/ChangeMasterDocType.aspx", "Change Master Doc Type", true,
            500, 480, 100, 100, "", "");

    but it stills returns a string with an apostrophe which gets converted to \u0027

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 26, 2010 @ 23:24
    Matt Brailsford
    0

    Ok, this works, but it seems a bit hacky:

    public string JsFunctionName
    {
        get
        {
            var page = HttpContext.Current.CurrentHandler as Page;
            if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("ChangeMasterDoctype"))
                page.ClientScript.RegisterClientScriptBlock(typeof (ChangeMasterDocTypeAction),
                    "ChangeMasterDoctype",
                    @"function actionChangeMasterDocType(){
                        UmbClientMgr.openModalWindow('theoutfield/doctypeextensions/dialogs/ChangeMasterDocType.aspx?id='+UmbClientMgr.mainTree().getActionNode().nodeId, 'Change Master Doc Type', true, 500, 480);
                    } ", true);

            return "actionChangeMasterDocType()";
        }
    }

    If this is the solution, this could be made cleaner if RegisterClientScript on ClientTools.Scripts was made public.

    Matt

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jun 26, 2010 @ 23:46
    Morten Christensen
    0

    I think what you should do is simply add your javascript function to the JsSource and simply keep the function call in the JsFunctionName.

    As I recall this is something Shannon made possible during the retreat, because the JsFunctionName expects a jQuery function call.

    public string JsFunctionName
    {
    get
    {
    return "actionChangeMasterDocType()";
    }
    }

    public string JsSource
    {
    get
    {
    return @"function actionChangeMasterDocType(){
    UmbClientMgr.openModalWindow('theoutfield/doctypeextensions/dialogs/ChangeMasterDocType.aspx?id='+UmbClientMgr.mainTree().getActionNode().nodeId, 'Change Master Doc Type', true, 500, 480);
    } ";
    }
    }

    In the source code there is the follow comment for JsSource:

    "A path to a supporting JavaScript file for the IAction. A script tag will be rendered out with the reference to the JavaScript file.", so yeah probably want to change that to a local js-file of your own. But remember that JsSource doesn't work in 4.0.x ;)

    - Morten

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 26, 2010 @ 23:53
    Matt Brailsford
    0

    Yea, that was my first solution here http://our.umbraco.org/forum/developers/extending-umbraco/10131-UmbClientMgropenModalWindow-encoding-apostrophies?p=0#comment36908 but I was hoping to avoid needing a seperate script file, but yea, it's looking like it's unavoidable now.

    Thanks for looking into this aswell, it was driving me insane.

    Matt

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Jun 27, 2010 @ 13:45
    Richard Soeteman
    0

    Hi Matt,

    You can include your javascript function in the JsSource property. This is inline javascript instead of referencing an external file, must be a bug in the documentation.... Downside is that you can't use it in 4.0 because of a bug in 4.0 :-(. In the JsFunctionName prroperty you can include javascript that calls your Javascript function, so no need for an external file. In the coming week I will create a blogpost how I solved the compatibility issue between 4.0 and 4.5.

    I had some issues when testing IAction functionality, I think related to caching. I solved it by logging out and do an iis reset before testing the feature.

    Cheers,

    Richard

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 27, 2010 @ 18:07
    Matt Brailsford
    0

    Ok, so just tried Morten and Richards suggestion, and yes it does work, but the output is:

     <script type="text/javascript" src="function actionChangeMasterDocType() {
                                UmbClientMgr.openModalWindow('theoutfield/doctypeextensions/dialogs/ChangeMasterDocType.aspx?id=' + UmbClientMgr.mainTree().getActionNode().nodeId, 'Change Master Doc Type', true, 500, 480);
                            }"></script>

    Is this even valid markup? Shouldn't the method be defined between the script tags? This to me suggests that the JsSource property should only really be used to link to an external file. Do you get different results Richard?

    Matt

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jun 27, 2010 @ 21:42
    Morten Christensen
    0

    Pretty sure its not valid, so a bit suprised it worked. I'm going to reference an external js file in my update of the Analytics package, and use the JsFunctionName from the Action with a combination of the compatibility check, which Ricard mentioned above. This'll work fine and I won't add inline JS to JsSource - thats just nasty :-D

    First off I wasn't sure if the content of JsSource would be added as inline JS or a reference to a file, but now I'm sure. I would recommend you also reference a js file. But if you find another solution please let me know ;)

    - Morten

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 27, 2010 @ 21:45
    Matt Brailsford
    0

    Yea, thats pretty much what I'm going with (again, would prefer not to have to have a js include for every action, but seems the only way right now).

    Now I just need to get my custom doc type tree to work =)

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 27, 2010 @ 21:50
    Matt Brailsford
    0

    Rich, if you could post a link here to your compatability check blog post once its up, that would be cool.

    Cheers

    Matt

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Jun 28, 2010 @ 08:42
    Richard Soeteman
    0

    Dunno about the Markup. If it is invalid it's something that should be fixed into the core ClientManager. I will write a blogpost about the compatibilty issues today or tomorrow.

    Cheers,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft