using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bowin.Web.Controls.Mvc
{
public class Combotree : BaseControl
{
public Combotree()
: base()
{
Enable = true;
}
public bool? Enable { get; set; }
public bool Required { get; set; }
public string DataSourceUrl { get; set; }
public string Style { get; set; }
public object SelectedValue { get; set; }
public string DataCondition { get; set; }
public override string Render()
{
StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.Append(" string.Format("{0}=\"{1}\"", x.Key, x.Value))));
htmlBuilder.AppendLine(" />");
return htmlBuilder.ToString();
}
public static BaseControl CreateControl(CombotreeOptions combotreeOptions, IDictionary attributes = null)
{
Combotree combotree = new Combotree();
combotree.ID = combotreeOptions.ID;
combotree.CssClass = combotreeOptions.CssClass;
combotree.DataSourceUrl = combotreeOptions.DataSourceUrl;
combotree.Style = combotreeOptions.Style;
//combotree.Required = combotreeOptions.Required;
combotree.SelectedValue = combotreeOptions.SelectedValue;
combotree.Name = combotreeOptions.Name;
combotree.DataCondition = combotreeOptions.DataCondition;
if (attributes != null)
{
Dictionary _attr = new Dictionary();
attributes.ToList().ForEach(it =>
{
_attr.Add(it.Key, (it.Value ?? "").ToString());
});
combotree.Attributes = _attr;
}
return combotree;
}
protected Dictionary GetPropertyList()
{
var dictPropertyList = new Dictionary();
if (!string.IsNullOrEmpty(this.ID))
{
dictPropertyList.Add("id", this.ID);
}
if (!string.IsNullOrEmpty(this.Name))
{
dictPropertyList.Add("name", this.Name);
}
if (!string.IsNullOrEmpty(this.DataCondition))
{
dictPropertyList.Add("data-condition", this.Name);
}
//if (this.SelectedValue != null)
//{
// dictPropertyList.Add("value", this.SelectedValue.ToString());
//}
if (!string.IsNullOrEmpty(Style))
dictPropertyList.Add("style", this.Style);
dictPropertyList.Add("class", string.Format("easyui-combotree {0}", this.CssClass == null ? "" : this.CssClass));
#region data-options
var dictOptions = new Dictionary();
if (!string.IsNullOrWhiteSpace(this.DataSourceUrl))
{
dictOptions.Add("url", "'" + this.DataSourceUrl + "'");
}
if (this.SelectedValue != null)
{
dictOptions.Add("value", "'" + this.SelectedValue.ToString() + "'");
}
//dictOptions.Add("required", "'" + this.Required.ToString() + "'");
if (Attributes.ContainsKey("data-val-required"))
{
//dictOptions.Add("required", "'false'");
//dictOptions.Add("missingMessage", "'" + Attributes["data-val-required"] + "'");
}
dictPropertyList.Add("data-options", string.Join(",", dictOptions.Select(x => string.Format("{0}:{1}", x.Key, x.Value))));
#endregion
//Where(w => w.Key != "data-val")
Attributes.ToList().ForEach(it =>
{
dictPropertyList.Add(it.Key, it.Value);
});
return dictPropertyList;
}
}
}