Example #1
0
        /// <summary>
        /// Searches and returns the menu with the specified search patern
        /// Will search in Names and URLs
        /// </summary>
        /// <param name="search">Search Keyword</param>
        /// <returns>The found menu or null</returns>
        public lwMenu GetMenu(string search)
        {
            if (search == null)
            {
                return(null);
            }
            if (search == "")
            {
                return(this);
            }
            lwMenu ret = this.Children.Find(m => m.Name.Contains(search) ||
                                            m.url.ToLower().Contains(search));

            if (ret == null)
            {
                foreach (lwMenu child in this.Children)
                {
                    lwMenu temp = child.GetMenu(search);
                    if (temp != null)
                    {
                        return(temp);
                    }
                }
            }

            return(ret);
        }
Example #2
0
        /// <summary>
        /// Adds a child to the menu
        /// </summary>
        /// <param name="menuName">The name of the child</param>
        /// <returns>The created menu</returns>
        public lwMenu AddChild(string menuName)
        {
            lwMenu m = new lwMenu(menuName, StringUtils.ToURL(menuName));

            AddChild(m);
            return(m);
        }
Example #3
0
        /// <summary>
        /// Adds a child to the menu
        /// </summary>
        /// <param name="menuName">The name of the child</param>
        /// <param name="url">the URL</param>
        /// <returns>The created menu</returns>
        public lwMenu AddChild(string menuName, string url)
        {
            lwMenu m = new lwMenu(menuName, url);

            AddChild(m);
            return(m);
        }
Example #4
0
 /// <summary>
 /// Adds a child to the menu
 /// </summary>
 /// <param name="m">The added menu</param>
 /// <returns>The created menu</returns>
 public lwMenu AddChild(lwMenu m)
 {
     this.Children.Add(m);
     m.IndexFromParent[this.Name] = this.Children.Count - 1;
     m.Parents.Add(this);
     return(m);
 }
Example #5
0
        /// <summary>
        /// Adds a child to the menu
        /// </summary>
        /// <param name="menuName">The name of the child</param>
        /// <param name="url">the URL</param>
        /// <param name="id">the ID</param>
        /// <returns>The created menu</returns>
        public lwMenu AddChild(string menuName, string url, int id)
        {
            lwMenu m = new lwMenu(menuName, url);

            m.id       = id;
            m.parentId = this.id;
            AddChild(m);
            return(m);
        }
Example #6
0
        public lwMenu AddChild(string menuName, string url, int id, bool secure)
        {
            lwMenu m = new lwMenu(menuName, url);

            m.id       = id;
            m.parentId = this.id;
            m.IsSecure = secure;
            AddChild(m);
            return(m);
        }
Example #7
0
        /// <summary>
        /// Returns the Previous menu
        /// </summary>
        /// <returns>the Previous menu</returns>
        public lwMenu PrevMenu()
        {
            lwMenu p = Parents[0];
            int    i = IndexFromParent[p.Name];

            i--;

            if (i < 0)
            {
                return(null);
            }
            return(p.Children[i]);
        }
Example #8
0
        /// <summary>
        /// Returns the Next Menu
        /// </summary>
        /// <returns>the next menu</returns>
        public lwMenu NextMenu()
        {
            lwMenu p = Parents[0];
            int    i = IndexFromParent[p.Name];

            i++;

            if (i >= p.Children.Count)
            {
                return(null);
            }
            return(p.Children[i]);
        }
Example #9
0
        public string GetKey(bool renderChildren, string tag)
        {
            string ret = this.url + this.Name + renderChildren.ToString() + tag;
            lwMenu m   = this;

            while (m.Parents.Count > 0)
            {
                if (ret.IndexOf("~") == 0)
                {
                    break;
                }
                ret = m.Parents[0].url + "/" + ret;
                m   = m.Parents[0];
            }
            return(ret);
        }
Example #10
0
        public string GetHistory(string sep, MenuDirection menuDirection)
        {
            string key = GetKey(false, "") + "-h";

            if (WebContext.Cache[key] != null)
            {
                return(WebContext.Cache[key].ToString());
            }

            StringBuilder ret = new StringBuilder();

            Regex re = new Regex("&reg;|®", RegexOptions.IgnoreCase);

            ret.Append(re.Replace(this.DisplayName, "<sup>&reg;</sup>"));
            if (menuDirection == MenuDirection.LTR)
            {
                ret.Insert(0, sep);
            }
            else
            {
                ret.Append(sep);
            }

            lwMenu m = this;

            while (m.Parents.Count > 0)
            {
                m = m.Parents[0];
                if (m.IsRoot)
                {
                    break;
                }
                if (menuDirection == MenuDirection.LTR)
                {
                    ret.Insert(0, m.GetLink());
                    ret.Insert(0, sep);
                }
                else
                {
                    ret.Append(m.GetLink());
                    ret.Append(sep);
                }
            }

            if (menuDirection == MenuDirection.LTR)
            {
                ret.Remove(0, sep.Length);
            }
            else
            {
                ret.Remove(ret.Length - sep.Length, sep.Length);
            }

            WebContext.Cache.Insert(
                key,
                ret.ToString(),
                new System.Web.Caching.CacheDependency(WebContext.Server.MapPath("~/App_Code/__Page.cs"))
                );

            return(ret.ToString());
        }
