/// <summary> /// Column header in a list/grid which is not sortable /// </summary> public static string ColHead(string title) { HtmlTag html = new HtmlTag("div"); html.Add("class", "colhead"); html.SetInnerHtml(title); return(html.ToString()); }
/// <summary> /// You can supply any of the parameters you like. You must supply either 'percentage' (as a whole number out of 100) or 'amount' and 'outOfTotal' parameters. /// </summary> /// <example> /// <%=Beweb.Html.BarGraph(percentage:project.PercentOfBudget.ToInt(0), amount:actualHours, showAmount:true, decimalPlaces:1) %> /// <%=Beweb.Html.BarGraph(amount:totalHoursUsed, outOfTotal:totalHoursPurchased, showPercentage:true) %> /// </example> public static string BarGraph(decimal?amount = null, decimal?outOfTotal = null, bool showPercentage = false, bool showAmount = false, bool showOutOf = false, decimal?percentage = null, string label = null, int decimalPlaces = 0) { /* You need to add the following CSS to your stylesheet. * .svyBarGraph { width: 150px; } * .svyBarGraphLabel { position: absolute;color:white;margin-left: 5px; } * .svyBarGraphOuter { width:50px;background:#333;float:left;margin-right:10px;height:18px;border-radius: 5px; } * .svyBarGraphInner { background:green;height:14px;margin-top:2px;margin-left:2px;border-radius: 4px; } */ if (percentage == null && amount != null && outOfTotal != null) { percentage = Numbers.Floor(Numbers.SafeDivide(amount.Value, outOfTotal.Value) * 100); } else if (percentage == null) { percentage = 0; } if (showAmount && amount == null) { throw new BewebException("Html.BarGraph: You need to supply 'amount' parameter if you set 'showAmount' to true."); } if (showOutOf && outOfTotal == null) { throw new BewebException("Html.BarGraph: You need to supply 'outOfTotal' parameter if you set 'showOutOf' to true."); } if (label.IsBlank()) { if (showAmount) { label = Fmt.Number(amount, decimalPlaces); if (showOutOf) { label += " of " + Fmt.Number(outOfTotal, decimalPlaces); } if (showPercentage) { label += " (" + Fmt.Percent(percentage, decimalPlaces) + ")"; } } else if (showPercentage) { label = Fmt.Percent(percentage, decimalPlaces); } } var html = new HtmlTag("div").Add("class", "svyBarGraph"); var labelSpan = new HtmlTag("span").Add("class", "svyBarGraphLabel").SetInnerText(label); var barOuter = new HtmlTag("div").Add("class", "svyBarGraphOuter"); var barInner = new HtmlTag("div").Add("class", "svyBarGraphInner").Add("style", "width:" + Fmt.Number(percentage, 0, false) + "%"); barOuter.AddTag(barInner); html.AddTag(labelSpan); html.AddTag(barOuter); return(html.ToString()); }
/// <summary> /// Returns a string containing an HTML IMG tag, given a SRC attribute (ie relative URL to image file), alt text and css class. /// Returns empty string (ie no tag) if imageSrc is null. /// </summary> /// <param name="imageSrc">this should include the attachments folder if required</param> /// <param name="altText"></param> /// <param name="cssClass"></param> /// <returns></returns> public static string Image(string imageSrc, string altText, string cssClass, int?width, int?height) { string result = ""; if (imageSrc.IsNotBlank()) { var html = new HtmlTag("img"); html.Add("src", imageSrc, false); html.AddIfNotBlank("alt", altText); html.AddIfNotBlank("class", cssClass); if (width != null) { html.Add("width", width.ToString()); } if (height != null) { html.Add("height", height.ToString()); } result = html.ToString(); } return(result); }
/// <summary> /// Sortable column header in a list/grid /// </summary> public static string ColSort(string fieldName, string title, string currentSortField, bool isDescending) { if (title == null) { title = Fmt.SplitTitleCase(fieldName); if (title.StartsWith("Is ")) { title = title.Substring(3); } } if (fieldName == "SortPosition") { isDescending = false; } HtmlTag html = new HtmlTag("a"); html.Add("href", "javascript:ColSortBy(" + fieldName.JsEnquote() + ")"); html.Add("title", "sort by " + title.JsEnquote() + ""); string css = "colhead colsort"; if (currentSortField == fieldName) { css += " selected"; if (isDescending) { css += " descending"; } else { css += " ascending"; } } html.Add("class", css); html.SetInnerHtml(title); return(html.ToString()); }
public string ToHtml() { // return an html table var table = new HtmlTag("table style='xwidth: 1000px; background-color: white ; border: 1px solid #CCC;'"); //style='font-family: 'Open Sans', Trebuchet MS, sans-serif, Arial; font-weight: 300; font-size: 13px;color: #000;' var thStyle = "background-color: #e0e7a2;font-family: Open Sans, Trebuchet MS, sans-serif, Arial; font-weight: 300; font-size: 13px;color: #000;text-align:left;"; var tdStyle = "font-family: Open Sans, Trebuchet MS, sans-serif, Arial; font-weight: 300; font-size: 12px;color: #000;border-bottom:1px solid #CCC;'"; var tr = new HtmlTag("tr"); HtmlTag th; //var th = new HtmlTag("th style='width:100px;" + thStyle + "'"); //th.SetInnerText("Status"); //tr.AddTag(th); th = new HtmlTag("th width=20% style='" + thStyle + "'"); th.SetInnerText("Title"); tr.AddTag(th); th = new HtmlTag("th width=20% style='" + thStyle + "'"); th.SetInnerText("Code"); tr.AddTag(th); th = new HtmlTag("th width=50% style='" + thStyle + "'"); th.SetInnerText("Description"); tr.AddTag(th); th = new HtmlTag("th width=10% style='" + thStyle + "'"); th.SetInnerText("Url"); tr.AddTag(th); table.AddTag(tr); foreach (var line in ImportReportLines) { // tr tr = new HtmlTag("tr"); HtmlTag td; var textColour = ""; if (line.Status == StatusFailed) { textColour = StatusFailed.DisplayName; } else if (line.Status == StatusWarning) { textColour = StatusWarning.DisplayName; } else if (line.Status == StatusInfo) { textColour = StatusInfo.DisplayName; } else if (line.Status == StatusSuccess) { textColour = StatusSuccess.DisplayName; } else { textColour = ""; } //td = new HtmlTag("td style='" + textColour + "" + tdStyle + "'"); //td.SetInnerText(line.Status); //tr.AddTag(td); if (line.LineType == LineTypeSubtitle) { td = new HtmlTag("td colspan='4' style ='" + LineTypeSubtitle.DisplayName + "" + tdStyle + "'"); td.SetInnerText(line.Title); tr.AddTag(td); } else if (line.LineType == LineTypeTitle) { td = new HtmlTag("td colspan=4 style ='" + LineTypeTitle.DisplayName + "" + tdStyle + "'"); var spanTag = new HtmlTag("span style = '" + textColour + "'"); spanTag.SetInnerHtml(line.Title); td.AddTag(spanTag); tr.AddTag(td); } else { td = new HtmlTag("td style ='" + textColour + "" + tdStyle + "'"); var spanTag = new HtmlTag("span style = '" + textColour + "'"); spanTag.SetInnerHtml(line.Title); td.AddTag(spanTag); tr.AddTag(td); } td = new HtmlTag("td style='" + tdStyle + "'"); td.SetInnerText(line.Identifier); tr.AddTag(td); td = new HtmlTag("td style='" + tdStyle + "'"); if (line.Description.IsBlank()) { td.SetInnerText(""); } else { td.SetInnerText(line.Description); } tr.AddTag(td); td = new HtmlTag("td style='" + tdStyle + "'"); if (line.LinkUrl.IsNotBlank()) { td.AddRawHtml("<a href='" + Web.ResolveUrlFull(line.LinkUrl) + "' target='_blank'>" + line.UrlCaption.DefaultValue("View/edit") + "</a>"); } tr.AddTag(td); table.AddTag(tr); } return(table.ToString()); }