Ejemplo n.º 1
0
        /// <summary>
        /// Render HTML ui element for web page structure.
        /// </summary>
        /// <param name="web">The parent web instance.</param>
        /// <param name="withAttributes"></param>
        /// <param name="showimg">Whether show image on the left of the node item.</param>
        /// <param name="ismenu">Show as menu</param>
        /// <param name="issitemap">Show as sitemap</param>
        /// <param name="htmlAttributes">The html attributes for output element.</param>
        /// <param name="dataType">The menu item filter:1:all pages. 2:root pages (the top level pages.) 3:show children pages</param>
        /// <returns></returns>
        public static HelperResult GetHtml(Web web = null, bool withAttributes = false, bool showimg = false, bool ismenu = false, bool issitemap = false, object htmlAttributes = null, int dataType = 1)
        {
            var _web = new WebDecorator(web == null ? AppModel.Get().Context.Web : web, AppModel.Get().DataContext);
            var locale = CurrentPage.Culture;// _web.DefaultLocale;
            var currentPage = AppModel.Get().CurrentPage;
            var currentID = currentPage != null ? currentPage.ID : 0;

            return new HelperResult(w =>
            {
                using (var writer = new HtmlTextWriter(w))
                {
                    var pages = _web.CachingPages.Where(p => p.Locale.Equals(locale, StringComparison.OrdinalIgnoreCase));
                    //IEnumerable<WebPage> pages = null;

                    if (ismenu)
                        pages = pages.Where(p => p.ShowInMenu);

                    if (issitemap)
                        pages = pages.Where(p => p.ShowInSitemap);

                    pages = pages.OrderBy(p => p.Pos).ToList();

                    var topPages = dataType == 3 ? pages.Where(p => p.ParentID == currentPage.ID) : pages.Where(p => p.ParentID == 0);

                    if (dataType == 4 && currentPage != null)
                    {
                        if (currentPage.ParentID == 0)
                            topPages = pages.Where(p => p.ParentID == currentPage.ID);
                        else
                            topPages = pages.Where(p => !string.IsNullOrEmpty(p.Path) && p.Path.Equals(currentPage.Path, StringComparison.OrdinalIgnoreCase));
                    }

                    if (topPages.Count() == 0)
                        return;

                    writer.WriteBeginTag("ul");
                    if (htmlAttributes != null)
                    {
                        var attrs = ObjectHelper.ConvertObjectToDictionary(htmlAttributes);
                        foreach (var attr in attrs)
                        {
                            var key = attr.Key;
                            if (key.StartsWith("data_"))
                                key = key.Replace("_", "-");

                            writer.WriteAttribute(key, attr.Value != null ? attr.Value.ToString() : "");
                        }
                    }
                    writer.Write(HtmlTextWriter.TagRightChar);

                    if (dataType == 3)
                    {
                        if (currentPage == null)
                        {
                            writer.WriteEndTag("ul");
                            return;
                        }
                        //pages = _web.Pages.Where(p => p.ParentID == currentPage.ID);
                    }

                    foreach (var p in topPages)
                    {
                        if (ismenu || issitemap)
                        {
                            if (!IsAccessibleToUser(p))
                                continue;
                        }

                        RenderNode(writer, p, pages, withAttributes, showimg, currentPage, dataType);
                    }

                    writer.WriteEndTag("ul");
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Render HTML ui element for web page structure.
        /// </summary>
        /// <param name="web">The parent web instance.</param>
        /// <param name="withAttributes"></param>
        /// <param name="showimg">Whether show image on the left of the node item.</param>
        /// <param name="ismenu">Show as menu</param>
        /// <param name="issitemap">Show as sitemap</param>
        /// <param name="htmlAttributes">The html attributes for output element.</param>
        /// <param name="dataType">The menu item filter:1:all pages. 2:root pages (the top level pages.) 3:show children pages</param>
        /// <returns></returns>
        public static HelperResult GetHtml(Web web = null, bool withAttributes = false, bool showimg = false, bool ismenu = false, bool issitemap = false, object htmlAttributes = null, int dataType = 1)
        {
            var _web        = new WebDecorator(web == null ? AppModel.Get().Context.Web : web, AppModel.Get().DataContext);
            var locale      = CurrentPage.Culture;// _web.DefaultLocale;
            var currentPage = AppModel.Get().CurrentPage;
            var currentID   = currentPage != null ? currentPage.ID : 0;

            return(new HelperResult(w =>
            {
                using (var writer = new HtmlTextWriter(w))
                {
                    var pages = _web.CachingPages.Where(p => p.Locale.Equals(locale, StringComparison.OrdinalIgnoreCase));
                    //IEnumerable<WebPage> pages = null;

                    if (ismenu)
                    {
                        pages = pages.Where(p => p.ShowInMenu);
                    }

                    if (issitemap)
                    {
                        pages = pages.Where(p => p.ShowInSitemap);
                    }

                    pages = pages.OrderBy(p => p.Pos).ToList();

                    var topPages = dataType == 3 ? pages.Where(p => p.ParentID == currentPage.ID) : pages.Where(p => p.ParentID == 0);

                    if (dataType == 4 && currentPage != null)
                    {
                        if (currentPage.ParentID == 0)
                        {
                            topPages = pages.Where(p => p.ParentID == currentPage.ID);
                        }
                        else
                        {
                            topPages = pages.Where(p => !string.IsNullOrEmpty(p.Path) && p.Path.Equals(currentPage.Path, StringComparison.OrdinalIgnoreCase));
                        }
                    }

                    if (topPages.Count() == 0)
                    {
                        return;
                    }

                    writer.WriteBeginTag("ul");
                    if (htmlAttributes != null)
                    {
                        var attrs = ObjectHelper.ConvertObjectToDictionary(htmlAttributes);
                        foreach (var attr in attrs)
                        {
                            var key = attr.Key;
                            if (key.StartsWith("data_"))
                            {
                                key = key.Replace("_", "-");
                            }

                            writer.WriteAttribute(key, attr.Value != null ? attr.Value.ToString() : "");
                        }
                    }
                    writer.Write(HtmlTextWriter.TagRightChar);

                    if (dataType == 3)
                    {
                        if (currentPage == null)
                        {
                            writer.WriteEndTag("ul");
                            return;
                        }
                        //pages = _web.Pages.Where(p => p.ParentID == currentPage.ID);
                    }

                    foreach (var p in topPages)
                    {
                        if (ismenu || issitemap)
                        {
                            if (!IsAccessibleToUser(p))
                            {
                                continue;
                            }
                        }

                        RenderNode(writer, p, pages, withAttributes, showimg, currentPage, dataType);
                    }

                    writer.WriteEndTag("ul");
                }
            }));
        }