public static HelperResult DraftIcon(this HtmlHelper html, ContentDataItemDecorator dataItem) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { if (!dataItem.IsPublished) { writer.WriteBeginTag("span"); writer.WriteAttribute("title", "Draft"); writer.WriteAttribute("class", "d-icon d-icon-draft"); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEndTag("span"); } } }); }
public static HelperResult AttachIcon(this HtmlHelper html, ContentDataItemDecorator dataItem) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { if (dataItem.HasAttachments) { var url = new UrlHelper(html.ViewContext.RequestContext); writer.WriteBeginTag("a"); writer.WriteAttribute("href", url.Content(dataItem) + "#attachments"); writer.WriteAttribute("class", "d-icon d-icon-attach"); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEndTag("a"); } } }); }
public static HelperResult NewStatus(this HtmlHelper html, ContentDataItemDecorator dataItem) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { if (dataItem.IsNew) { writer.WriteBeginTag("sup"); //writer.WriteAttribute("for", field.ClientID); writer.Write(HtmlTextWriter.TagRightChar); writer.Write("new"); //writer.WriteEncodedText(field.Title); writer.WriteEndTag("sup"); } } }); }
public static HelperResult ModerateStatus(this HtmlHelper html, ContentDataItemDecorator dataItem) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { writer.WriteBeginTag("span"); writer.Write(HtmlTextWriter.TagRightChar); if (dataItem.IsPublished) { if (dataItem.Parent.IsModerated) { var state = (ModerateStates)dataItem.ModerateState; switch (state) { case ModerateStates.Pending: writer.Write("Pending review"); break; case ModerateStates.Rejected: writer.Write("Rejected"); break; default: writer.Write("Published"); break; } } else writer.Write("Published"); } else writer.Write("Draft"); writer.WriteEndTag("span"); } }); }
/// <summary> /// Render html element for specified field object. /// </summary> /// <param name="html">The html helper object.</param> /// <param name="field">The field object</param> /// <returns></returns> public static HelperResult Label(this HtmlHelper html, ContentField field) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { try { writer.WriteBeginTag("label"); writer.WriteAttribute("for", field.ClientID); writer.Write(HtmlTextWriter.TagRightChar); if (!string.IsNullOrEmpty(field.Title)) writer.WriteEncodedText(field.Title); else writer.WriteEncodedText(field.Name); writer.WriteEndTag("label"); } catch { } } }); }
/// <summary> /// Render hidden input element for field value. /// </summary> /// <param name="html">The html helper object.</param> /// <param name="field">The field object</param> /// <param name="value">the field value</param> /// <returns></returns> public static HelperResult Hidden(this HtmlHelper html, ContentField field, object value = null) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { writer.WriteBeginTag("input"); writer.WriteAttribute("type", "hidden"); writer.WriteAttribute("id", field.ClientID); writer.WriteAttribute("name", field.Name); if (value != null) { writer.WriteAttribute("value", value.ToString()); } else { if (field.DefaultValue != null) writer.WriteAttribute("value", field.DefaultValue.ToString()); } writer.Write(HtmlTextWriter.SelfClosingTagEnd); } }); }
/// <summary> /// Render validation HTML elements for specified field object. /// </summary> /// <param name="html">The html helper object.</param> /// <param name="field">The field object.</param> /// <returns></returns> public static HelperResult ValidationMessage(this HtmlHelper html, ContentField field) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { writer.WriteBeginTag("span"); writer.WriteAttribute("class", "d-field-val-msg d-valmsg"); writer.WriteAttribute("data-valmsg-for", field.Name); writer.WriteAttribute("data-valmsg-replace", "true"); writer.Write(HtmlTextWriter.TagRightChar); //writer.WriteEncodedText(field.Description); writer.WriteEndTag("span"); } }); }
/// <summary> /// Render the tags element for specified data item. /// </summary> /// <param name="helper">The html helper object.</param> /// <param name="dataItem">The data item instance.</param> /// <returns></returns> public static HelperResult Tags(this HtmlHelper helper, ContentDataItem dataItem) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { if (!string.IsNullOrEmpty(dataItem.Tags)) { writer.WriteBeginTag("input"); writer.WriteAttribute("data-role", "tags"); writer.WriteAttribute("readonly", "readonly"); writer.WriteAttribute("value", dataItem.Tags); writer.Write(Html32TextWriter.SelfClosingTagEnd); } } }); }
/// <summary> /// Render field description text for specified field object. /// </summary> /// <param name="html">The html helper object.</param> /// <param name="field">The field object.</param> /// <returns></returns> public static HelperResult Notes(this HtmlHelper html, ContentField field) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { if (!string.IsNullOrEmpty(field.Description)) { writer.WriteBeginTag("small"); //writer.WriteAttribute("class", "d-field-notes d-notes"); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEncodedText(field.Description); writer.WriteEndTag("small"); } } }); }
/// <summary> /// Render an items tree for specified list /// </summary> /// <param name="list">The content list object</param> /// <param name="current">The content data item object.</param> /// <param name="htmlAttributes">The html attributes object.</param> /// <returns></returns> public static HelperResult Tree(ContentListDecorator list, ContentDataItemDecorator current = null, object htmlAttributes = null) { return new HelperResult((w) => { using (var writer = new Html32TextWriter(w)) { writer.WriteBeginTag("ul"); writer.WriteAttribute("data-role", "tree"); if (htmlAttributes != null) { var dict = htmlAttributes.ToDictionary(); foreach (var key in dict.Keys) { if (key.StartsWith("data_")) writer.WriteAttribute(key.Replace("_", "-"), (string)dict[key]); else writer.WriteAttribute(key, (string)dict[key]); } } writer.Write(Html32TextWriter.TagRightChar); var items = list.GetItems(i => i.ParentItemID == Guid.Empty && i.IsPublished && i.IsCurrentVersion).OrderBy(i => i.Pos); RenderChildren(writer, list, items, current); writer.WriteEndTag("ul"); } }); }
private static void RenderChildren(Html32TextWriter writer, ContentListDecorator list, IEnumerable<ContentDataItem> items, ContentDataItem current) { var app = App.Get(); var fieldName = list.GetDefaultTitleField().Name; var Url = DNA.Utility.UrlUtility.CreateUrlHelper(); foreach (var item in items) { var itemWrapper = app.Wrap(item); writer.WriteBeginTag("li"); var _class = "d-node"; var children = itemWrapper.Children(); var childrenCount = children.Count(); if (childrenCount > 0) _class += " d-node-hasChildren"; //writer.WriteAttribute("class", "d-node d-node-hasChildren"); var isInPath = false; if (current != null && !string.IsNullOrEmpty(current.Path) && !string.IsNullOrEmpty(item.Path) && current.Path.StartsWith(item.Path)) { isInPath = true; if (childrenCount > 0) writer.WriteAttribute("data-expanded", "true"); } writer.WriteAttribute("data-id", itemWrapper.ID.ToString()); if (current != null && itemWrapper.ID.Equals(current.ID)) writer.WriteAttribute("data-selected", "true"); if (itemWrapper.ParentItemID != Guid.Empty) writer.WriteAttribute("data-parentid", itemWrapper.ParentItemID.ToString()); if (childrenCount > 0) { if (!isInPath) { var urlformat = "~/api/contents/items?name={0}&slug={1}&parentId={2}"; var popupUrl = Url.Content(string.Format(urlformat, list.Name, list.Views.Default.Name, itemWrapper.ID.ToString())); writer.WriteAttribute("data-popupurl", popupUrl); } } writer.WriteAttribute("class", _class); writer.Write(Html32TextWriter.TagRightChar); writer.WriteBeginTag("a"); writer.WriteAttribute("href", itemWrapper.UrlComponent); writer.Write(Html32TextWriter.TagRightChar); writer.Write(itemWrapper.Value(fieldName).Raw); writer.WriteEndTag("a"); if (childrenCount > 0) { if (isInPath) { writer.WriteFullBeginTag("ul"); RenderChildren(writer, list, children, current); writer.WriteEndTag("ul"); } } writer.WriteEndTag("li"); } }