public virtual string RenderAction(IHtmlHelper htmlHelper, RoboUIFormAction action) { throw new NotSupportedException(); }
public string RenderAction(IHtmlHelper htmlHelper, RoboUIFormAction action) { if (action.HtmlBuilder != null) { return(action.HtmlBuilder()); } if (action.MenuItems.Count > 0) { var sb = new StringBuilder(); sb.AppendFormat("<button data-toggle=\"dropdown\" class=\"{0} dropdown-toggle\">", string.IsNullOrEmpty(action.CssClass) ? "btn btn-default" : action.CssClass.Trim()); sb.Append(action.Text); sb.Append(" <span class=\"caret\"></span>"); sb.AppendFormat("</button>"); sb.Append("<ul class=\"dropdown-menu\">"); foreach (var childAction in action.MenuItems) { sb.Append(childAction); } sb.Append("</ul>"); return(sb.ToString()); } if (action.IsSubmitButton) { var attributes = new RouteValueDictionary(); if (!action.HtmlAttributes.IsNullOrEmpty()) { foreach (var attribute in action.HtmlAttributes) { attributes.Add(attribute.Key, attribute.Value); } } var cssClass = (RoboUI.DefaultRoboUIFormProvider.GetButtonSizeCssClass(action.ButtonSize) + " " + RoboUI.DefaultRoboUIFormProvider.GetButtonStyleCssClass(action.ButtonStyle) + " " + action.CssClass + (!action.IsValidationSupported ? " cancel" : "")).Trim(); if (!string.IsNullOrEmpty(cssClass)) { attributes.Add("class", cssClass); } if (!string.IsNullOrEmpty(action.ClientId)) { attributes.Add("id", action.ClientId); } if (!string.IsNullOrEmpty(action.ConfirmMessage)) { attributes.Add("onclick", string.Format("return confirm(\"{0}\");", action.ConfirmMessage)); } if (!string.IsNullOrEmpty(action.ClientClickCode)) { attributes["onclick"] = action.ClientClickCode; } var tagBuilder = new TagBuilder("button"); tagBuilder.MergeAttribute("type", "submit"); tagBuilder.MergeAttribute("value", action.Value); tagBuilder.MergeAttribute("name", action.Name); tagBuilder.MergeAttribute("id", "btn" + action.Name); tagBuilder.MergeAttribute("title", action.Description ?? action.Text); tagBuilder.MergeAttributes(attributes, true); if (!string.IsNullOrEmpty(action.IconCssClass)) { var icon = new TagBuilder("i"); icon.AddCssClass(action.IconCssClass); tagBuilder.InnerHtml.AppendHtml(string.Concat(icon.ToHtmlString(), " ", action.Text)); } else { tagBuilder.InnerHtml.AppendHtml(action.Text); } return(tagBuilder.ToHtmlString()); } else { var attributes = new RouteValueDictionary(); if (!action.HtmlAttributes.IsNullOrEmpty()) { foreach (var attribute in action.HtmlAttributes) { attributes.Add(attribute.Key, attribute.Value); } } var cssClass = (RoboUI.DefaultRoboUIFormProvider.GetButtonSizeCssClass(action.ButtonSize) + " " + RoboUI.DefaultRoboUIFormProvider.GetButtonStyleCssClass(action.ButtonStyle) + " " + action.CssClass + (!action.IsValidationSupported ? " cancel" : "")).Trim(); if (!string.IsNullOrEmpty(cssClass)) { attributes.Add("class", cssClass); } if (!string.IsNullOrEmpty(action.ClientId)) { attributes.Add("id", action.ClientId); } if (!string.IsNullOrEmpty(action.ConfirmMessage)) { attributes.Add("onclick", string.Format("return confirm(\"{0}\");", action.ConfirmMessage)); } if (!string.IsNullOrEmpty(action.ClientClickCode)) { attributes["onclick"] = action.ClientClickCode; } attributes["href"] = action.Url; if (action.IsShowModalDialog) { attributes.Add("data-toggle", "fancybox"); attributes.Add("data-fancybox-type", "iframe"); attributes.Add("data-fancybox-width", action.ModalDialogWidth); } var tagBuilder = new TagBuilder("a"); tagBuilder.MergeAttributes(attributes); if (!string.IsNullOrEmpty(action.IconCssClass)) { var icon = new TagBuilder("i"); icon.AddCssClass(action.IconCssClass); tagBuilder.InnerHtml.AppendHtml(string.Concat(icon.ToHtmlString(), " ", action.Text)); } else { tagBuilder.InnerHtml.AppendHtml(action.Text); } return(tagBuilder.ToHtmlString()); } }