/*
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.Linq;
using System.Text;
using System.Collections.Generic;
using System.Collections.Specialized;
using Everest.Library.ExtensionMethod;
namespace Everest.Forms.ExtForm.Controls{
public class Combobox : ExtControlBase
{
public override string Name
{
get { return "Combobox"; }
}
protected override string XType
{
get { return "combo"; }
}
protected override string RenderConfig(IColumn column)
{
StringBuilder storeBuilder = new StringBuilder();
string mode = "local";
if (string.IsNullOrEmpty(column.DetailAttributes["url"]))
{
if (string.IsNullOrEmpty(column.Items))
{
column.Items = "NULL:::NULL";
}
mode = "local";
NameValueCollection nameValues = ColumnHelper.ParseColumnItems(column.Items);
StringBuilder jsonBuilder = new StringBuilder("[");
if (nameValues.Count > 0)
{
foreach (string key in nameValues.Keys)
{
jsonBuilder.AppendFormat("['{0}','{1}'],", key, nameValues[key]);
}
jsonBuilder.RemoveLastSpecifiedChar(',');
}
jsonBuilder.Append("]");
storeBuilder.AppendFormat(@"new Ext.data.SimpleStore({{
fields: ['Name', 'Value','Image','ImageAlt','Checked'],
data : {0}
}})", jsonBuilder.ToString());
}
else
{
mode = "remote";
string baseParams = "{}";
if (!string.IsNullOrEmpty(column.DetailAttributes["baseParams"]))
{
baseParams = column.DetailAttributes["baseParams"];
column.DetailAttributes.Remove("baseParams");
}
string requestMethod = "GET";
if (!string.IsNullOrEmpty(column.DetailAttributes["requestMethod"]))
{
requestMethod = column.DetailAttributes["requestMethod"];
}
storeBuilder.AppendFormat(@"new Ext.data.JsonStore({{proxy: new Ext.data.HttpProxy({{
url: '{0}',
method: '{2}'
}}),url : '{0}',baseParams:{1},root:'Rows',totalProperty: 'TotalCount',fields: ['Name', 'Value','Image','ImageAlt','Checked']
}})", column.DetailAttributes["url"], baseParams, requestMethod);
}
//listWidth value refer to form defaults: {{width: 230}},
string listWidth = "230";
if (!string.IsNullOrEmpty(column.DetailAttributes["width"]))
{
listWidth = column.DetailAttributes["width"];
}
return string.Format(@"resizable:true,editable:false,listWidth:{3}, hiddenName:'{0}',triggerAction: 'all',selectOnFocus:true,mode: '{2}',
displayField:'Name', valueField:'Value',checkField:'Checked',
store:{1}", column.Name, storeBuilder.ToString(), mode, listWidth);
}
}
}
|