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 string Pager(this HtmlHelper htmlHelper, IPagination pagination, string actionName, string controllerName, RouteValueDictionary routeValues) { routeValues = routeValues ?? new RouteValueDictionary(); var routeValueDictionary = new RouteValueDictionary(routeValues); if(!routeValueDictionary.ContainsKey("page")) routeValueDictionary.Add("page", 0); if(!routeValueDictionary.ContainsKey("controller")) routeValueDictionary.Add("controller", controllerName); int min = Math.Max(pagination.PageNumber - 2, 1); int max = Math.Min(pagination.PageNumber + 2, pagination.TotalPages); int startPage = Math.Min(min, 1); int endPage = Math.Max(max, pagination.TotalPages); int currentPage = pagination.PageNumber; var sb = new StringBuilder(); var sw = new StringWriter(sb, System.Globalization.CultureInfo.InvariantCulture); var hw = new Html32TextWriter(sw, " "); hw.WriteFullBeginTag("ul"); if (pagination.HasPreviousPage) { hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = currentPage - 1; hw.Write(htmlHelper.ActionLink("prev", actionName, routeValueDictionary, new Dictionary<string, object> {{"class", "previous"}})); hw.WriteEndTag("li"); } if(min != startPage) { hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = startPage; hw.Write(htmlHelper.ActionLink(startPage.ToInvariantString(), actionName, routeValueDictionary)); hw.WriteEndTag("li"); if (min - startPage > 1) { hw.WriteFullBeginTag("li"); hw.Write("..."); hw.WriteEndTag("li"); } } for (var i = min; i <= max; i++) { hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = i; if (i == currentPage) { hw.WriteFullBeginTag("span"); hw.Write(i.ToInvariantString()); hw.WriteEndTag("span"); } else hw.Write(htmlHelper.ActionLink(i.ToInvariantString(), actionName, routeValueDictionary)); hw.WriteEndTag("li"); } if(max != endPage) { if (endPage - max > 1) { hw.WriteLine(); hw.WriteFullBeginTag("li"); hw.Write("..."); hw.WriteEndTag("li"); } hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = endPage; hw.Write(htmlHelper.ActionLink(endPage.ToInvariantString(), actionName, routeValueDictionary)); hw.WriteEndTag("li"); } if(pagination.HasNextPage) { hw.WriteLine(); hw.WriteFullBeginTag("li"); routeValueDictionary["page"] = currentPage + 1; hw.Write(htmlHelper.ActionLink("next", actionName, routeValueDictionary, new Dictionary<string, object> {{"class", "next"}})); hw.WriteEndTag("li"); } hw.WriteLine(); hw.WriteEndTag("ul"); return sb.ToString(); //StringBuilder sb1 = new StringBuilder(); //int seed = pagination.PageNumber % pagination.PageSize == 0 ? pagination.PageNumber : pagination.PageNumber - (pagination.PageNumber % pagination.PageSize); //if (pagination.PageNumber > 1) // sb1.AppendLine(htmlHelper.ActionLink("prev", "index", controllerName, new { page = pagination.PageNumber }));// String.Format("<a href=\"{0}/{1}\">Previous</a>", urlPrefix, pagination.PageNumber)); //if (pagination.PageNumber - pagination.PageSize >= 1) //{ // var pageNumber = (pagination.PageNumber - pagination.PageSize) + 1) // sb1.AppendLine(htmlHelper.ActionLink("...", "index", controllerName, new {page = pageNumber})); //} //for (int i = seed; i < Math.Round((pagination.TotalItems / 10) + 0.5) && i < seed + pagination.PageSize; i++) //{ // //sb1.AppendLine(htmlHelper.ActionLink("{0}".ToFormat(i + 1)) String.Format("<a href=\"{0}/{1}\">{1}</a>", urlPrefix, i + 1)); //} //if (pagination.PageNumber + pagination.PageSize <= (Math.Round((pagination.TotalItems / 10) + 0.5) - 1)) // sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">...</a>", urlPrefix, (pagination.PageNumber + pagination.PageSize) + 1)); //if (currentPage < (Math.Round((pagination.TotalItems / 10) + 0.5) - 1)) // sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">Next</a>", urlPrefix, pagination.PageNumber + 2)); //return sb1.ToString(); //var pagesToDisplay = 5; //var sb = new StringBuilder(); //var textWriter = new StringWriter(sb); //var builder = new HtmlTextWriter(textWriter); ////opening ul tag //builder.RenderBeginTag("ul"); ////prev tag //builder.RenderBeginTag("li"); //if (pagination.HasPreviousPage) // builder.Write(urlHelper.ActionLink("prev", actionName, new{id = pagination.PageNumber - 1})); //else // builder.WriteEncodedUrl("prev"); //builder.RenderEndTag(); ////R //builder.RenderBeginTag("li"); //if(pag) ////next tag //builder.RenderBeginTag("li"); //if (pagination.HasPreviousPage) // builder.Write(urlHelper.ActionLink("next", actionName, new { id = pagination.LastItem })); //else // builder.WriteEncodedUrl("next"); //builder.RenderEndTag(); ////close ul tag //builder.RenderEndTag(); //return sb.ToString(); }
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 { } } }); }
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"); } } }); }
/// <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 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"); } }