diff --git a/components/editorControls/userControlWrapper/usercontrolDataEditor.cs b/components/editorControls/userControlWrapper/usercontrolDataEditor.cs index 0f7b4e8b91..aeaef5ac21 100644 --- a/components/editorControls/userControlWrapper/usercontrolDataEditor.cs +++ b/components/editorControls/userControlWrapper/usercontrolDataEditor.cs @@ -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> s = ss.GetSettings(((umbraco.cms.businesslogic.datatype.DefaultData)_data).DataTypeDefinitionId); + ss.Dispose(); + + foreach (Setting 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; + } + } } \ No newline at end of file diff --git a/components/editorControls/userControlWrapper/usercontrolPrevalueEditor.cs b/components/editorControls/userControlWrapper/usercontrolPrevalueEditor.cs index 49394661bc..90ab24b54c 100644 --- a/components/editorControls/userControlWrapper/usercontrolPrevalueEditor.cs +++ b/components/editorControls/userControlWrapper/usercontrolPrevalueEditor.cs @@ -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 dtSettings = new Dictionary(); 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 GetSettings(Type t) + { + Dictionary settings = new Dictionary(); + + 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 settings = GetSettings(type); + + foreach (KeyValuePair kv in settings) + { + DataEditorSettingType dst = kv.Value.GetDataEditorSettingType(); + dtSettings.Add(kv.Key, dst); + + DataEditorPropertyPanel panel = new DataEditorPropertyPanel(); + panel.Text = kv.Value.GetName(); + panel.Text += "
" + kv.Value.description + ""; + + + if (HasSettings(type)) + { + DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); + + List> 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 k in dtSettings) + { + ss.InsertSetting(_datatype.DataTypeDefinitionId, k.Key, k.Value.Value, i); + i++; + + } + + ss.Dispose(); } protected override void Render(HtmlTextWriter writer) { - writer.WriteLine(""); - writer.WriteLine(""); - writer.Write(""); - writer.Write("
Database datatype"); + writer.WriteLine("
"); + writer.WriteLine("
Database datatype
"); + writer.WriteLine("
"); _dropdownlist.RenderControl(writer); - writer.Write("
Usercontrol:"); + writer.Write(""); + + writer.WriteLine("
"); + writer.WriteLine("
Usercontrol:
"); + writer.WriteLine("
"); _dropdownlistUserControl.RenderControl(writer); - writer.Write("
"); + writer.Write(""); + + _phSettings.RenderControl(writer); } public string Configuration diff --git a/umbraco/cms/businesslogic/datatype/DefaultData.cs b/umbraco/cms/businesslogic/datatype/DefaultData.cs index 6b18ce0402..6d42ab748f 100644 --- a/umbraco/cms/businesslogic/datatype/DefaultData.cs +++ b/umbraco/cms/businesslogic/datatype/DefaultData.cs @@ -87,6 +87,15 @@ namespace umbraco.cms.businesslogic.datatype } } + public int DataTypeDefinitionId + { + get + { + return _dataType.DataTypeDefinitionId; + } + } + + #region IData Members ///