makes it possible to have custom settings on datatypes using the usercontrol wrapper
This commit is contained in:
@@ -10,6 +10,9 @@ using System.Web.UI.HtmlControls;
|
||||
|
||||
using umbraco.interfaces;
|
||||
using umbraco.editorControls;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
using System.Collections.Generic;
|
||||
using umbraco.IO;
|
||||
|
||||
namespace umbraco.editorControls.userControlGrapper
|
||||
{
|
||||
@@ -49,13 +52,52 @@ namespace umbraco.editorControls.userControlGrapper
|
||||
{
|
||||
base.OnInit (e);
|
||||
|
||||
this.Controls.Add(
|
||||
new System.Web.UI.UserControl().LoadControl(_usercontrolPath));
|
||||
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);
|
||||
|
||||
if (!Page.IsPostBack)
|
||||
((IUsercontrolDataEditor)Controls[0] as IUsercontrolDataEditor).value = _data.Value;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ using umbraco.BusinessLogic;
|
||||
|
||||
using umbraco.editorControls;
|
||||
using umbraco.IO;
|
||||
using System.Collections.Generic;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
|
||||
namespace umbraco.editorControls.userControlGrapper
|
||||
{
|
||||
@@ -30,7 +32,9 @@ namespace umbraco.editorControls.userControlGrapper
|
||||
|
||||
private DropDownList _dropdownlist;
|
||||
private DropDownList _dropdownlistUserControl;
|
||||
private PlaceHolder _phSettings;
|
||||
|
||||
private Dictionary<string, DataEditorSettingType> dtSettings = new Dictionary<string, DataEditorSettingType>();
|
||||
|
||||
public usercontrolPrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType DataType)
|
||||
{
|
||||
@@ -52,10 +56,14 @@ namespace umbraco.editorControls.userControlGrapper
|
||||
_dropdownlistUserControl = new DropDownList();
|
||||
_dropdownlistUserControl.ID = "usercontrol";
|
||||
|
||||
_phSettings = new PlaceHolder();
|
||||
_phSettings.ID = "settings";
|
||||
|
||||
// put the childcontrols in context - ensuring that
|
||||
// the viewstate is persisted etc.
|
||||
Controls.Add(_dropdownlist);
|
||||
Controls.Add(_dropdownlistUserControl);
|
||||
Controls.Add(_phSettings);
|
||||
|
||||
// populate the usercontrol dropdown
|
||||
_dropdownlistUserControl.Items.Add(new ListItem(ui.Text("choose"), ""));
|
||||
@@ -104,10 +112,91 @@ namespace umbraco.editorControls.userControlGrapper
|
||||
if (config != "")
|
||||
{
|
||||
_dropdownlistUserControl.SelectedValue = config;
|
||||
|
||||
|
||||
}
|
||||
_dropdownlist.SelectedValue = _datatype.DBType.ToString();
|
||||
|
||||
}
|
||||
|
||||
//check for settings
|
||||
if(!string.IsNullOrEmpty(Configuration))
|
||||
LoadSetttings(Configuration);
|
||||
|
||||
}
|
||||
|
||||
private Dictionary<string, DataEditorSetting> GetSettings(Type t)
|
||||
{
|
||||
Dictionary<string, DataEditorSetting> settings = new Dictionary<string, DataEditorSetting>();
|
||||
|
||||
foreach (System.Reflection.PropertyInfo p in t.GetProperties())
|
||||
{
|
||||
|
||||
object[] o = p.GetCustomAttributes(typeof(DataEditorSetting), true);
|
||||
|
||||
if (o.Length > 0)
|
||||
settings.Add(p.Name, (DataEditorSetting)o[0]);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private void LoadSetttings(string fileName)
|
||||
{
|
||||
if (System.IO.File.Exists(IOHelper.MapPath("~/" + fileName)))
|
||||
{
|
||||
|
||||
UserControl oControl = (UserControl)this.Page.LoadControl(@"~/" + fileName);
|
||||
|
||||
Type type = oControl.GetType();
|
||||
|
||||
|
||||
Dictionary<string, DataEditorSetting> settings = GetSettings(type);
|
||||
|
||||
foreach (KeyValuePair<string, DataEditorSetting> kv in settings)
|
||||
{
|
||||
DataEditorSettingType dst = kv.Value.GetDataEditorSettingType();
|
||||
dtSettings.Add(kv.Key, dst);
|
||||
|
||||
DataEditorPropertyPanel panel = new DataEditorPropertyPanel();
|
||||
panel.Text = kv.Value.GetName();
|
||||
panel.Text += "<br/><small>" + kv.Value.description + "</small>";
|
||||
|
||||
|
||||
if (HasSettings(type))
|
||||
{
|
||||
DataEditorSettingsStorage ss = new DataEditorSettingsStorage();
|
||||
|
||||
List<Setting<string, string>> s = ss.GetSettings(_datatype.DataTypeDefinitionId);
|
||||
ss.Dispose();
|
||||
|
||||
if (s.Find(set => set.Key == kv.Key).Value != null)
|
||||
dst.Value = s.Find(set => set.Key == kv.Key).Value;
|
||||
|
||||
}
|
||||
|
||||
panel.Controls.Add(dst.RenderControl(kv.Value));
|
||||
|
||||
_phSettings.Controls.Add(panel);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Save()
|
||||
@@ -123,18 +212,40 @@ namespace umbraco.editorControls.userControlGrapper
|
||||
SqlHelper.CreateParameter("@dtdefid",_datatype.DataTypeDefinitionId)};
|
||||
SqlHelper.ExecuteNonQuery("delete from cmsDataTypePreValues where datatypenodeid = @dtdefid", SqlParams);
|
||||
SqlHelper.ExecuteNonQuery("insert into cmsDataTypePreValues (datatypenodeid,[value],sortorder,alias) values (@dtdefid,@value,0,'')", SqlParams);
|
||||
|
||||
|
||||
//settings
|
||||
|
||||
DataEditorSettingsStorage ss = new DataEditorSettingsStorage();
|
||||
|
||||
//ss.ClearSettings(_datatype.DataTypeDefinitionId);
|
||||
|
||||
int i = 0;
|
||||
foreach (KeyValuePair<string, DataEditorSettingType> k in dtSettings)
|
||||
{
|
||||
ss.InsertSetting(_datatype.DataTypeDefinitionId, k.Key, k.Value.Value, i);
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
ss.Dispose();
|
||||
}
|
||||
|
||||
protected override void Render(HtmlTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("<table>");
|
||||
writer.WriteLine("<tr><th>Database datatype</th><td>");
|
||||
writer.WriteLine("<div class=\"propertyItem\">");
|
||||
writer.WriteLine("<div class=\"propertyItemheader\">Database datatype</div>");
|
||||
writer.WriteLine("<div class=\"propertyItemContent\">");
|
||||
_dropdownlist.RenderControl(writer);
|
||||
writer.Write("</td></tr>");
|
||||
writer.Write("<tr><th>Usercontrol:</th><td>");
|
||||
writer.Write("</div></div>");
|
||||
|
||||
writer.WriteLine("<div class=\"propertyItem\">");
|
||||
writer.WriteLine("<div class=\"propertyItemheader\">Usercontrol:</div>");
|
||||
writer.WriteLine("<div class=\"propertyItemContent\">");
|
||||
_dropdownlistUserControl.RenderControl(writer);
|
||||
writer.Write("</td></tr>");
|
||||
writer.Write("</table>");
|
||||
writer.Write("</div></div>");
|
||||
|
||||
_phSettings.RenderControl(writer);
|
||||
}
|
||||
|
||||
public string Configuration
|
||||
|
||||
Reference in New Issue
Block a user