示例#1
0
        //private IEnumerable SerializeItems(IList<TreeViewItem> items)
        //{
        //    Dictionary<string, object> jsonData = new Dictionary<string, object>();
        //    if (this.Items.Any())
        //    {

        //        TreeViewItem.SetItemsTreeToJson(jsonData, this.Items);
        //        jsonData["items"] = this.Items;
        //    }
        //    return jsonData;
        //}

        protected override void WriteHtml(HtmlTextWriter writer)
        {
            var builder = new TreeViewHtmlBuilder(this);

            IHtmlNode treeViewTag = builder.TreeViewTag();

            if (Items.Any())
            {
                if (SelectedIndex != -1 && Items.Count < SelectedIndex)
                {
                    throw new ArgumentOutOfRangeException("شاخص خارج از محدوده داده های موجود است");
                }

                //this loop is required because of SelectedIndex feature.
                //if (HighlightPath)
                //{
                //    Items.Each(HighlightSelectedItem);
                //}

                Items.Each((item, index) =>
                {
                    if (!this.HighlightPath)
                    {
                        if (index == this.SelectedIndex)
                        {
                            item.Selected = true;

                            if (item.Items.Any() || item.Template.HasValue())
                            {
                                item.Expanded = true;
                            }
                        }
                    }

                    if (item.HasChildren)
                    {
                        item.Expanded = false;
                    }

                    if (ExpandAll)
                    {
                        ExpandAllChildrens(item);
                    }

                    if (string.IsNullOrEmpty(item.Id))
                    {
                        item.Id = item.Text;
                    }

                    WriteItem(item, treeViewTag.Children[0], builder);
                });
            }

            treeViewTag.WriteTo(writer);

            base.WriteHtml(writer);
        }
示例#2
0
        private void WriteItem(TreeViewItem item, IHtmlNode parentTag, TreeViewHtmlBuilder builder)
        {
            //if (ItemAction != null)
            //{
            //    ItemAction(item);
            //}
            if (item.Visible)
            {
                var accessible = true;
                //if (this.SecurityTrimming.Enabled)
                //{
                //    accessible = item.IsAccessible(Authorization, ViewContext);
                //}


                //if (accessible)
                //{
                //    var hasAccessibleChildren = item.Items.Any(x => x.Visible);
                //    if (hasAccessibleChildren && this.SecurityTrimming.Enabled)
                //    {
                //        hasAccessibleChildren = item.Items.IsAccessible(Authorization, ViewContext);

                //        if (this.SecurityTrimming.HideParent && !hasAccessibleChildren)
                //        {
                //            return;
                //        }
                //    }
                if (accessible)
                {
                    var hasAccessibleChildren = item.Items.Any(x => x.Visible);
                    if (!hasAccessibleChildren)
                    {
                        return;
                    }


                    IHtmlNode itemTag = builder.ItemTag(item, hasAccessibleChildren).AppendTo(parentTag);

                    builder.ItemInnerContent(item).AppendTo(itemTag.Children[0]);

                    if (item.Template.HasValue())
                    {
                        builder.ItemContentTag(item).AppendTo(itemTag);
                    }
                    else if (hasAccessibleChildren)
                    {
                        IHtmlNode ul = builder.ChildrenTag(item).AppendTo(itemTag);

                        item.Items.Each(child => WriteItem(child, ul, builder));
                    }
                }
            }
        }