Beispiel #1
0
        private void AddControlsRecursive(Control container, IHierarchyNavigator <ContentItem> ih, ContentItem selectedPage, IEnumerable <ContentItem> ancestors)
        {
            foreach (ItemHierarchyNavigator childHierarchy in ih.Children)
            {
                if (!childHierarchy.Current.IsPage)
                {
                    continue;
                }

                ContentItem current = childHierarchy.Current;

                string _cssClass =
                    current == selectedPage ||
                    string.Equals(current.Url, selectedPage.Url, StringComparison.OrdinalIgnoreCase)
                        ? "current"
                        : Contains(ancestors, current)
                            ? "trail"
                            : string.Empty;

                HtmlGenericControl li = CreateAndAdd(container, "li", _cssClass);

                if (UseMenuIdentifiers)
                {
                    string name = Regex.Replace(current.Name, "[^_0-1a-z]", "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    if (!addedControls.ContainsKey(name))
                    {
                        addedControls[current.Name] = li;
                        li.Attributes["id"]         = MenuIdentifierPrefix + name;
                    }
                }

                li.Controls.Add(N2.Web.Link.To(current).ToControl());

                HtmlGenericControl ul = new HtmlGenericControl("ul");
                AddControlsRecursive(ul, childHierarchy, selectedPage, ancestors);
                if (ul.Controls.Count > 0)
                {
                    li.Controls.Add(ul);
                }
            }
        }
Beispiel #2
0
        private void AddControlsRecursive(Control container, IHierarchyNavigator<ContentItem> ih, ContentItem selectedPage, IEnumerable<ContentItem> ancestors)
        {
            foreach (ItemHierarchyNavigator childHierarchy in ih.Children)
            {
                if (!childHierarchy.Current.IsPage)
                    continue;

                ContentItem current = childHierarchy.Current;

                string _cssClass =
                    current == selectedPage
                    || string.Equals(current.Url, selectedPage.Url, StringComparison.OrdinalIgnoreCase)
                        ? "current"
                        : Contains(ancestors, current)
                          	? "trail"
                          	: string.Empty;

                HtmlGenericControl li = CreateAndAdd(container, "li", _cssClass);

                if (UseMenuIdentifiers)
                {
                    string name = Regex.Replace(current.Name, "[^_0-1a-z]", "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    if(!addedControls.ContainsKey(name))
                    {
                        addedControls[current.Name] = li;
                        li.Attributes["id"] = MenuIdentifierPrefix + name;
                    }
                }

                li.Controls.Add(N2.Web.Link.To(current).ToControl());

                HtmlGenericControl ul = new HtmlGenericControl("ul");
                AddControlsRecursive(ul, childHierarchy, selectedPage, ancestors);
                if (ul.Controls.Count > 0)
                    li.Controls.Add(ul);
            }
        }
Beispiel #3
0
        private static TreeNodeBase BuildNodesRecursive(IHierarchyNavigator<ContentItem> navigator, bool rootOnly, bool withLinks,
			Func<IEnumerable<ContentItem>, IEnumerable<ContentItem>> filter)
        {
            ContentItem item = navigator.Current;

            ContentItem translatedItem;
            TranslationStatus translationStatus = GetTranslationStatus(item, out translatedItem);

            var itemChildren = item.GetChildren();
            if (filter != null)
                itemChildren = filter(itemChildren);
            bool hasAsyncChildren = ((!navigator.Children.Any() && itemChildren.Any()) || rootOnly);
            TreeNodeBase node = (hasAsyncChildren) ? new AsyncTreeNode() as TreeNodeBase : new TreeNode();
            node.Text = ((INode) translatedItem).Contents;

            if (translationStatus == TranslationStatus.NotAvailableInSelectedLanguage || translationStatus == TranslationStatus.DisplayedInAnotherLanguage)
            {
                node.Text += "&nbsp;";
                switch (translationStatus)
                {
                    case TranslationStatus.NotAvailableInSelectedLanguage:
                        node.Text += "<img src='" + WebResourceUtility.GetUrl(typeof(SiteTree), "Zeus.Admin.Assets.Images.Icons.LanguageMissing.gif") + "' title='Page is missing for the current language and will not be displayed.' />";
                        break;
                    case TranslationStatus.DisplayedInAnotherLanguage:
                        Language language = Context.Current.LanguageManager.GetLanguage(translatedItem.Language);
                        node.Text += "<img src='" + language.IconUrl + "' title='Page is displayed in another language (" + language.Title + ").' />";
                        break;
                }
            }

            node.IconFile = item.IconUrl;
            node.IconCls = "zeus-tree-icon";
            node.Cls = "zeus-tree-node";
            if (translationStatus == TranslationStatus.NotAvailableInSelectedLanguage)
                node.Cls += " notAvailableInSelectedLanguage";
            node.NodeID = item.ID.ToString();
            if (withLinks)
            {
                // Allow plugin to set the href (it will be based on whatever is the default context menu plugin).
                foreach (ITreePlugin treePlugin in Context.Current.ResolveAll<ITreePlugin>())
                    treePlugin.ModifyTreeNode(node, item);
            }

            if (!hasAsyncChildren)
            {
                // Allow for grouping of child items into folders.
                var folderGroups = navigator.Children
                    .Select(ci => ci.Current.FolderPlacementGroup)
                    .Where(s => s != null)
                    .Distinct();

                int uniqueCount = 0;
                foreach (string folderGroup in folderGroups)
                {
                    uniqueCount += 100000;
                    TreeNode folderNode = new TreeNode
                    {
                        Text = folderGroup,
                        IconFile = Utility.GetCooliteIconUrl(Icon.FolderGo),
                        Cls = "zeus-tree-node",
                        Expanded = false,
                        NodeID = (-1 * (Int32.Parse(node.NodeID) + uniqueCount)).ToString()
                    };

                    ((TreeNode) node).Nodes.Add(folderNode);
                    foreach (IHierarchyNavigator<ContentItem> childNavigator in navigator.Children.Where(n => n.Current.FolderPlacementGroup == folderGroup))
                    {
                        TreeNodeBase childNode = BuildNodesRecursive(childNavigator, rootOnly, withLinks, filter);
                        folderNode.Nodes.Add(childNode);
                    }
                }
                foreach (IHierarchyNavigator<ContentItem> childNavigator in navigator.Children.Where(n => n.Current.FolderPlacementGroup == null))
                {
                    TreeNodeBase childNode = BuildNodesRecursive(childNavigator, rootOnly, withLinks, filter);
                    ((TreeNode) node).Nodes.Add(childNode);
                }
            }
            if (!itemChildren.Any())
            {
                node.CustomAttributes.Add(new ConfigItem("children", "[]", ParameterMode.Raw));
                node.Expanded = true;
            }
            else if (navigator.Children.Any())
                node.Expanded = true;
            return node;
        }