Copied to clipboard

Flag this post as spam?

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


  • Dave 14 posts 35 karma points
    Sep 04, 2014 @ 23:57
    Dave
    0

    Tree Node Javascript Action Not Fired

    I am testing version 7 again to see where it is at! As a .NET MVC developer I want to be able to create a custom section, add a tree, populate it with some nodes and render a hello world page in the back office by hitting an MVC ontroller and then rendering an MVC view. After some digging it seems like this should be possible and that I can still use the legacy tree approach and trigger a JavaScript method to fire a controller method.

    In order to make life easier i have created a balnk VS solution and added umbraco 7 and then my own MVC project, I have attached build events to place the files in the correct locations within the Umbraco project once it compiles.

    The object behind this approach is that in my real world projects my bespoke sections within Umbraco contain complex displays of data from custom database tables and require extensive processing of business logic, by separating the project and having a traditional MVC project compile the DLL's, Views etc into umbraco it offers me a native .NEt environment from within visual studio to develop custom functionality, this is exactly how i work with version 6 and it works very well.

    In version 7 I have created a custom section and then a test tree with a sample node using the version 6 approach, this works fine and renders in the CMS. 

    My issue is that when clicking the node the action on the node attempts to route via Angular, ignoring the RenderJS section of my tree.

            public override void Render(ref XmlTree tree)
            {
                var node = XmlTreeNode.Create(this);
                node.NodeID = "0";
                node.NodeType = TreeAlias;
                node.Text = "meh";
                node.Action = string.Format("javascript:openTestPage ({0});", 0);
                node.Icon = "icon-box";
                node.OpenIcon = "icon-box";
                node.HasChildren = false;
                OnBeforeNodeRender(ref tree, ref node, EventArgs.Empty);
                if (node != null)
                {
                    tree.Add(node);
                    OnAfterNodeRender(ref tree, ref node, EventArgs.Empty);
                }
            }

            public override void RenderJS(ref System.Text.StringBuilder Javascript)
            {
                Javascript.Append(
                        @"function openTestPage (id) {
                     UmbClientMgr.contentFrame('../App_Plugins/WatBespokes/Views/Sample/Index);} ");
            }

    The above produces an error when clicking the node.

    Error evaluating js callback from legacy tree node: ReferenceError: openTestPage is not defined 

    The error is raised by angular.js

    Can anybody explain what I am missing? I thought it might be a routing issue at first so I added a route config file and manually placed the route in there with no luck, so any ideas are welcome! 

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Sep 11, 2014 @ 17:04
    David Brendel
    0

    Hi Dave,

    in my opinion you should create the trees in the legacy way in v7. You should use the normal/new way of doing it. Using a TreeController and AngularJS for routing to the correct view, loading and displaying your stuff.

    Don't think that the legacy way is a good approach here and don't think that it will work.

    David 

Please Sign in or register to post replies

Write your reply to:

Draft