Copied to clipboard

Flag this post as spam?

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


  • Chris White 23 posts 43 karma points
    Jun 29, 2010 @ 17:14
    Chris White
    0

    Custom Section / Tree in Umbraco 4.5

    Hi all,

    I've been working through the umbraco.tv videos on an instance of Umbraco 4.0.4.1 and they all seem to work fine. I'm looking at custom sections / trees in particular.

    I've now set up an instance of Umbraco 4.5 and when I copy the DLL containing my custom tree into the bin folder all nodes from all sections dissapear !!!

    Has anyone else come accross this - has the way to implement custom trees in Umbraco 4.5 changed substantially ??

    Thanks,

    Chris

  • Richard Soeteman 3682 posts 11270 karma points MVP
    Jun 30, 2010 @ 08:14
    Richard Soeteman
    2

    Hi Chris,

    The tree implementation hasn't changed, only when you create context menu's. In 4.0.x you needed to use inline javascript into the JsFunctionName property. Below an example of a CMSImport Action

     

     

    " parent.right.document.location.href = '" + umbraco.GlobalSettings.Path + "/plugins/CMSImport/Pages/wizard.aspx?id=' + nodeID; "

     

    Because of the new tree this doesn't work anymore and you need to specify a FunctionName. You can include the function  in the JSSource Property. Downside is that this doesn't work in 4.0.x. So for CMSImport I ended up creating a Compatibilty class to check which version of Umbraco I'm using and render the Javascript based on that condition.

    Below the full implementation of the Action and the compatibilty class

     

     

    public class StartWizardAction : IAction

    {

     

    //create singleton

     

    private static readonly StartWizardAction _instance = new StartWizardAction();

     

    private StartWizardAction() { }

     

    public static StartWizardAction Instance

    {

     

    get { return _instance; }

    }

    #region

     

    IAction Members

     

    public char Letter

    {

     

    get

    {

     

    return '@';

    }

    }

     

    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 = '" + UrlHelper.FormatUrl("/plugins/CMSImport/Pages/wizard.aspx") + "?id=' + UmbClientMgr.mainTree().getActionNode().nodeId ; }";

    }

     

    else

    {

     

    //Doesn't work in 4.0.x

     

    return string.Empty;

    }

    }

    }

     

    public string Alias

    {

     

    get

    {

     

    return "StartCMSImportWizardAction";

    }

    }

     

    public string Icon

    {

     

    get

    {

     

    return "/umbraco/plugins/cmsImport/images/NewCardHS.png";

    }

    }

     

    public bool ShowInNotifier

    {

     

    get

    {

     

    return true;

    }

    }

     

    public bool CanBePermissionAssigned

    {

     

    get

    {

     

    return true;

    }

    }

    #endregion

    }

    CompaitibiltyHelper class

     

    /// <summary>

     

    /// This class is introduced because 4.1 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 CompatibiltyHelper

    {

     

    public static bool SupportsJQueryTree

    {

     

    get

    {

     

    return !GlobalSettings.CurrentVersion.StartsWith("4.0");

    }

    }

    }

    Hope this helps you,

    Richard

  • Chris White 23 posts 43 karma points
    Jun 30, 2010 @ 11:23
    Chris White
    0

    Hi Richard,

    Many thanks for the code - that has sorted the issue !! Weird that it "blows up" all of the other trees too (e.g. content, media etc.) rather than just the custom one.

    As an aside, do you know of a way to add custom tree actions to a custom tree in ? Using the "umbraco.cms.presentation.Trees.BaseTree.BeforeNodeRender" event only appears to add the new action for the content and media trees. Is there a way to add this to a custom tree ?

    Thanks again,

    Chris

  • Richard Soeteman 3682 posts 11270 karma points MVP
    Jun 30, 2010 @ 11:28
    Richard Soeteman
    0

    Hi Chris,

    Yes it's one Javascript include so that's why it blows up. Regarding your custom tree question, do you derive from the BaseTree?

    Cheers,

    Richard

  • Chris White 23 posts 43 karma points
    Jun 30, 2010 @ 11:32
    Chris White
    0

    Hi Richard,

    Yes, my custom tree derives from BaseTree (I've basically followed the example on Umbraco.TV). It is mentioned in that screencast that custom tree actions are only available in the content and media sections, but I wasn't sure if this has changed in 4.5 or not. I would have thought having custom actions in a custom section would be a common requirement.

    Many thanks,

    Chris

  • Richard Soeteman 3682 posts 11270 karma points MVP
    Jun 30, 2010 @ 11:43
    Richard Soeteman
    0

    Hi Chris,

    Yes it's still the case. The Tree events are used in the BaseContentTree Class. But you can use it in your own Render method of the tree (need to write a bnlogpost/wiki for this). Below the render method of the BaseContent Tree of Umbraco

    Cheers,

    Richard

     

    /// <summary>

     

    /// Renders the specified tree item.

     

    /// </summary>

     

    /// <param name="Tree">The tree.</param>

     

    public override void Render(ref XmlTree Tree)

    {

     

    //get documents to render

     

    Document[] docs = Document.GetChildrenForTree(m_id);

     

    var args = new TreeEventArgs(Tree);

    OnBeforeTreeRender(docs, args);

     

    foreach (Document dd in docs)

    {

     

    List<IAction> allowedUserOptions = GetUserActionsForNode(dd);

     

    if (CanUserAccessNode(dd, allowedUserOptions))

    {

     

    XmlTreeNode node = CreateNode(dd, allowedUserOptions);

    OnRenderNode(

    ref node, dd);

    OnBeforeNodeRender(

    ref Tree, ref node, EventArgs.Empty);

     

    if (node != null)

    {

    Tree.Add(node);

    OnAfterNodeRender(

    ref Tree, ref node, EventArgs.Empty);

    }

    }

    }

     

    //args = new TreeEventArgs(Tree);

    OnAfterTreeRender(docs, args);

    }

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Jun 30, 2010 @ 11:44
    Steen T√łttrup
    0

    If you have made you own custom tree class, base on BaseTree, all you need to do in the Render method of you tree class is:

     

           XmlTreeNode treeElement = XmlTreeNode.Create(this);

    treeElement.Menu.Clear();
    treeElement.Menu.Add(NewFolderAction.Instance);
    treeElement.Menu.Add(NewDocumentAction.Instance);

    tree.Add(treeElement);

    Where both NewFolderAction and NewDocumentAction are my own custom classes with the IAction interface.

     

  • Chris White 23 posts 43 karma points
    Jun 30, 2010 @ 14:21
    Chris White
    0

    Hi Richard,

    Yeah, if you could explain that in more detail in a blog post that would be extremely useful. Unfortunately I don't understand what you're getting at with the code snippet you posted - is that meant to go in my Render() method of my custom tree ?

    Thanks,

    Chris

  • Chris White 23 posts 43 karma points
    Jun 30, 2010 @ 14:22
    Chris White
    0

    Hi Steen,

    Thanks for the suggestion, but this doesn't appear to work . . .

    Regards,

    Chris

  • Chris White 23 posts 43 karma points
    Jun 30, 2010 @ 14:30
    Chris White
    0

    Hi all,

    Just to let you know I found a solution to this. You need to override the method in your custom tree as shown below:

    protected override void CreateAllowedActions(ref List<IAction> actions)

     

    {

    actions.Clear();

    actions.Add(TestAction.Instance);

     

     

    actions.Add(ActionDelete.Instance);

     

     

    actions.Add(ContextMenuSeperator.Instance);

     

     

    actions.Add(ActionRefresh.Instance);

      

    }

     

     

    Hopefully this will help someone else stuck with this. (Note: TestAction.Instance is my own custom action).

    Thanks,

    Chris

  • Richard Soeteman 3682 posts 11270 karma points MVP
    Jul 02, 2010 @ 10:20
    Richard Soeteman
    0

    I've written a blogpost regarding the Compatibilty issues between 4.0 and 4.5 which can cause the tree to break

    Cheers,

     

    Richard

  • Daniel Bardi 918 posts 2546 karma points
    Jan 15, 2011 @ 20:19
    Daniel Bardi
    0

    All my actions load fine, but the tree is not rendering... The Render method is never hit.

    What's happening to me.. I'm pulling my hair out.

    These are my CreateRootNode, CreateRootNodeActions, Render, and RenderJS methods:

    /// <summary> /// Creates the root node. /// </summary> /// <param name = "rootNode">The root node.</param> protected override void CreateRootNode(ref XmlTreeNode rootNode) { var userRootPath = FileManagerConfig.CurrentUserRootUrl; rootNode.Text = string.Format("Root - [ {0} ]", userRootPath); rootNode.Icon = Constants.FolderTreeIcon; rootNode.OpenIcon = Constants.FolderTreeIcon; rootNode.NodeType = "initFileman"; //TreeAlias; rootNode.NodeID = userRootPath; rootNode.Action = string.Format("javascript:viewFolder('{0}')", rootNode.NodeID); } /// <summary> /// Creates the root node actions. /// </summary> /// <param name = "actions">The actions.</param> protected override void CreateRootNodeActions(ref List<umbraco.interfaces.IAction> actions) { actions.AddRange(Menus.RootFolderMenu); actions.Add(ContextMenuSeperator.Instance); actions.Add(ActionRefresh.Instance); } /// <summary> /// Renders the specified tree. /// </summary> /// <param name = "tree">The tree.</param> public override void Render(ref XmlTree tree) { var rootDirectoryInfo = NodeKey == string.Empty ? new DirectoryInfo(FileManagerConfig.CurrentUserRootPath) : new DirectoryInfo(NodeKey); BuildFileManagerTree(rootDirectoryInfo, tree); } /// <summary> /// Renders the JavaScript to open file editor. /// </summary> /// <param name = "javascript">The javascript.</param> public override void RenderJS(ref StringBuilder javascript) { // Folder Viewer Function if (IsDialog) { javascript.Append(@" /* Node action to select folder */ function viewFolder(folder) { if (parent.opener) {parent.opener.dialogHandler(folder);} else {parent.dialogHandler(folder);} }"); } else { if (javascript.ToString() == "{}") { javascript = new StringBuilder(); } javascript.Append(@" /* File Node Actions - Generated from <filePages> in '~/config/fileManager.config' */"); var fileOpeners = FileManagerConfig.FileOpeners; foreach ( var value in from fileOpener in fileOpeners where fileOpener.Page != String.Empty select Util.GetJsFunction(fileOpener)) { javascript.AppendLine(value); } // Default File Function javascript.AppendFormat(@" /* Default File Node Action - Generated from <filePages> in 'fileManager.config' */ function {0}(file) {{ parent.right.document.location.href = '{1}/Pages/{2}?file=' + file; }}", FileManagerConfig.DefaultFileFunction, Constants.FileManagerGlobalUrl, FileManagerConfig.DefaultFilePage); javascript.AppendLine(); // Folder Viewer Function javascript.AppendFormat(@" /* Folder Node Action */ function viewFolder(folder) {{ parent.right.document.location.href = '{0}/Pages/FolderViewer.aspx?folder=' + folder; }}", Constants.FileManagerGlobalUrl); javascript.AppendLine(); // Umbraco Functions javascript.Append(@" /* Umbraco Node Actions - Used when <umbracoTrees> are enabled in 'fileManger.config' */ function openMedia(id) { parent.right.document.location.href = 'editMedia.aspx?id=' + id; } function openStylesheet(id) { parent.right.document.location.href = 'settings/stylesheet/editStylesheet.aspx?id=' + id; } function openTemplate(id) { parent.right.document.location.href = 'settings/editTemplate.aspx?templateID=' + id; } function openScriptEditor(file) { parent.right.document.location.href = 'settings/scripts/editScript.aspx?file=' + file; } function openPython(file) { parent.right.document.location.href = 'developer/python/editPython.aspx?file=' + file; } function openXslt(file) { parent.right.document.location.href = 'developer/xslt/editXslt.aspx?file=' + file; }"); } }

  • Daniel Bardi 918 posts 2546 karma points
    Jan 17, 2011 @ 17:50
    Daniel Bardi
    0

    Nevermind.. working now!

Please Sign in or register to post replies

Write your reply to:

Draft