Example #11
0
        /// <summary>
        /// Generates the html that will render the menu
        /// </summary>
        /// <param name="tag">the tag used to render each menu item, can be li, span, div...</param>
        /// <param name="includeParentLink">Include the link of the parent when generating the link hierarchy
        /// this will not override the original property IncludeParentLink
        /// </param>
        /// <param name="renderChildren">flag to render children or not</param>
        /// <param name="childrenParentTag">The tag container for the children can be ul or div or ol...</param>
        /// <param name="childrenTag">the tag used to render each menu item, can be li, span, div...</param>
        /// <returns>HTML String</returns>
        public string ToString(string tag, bool includeParentLink, bool renderChildren, string childrenContainerTag, string childrenTag)
        {
            //TODO: fix caching by creating a unique key
            //Testing unique key from url
            //TODO: destroy cach when any related item is changed
            //It can be done by running through the cach's and destroying any related news or category
            //Another problem is to not cach the non-direct calls

            //string key = GetKey(renderChildren, tag);
            //if (WebContext.Cache[CachKey] != null)
            //	return WebContext.Cache[CachKey].ToString();

            bool   hasOneItem = false;
            string _ret       = "";

            try
            {
                //_lock.AcquireWriterLock(-1);

                if (!CanRender)
                {
                    return("");
                }

                if (_renderChildren != null)
                {
                    renderChildren = _renderChildren.Value;
                }

                StringBuilder ret = new StringBuilder();

                int?col = null;
                if (BreakAt != null)
                {
                    col = 0;
                }


                if (renderChildren)
                {
                    if (!String.IsNullOrWhiteSpace(SubPlaceHolder))
                    {
                        ret.Append("<" + SubPlaceHolder + ">");
                    }

                    if (!String.IsNullOrWhiteSpace(ContainerTag))
                    {
                        if (ContainerTag.ToLower() == "ol")
                        {
                            ClassName = "dd-list";
                        }
                        ret.Append("<" + ContainerTag + " start=\"1\" class=\"first" + (!String.IsNullOrEmpty(ClassName) ? " " + ClassName : "") + "\">");
                    }
                    for (int i = 0; i < Children.Count; i++)
                    {
                        lwMenu m = Children[i];
                        if (!m.CanRender)
                        {
                            continue;
                        }

                        hasOneItem = true;


                        //TODO: check first and last depending on visible items and not only on count.

                        string _class = m.Current ? " current" : "";
                        if (i == 0)
                        {
                            _class += " first";
                        }
                        if (i == Children.Count - 1)
                        {
                            _class += " last";
                        }

                        _class += " " + StringUtils.ToURL(m.url.Replace(".aspx", ""));

                        if (!String.IsNullOrWhiteSpace(m.ClassName))
                        {
                            _class = _class.Trim() + " " + m.ClassName;
                        }

                        if (_class != "")
                        {
                            _class = " class=\"" + _class.Trim() +
                                     (tag.ToLower().IndexOf("li") >= 0 && _class.Trim().IndexOf("dd-item") < 0 ? " dd-item" : "") + "\"";
                        }

                        string _children = "";
                        if (renderChildren && m.Children.Count > 0)
                        {
                            _children = m.ToString(childrenTag, includeParentLink, renderChildren, childrenContainerTag);
                            if (!String.IsNullOrEmpty(childrenContainerTag))
                            {
                                _children = _children != "" ? string.Format("<{0}>{1}</{0}>", childrenContainerTag, _children) : "";
                            }
                        }
                        ret.Append(String.Format(
                                       "<{0}{3}{4}>{1}{2}</{0}>",
                                       tag,
                                       m.GetLink(),
                                       _children,
                                       _class,
                                       (tag.ToLower().IndexOf("li") >= 0 ? " data-root=\"" + m.IsRoot + (m.id > 0 ? "\" data-id=\"" + m.id : "")
                                        + "\" data-parent=\"" + (m.parentId.HasValue && m.parentId.Value > 0 ? m.parentId.Value : -1) + "\"" : ""))
                                   );

                        if (BreakAt != null)
                        {
                            if (i > 0 && (i + 1) % BreakAt == 0 && i < Children.Count - 1 && !String.IsNullOrWhiteSpace(ContainerTag))
                            {
                                ret.Append(string.Format("</{0}><{0} start=\"{1}\"{2}>",
                                                         ContainerTag,
                                                         this.BreakAt + i,
                                                         i + BreakAt >= Children.Count - 1 ? " class=\"last\"" : ""));
                            }
                        }
                    }
                    ret.Append("</" + ContainerTag + ">");
                    if (!String.IsNullOrWhiteSpace(SubPlaceHolder))
                    {
                        ret.Append("</" + SubPlaceHolder + ">");
                    }
                }



                _ret = ret.ToString();

                //TODO: fix this after fixing the key

                /*
                 * WebContext.Cache.Insert(
                 *      CachKey,
                 *      _ret,
                 *      new System.Web.Caching.CacheDependency(WebContext.Server.MapPath("~/App_Code/Menu.cs"))
                 * );
                 * */
            }
            finally
            {
                //_lock.ReleaseWriterLock();
            }
            return(hasOneItem ? _ret : "");
        }