2009-06-19 07:39:16 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Security;
|
|
|
|
|
using System.Web.UI;
|
|
|
|
|
using System.Web.UI.WebControls;
|
|
|
|
|
using System.Web.UI.WebControls.WebParts;
|
|
|
|
|
using System.Web.UI.HtmlControls;
|
|
|
|
|
|
|
|
|
|
using umbraco.interfaces;
|
|
|
|
|
using umbraco.editorControls;
|
2010-12-17 08:00:08 -01:00
|
|
|
using umbraco.cms.businesslogic.datatype;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using umbraco.IO;
|
2009-06-19 07:39:16 +00:00
|
|
|
|
|
|
|
|
namespace umbraco.editorControls.userControlGrapper
|
|
|
|
|
{
|
|
|
|
|
public class usercontrolDataEditor : System.Web.UI.WebControls.PlaceHolder, umbraco.interfaces.IDataEditor
|
|
|
|
|
{
|
|
|
|
|
private umbraco.interfaces.IData _data;
|
|
|
|
|
private string _usercontrolPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public usercontrolDataEditor(umbraco.interfaces.IData Data, string UsercontrolPath)
|
|
|
|
|
{
|
|
|
|
|
_data = Data;
|
|
|
|
|
_usercontrolPath = UsercontrolPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool TreatAsRichTextEditor
|
|
|
|
|
{
|
|
|
|
|
get {return false;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ShowLabel
|
|
|
|
|
{
|
|
|
|
|
get {return true;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Control Editor {get{return this;}}
|
|
|
|
|
|
|
|
|
|
public void Save()
|
|
|
|
|
{
|
|
|
|
|
IUsercontrolDataEditor uc =
|
|
|
|
|
(IUsercontrolDataEditor)Controls[0] as IUsercontrolDataEditor;
|
|
|
|
|
|
|
|
|
|
_data.Value = uc.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInit(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnInit (e);
|
|
|
|
|
|
2010-12-17 08:00:08 -01:00
|
|
|
Control oControl = new System.Web.UI.UserControl().LoadControl(_usercontrolPath);
|
|
|
|
|
|
|
|
|
|
if (HasSettings(oControl.GetType()))
|
|
|
|
|
{
|
|
|
|
|
DataEditorSettingsStorage ss = new DataEditorSettingsStorage();
|
|
|
|
|
List<Setting<string, string>> s = ss.GetSettings(((umbraco.cms.businesslogic.datatype.DefaultData)_data).DataTypeDefinitionId);
|
|
|
|
|
ss.Dispose();
|
|
|
|
|
|
|
|
|
|
foreach (Setting<string, string> setting in s)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrEmpty(setting.Key))
|
|
|
|
|
{
|
|
|
|
|
oControl.GetType().InvokeMember(setting.Key, System.Reflection.BindingFlags.SetProperty, null, oControl, new object[] { setting.Value });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (MissingMethodException ex) { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(oControl);
|
2009-06-19 07:39:16 +00:00
|
|
|
|
|
|
|
|
if (!Page.IsPostBack)
|
|
|
|
|
((IUsercontrolDataEditor)Controls[0] as IUsercontrolDataEditor).value = _data.Value;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-17 08:00:08 -01:00
|
|
|
private bool HasSettings(Type t)
|
|
|
|
|
{
|
|
|
|
|
bool hasSettings = false;
|
|
|
|
|
foreach (System.Reflection.PropertyInfo p in t.GetProperties())
|
|
|
|
|
{
|
|
|
|
|
object[] o = p.GetCustomAttributes(typeof(DataEditorSetting), true);
|
|
|
|
|
|
|
|
|
|
if (o.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
hasSettings = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hasSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-19 07:39:16 +00:00
|
|
|
}
|
|
|
|
|
}
|