Relocated the uComponents data-type base classes to from 'cms' to 'editorControls' - better to keep them self-contained, (at this time).
This commit is contained in:
107
components/editorControls/AbstractJsonPrevalueEditor.cs
Normal file
107
components/editorControls/AbstractJsonPrevalueEditor.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Web.Script.Serialization;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
|
||||
namespace umbraco.editorControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract class for the PreValue Editor.
|
||||
/// Specifically designed to serialize/deserialize the options as JSON.
|
||||
/// </summary>
|
||||
public abstract class AbstractJsonPrevalueEditor : AbstractPrevalueEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// The underlying base data-type.
|
||||
/// </summary>
|
||||
protected readonly umbraco.cms.businesslogic.datatype.BaseDataType m_DataType;
|
||||
|
||||
/// <summary>
|
||||
/// An object to temporarily lock writing to the database.
|
||||
/// </summary>
|
||||
private static readonly object m_Locker = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractJsonPrevalueEditor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dataType">Type of the data.</param>
|
||||
public AbstractJsonPrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType dataType)
|
||||
{
|
||||
this.m_DataType = dataType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractJsonPrevalueEditor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dataType">Type of the data.</param>
|
||||
/// <param name="dbType">Type of the database field.</param>
|
||||
public AbstractJsonPrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType dataType, umbraco.cms.businesslogic.datatype.DBTypes dbType)
|
||||
: base()
|
||||
{
|
||||
this.m_DataType = dataType;
|
||||
this.m_DataType.DBType = dbType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the PreValue options for the data-type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the resulting object.</typeparam>
|
||||
/// <returns>
|
||||
/// Returns the options for the PreValue Editor
|
||||
/// </returns>
|
||||
public T GetPreValueOptions<T>()
|
||||
{
|
||||
var prevalues = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
|
||||
if (prevalues.Count > 0)
|
||||
{
|
||||
var prevalue = (PreValue)prevalues[0];
|
||||
if (!string.IsNullOrEmpty(prevalue.Value))
|
||||
{
|
||||
try
|
||||
{
|
||||
// deserialize the options
|
||||
var serializer = new JavaScriptSerializer();
|
||||
|
||||
// return the options
|
||||
return serializer.Deserialize<T>(prevalue.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Add(LogTypes.Error, this.m_DataType.DataTypeDefinitionId, string.Concat("umbraco.editorControls: Execption thrown: ", ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if all else fails, return default options
|
||||
return default(T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the data-type PreValue options.
|
||||
/// </summary>
|
||||
public void SaveAsJson(object options)
|
||||
{
|
||||
// serialize the options into JSON
|
||||
var serializer = new JavaScriptSerializer();
|
||||
var json = serializer.Serialize(options);
|
||||
|
||||
lock (m_Locker)
|
||||
{
|
||||
var prevalues = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
|
||||
if (prevalues.Count > 0)
|
||||
{
|
||||
var prevalue = (PreValue)prevalues[0];
|
||||
|
||||
// update
|
||||
prevalue.Value = json;
|
||||
prevalue.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
// insert
|
||||
PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace umbraco.cms.businesslogic.datatype
|
||||
namespace umbraco.editorControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract class for the Prevalue Editor options.
|
||||
79
components/editorControls/AbstractPrevalueEditor.cs
Normal file
79
components/editorControls/AbstractPrevalueEditor.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using umbraco.interfaces;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
|
||||
[assembly: WebResource("umbraco.editorControls.PrevalueEditor.css", "text/css")]
|
||||
|
||||
namespace umbraco.editorControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract class for the PreValue Editor.
|
||||
/// </summary>
|
||||
public abstract class AbstractPrevalueEditor : WebControl, IDataPrevalue
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractPrevalueEditor"/> class.
|
||||
/// </summary>
|
||||
public AbstractPrevalueEditor()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the editor.
|
||||
/// </summary>
|
||||
/// <value>The editor.</value>
|
||||
public virtual Control Editor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves this instance.
|
||||
/// </summary>
|
||||
public virtual void Save()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
this.EnsureChildControls();
|
||||
|
||||
// Adds the client dependencies.
|
||||
this.RegisterEmbeddedClientResource("umbraco.editorControls.PrevalueEditor.css", ClientDependencyType.Css);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the HTML opening tag of the control to the specified writer. This method is used primarily by control developers.
|
||||
/// </summary>
|
||||
/// <param name="writer">A <see cref="T:System.Web.UI.HtmlTextWriter"/> that represents the output stream to render HTML content on the client.</param>
|
||||
public override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "PrevalueEditor");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div);
|
||||
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the HTML closing tag of the control into the specified writer. This method is used primarily by control developers.
|
||||
/// </summary>
|
||||
/// <param name="writer">A <see cref="T:System.Web.UI.HtmlTextWriter"/> that represents the output stream to render HTML content on the client.</param>
|
||||
public override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
|
||||
writer.RenderEndTag();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@
|
||||
using umbraco;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
|
||||
namespace umbraco.cms.businesslogic.datatype
|
||||
namespace umbraco.editorControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Overrides the <see cref="umbraco.cms.businesslogic.datatype.DefaultData"/> object to return the value as XML.
|
||||
/// </summary>
|
||||
public class CsvToXmlData : DefaultData
|
||||
public class CsvToXmlData : umbraco.cms.businesslogic.datatype.DefaultData
|
||||
{
|
||||
/// <summary>
|
||||
/// The separators to split the delimited string.
|
||||
@@ -28,7 +28,7 @@ namespace umbraco.cms.businesslogic.datatype
|
||||
/// Initializes a new instance of the <see cref="CsvToXmlData"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dataType">Type of the data.</param>
|
||||
public CsvToXmlData(BaseDataType dataType)
|
||||
public CsvToXmlData(umbraco.cms.businesslogic.datatype.BaseDataType dataType)
|
||||
: this(dataType, "values")
|
||||
{
|
||||
}
|
||||
@@ -38,7 +38,7 @@ namespace umbraco.cms.businesslogic.datatype
|
||||
/// </summary>
|
||||
/// <param name="dataType">Type of the data.</param>
|
||||
/// <param name="rootName">Name of the root.</param>
|
||||
public CsvToXmlData(BaseDataType dataType, string rootName)
|
||||
public CsvToXmlData(umbraco.cms.businesslogic.datatype.BaseDataType dataType, string rootName)
|
||||
: this(dataType, rootName, "value")
|
||||
{
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace umbraco.cms.businesslogic.datatype
|
||||
/// <param name="dataType">Type of the data.</param>
|
||||
/// <param name="rootName">Name of the root.</param>
|
||||
/// <param name="elementName">Name of the element.</param>
|
||||
public CsvToXmlData(BaseDataType dataType, string rootName, string elementName)
|
||||
public CsvToXmlData(umbraco.cms.businesslogic.datatype.BaseDataType dataType, string rootName, string elementName)
|
||||
: this(dataType, rootName, elementName, new[] { "," })
|
||||
{
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace umbraco.cms.businesslogic.datatype
|
||||
/// <param name="rootName">Name of the root.</param>
|
||||
/// <param name="elementName">Name of the element.</param>
|
||||
/// <param name="separator">The separator.</param>
|
||||
public CsvToXmlData(BaseDataType dataType, string rootName, string elementName, string[] separator)
|
||||
public CsvToXmlData(umbraco.cms.businesslogic.datatype.BaseDataType dataType, string rootName, string elementName, string[] separator)
|
||||
: base(dataType)
|
||||
{
|
||||
this.rootName = rootName;
|
||||
83
components/editorControls/PrevalueEditor.css
Normal file
83
components/editorControls/PrevalueEditor.css
Normal file
@@ -0,0 +1,83 @@
|
||||
/* Standard clearfix */
|
||||
.clearfix:after
|
||||
{
|
||||
content: ".";
|
||||
display: block;
|
||||
clear: both;
|
||||
visibility: hidden;
|
||||
line-height: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.clearfix
|
||||
{
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
html[xmlns] .clearfix
|
||||
{
|
||||
display: block;
|
||||
}
|
||||
|
||||
* html .clearfix
|
||||
{
|
||||
height: 1%;
|
||||
}
|
||||
|
||||
.PrevalueEditor
|
||||
{
|
||||
background: transparent url('<%= WebResource("uComponents.Core.Shared.Resources.Images.ucomponents-logo-small.png")%>') no-repeat right 8px;
|
||||
padding-top: 40px;
|
||||
}
|
||||
.PrevalueEditor div.row
|
||||
{
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.PrevalueEditor div.label
|
||||
{
|
||||
float: left;
|
||||
width: 120px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.PrevalueEditor div.field
|
||||
{
|
||||
float: left;
|
||||
}
|
||||
|
||||
.PrevalueEditor div.description
|
||||
{
|
||||
clear: left;
|
||||
color: #666;
|
||||
float: left;
|
||||
font-style: italic;
|
||||
margin: 3px 0 10px 130px;
|
||||
}
|
||||
|
||||
/* validation */
|
||||
.PrevalueEditor .validator
|
||||
{
|
||||
color: red;
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
margin-bottom: 3px;
|
||||
margin-top: 3px;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
/* headers */
|
||||
.PrevalueEditor h3
|
||||
{
|
||||
clear: left;
|
||||
color: #666;
|
||||
float: left;
|
||||
font-style: italic;
|
||||
font-weight: bold;
|
||||
margin: 3px 10px 10px 0;
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
.PrevalueEditor td
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
105
components/editorControls/PrevalueEditorExtensions.cs
Normal file
105
components/editorControls/PrevalueEditorExtensions.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace umbraco.editorControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for the Prevalue Editor
|
||||
/// </summary>
|
||||
public static class PrevalueEditorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the prevalue controls.
|
||||
/// </summary>
|
||||
/// <param name="collection">The collection.</param>
|
||||
/// <param name="controls">The controls.</param>
|
||||
public static void AddPrevalueControls(this ControlCollection collection, params Control[] controls)
|
||||
{
|
||||
foreach (var control in controls)
|
||||
{
|
||||
collection.Add(control);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the prevalue row heading.
|
||||
/// </summary>
|
||||
/// <param name="writer">The writer.</param>
|
||||
/// <param name="heading">The heading.</param>
|
||||
public static void AddPrevalueHeading(this HtmlTextWriter writer, string heading)
|
||||
{
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "row clearfix");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'row'
|
||||
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.H3); // start 'h3'
|
||||
|
||||
writer.Write(heading);
|
||||
|
||||
writer.RenderEndTag(); // end 'h3'
|
||||
|
||||
writer.RenderEndTag(); // end 'row'
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new row to the Prevalue Editor.
|
||||
/// </summary>
|
||||
/// <param name="writer">The HtmlTextWriter.</param>
|
||||
/// <param name="label">The label for the field.</param>
|
||||
/// <param name="controls">The controls for the field.</param>
|
||||
public static void AddPrevalueRow(this HtmlTextWriter writer, string label, params Control[] controls)
|
||||
{
|
||||
writer.AddPrevalueRow(label, string.Empty, controls);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new row to the Prevalue Editor, (with an optional description).
|
||||
/// </summary>
|
||||
/// <param name="writer">The HtmlTextWriter.</param>
|
||||
/// <param name="label">The label for the field.</param>
|
||||
/// <param name="description">The description for the field.</param>
|
||||
/// <param name="controls">The controls for the field.</param>
|
||||
public static void AddPrevalueRow(this HtmlTextWriter writer, string label, string description, params Control[] controls)
|
||||
{
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "row clearfix");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'row'
|
||||
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "label");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'label'
|
||||
|
||||
var lbl = new HtmlGenericControl("label") { InnerText = label };
|
||||
|
||||
if (controls.Length > 0 && !string.IsNullOrEmpty(controls[0].ClientID))
|
||||
{
|
||||
lbl.Attributes.Add("for", controls[0].ClientID);
|
||||
}
|
||||
|
||||
lbl.RenderControl(writer);
|
||||
|
||||
writer.RenderEndTag(); // end 'label'
|
||||
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "field");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'field'
|
||||
|
||||
foreach (var control in controls)
|
||||
{
|
||||
control.RenderControl(writer);
|
||||
}
|
||||
|
||||
writer.RenderEndTag(); // end 'field'
|
||||
|
||||
if (!string.IsNullOrEmpty(description))
|
||||
{
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "description");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'description'
|
||||
|
||||
Label desc = new Label() { Text = description };
|
||||
desc.RenderControl(writer);
|
||||
|
||||
writer.RenderEndTag(); // end 'description'
|
||||
}
|
||||
|
||||
writer.RenderEndTag(); // end 'row'
|
||||
}
|
||||
}
|
||||
}
|
||||
73
components/editorControls/ResourceExtensions.cs
Normal file
73
components/editorControls/ResourceExtensions.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Web.UI;
|
||||
using umbraco;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace umbraco.editorControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for embedded resources
|
||||
/// </summary>
|
||||
public static class ResourceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the embedded client resource.
|
||||
/// </summary>
|
||||
/// <param name="ctl">The control.</param>
|
||||
/// <param name="resourceName">Name of the resource.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
public static void RegisterEmbeddedClientResource(this Control ctl, string resourceName, ClientDependencyType type)
|
||||
{
|
||||
ctl.RegisterEmbeddedClientResource(ctl.GetType(), resourceName, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the embedded client resource.
|
||||
/// </summary>
|
||||
/// <param name="ctl">The control.</param>
|
||||
/// <param name="resourceContainer">The resource container.</param>
|
||||
/// <param name="resourceName">Name of the resource.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
public static void RegisterEmbeddedClientResource(this Control ctl, Type resourceContainer, string resourceName, ClientDependencyType type)
|
||||
{
|
||||
ctl.Page.RegisterEmbeddedClientResource(resourceContainer, resourceName, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the embedded client resource.
|
||||
/// </summary>
|
||||
/// <param name="page">The page.</param>
|
||||
/// <param name="resourceContainer">The type containing the embedded resource</param>
|
||||
/// <param name="resourceName">Name of the resource.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
public static void RegisterEmbeddedClientResource(this Page page, Type resourceContainer, string resourceName, ClientDependencyType type)
|
||||
{
|
||||
var target = page.Header;
|
||||
|
||||
// if there's no <head runat="server" /> don't throw an exception.
|
||||
if (target != null)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ClientDependencyType.Css:
|
||||
// get the urls for the embedded resources
|
||||
var resourceUrl = page.ClientScript.GetWebResourceUrl(resourceContainer, resourceName);
|
||||
var link = new HtmlLink();
|
||||
link.Attributes.Add("href", resourceUrl);
|
||||
link.Attributes.Add("type", "text/css");
|
||||
link.Attributes.Add("rel", "stylesheet");
|
||||
target.Controls.Add(link);
|
||||
break;
|
||||
|
||||
case ClientDependencyType.Javascript:
|
||||
page.ClientScript.RegisterClientScriptResource(resourceContainer, resourceName);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
using System.Xml;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
|
||||
namespace umbraco.cms.businesslogic.datatype
|
||||
namespace umbraco.editorControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Overrides the <see cref="umbraco.cms.businesslogic.datatype.DefaultData"/> object to return the value as XML.
|
||||
/// </summary>
|
||||
public class XmlData : DefaultData
|
||||
public class XmlData : umbraco.cms.businesslogic.datatype.DefaultData
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="XmlData"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dataType">Type of the data.</param>
|
||||
public XmlData(BaseDataType dataType)
|
||||
public XmlData(umbraco.cms.businesslogic.datatype.BaseDataType dataType)
|
||||
: base(dataType)
|
||||
{
|
||||
}
|
||||
@@ -167,6 +167,9 @@
|
||||
<Compile Include="..\..\LinqToUmbraco\src\umbraco.Linq\Solution Items\SolutionInfo.cs">
|
||||
<Link>SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="AbstractJsonPrevalueEditor.cs" />
|
||||
<Compile Include="AbstractOptions.cs" />
|
||||
<Compile Include="AbstractPrevalueEditor.cs" />
|
||||
<Compile Include="AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
@@ -186,6 +189,7 @@
|
||||
<Compile Include="colorpicker\ColorPickerDataType.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CsvToXmlData.cs" />
|
||||
<Compile Include="DataTypeGuids.cs" />
|
||||
<Compile Include="datefieldmultiple\DataTypeDatefieldMultiple.cs">
|
||||
<SubType>Code</SubType>
|
||||
@@ -311,6 +315,7 @@
|
||||
<Compile Include="pagepicker\PagePickerDataType.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="PrevalueEditorExtensions.cs" />
|
||||
<Compile Include="radiobuttonlist\radiobox.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
@@ -322,6 +327,7 @@
|
||||
<Compile Include="relatedlinks\RelatedLinksDataEditor.cs" />
|
||||
<Compile Include="relatedlinks\RelatedLinksDataType.cs" />
|
||||
<Compile Include="relatedlinks\RelatedLinksPrevalueEditor.cs" />
|
||||
<Compile Include="ResourceExtensions.cs" />
|
||||
<Compile Include="SettingControls\CheckBox.cs" />
|
||||
<Compile Include="SettingControls\CheckBoxList.cs" />
|
||||
<Compile Include="SettingControls\DropDownList.cs" />
|
||||
@@ -398,6 +404,7 @@
|
||||
<Compile Include="userControlWrapper\usercontrolDataEditor.cs" />
|
||||
<Compile Include="userControlWrapper\usercontrolDataType.cs" />
|
||||
<Compile Include="userControlWrapper\usercontrolPrevalueEditor.cs" />
|
||||
<Compile Include="XmlData.cs" />
|
||||
<Compile Include="XPathCheckBoxList\XPathCheckBoxListDataEditor.cs" />
|
||||
<Compile Include="XPathCheckBoxList\XPathCheckBoxListDataType.cs" />
|
||||
<Compile Include="XPathCheckBoxList\XPathCheckBoxListOptions.cs" />
|
||||
@@ -459,6 +466,7 @@
|
||||
<Content Include="MultiNodeTreePicker\MultiNodePickerStyles.css" />
|
||||
<Content Include="MultipleTextstring\MultipleTextstring.css" />
|
||||
<Content Include="MultipleTextstring\MultipleTextstring.js" />
|
||||
<EmbeddedResource Include="PrevalueEditor.css" />
|
||||
<EmbeddedResource Include="KeyValuePrevalueEditor.js" />
|
||||
<EmbeddedResource Include="KeyValuePrevalueEditor.css" />
|
||||
<Content Include="mediapicker\MediaPicker.js" />
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
using System;
|
||||
using System.Web.Script.Serialization;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
|
||||
namespace umbraco.cms.businesslogic.datatype
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract class for the PreValue Editor.
|
||||
/// Specifically designed to serialize/deserialize the options as JSON.
|
||||
/// </summary>
|
||||
public abstract class AbstractJsonPrevalueEditor : AbstractPrevalueEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// The underlying base data-type.
|
||||
/// </summary>
|
||||
protected readonly BaseDataType m_DataType;
|
||||
|
||||
/// <summary>
|
||||
/// An object to temporarily lock writing to the database.
|
||||
/// </summary>
|
||||
private static readonly object m_Locker = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractJsonPrevalueEditor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dataType">Type of the data.</param>
|
||||
public AbstractJsonPrevalueEditor(BaseDataType dataType)
|
||||
{
|
||||
this.m_DataType = dataType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractJsonPrevalueEditor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dataType">Type of the data.</param>
|
||||
/// <param name="dbType">Type of the database field.</param>
|
||||
public AbstractJsonPrevalueEditor(BaseDataType dataType, DBTypes dbType)
|
||||
: base()
|
||||
{
|
||||
this.m_DataType = dataType;
|
||||
this.m_DataType.DBType = dbType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the PreValue options for the data-type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the resulting object.</typeparam>
|
||||
/// <returns>
|
||||
/// Returns the options for the PreValue Editor
|
||||
/// </returns>
|
||||
public T GetPreValueOptions<T>()
|
||||
{
|
||||
var prevalues = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
|
||||
if (prevalues.Count > 0)
|
||||
{
|
||||
var prevalue = (PreValue)prevalues[0];
|
||||
if (!string.IsNullOrEmpty(prevalue.Value))
|
||||
{
|
||||
try
|
||||
{
|
||||
// deserialize the options
|
||||
var serializer = new JavaScriptSerializer();
|
||||
|
||||
// return the options
|
||||
return serializer.Deserialize<T>(prevalue.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Add(LogTypes.Error, this.m_DataType.DataTypeDefinitionId, string.Concat("uComponents: Execption thrown: ", ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if all else fails, return default options
|
||||
return default(T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the data-type PreValue options.
|
||||
/// </summary>
|
||||
public void SaveAsJson(object options)
|
||||
{
|
||||
// serialize the options into JSON
|
||||
var serializer = new JavaScriptSerializer();
|
||||
var json = serializer.Serialize(options);
|
||||
|
||||
lock (m_Locker)
|
||||
{
|
||||
var prevalues = PreValues.GetPreValues(this.m_DataType.DataTypeDefinitionId);
|
||||
if (prevalues.Count > 0)
|
||||
{
|
||||
PreValue prevalue = (PreValue)prevalues[0];
|
||||
|
||||
// update
|
||||
prevalue.Value = json;
|
||||
prevalue.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
// insert
|
||||
PreValue.MakeNew(this.m_DataType.DataTypeDefinitionId, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using ClientDependency.Core;
|
||||
using umbraco.interfaces;
|
||||
|
||||
namespace umbraco.cms.businesslogic.datatype
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract class for the PreValue Editor.
|
||||
/// </summary>
|
||||
public abstract class AbstractPrevalueEditor : WebControl, IDataPrevalue
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractPrevalueEditor"/> class.
|
||||
/// </summary>
|
||||
public AbstractPrevalueEditor()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the editor.
|
||||
/// </summary>
|
||||
/// <value>The editor.</value>
|
||||
public virtual Control Editor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves this instance.
|
||||
/// </summary>
|
||||
public virtual void Save()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
this.EnsureChildControls();
|
||||
|
||||
// Adds the client dependencies.
|
||||
this.AddResourceToClientDependency("uComponents.DataTypes.Shared.Resources.Styles.PrevalueEditor.css", ClientDependencyType.Css);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the HTML opening tag of the control to the specified writer. This method is used primarily by control developers.
|
||||
/// </summary>
|
||||
/// <param name="writer">A <see cref="T:System.Web.UI.HtmlTextWriter"/> that represents the output stream to render HTML content on the client.</param>
|
||||
public override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "uComponents");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div);
|
||||
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the HTML closing tag of the control into the specified writer. This method is used primarily by control developers.
|
||||
/// </summary>
|
||||
/// <param name="writer">A <see cref="T:System.Web.UI.HtmlTextWriter"/> that represents the output stream to render HTML content on the client.</param>
|
||||
public override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
|
||||
writer.RenderEndTag();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace umbraco.cms.businesslogic.datatype
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for the Prevalue Editor
|
||||
/// </summary>
|
||||
public static class PrevalueEditorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the prevalue controls.
|
||||
/// </summary>
|
||||
/// <param name="collection">The collection.</param>
|
||||
/// <param name="controls">The controls.</param>
|
||||
public static void AddPrevalueControls(this ControlCollection collection, params Control[] controls)
|
||||
{
|
||||
foreach (var control in controls)
|
||||
{
|
||||
collection.Add(control);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the prevalue row heading.
|
||||
/// </summary>
|
||||
/// <param name="writer">The writer.</param>
|
||||
/// <param name="heading">The heading.</param>
|
||||
public static void AddPrevalueHeading(this HtmlTextWriter writer, string heading)
|
||||
{
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "row clearfix");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'row'
|
||||
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.H3); // start 'h3'
|
||||
|
||||
writer.Write(heading);
|
||||
|
||||
writer.RenderEndTag(); // end 'h3'
|
||||
|
||||
writer.RenderEndTag(); // end 'row'
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new row to the Prevalue Editor.
|
||||
/// </summary>
|
||||
/// <param name="writer">The HtmlTextWriter.</param>
|
||||
/// <param name="label">The label for the field.</param>
|
||||
/// <param name="controls">The controls for the field.</param>
|
||||
public static void AddPrevalueRow(this HtmlTextWriter writer, string label, params Control[] controls)
|
||||
{
|
||||
writer.AddPrevalueRow(label, string.Empty, controls);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new row to the Prevalue Editor, (with an optional description).
|
||||
/// </summary>
|
||||
/// <param name="writer">The HtmlTextWriter.</param>
|
||||
/// <param name="label">The label for the field.</param>
|
||||
/// <param name="description">The description for the field.</param>
|
||||
/// <param name="controls">The controls for the field.</param>
|
||||
public static void AddPrevalueRow(this HtmlTextWriter writer, string label, string description, params Control[] controls)
|
||||
{
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "row clearfix");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'row'
|
||||
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "label");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'label'
|
||||
|
||||
var lbl = new HtmlGenericControl("label") { InnerText = label };
|
||||
|
||||
if (controls.Length > 0 && !string.IsNullOrEmpty(controls[0].ClientID))
|
||||
{
|
||||
lbl.Attributes.Add("for", controls[0].ClientID);
|
||||
}
|
||||
|
||||
lbl.RenderControl(writer);
|
||||
|
||||
writer.RenderEndTag(); // end 'label'
|
||||
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "field");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'field'
|
||||
|
||||
foreach (var control in controls)
|
||||
{
|
||||
control.RenderControl(writer);
|
||||
}
|
||||
|
||||
writer.RenderEndTag(); // end 'field'
|
||||
|
||||
if (!string.IsNullOrEmpty(description))
|
||||
{
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Class, "description");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'description'
|
||||
|
||||
Label desc = new Label() { Text = description };
|
||||
desc.RenderControl(writer);
|
||||
|
||||
writer.RenderEndTag(); // end 'description'
|
||||
}
|
||||
|
||||
writer.RenderEndTag(); // end 'row'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,11 +200,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Actions\IActionHandler.cs" />
|
||||
<Compile Include="businesslogic\CMSPreviewNode.cs" />
|
||||
<Compile Include="businesslogic\datatype\AbstractJsonPrevalueEditor.cs" />
|
||||
<Compile Include="businesslogic\datatype\AbstractOptions.cs" />
|
||||
<Compile Include="businesslogic\datatype\AbstractPrevalueEditor.cs" />
|
||||
<Compile Include="businesslogic\datatype\ClientDependencyAttribute.cs" />
|
||||
<Compile Include="businesslogic\datatype\CsvToXmlData.cs" />
|
||||
<Compile Include="businesslogic\datatype\DataEditorSetting.cs" />
|
||||
<Compile Include="businesslogic\datatype\DataEditorSettingsStorage.cs" />
|
||||
<Compile Include="businesslogic\datatype\DataEditorSettingType.cs" />
|
||||
@@ -212,9 +208,6 @@
|
||||
<Compile Include="businesslogic\datatype\DBTypes.cs" />
|
||||
<Compile Include="businesslogic\datatype\IDataEditorSettingType.cs" />
|
||||
<Compile Include="businesslogic\datatype\PreValue.cs" />
|
||||
<Compile Include="businesslogic\datatype\PrevalueEditorExtensions.cs" />
|
||||
<Compile Include="businesslogic\datatype\ResourceExtensions.cs" />
|
||||
<Compile Include="businesslogic\datatype\XmlData.cs" />
|
||||
<Compile Include="businesslogic\installer\IInstallerStep.cs" />
|
||||
<Compile Include="businesslogic\installer\InstallerStep.cs" />
|
||||
<Compile Include="businesslogic\installer\InstallStepCollection.cs">
|
||||
|
||||
Reference in New Issue
Block a user