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 ??
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
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
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 ?
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.
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
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 ?
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
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
CompaitibiltyHelper class
Hope this helps you,
Richard
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
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
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
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
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:
Where both NewFolderAction and NewDocumentAction are my own custom classes with the IAction interface.
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
Hi Steen,
Thanks for the suggestion, but this doesn't appear to work . . .
Regards,
Chris
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:
Hopefully this will help someone else stuck with this. (Note: TestAction.Instance is my own custom action).
Thanks,
Chris
I've written a blogpost regarding the Compatibilty issues between 4.0 and 4.5 which can cause the tree to break
Cheers,
Richard
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; }"); } }
Nevermind.. working now!
is working on a reply...