Navigatie

Contact

Send mail to the author(s) E-mail

View Richard Soeteman's profile on LinkedIn

RSS 2.0 | Atom 1.0 | CDF

Archief

Categorieën

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Sign In

Zoeken

# Friday, 02 July 2010
Friday, 02 July 2010 09:13:38 (GMT Daylight Time, UTC+01:00) ( Umbraco )

This Blog is not active anymore, further posts will be available on my company website. Read new posts here

Now that version 4.5 of Umbraco is out you want to make sure that your packages work in both 4.0.x and 4.5. Or is that just me? So far I’ve had two compatibility issues

~ prefix in UmbracoPath setting

I’m  using the Umbraco property GlobalSettings.Path (which correspondents with the umbracoPath setting in the web.config file) to determine the Umbraco folder. This used to be /Umbraco, Umbraco 4.5 supports virtual folder so it’s changed to ~/umbraco. To solve this for both 4.0.x and 4.5 you can use the ToAbsolute method of the  VirtualPathUtility class.  The example below will convert the virtual path ~/umbraco to absolute.

VirtualPathUtility.ToAbsolute(umbraco.GlobalSettings.Path);

Using inline javascript in Action class breaks the complete tree

In Umbraco you can create classed that implement the IAction interface which gives you the possibility to add menu options to the context menu of a tree. In previous versions of Umbraco you could use inline JavaScript in the JSFunctionName property to have client side functionality. In Umbraco 4.5 the clientside model is changed and if you include direct JavaScript into the JSFunction  name the complete tree will break. Good thing is that Shannon AKA @Shazwazza fixed a bug in 4.5 so the JSSource property of your action class now actually gets rendered and you can include the function here, downside is that this isn’t the case in 4.0 and we now need to think of a way to determine if we are in 4.0 or 4.5. For CMSImport and MemberExport I’m using a CompatibilityHelper Class that I’ve created. On this class I have a property SupportsJQueryTree that returns true if the CurrentVersion setting is not 4.0.

    /// <summary>
    /// This class is introduced because 4.5 is a little bit different from 4.0.x 
    /// One single place to have nasty checks if the Umbraco environment supports a feature or not
    /// </summary>
    public static class CompatibilityHelper
    {
        public static bool SupportsJQueryTree
        {
            get
            {
                return !GlobalSettings.CurrentVersion.StartsWith("4.0");
            }
        }
    }

Now I can determine in my action if the JQueryTree is supported and render JavaScript for that, otherwise I will render JavaScript for the old Tree. In the snippet below you see the Implementation that I’m using in CMSImport to start an import from a node tree

        public string JsFunctionName
        {
            get
            {
                if (CompatibiltyHelper.SupportsJQueryTree)
                {
                    //Environment supports the new tree call Javascript via a function
                    //doing this with inline script this will cause the tree to crash
                    return "StartWizard()";
                }
                else
                {
                    //The old tree could not have a function in JsSource, use inline script instead.
                    return " parent.right.document.location.href = '" + umbraco.GlobalSettings.Path + "/plugins/CMSImport/Pages/wizard.aspx?id=' + nodeID; ";
                }
            }
        }

        public string JsSource
        {
            get
            {
                if (CompatibiltyHelper.SupportsJQueryTree)
                {
                    //Assign a function.
                    return "function StartWizard(){ parent.right.document.location.href = '" + VirtualPathUtility.ToAbsolute("/plugins/CMSImport/Pages/wizard.aspx") + "?id=' + 
UmbClientMgr.mainTree().getActionNode().nodeId ; }";
                }
                else
                {
                    //Doesn't work in 4.0.x
                    return string.Empty;
                }
            }
        }

This might sound like a hack and it really is a hack. But for me this works. Within a few months just a small percentage of the Umbraco users is using 4.0, the rest is on 4.5 and I might drop support for 4.0 then and only need to delete this CompatibilityHelper class and delete the old 4.0.x code 

So far these are the only compatibility issues I’ve found (I don’t use the new schema in my packages). If I find more I will create a separate blogpost for it. Hope this post helps you with your compatibility issues in your packages

Comments [1] | | #