using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Bowin.Web.Controls.Mvc { public class Button:BaseControl { public Button() { Enable = true; IsPlain = false; } public ButtonIcon? Icon { get; set; } public string Text { get; set; } public bool? Enable { get; set; } public bool? IsPlain { get; set; } public string OnClick { get; set; } public override string Render() { StringBuilder htmlBuilder = new StringBuilder(); htmlBuilder.Append(" string.Format("{0}=\"{1}\"", x.Key, x.Value)))); htmlBuilder.AppendLine(" >"); if (!string.IsNullOrEmpty(this.Text)) { htmlBuilder.AppendLine(this.Text); } else { htmlBuilder.AppendLine(" "); } htmlBuilder.AppendLine(" "); return htmlBuilder.ToString(); } protected IDictionary GetPropertyList() { var dictPropertyList = new Dictionary(); if (!string.IsNullOrEmpty(this.ID)) { dictPropertyList.Add("id", this.ID); } dictPropertyList.Add("class", string.Format("easyui-linkbutton {0}", string.IsNullOrEmpty(this.CssClass) ? "" : this.CssClass)); dictPropertyList.Add("href", "javascript:void(0);"); if (!string.IsNullOrEmpty(this.OnClick)) { dictPropertyList.Add("onclick", this.OnClick ); } #region data-options var dictOptions = new Dictionary(); if (Icon.HasValue) { dictOptions.Add("iconCls", "'" + ButtonIconHelper.GetButtonIconClass(Icon.Value) + "'"); } if (IsPlain.HasValue) { dictOptions.Add("plain", IsPlain.ToString().ToLower()); } if (Enable.HasValue) { dictOptions.Add("disabled", (!Enable).ToString().ToLower()); } dictPropertyList.Add("data-options", string.Join(",", dictOptions.Select(x => string.Format("{0}:{1}", x.Key, x.Value)))); #endregion data-options if (Enable.HasValue && !Enable.Value) { dictPropertyList.Add("disabled", "disabled"); } return dictPropertyList; } public static Button CreateControl(ButtonOptions buttonOptions, IDictionary attributes = null) { Button button = new Button(); if (attributes != null) { button.Attributes = attributes; } button.CssClass = buttonOptions.CssClass; button.Icon = buttonOptions.Icon; button.ID = buttonOptions.ID; button.Text = buttonOptions.Text; button.IsPlain = buttonOptions.IsPlain; button.Enable = buttonOptions.Enable; button.OnClick = buttonOptions.OnClick; return button; } } }