Login

Username

Password





Register   Reset password

Get Cuyahoga at SourceForge.net. Fast, secure and Free Open Source software downloads

Forum

Welcome Guest Search | Active Topics | Members

Generating a menu starting at the children of node X Options
baldec
Posted: Tuesday, August 26, 2008 7:36:22 AM
Rank: Advanced Member
Groups: Member

Joined: 8/21/2008
Posts: 61
Points: 183
Hello, I have been looking for a way to create a sub menu starting at node Foo. Building a structure with several language sites and on each side there is the type X and type Y settings.

i.e.
Code:

Home
-- se
-- no
-- dk


Below each country we have pages A, B, C visible when at type X. Though when clicking to enter type Y settings the main menu should swap to the children nodes of page D.


i.e.
Code:

Home
* se
    - A
    - B
    - C
    - D
      * a
      * b
      * c
      * d
       


So the idea is that if youre in Type X you see

A B C D

And when youre in Type Y you see

a b c d


To show A B C D aint a problem. And when entering type Y another template is used that should call another menu. Though how do one show another menu in that fashion? Up until now I haven't noticed any way to manipulate HierarchicalMenu, NavigationLevelZeroOne or NavigationLevelTwo to do what it is I am asking it to do.

And the icing on the cake would be if one could get the sub menu to not show on node D, but show when entering the children of node D.

So, do I need to get to the drawing board and make something or is it possible to do with existing menu functionality?

And thank you happy
baldec
Posted: Tuesday, August 26, 2008 7:45:50 AM
Rank: Advanced Member
Groups: Member

Joined: 8/21/2008
Posts: 61
Points: 183
If I had put down the page to use the correct template I managed to get it to do as I please on the sub menu. Though I do get problems with the sidebar menu.

Any suggestions on how I can get the sub menu of a specifig page to show?

And yet again, thank you.
hobbis
Posted: Tuesday, August 26, 2008 11:33:59 PM

Rank: Advanced Member
Groups: Member

Joined: 12/11/2007
Posts: 89
Points: 267
Hello, I may have done done something similar but forgive me if I have misunderstood you. I did it in a control (or added to existing one) like this:

HeirarchicalMenu.ascx.cs

The only thing is, you have to know the node id of the root menu.


Code:

namespace Cuyahoga.Web.Templates.Controls
{
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Collections;

    using Cuyahoga.Core.Domain;
    using Cuyahoga.Web.UI;
    using Cuyahoga.Web.Util;

    public class HierarchicalMenu : System.Web.UI.UserControl
    {
        private Cuyahoga.Web.UI.PageEngine _page;
        protected System.Web.UI.WebControls.PlaceHolder plhNodes;

        protected string _NodeID;



        private void Page_Load(object sender, System.EventArgs e)
        {
            if (this.Page is PageEngine)
            {
                this._page = (PageEngine)this.Page;    
                //BuildNavigationTree();
                if (!String.IsNullOrEmpty(_NodeID))
                    BuildNavigationTreeFromSpecificNode(Int32.Parse(_NodeID));
            }
        }
        private void BuildNavigationTreeFromSpecificNode(int nodeID)
        {
            HtmlGenericControl mainList = new HtmlGenericControl("ul");

            Node specificNode = new Node();

            foreach (Node node in this._page.RootNode.ChildNodes)
            {
                if (node.Id == nodeID)
                {
                    specificNode = node;
                    break;
                }
            }

            //specificNode should be set
            if (specificNode != null)
            {
                if (specificNode.ShowInNavigation && specificNode.ViewAllowed(this._page.CuyahogaUser))
                {
                    //don't want specific node to appear, just it's children
                    //mainList.Controls.Add(BuildListItemFromNode(specificNode));
                }
                foreach (Node node in specificNode.ChildNodes)
                {
                    if (node.ShowInNavigation && node.ViewAllowed(this._page.CuyahogaUser))
                    {
                        HtmlControl listItem = BuildListItemFromNode(node);
                        if (node.Level <= this._page.ActiveNode.Level
                            && node.Id == this._page.ActiveNode.Trail[node.Level]
                            && node.ChildNodes.Count > 0)
                        {
                            listItem.Controls.Add(BuildListFromNodes(node.ChildNodes));
                        }
                        mainList.Controls.Add(listItem);
                    }
                }
                if (this._page.CuyahogaUser != null
                    && this._page.CuyahogaUser.HasPermission(AccessLevel.Administrator))
                {
                    HtmlGenericControl listItem = new HtmlGenericControl("li");
                    HyperLink hpl = new HyperLink();
                    hpl.NavigateUrl = this._page.ResolveUrl("~/Admin");
                    hpl.Text = "Admin";
                    listItem.Controls.Add(hpl);
                    mainList.Controls.Add(listItem);
                }
                this.plhNodes.Controls.Add(mainList);
            }
        }

