/*
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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using Everest.Library.ExtensionMethod;
namespace Everest.Forms.ExtForm.Controls{
public abstract class ExtControlBase : IControlType
{
static List<string> NotStringValueList = new List<string>();
static ExtControlBase()
{
NotStringValueList.Add("depency");
NotStringValueList.Add("allowBlank");
NotStringValueList.Add("allowDomMove");
NotStringValueList.Add("disabled");
NotStringValueList.Add("grow");
NotStringValueList.Add("growMax");
NotStringValueList.Add("growMin");
NotStringValueList.Add("height");
NotStringValueList.Add("hidden");
NotStringValueList.Add("maxLength");
NotStringValueList.Add("minLength");
NotStringValueList.Add("readOnly");
NotStringValueList.Add("plugins");
NotStringValueList.Add("listeners");
NotStringValueList.Add("selectOnFocus");
NotStringValueList.Add("tabIndex");
NotStringValueList.Add("validateOnBlur");
NotStringValueList.Add("validationDelay");
NotStringValueList.Add("validator");
NotStringValueList.Add("width");
NotStringValueList.Add("tinymceSettings");
NotStringValueList.Add("allowDomMove");
NotStringValueList.Add("animCollapse");
NotStringValueList.Add("autoDestroy");
NotStringValueList.Add("autoHeight");
NotStringValueList.Add("autoLoad");
NotStringValueList.Add("autoScroll");
NotStringValueList.Add("autoShow");
NotStringValueList.Add("autoWidth");
NotStringValueList.Add("autoResize");
NotStringValueList.Add("checkboxToggle");
NotStringValueList.Add("closable");
NotStringValueList.Add("collapsed");
NotStringValueList.Add("collapsible");
NotStringValueList.Add("hideLabel");
NotStringValueList.Add("monitorResize");
NotStringValueList.Add("typeAhead");
NotStringValueList.Add("enableTopbar");
NotStringValueList.Add("editable");
NotStringValueList.Add("resizable");
NotStringValueList.Add("stateful");
NotStringValueList.Add("renderer");
}
#region IControlType Members
public abstract string Name { get; }
public virtual string Render(IColumn column)
{
string children = RenderConfig(column);
if (!string.IsNullOrEmpty(children))
{
children = "," + children;
}
StringBuilder attributsBuilder = new StringBuilder(",");
foreach (string s in column.DetailAttributes.Keys)
{
if (s == "regex" || s == "maskRe")
{
attributsBuilder.AppendFormat("{0}:/{1}/i,", s, column.DetailAttributes[s]);
}
else if (NotStringValueList.Contains(s) || column.DetailAttributes[s].ToLower() == "true" || column.DetailAttributes[s].ToLower() == "false")
{
attributsBuilder.AppendFormat("{0}:{1},", s, column.DetailAttributes[s]);
}
else
attributsBuilder.AppendFormat("{0}:'{1}',", s, column.DetailAttributes[s]);
}
StringBuilder eventsBuilder = new StringBuilder("");
foreach (string s in column.Events)
{
eventsBuilder.AppendFormat("{0}:{1},", s, column.Events[s]);
}
eventsBuilder.RemoveLastSpecifiedChar(',');
string defalutValue = "";
if (!string.IsNullOrEmpty(column.DefaultValue))
{
defalutValue = string.Format(",value:'{0}'", column.DefaultValue);
}
if (column.Length > 0)
{
attributsBuilder.AppendFormat("maxLength:{0},", column.Length);
}
attributsBuilder = attributsBuilder.RemoveLastSpecifiedChar(',');
return string.Format("{{xtype:'{0}',fieldLabel:'{1}',name:'{2}',dataIndex:'{7}',modifiable:{8},width: 230,allowBlank:{3} {4} {5} {6},listeners:{{{9}}}}}",
XType, column.Label, column.Name, column.AllowNull.ToString().ToLower(), defalutValue, children, attributsBuilder.ToString(), column.DataIndexInDetail, column.Modifiable.ToString().ToLower()
, eventsBuilder.ToString());
}
#endregion
/// <summary>
///
/// </summary>
protected abstract string XType { get; }
/// <summary>
/// Childrens the render.
/// </summary>
/// <param name="column">The column.</param>
/// <returns></returns>
protected virtual string RenderConfig(IColumn column) { return ""; }
#region IColumnControlType Members
/// <summary>
/// Gets a value indicating whether [available to set length].
/// </summary>
/// <value>
/// <c>true</c> if [available to set length]; otherwise, <c>false</c>.
/// </value>
public virtual bool AvailableToSetLength { get { return true; } }
/// <summary>
/// Gets a value indicating whether [available to set items].
/// </summary>
/// <value>
/// <c>true</c> if [available to set items]; otherwise, <c>false</c>.
/// </value>
public virtual bool AvailableToSetItems { get { return false; } }
#endregion
#region IControlType Members
/// <summary>
/// Gets a value indicating whether [require single row].
/// like htmleditor control require entire row.
/// </summary>
/// <value><c>true</c> if [require single row]; otherwise, <c>false</c>.</value>
public virtual bool EntireRow
{
get { return false; }
}
#endregion
public virtual bool FileUpload
{
get { return false; }
}
}
}
|