protected virtual void AddClearFix(StringBuilder cells, string className, bool endOfRow) { if (endOfRow) { var cell = new HtmlTagBuilder("div"); cell.AddCssClass("clearfix"); cell.AddCssClass(className); cells.Append(cell.ToString()); } }
public string ToHtmlString() { var tag = CreateTag(); bool requiresContainer = false; string output = ""; string header = Context.Header; if (header != null) { requiresContainer = true; if (string.IsNullOrWhiteSpace(Context.Id)) { output += "<label>"; } else { output += "<label for='" + Context.Id + "'>"; } output += header + "</label>"; } output += tag.ToString(); string description = Context.Description; if (!string.IsNullOrWhiteSpace(description)) { requiresContainer = true; output += "<div class='help-block'>" + description + "</div>"; } string name = Context.Name; if (!requiresContainer) { if (!string.IsNullOrWhiteSpace(name)) { tag.MergeAttribute("data-container-for", name); } return(tag.ToString()); } var div = new HtmlTagBuilder("div"); if (!string.IsNullOrWhiteSpace(name)) { div.Attributes.Add("data-container-for", name); } div.AddCssClass("form-group"); div.InnerHtml = output; return(div.ToString()); }
public override string ToHtmlString() { var tag = CreateTag(); var label = new HtmlTagBuilder("label"); string id = Context.Id; if (!string.IsNullOrWhiteSpace(id)) { label.Attributes.Add("for", id); } label.InnerHtml = tag.ToString() + Context.Header; string name = Context.Name; HtmlTagBuilder container; if (!Context.IsInline) { label.AddCssClass("clearfix"); container = new HtmlTagBuilder("div"); container.AddCssClass("form-group"); } else { label.AddCssClass("checkbox-inline"); container = label; } if (!string.IsNullOrWhiteSpace(name)) { container.MergeAttribute("data-container-for", name); } if (Context.IsHidden) { container.MergeAttribute("style", "display: none;", true); } if (Context.IsInvisible) { container.AddCssClass("invisible"); } if (!Context.IsInline) { string output = "<div class='checkbox'>" + label.ToString() + "</div>"; string description = Context.Description; if (!string.IsNullOrWhiteSpace(description)) { output += "<div class='help-block'>" + description + "</div>"; } container.InnerHtml = output; } return(container.ToString()); }
public override string ToHtmlString() { var tag = CreateTag(); var label = new HtmlTagBuilder("label"); string id = Context.Id; if (!string.IsNullOrWhiteSpace(id) && !Context.AllowMultiple) { label.Attributes.Add("for", id); } if (Context.IsHidden) { label.MergeAttribute("style", "display: none;", true); } if (Context.IsInvisible) { label.AddCssClass("invisible"); } label.InnerHtml = tag.ToString() + Context.Header; string name = Context.Name; if (Context.IsInline) { if (!string.IsNullOrWhiteSpace(name)) { label.Attributes.Add("data-container-for", name); } label.AddCssClass("radio-inline"); return(label.ToString()); } string output = "<div class='" + (Context.AllowMultiple ? "checkbox" : "radio") + "'"; if (!string.IsNullOrWhiteSpace(name)) { output += " data-container-for='" + name + "'"; } output += ">" + label.ToString() + "</div>"; string description = Context.Description; if (!string.IsNullOrWhiteSpace(description)) { output += "<div class='help-block'>" + description + "</div>"; } return(output); }
public virtual string ToHtmlString() { var tag = CreateTag(); string id = Context.Id; bool requiresContainer = false; string output = ""; string feedBackStyle; string header = Context.Header; if (header != null) { requiresContainer = true; if (string.IsNullOrWhiteSpace(Context.Id)) { output += "<label>"; } else { output += "<label for='" + Context.Id + "'>"; } output += header + "</label>"; feedBackStyle = ""; } else { feedBackStyle = " style='top: 0px;'"; } if (tag.IsValidated) { if (!string.IsNullOrWhiteSpace(Context.ValidationMessage)) { output += Context.ValidationMessage; } else if (!string.IsNullOrWhiteSpace(FullHtmlFieldName)) { output += "<span class='field-validation-valid' data-valmsg-for='" + FullHtmlFieldName + "' data-valmsg-replace='true'></span>"; } } output += WrapTag(tag) + AppendToTag(); if (Context.IsRequired) { requiresContainer = true; output += "<span class='fa fa-star form-control-feedback'" + feedBackStyle + "></span>"; } else if (!string.IsNullOrWhiteSpace(id)) { requiresContainer = true; if (string.IsNullOrWhiteSpace(feedBackStyle)) { feedBackStyle = "style='display: none;'"; } else { feedBackStyle = feedBackStyle.Substring(0, feedBackStyle.Length - 1) + ";display: none;'"; } output += "<span class='fa form-control-feedback' " + feedBackStyle + "></span>"; } string description = Context.Description; if (!string.IsNullOrWhiteSpace(description)) { requiresContainer = true; output += "<div class='help-block'>" + description + "</div>"; } string name = Context.Name; HtmlTagBuilder container; if (requiresContainer) { container = new HtmlTagBuilder("div"); container.AddCssClass("form-group"); if (Context.IsRequired || !string.IsNullOrWhiteSpace(id)) { container.AddCssClass("has-feedback"); } } else { container = tag; // * } if (!string.IsNullOrWhiteSpace(name)) { container.MergeAttribute("data-container-for", name); } if (Context.IsHidden) { container.MergeAttribute("style", "display: none;", true); } if (Context.IsInvisible) { container.AddCssClass("invisible"); } if (!requiresContainer) { return(WrapTag(container) + AppendToTag()); // container was set to tag (See * above) } container.InnerHtml = output + AppendToTag(); return(container.ToString()); }
public TControl Begin() { if (_begun) { throw new Exception("Already called Begin"); } string name = Context.Name; string id = Context.Id; var div = new HtmlTagBuilder("div"); if (!string.IsNullOrWhiteSpace(name)) { div.Attributes.Add("data-container-for", name); } if (!string.IsNullOrWhiteSpace(id)) { div.Attributes.Add("data-group", id); } if (Context.IsHidden) { div.Attributes.Add("style", "display: none;"); } if (Context.IsInvisible) { div.AddCssClass("invisible"); } div.AddCssClass("form-group"); div.AddCssClass("has-feedback"); var context = HtmlHelper.ViewContext; context.Writer.Write(div.ToString(TagRenderMode.StartTag)); string header = Context.Header; if (header != null) { if (string.IsNullOrWhiteSpace(name)) { context.Writer.Write("<label>"); } else { context.Writer.Write("<label for='" + name + "'>"); } context.Writer.Write(header + "</label>"); if (!string.IsNullOrWhiteSpace(name)) { context.Writer.Write("<span class='field-validation-valid' data-valmsg-for='" + name + "' data-valmsg-replace='true'></span>"); } } string description = Context.Description; if (!string.IsNullOrWhiteSpace(description)) { context.Writer.Write("<div class='help-block'>" + description + "</div>"); } var tag = new HtmlTagBuilder(TagType); tag.MergeAttributes(Context.HtmlAttributes); tag.MergeIfAttribute("readonly", "readonly", Context.IsReadOnly); tag.MergeIfAttribute("disabled", "disabled", Context.IsDisabled); context.Writer.Write(tag.ToString(TagRenderMode.StartTag)); _begun = true; return((TControl)this); }
protected override string WrapTag(TagBuilder tag) { string imageId = Context.Id + "_Image"; string imageName = FullHtmlFieldName + "_Image"; var img = new HtmlTagBuilder("img"); img.AddCssClass("img-preview"); img.Attributes.Add("id", imageId); img.Attributes.Add("name", imageName); string selected; if (!string.IsNullOrEmpty(Context.FileName)) { img.Attributes.Add("src", Context.FileName); selected = " selected"; } else { selected = ""; } string output = tag.ToString() + "<div class='filepicker'>" + img.ToString() + "<div class='filepicker-buttons" + selected + "'>"; bool havePreAppend = Context.Append.Count > 0 || Context.Prepend.Count > 0; bool moreButtons = Context.CanRotate || Context.CanCrop || havePreAppend; if (!moreButtons && (Context.CanDelete || Context.CanCapture)) { output += "<div class='btn-group'>"; } if (Context.Button == null) { Button(Context.FileType == FilePickerContext.ImageFileType ? "Add Image" : "Add File"); } var button = Context.Button.Id(Context.Id + "_Button"); var htmlAttributes = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(button.Context.HtmlAttributes); AdditionalButtonAttributes(htmlAttributes); button.HtmlAttributes(htmlAttributes); output += button.ToString(); if (moreButtons) { output += " <br /><div class='btn-group'>"; } output += GetPreAppendString(Context.Prepend).ToString(); if (Context.CanCapture) { output += " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-info'" + " data-file-capture-for='" + Context.Id + "'" + " data-file-type='" + Context.FileType + "'" + " title='Webcam Capture'>" + "<span class='fa fa-camera'></span>" + " </button>" + " </span>"; } if (Context.CanRotate) { output += " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-success'" + " data-file-rotate-for='" + Context.Id + "'" + " data-file-url='" + UrlHelper.Action("RotateLeft", Context.ControllerName, new { id = "_ID_" }) + "'" + " title='Rotate image anti-clockwise'>" + "<span class='fa fa-rotate-left'></span>" + " </button>" + " </span>" + " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-success'" + " data-file-rotate-for='" + Context.Id + "'" + " data-file-url='" + UrlHelper.Action("RotateRight", Context.ControllerName, new { id = "_ID_" }) + "'" + " title='Rotate image clockwise'>" + "<span class='fa fa-rotate-right'></span>" + " </button>" + " </span>"; } if (Context.CanCrop) { output += " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-success'" + " data-file-crop-for='" + Context.Id + "'" + " data-file-url='" + UrlHelper.Action("Crop", Context.ControllerName) + "'" + " title='Crop image'>" + "<span class='fa fa-crop'></span>" + " </button>" + " </span>" + "<input id='" + Context.Id + "_Crop' name='" + Context.Id + "_Crop' type='hidden' />"; } output += GetPreAppendString(Context.Append).ToString(); if (Context.CanDelete) { output += " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-danger'" + " data-file-cancel-for='" + Context.Id + "'" + " data-file-type='" + Context.FileType + "'" + " title='Delete'>" + "<span class='fa fa-trash-o'></span>" + " </button>" + " </span>"; } if (moreButtons || Context.CanDelete || Context.CanCapture) { output += " </div>"; // btn-group } output += " </div>" // filepicker-buttons + " <span id='" + Context.Id + "_FileName'>" + GeneratePlaceholder() + "</span>" + " <div id='" + Context.Id + "_ProgressContainer'>" + " <div id='" + Context.Id + "_ProgressPercent'>100%</div>" + " <div class='progress progress-striped active'>" + " <div id='" + Context.Id + "_Progress' class='progress-bar' role='progressbar'></div>" + " </div>" // progress + " </div>" // ProgressContainer + "</div>"; // filepicker return(output); }
private static string GetSummary(HtmlHelper htmlHelper) { var viewContext = htmlHelper.ViewContext; System.Web.Mvc.FormContext formContext = viewContext.ClientValidationEnabled ? viewContext.FormContext : null; if (htmlHelper.ViewData.ModelState.IsValid && formContext == null) { return(null); } var modelState = GetModelStateList(htmlHelper); StringBuilder listBuilder = new StringBuilder(); foreach (var state in modelState) { foreach (var error in state.Value.Errors) { string message = error.ErrorMessage; if (!string.IsNullOrWhiteSpace(message)) { listBuilder.Append("<li>"); string key = state.Key; if (!string.IsNullOrWhiteSpace(key) && !message.Contains(key)) { int lastDot = key.LastIndexOf('.'); if (lastDot != -1) { string suffix = key.Substring(lastDot + 1); if (message.Contains(suffix)) { key = key.Substring(0, lastDot); } } listBuilder.Append("<strong>"); listBuilder.Append(key.Replace('.', ' ').ToWords(true)); listBuilder.Append("</strong> "); } listBuilder.Append(message); listBuilder.AppendLine("</li>"); } } } if (listBuilder.Length == 0) { if (viewContext.UnobtrusiveJavaScriptEnabled || formContext == null) { return(null); } listBuilder.AppendLine("<li style=\"display:none\"></li>"); } var listTag = new HtmlTagBuilder("ul") { InnerHtml = listBuilder.ToString() }; var divBuilder = new HtmlTagBuilder("div"); divBuilder.AddCssClass(htmlHelper.ViewData.ModelState.IsValid ? HtmlHelper.ValidationSummaryValidCssClassName : HtmlHelper.ValidationSummaryCssClassName); divBuilder.AddCssClass("alert alert-danger fade in"); if (formContext != null) { if (viewContext.UnobtrusiveJavaScriptEnabled) { divBuilder.MergeAttribute("data-valmsg-summary", "true"); } else { divBuilder.GenerateId("validationSummary"); formContext.ValidationSummaryId = divBuilder.Attributes["id"]; formContext.ReplaceValidationSummary = true; } } divBuilder.InnerHtml = "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>" + listTag.ToString(); return(divBuilder.ToString()); }
public virtual bool CreateCell(StringBuilder cells, object cellData, string columnClassPrefix, bool isHeader, bool isTotal, GridColumnContext <TRow> context, object htmlAttributes) { var cell = new HtmlTagBuilder("div"); int width = AddColClass(cell, columnClassPrefix, "xs", Position.Width(0), -1); width = AddColClass(cell, columnClassPrefix, "sm", Position.Width(1), width); width = AddColClass(cell, columnClassPrefix, "md", Position.Width(2), width); width = AddColClass(cell, columnClassPrefix, "lg", Position.Width(3), width); int offset = AddOffsetClass(cell, columnClassPrefix, "xs", Position.Offset(0), 0); offset = AddOffsetClass(cell, columnClassPrefix, "sm", Position.Offset(1), offset); offset = AddOffsetClass(cell, columnClassPrefix, "md", Position.Offset(2), offset); offset = AddOffsetClass(cell, columnClassPrefix, "lg", Position.Offset(3), offset); string style = Context.Style.ToString().ToLowerInvariant(); if (Context.Style != GridColumnStyle.Text) { cell.AddCssClass(columnClassPrefix + "-" + style); } if (isHeader) { if (context.WrapHeader) { cell.AddCssClass("wrap"); } string valueId = context.Index.ToString(CultureInfo.InvariantCulture); var sortable = context.IsSortable; if (sortable != GridBooleanPlus.False) { cell.MergeAttribute("data-sortable", valueId); if (sortable != GridBooleanPlus.True) { cell.MergeAttribute("data-sortable-type", sortable.ToString().ToLowerInvariant()); } } var filterable = context.IsFilterable; if (filterable != GridBooleanPlus.False) { cell.MergeAttribute("data-filterable", valueId); if (filterable != GridBooleanPlus.True) { cell.MergeAttribute("data-filterable-type", filterable.ToString().ToLowerInvariant()); } } var groupable = context.IsGroupable; if (groupable != GridBooleanPlus.False) { cell.MergeAttribute("data-groupable", valueId); if (groupable != GridBooleanPlus.True) { cell.MergeAttribute("data-groupable-type", groupable.ToString().ToLowerInvariant()); } var groupsExpanded = context.GroupsExpanded; if (groupsExpanded != GridGroupsExpanded.First) { cell.MergeAttribute("data-groupable-expanded", groupsExpanded.ToString().ToLowerInvariant()); } } } else if (isTotal && context.Total > GridColumnTotal.Title) // Skip total titles { cell.MergeAttribute("data-total", context.Index.ToString(CultureInfo.InvariantCulture)); cell.MergeAttribute("data-total-type", context.Total.ToString().ToLowerInvariant()); switch (context.Subtotal) { case GridColumnSubtotal.Prefix: if (context.Prefix != null) { cell.MergeAttribute("data-total-sub", "true"); } break; case GridColumnSubtotal.Suffix: if (context.Suffix != null) { cell.MergeAttribute("data-total-sub", "true"); } break; } cell.MergeAttribute("data-total-style", context.Style.ToString().ToLowerInvariant()); } bool hasData; if (cellData == null) { hasData = false; } else { string cellString = cellData.ToString(); if (string.IsNullOrWhiteSpace(cellString)) { hasData = false; } else { cell.InnerHtml = cellString; hasData = true; } } cell.MergeAttributes(htmlAttributes); AddCell(cells, cell); AddClearFix(cells, "visible-xs", Position.EndOfRow(0)); AddClearFix(cells, "visible-sm", Position.EndOfRow(1)); AddClearFix(cells, "visible-md", Position.EndOfRow(2)); AddClearFix(cells, "visible-lg", Position.EndOfRow(3)); return(hasData); }