Ejemplo n.º 1
0
        private void WriteChildren(TextWriter writer, HierarchyNode <ContentItem> parent, bool renderUl)
        {
            IDisposable wrapper = null;

            foreach (var child in parent.Children)
            {
                if (!filter.Match(child.Current))
                {
                    continue;
                }

                if (renderUl && wrapper == null)
                {
                    wrapper = TagWrapper.Begin("ul", child, tagModifier, writer);
                }

                using (TagWrapper.Begin("li", child, tagModifier, writer))
                {
                    linkWriter(child, writer);
                    WriteChildren(writer, child, true);
                }
            }

            if (wrapper != null)
            {
                wrapper.Dispose();
            }
        }
Ejemplo n.º 2
0
        internal static IDisposable GetEditableWrapper(ContentItem item, bool isEditable, string propertyName, IDisplayable displayable, TextWriter writer)
        {
            var viewEditable    = displayable as IViewEditable;
            var contentEditable = displayable as IContentEditable;
            var cssClass        = contentEditable != null?contentEditable.GetEditorCssClass() : "editable"; /*+ " " + displayable.GetType().Name + " Editable" + propertyName*/

            if (isEditable && item != null && displayable != null && (viewEditable == null || viewEditable.IsViewEditable))
            {
                var id = (item.ID != 0) ? item.ID : item.VersionOf.ID.GetValueOrDefault(0);
                var rv = new RouteValueDictionary
                {
                    { "id", string.Format("{0}.{1}.{2}", displayable.GetType().Name, id, propertyName) },       // provide unique ID
                    { "data-id", id },
                    { "data-property", propertyName },
                    { "class", cssClass },
                    { "title", (displayable is IEditable) ? (displayable as IEditable).Title : displayable.Name }
                };

                // same logic as in DroppableZoneHelper.RenderTemplate
                if (item.ID != 0 && !item.VersionOf.HasValue)
                {
                    rv[PartUtilities.PathAttribute] = item.Path;
                }
                else
                {
                    var page = Find.ClosestPage(item);
                    rv[PartUtilities.PathAttribute] = page.Path;
                    rv["data-versionIndex"]         = page.VersionIndex.ToString();
                    rv["data-versionKey"]           = item.GetVersionKey();
                }

                return(TagWrapper.Begin("div", writer, rv));
            }
            return(new EmptyDisposable());
        }
Ejemplo n.º 3
0
        internal static IDisposable GetEditableWrapper(ContentItem item, bool isEditable, string propertyName, IDisplayable displayable, TextWriter writer)
        {
            var viewEditable = displayable as IViewEditable;

            if (isEditable && (viewEditable == null || viewEditable.IsViewEditable) && item != null && displayable != null)
            {
                return(TagWrapper.Begin("div", writer, htmlAttributes: new RouteValueDictionary {
                    { "data-id", item.ID }, { "data-path", item.Path }, { "data-property", propertyName }, { "data-displayable", displayable.GetType().Name }, { "data-versionIndex", item.VersionIndex }, { "data-versionKey", item.GetVersionKey() }, { "class", "editable " + displayable.GetType().Name + " Editable" + propertyName }, { "title", (displayable is IEditable) ? (displayable as IEditable).Title : displayable.Name }
                }));
            }
            else
            {
                return(new EmptyDisposable());
            }
        }
Ejemplo n.º 4
0
        public void WriteTo(TextWriter writer)
        {
            var root = hierarchy.Build();

            if (excludeRoot || root.Current == null)
            {
                WriteChildren(writer, root, !excludeRoot);
            }
            else
            {
                using (TagWrapper.Begin("ul", root, tagModifier, writer))
                {
                    using (TagWrapper.Begin("li", root, tagModifier, writer))
                    {
                        linkWriter(root, writer);
                        WriteChildren(writer, root, !excludeRoot);
                    }
                }
            }
        }