        private void BuildNavigationTree()
        {
            HtmlGenericControl mainList = new HtmlGenericControl("ul");
           
            if (this._page.RootNode.ShowInNavigation && this._page.RootNode.ViewAllowed(this._page.CuyahogaUser))
            {
                mainList.Controls.Add(BuildListItemFromNode(this._page.RootNode));
            }
            foreach (Node node in this._page.RootNode.ChildNodes)
            {
                if (node.ShowInNavigation && node.ViewAllowed(this._page.CuyahogaUser))
                {
                    HtmlControl listItem = BuildListItemFromNode(node);
                    if (node.Level <= this._page.ActiveNode.Level
                        && node.Id == this._page.ActiveNode.Trail[node.Level]
                        && node.ChildNodes.Count > 0)
                    {
                        listItem.Controls.Add(BuildListFromNodes(node.ChildNodes));
                    }
                    mainList.Controls.Add(listItem);
                }
            }
            if (this._page.CuyahogaUser != null
                && this._page.CuyahogaUser.HasPermission(AccessLevel.Administrator))
            {
                HtmlGenericControl listItem = new HtmlGenericControl("li");
                HyperLink hpl = new HyperLink();
                hpl.NavigateUrl = this._page.ResolveUrl("~/Admin");
                hpl.Text = "Admin";
                listItem.Controls.Add(hpl);
                mainList.Controls.Add(listItem);
            }
            this.plhNodes.Controls.Add(mainList);
        }

        private HtmlControl BuildListItemFromNode(Node node)
        {
            HtmlGenericControl listItem = new HtmlGenericControl("li");
            HyperLink hpl = new HyperLink();
            hpl.NavigateUrl = UrlHelper.GetUrlFromNode(node);
            UrlHelper.SetHyperLinkTarget(hpl, node);
            hpl.Text = node.Title;

            if (node.Id == this._page.ActiveNode.Id)
            {
                hpl.CssClass = "selected";
            }

            if (node.Id == this._page.RootNode.Id)
            {
                hpl.CssClass = "home";
            }

            listItem.Controls.Add(hpl);
            return listItem;
        }

        private HtmlControl BuildListFromNodes(IList nodes)
        {
            HtmlGenericControl list = new HtmlGenericControl("ul");
            foreach (Node node in nodes)
            {
                if (node.ViewAllowed(this._page.CuyahogaUser) && node.ShowInNavigation)
                {
                    HtmlControl listItem = BuildListItemFromNode(node);
                    if (node.Level <= this._page.ActiveNode.Level
                        && node.Id == this._page.ActiveNode.Trail[node.Level]
                        && node.ChildNodes.Count > 0)
                    {
                        listItem.Controls.Add(BuildListFromNodes(node.ChildNodes));
                    }
                    list.Controls.Add(listItem);
                }
            }
            return list;
        }

        public string NodeID
        {
            get { return _NodeID; }
            set { _NodeID = value; }
        }

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }
        
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }
    }
}



Web Developer, Kent - Coolbytes
baldec
Posted: Wednesday, August 27, 2008 12:10:40 AM
Rank: Advanced Member
Groups: Member

Joined: 8/21/2008
Posts: 61
Points: 183
Thank you, that looks interesting. Will see if the module named Menu that I managed to find will do the trick. If not I'll take a further look at your suggestion.
hobbis
Posted: Monday, September 1, 2008 3:50:23 AM

Rank: Advanced Member
Groups: Member

Joined: 12/11/2007
Posts: 89
Points: 267
Let me know how you get on, because my way is a bit of a hack really.

Web Developer, Kent - Coolbytes
baldec
Posted: Wednesday, September 3, 2008 7:01:47 AM
Rank: Advanced Member
Groups: Member

Joined: 8/21/2008
Posts: 61
Points: 183
http://wiki.cuyahoga-project.org/(S(cezpnp55u4frocalo3opgr55))/CuyahogaModulesMenu.ashx

is the menu module that I am using. It fulfills my purpose, though it shows a breadcrumb trail if you have to many levels on it. Though since I am onlu interested in one level below the chosen node I aint running into any problems there.

So I haven't looked further into the menu things since then. Noticed that I could get it to do what I wanted and then I dropped the issue of making something precisely as I want, atleast for now.
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

Yet Another Forum.net version 1.9.0 running under Cuyahoga.
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.