/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System.Collections.Generic;
using Everest.Library.ExtensionMethod;
namespace Everest.Library.Extjs.Tree{
/// <summary>
/// serialize the Attributes to json.
/// </summary>
public class TreeNode
{
public string NodeType
{
get { return Attributes.GetString("nodeType", null); }
set { Attributes["nodeType"] = value; }
}
public bool AllowChildren
{
get { return Attributes.GetBoolean("allowChildren", true); }
set { Attributes["allowChildren"] = value; }
}
public bool AllowDrag
{
get { return Attributes.GetBoolean("allowDrag", false); }
set { Attributes["allowDrag"] = value; }
}
public bool AllowDrop
{
get { return Attributes.GetBoolean("allowDrop", false); }
set { Attributes["allowDrop"] = value; }
}
public bool? Checked
{
get
{
return Attributes.GetBoolean("checked", null);
}
set
{
if (value == null)
{
Attributes["checked"] = null;
}
Attributes["checked"] = value;
}
}//checked=falsecheckboxnullcheckbox
public string Cls
{
get { return Attributes.GetString("cls", null); }
set { Attributes["cls"] = value; }
}
public bool Disabled
{
get { return Attributes.GetBoolean("disabled", false); }
set { Attributes["disabled"] = value; ; }
}
public bool Draggable
{
get { return Attributes.GetBoolean("draggable", false); }
set { Attributes["draggable"] = value; }
}
public bool Expandable
{
get { return Attributes.GetBoolean("expandable", true); }
set { Attributes["expandable"] = value; }
}
public bool Expanded
{
get { return Attributes.GetBoolean("expanded", false); }
set { Attributes["expanded"] = value; }
}
public string Href
{
get { return Attributes.GetString("href", null); }
set { Attributes["href"] = value; }
}
public string HrefTarget
{
get { return Attributes.GetString("hrefTarget", null); }
set { Attributes["hrefTarget"] = value; }
}
public string Icon
{
get { return Attributes.GetString("icon", null); }
set { Attributes["icon"] = value; }
}
public string IconCls
{
get { return Attributes.GetString("iconCls", null); }
set { Attributes["iconCls"] = value; }
}
public string Id
{
get { return Attributes.GetString("id", null); }
set { Attributes["id"] = value; }
}
public bool IsTarget
{
get { return Attributes.GetBoolean("isTarget", false); }
set { Attributes["isTarget"] = value; }
}
public bool Leaf
{
get { return Attributes.GetBoolean("leaf", false); }
set { Attributes["leaf"] = value; }
}
public string Qtip
{
get { return Attributes.GetString("qtip", null); }
set { Attributes["qtip"] = value; }
}
public string QtipCfg
{
get { return Attributes.GetString("qtipCfg", null); }
set { Attributes["qtipCfg"] = value; }
}
public bool SingleClickExpand
{
get { return Attributes.GetBoolean("singleClickExpand", false); }
set { Attributes["singleClickExpand"] = value; }
}
public string Text
{
get { return Attributes.GetString("text", null); }
set { Attributes["text"] = value; }
}
public string UiProvider
{
get { return Attributes.GetString("uiProvider", null); }
set { Attributes["uiProvider"] = value; }
}
public string ParentNode
{
get { return Attributes.GetString("parentNode", null); }
set { Attributes["parentNode"] = value; }
}
public IList<IDictionary<string, object>> children
{
get { return Attributes.GetValue<string, object, IList<IDictionary<string, object>>>("children", null); }
set { Attributes["children"] = value; }
}
public Dictionary<string, object> Attributes;
public TreeNode()
{
//this.children = new List<TreeNode>();
Attributes = new Dictionary<string, object>();
//this.Attributes["href"] = "#";
this.Attributes["checked"] = null;
}
public TreeNode(string id, string text, string parentNode)
: base()
{
}
public void AddAttribute(string name, object value)
{
switch (name)
{
case "allowChildren":
case "allowDrag":
case "AllowDrop":
case "checked":
case "disabled":
case "draggable":
case "expandable":
case "expanded":
case "isTarget":
case "leaf":
case "SingleClickExpand":
Attributes[name] = bool.Parse(value.ToString());
break;
default:
Attributes[name] = value;
break;
}
}
public void AddChild(TreeNode treeNode)
{
if (this.children == null)
{
this.children = new List<IDictionary<string, object>>();
}
this.children.Add(treeNode.Attributes);
}
}
}
|