/*
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.CmsServices.Models;
using Everest.Forms;
using Everest.Forms.SchemaProvider;
using Everest.Library.ExtensionMethod;
namespace Everest.CmsServices.Providers{
public class MultiSelectContentSchemaProvider : ISchemaProvider
{
private IControlTypeFactory controlTypeFactory;
public MultiSelectContentSchemaProvider(IControlTypeFactory controlTypeFactory)
{
this.controlTypeFactory = controlTypeFactory;
}
#region ISchemaProvider Members
public ISchema GetSchema(string name, NameValueCollection nameValues)
{
Guid schemaUUID = new Guid(name);
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
dataContext.EnableCaching = true;
ISchema schema = new Schema();
Cms_Schema cms_schema = dataContext.QuerySchema(schemaUUID).FirstOrDefault();
if (cms_schema != null)
{
schema.Name = cms_schema.SchemaName;
schema.Title = cms_schema.SchemaName;
schema.GridType = "Everest.Cms.MultiSelectGridPanel";
if (cms_schema.SchemaType == (int)SchemaType.Binary)
{
// referencing binary contents
schema.QueryUrl = "Kooboo_Content/GetReferencingBinaryContents"; // getDataUrl
schema.GridAttributes.Add("getDataSelectedUrl", "Kooboo_Content/GetReferencingBinaryContentsSelected"); // getDataSelectedUrl
}
else
{
// referencing text contents
schema.QueryUrl = "Kooboo_Content/GetReferencingTextContents"; // getDataUrl
schema.GridAttributes.Add("getDataSelectedUrl", "Kooboo_Content/GetReferencingTextContentsSelected"); // getDataSelectedUrl
}
// columns
Column uuid = new Column();
uuid.Name = "UUID";
uuid.Label = "UUID";
uuid.DataIndexInList = "UUID";
uuid.ListAttributes.Add("hidden", "true");
schema.AddColumn(uuid);
if (cms_schema.SchemaType == (int)SchemaType.Binary)
{
Column title = CreateTitleColumn();
schema.AddColumn(title);
Column filePath = new Column();
filePath.Name = "FileUrl";
filePath.Label = Resources.ContentForm_FilePath;
filePath.DataIndexInList = "FileUrl";
filePath.ListAttributes.Add("sortable", "false");
filePath.ListAttributes.Add("width", "100");
filePath.ListAttributes.Add("renderer", "Ext.util.Format.preview");
filePath.Control = controlTypeFactory.ResolveControl(ControlType.Text.ToString());
schema.AddColumn(filePath);
}
else
{
cms_schema.Cms_Column.Load();
var titleColumn = cms_schema.TitleColumn;
if (titleColumn == null)
{
Column title = CreateTitleColumn();
schema.AddColumn(title);
}
else
{
Column column = CreateColumn(titleColumn);
schema.AddColumn(column);
}
foreach (var item in cms_schema.DynamicTableColumns)
{
if (item.VisibleInList == null || item.VisibleInList.Value == false)
{
continue;
}
Column column = CreateColumn(item);
schema.AddColumn(column);
}
}
Column folder = new Column();
folder.Name = "FolderName";
folder.Label = Resources.ContentForm_FolderName;
folder.DataIndexInList = "FolderName";
folder.ListAttributes.Add("sortable", "false");
schema.AddColumn(folder);
Column app = new Column();
app.Name = "Application";
app.Label = Resources.ContentForm_Application;
app.DataIndexInList = "Application";
app.ListAttributes.Add("sortable", "false");
app.ListAttributes.Add("width", "80");
app.Control = controlTypeFactory.ResolveControl(ControlType.Text.ToString());
schema.AddColumn(app);
}
return schema;
}
private static Column CreateColumn(Cms_Column item)
{
Column column = new Column();
column.Name = item.ColumnName;
column.Label = item.Label;
column.DataIndexInList = item.ColumnName;
//column.Control = controlTypeFactory.ResolveControl(item.ControlType);
if (!StringExtensions.IsNullOrEmptyTrim(item.Tpl))
{
column.ListAttributes.Add("tpl", item.Tpl.Trim());
column.ListAttributes.Add("xtype", "templatecolumn");
}
if (item.DataType.Equals("datetime", StringComparison.InvariantCultureIgnoreCase))
{
column.ListAttributes.Add("renderer", "Ext.util.Format.dateTime");
}
return column;
}
private Column CreateTitleColumn()
{
Column title = new Column();
title.Name = "Title";
title.Label = Resources.ContentForm_Title;
title.DataIndexInList = "Title";
title.Queryable = true;
title.ListAttributes.Add("width", "150");
title.Control = controlTypeFactory.ResolveControl(ControlType.Text.ToString());
return title;
}
#endregion
}
}
|