Fixes some issues with pre-values with the previous changes made to include the IDs of the pre-values, needed to ensure they are formatted incoming/outgoing properly so the id isn't included.
This commit is contained in:
@@ -22,13 +22,17 @@ namespace Umbraco.Core.Manifest
|
||||
{
|
||||
if (jObject["editor"] != null)
|
||||
{
|
||||
//we need to specify the view value for the editor here otherwise we'll get an exception
|
||||
target.StaticallyDefinedValueEditor.View = jObject["editor"]["view"].ToString();
|
||||
//since it's a manifest editor, we need to create it's instance.
|
||||
//we need to specify the view value for the editor here otherwise we'll get an exception.
|
||||
target.ManifestDefinedValueEditor = new ValueEditor
|
||||
{
|
||||
View = jObject["editor"]["view"].ToString()
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if (jObject["preValueEditor"] != null)
|
||||
{
|
||||
target.StaticallyDefinedPreValueEditor.Fields = new List<PreValueField>();
|
||||
target.ManifestDefinedPreValueEditor = new PreValueEditor();
|
||||
}
|
||||
|
||||
base.Deserialize(jObject, target, serializer);
|
||||
|
||||
26
src/Umbraco.Core/PropertyEditors/IntegerValidator.cs
Normal file
26
src/Umbraco.Core/PropertyEditors/IntegerValidator.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
/// <summary>
|
||||
/// A validator that validates that the value is a valid integer
|
||||
/// </summary>
|
||||
[ValueValidator("Integer")]
|
||||
internal sealed class IntegerValidator : ManifestValueValidator, IPropertyValidator
|
||||
{
|
||||
public override IEnumerable<ValidationResult> Validate(object value, string config, string preValues, PropertyEditor editor)
|
||||
{
|
||||
var result = value.TryConvertTo<int>();
|
||||
if (result.Success == false)
|
||||
{
|
||||
yield return new ValidationResult("The value " + value + " is not a valid integer", new[] {"value"});
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(object value, string preValues, PropertyEditor editor)
|
||||
{
|
||||
return Validate(value, "", preValues, editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ namespace Umbraco.Core.PropertyEditors
|
||||
/// If fields are specified then the master View and Validators will be ignored
|
||||
/// </remarks>
|
||||
[JsonProperty("fields")]
|
||||
public IEnumerable<PreValueField> Fields { get; set; }
|
||||
public List<PreValueField> Fields { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// A method to format the posted values from the editor to the values to be persisted
|
||||
@@ -135,7 +135,13 @@ namespace Umbraco.Core.PropertyEditors
|
||||
//we just need to merge the dictionaries now, the persisted will replace default.
|
||||
foreach (var item in persistedPreVals.PreValuesAsDictionary)
|
||||
{
|
||||
defaultPreVals[item.Key] = item.Value;
|
||||
//we want the json output to be in camelcase so change the value to a custom dictionary
|
||||
|
||||
defaultPreVals[item.Key] = new Dictionary<string, object>
|
||||
{
|
||||
{"id", item.Value.Id},
|
||||
{"value", item.Value.Value}
|
||||
};
|
||||
}
|
||||
return defaultPreVals;
|
||||
}
|
||||
|
||||
@@ -16,23 +16,20 @@ namespace Umbraco.Core.PropertyEditors
|
||||
/// </remarks>
|
||||
public class PropertyEditor
|
||||
{
|
||||
private readonly PropertyEditorAttribute _attribute;
|
||||
|
||||
/// <summary>
|
||||
/// The constructor will setup the property editor based on the attribute if one is found
|
||||
/// </summary>
|
||||
internal PropertyEditor()
|
||||
{
|
||||
StaticallyDefinedValueEditor = new ValueEditor();
|
||||
StaticallyDefinedPreValueEditor = new PreValueEditor();
|
||||
|
||||
//assign properties based on the attribute if it is found
|
||||
var att = GetType().GetCustomAttribute<PropertyEditorAttribute>(false);
|
||||
if (att != null)
|
||||
_attribute = GetType().GetCustomAttribute<PropertyEditorAttribute>(false);
|
||||
if (_attribute != null)
|
||||
{
|
||||
Id = Guid.Parse(att.Id);
|
||||
Name = att.Name;
|
||||
|
||||
StaticallyDefinedValueEditor.ValueType = att.ValueType;
|
||||
StaticallyDefinedValueEditor.View = att.EditorView;
|
||||
//set the id/name from the attribute
|
||||
Id = Guid.Parse(_attribute.Id);
|
||||
Name = _attribute.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,13 +37,13 @@ namespace Umbraco.Core.PropertyEditors
|
||||
/// These are assigned by default normally based on property editor attributes or manifest definitions,
|
||||
/// developers have the chance to override CreateValueEditor if they don't want to use the pre-defined instance
|
||||
/// </summary>
|
||||
internal ValueEditor StaticallyDefinedValueEditor = null;
|
||||
internal ValueEditor ManifestDefinedValueEditor = null;
|
||||
|
||||
/// <summary>
|
||||
/// These are assigned by default normally based on property editor attributes or manifest definitions,
|
||||
/// developers have the chance to override CreatePreValueEditor if they don't want to use the pre-defined instance
|
||||
/// </summary>
|
||||
internal PreValueEditor StaticallyDefinedPreValueEditor = null;
|
||||
internal PreValueEditor ManifestDefinedPreValueEditor = null;
|
||||
|
||||
/// <summary>
|
||||
/// The id of the property editor
|
||||
@@ -81,17 +78,28 @@ namespace Umbraco.Core.PropertyEditors
|
||||
/// <returns></returns>
|
||||
protected virtual ValueEditor CreateValueEditor()
|
||||
{
|
||||
if (StaticallyDefinedValueEditor != null && !StaticallyDefinedValueEditor.View.IsNullOrWhiteSpace())
|
||||
if (ManifestDefinedValueEditor != null)
|
||||
{
|
||||
//detect if the view is a virtual path (in most cases, yes) then convert it
|
||||
if (StaticallyDefinedValueEditor.View.StartsWith("~/"))
|
||||
if (ManifestDefinedValueEditor.View.StartsWith("~/"))
|
||||
{
|
||||
StaticallyDefinedValueEditor.View = IOHelper.ResolveUrl(StaticallyDefinedValueEditor.View);
|
||||
ManifestDefinedValueEditor.View = IOHelper.ResolveUrl(ManifestDefinedValueEditor.View);
|
||||
}
|
||||
|
||||
return StaticallyDefinedValueEditor;
|
||||
return ManifestDefinedValueEditor;
|
||||
}
|
||||
throw new NotImplementedException("This method must be implemented if a view is not explicitly set");
|
||||
|
||||
//create a new editor
|
||||
var editor = new ValueEditor();
|
||||
|
||||
if (_attribute.EditorView.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw new NotImplementedException("This method must be implemented if a view is not explicitly set");
|
||||
}
|
||||
|
||||
editor.View = _attribute.EditorView;
|
||||
editor.ValueType = _attribute.ValueType;
|
||||
return editor;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,19 +107,23 @@ namespace Umbraco.Core.PropertyEditors
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected virtual PreValueEditor CreatePreValueEditor()
|
||||
{
|
||||
if (StaticallyDefinedPreValueEditor != null)
|
||||
{
|
||||
//This will not be null if it is a manifest defined editor
|
||||
if (ManifestDefinedPreValueEditor != null)
|
||||
{
|
||||
foreach (var f in StaticallyDefinedPreValueEditor.Fields)
|
||||
foreach (var f in ManifestDefinedPreValueEditor.Fields)
|
||||
{
|
||||
//detect if the view is a virtual path (in most cases, yes) then convert it
|
||||
if (f.View.StartsWith("~/"))
|
||||
{
|
||||
f.View = IOHelper.ResolveUrl(f.View);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ManifestDefinedPreValueEditor;
|
||||
}
|
||||
return StaticallyDefinedPreValueEditor;
|
||||
|
||||
//There's no manifest, just return an empty one
|
||||
return new PreValueEditor();
|
||||
}
|
||||
|
||||
protected bool Equals(PropertyEditor other)
|
||||
|
||||
@@ -582,6 +582,7 @@
|
||||
<Compile Include="Profiling\ProfilerResolver.cs" />
|
||||
<Compile Include="Profiling\WebProfiler.cs" />
|
||||
<Compile Include="PropertyEditors\DelimitedManifestValueValidator.cs" />
|
||||
<Compile Include="PropertyEditors\IntegerValidator.cs" />
|
||||
<Compile Include="PropertyEditors\ManifestPropertyValidator.cs" />
|
||||
<Compile Include="PropertyEditors\PreValueField.cs" />
|
||||
<Compile Include="PropertyEditors\PreValueFieldAttribute.cs" />
|
||||
|
||||
@@ -139,6 +139,7 @@ function umbDataFormatter() {
|
||||
/** formats the display model used to display the data type to the model used to save the data type */
|
||||
formatDataTypePostData: function(displayModel, preValues, action) {
|
||||
var saveModel = {
|
||||
parentId: -1,
|
||||
id: displayModel.id,
|
||||
name: displayModel.name,
|
||||
selectedEditor: displayModel.selectedEditor,
|
||||
@@ -149,7 +150,7 @@ function umbDataFormatter() {
|
||||
for (var i = 0; i < preValues.length; i++) {
|
||||
saveModel.preValues.push({
|
||||
key: preValues[i].alias,
|
||||
value: preValues[i].value
|
||||
value: preValues[i].value.value
|
||||
});
|
||||
}
|
||||
return saveModel;
|
||||
|
||||
@@ -1 +1 @@
|
||||
<input name="boolean" type="checkbox" ng-model="model.value" ng-true-value="1" ng-false-value="0" />
|
||||
<input name="boolean" type="checkbox" ng-model="model.value.value" ng-true-value="1" ng-false-value="0" />
|
||||
@@ -1 +1 @@
|
||||
<input name="hidden" type="hidden" ng-model="model.value" name="{{model.alias}" />
|
||||
<input name="hidden" type="hidden" ng-model="model.value.value" name="{{model.alias}" />
|
||||
@@ -1,6 +1,6 @@
|
||||
<div>
|
||||
<input name="requiredfield" type="text" class="umb-textstring span7 textstring"
|
||||
ng-model="model.value"
|
||||
ng-model="model.value.value"
|
||||
required
|
||||
val-server="value" />
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
<textarea name="textarea" ng-model="model.value" rows="4" class="span8"></textarea>
|
||||
<textarea name="textarea" ng-model="model.value.value" rows="4" class="span8"></textarea>
|
||||
@@ -8,6 +8,30 @@ using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
[PropertyEditor(Constants.PropertyEditors.MultipleTextstring, "Multiple Textbox", "multipletextbox")]
|
||||
public class MultipleTextStringPropertyEditor : PropertyEditor
|
||||
{
|
||||
protected override PreValueEditor CreatePreValueEditor()
|
||||
{
|
||||
var prevals = base.CreatePreValueEditor();
|
||||
prevals.Fields.Add(new PreValueField(new IntegerValidator())
|
||||
{
|
||||
Description = "Enter the minimum amount of text boxes to be displayed",
|
||||
Key = "min",
|
||||
View = "requiredfield",
|
||||
Name = "Minimum"
|
||||
});
|
||||
prevals.Fields.Add(new PreValueField(new IntegerValidator())
|
||||
{
|
||||
Description = "Enter the maximum amount of text boxes to be displayed, enter -1 for unlimited",
|
||||
Key = "max",
|
||||
View = "requiredfield",
|
||||
Name = "Maximum"
|
||||
});
|
||||
return prevals;
|
||||
}
|
||||
}
|
||||
|
||||
[PropertyEditor(Constants.PropertyEditors.ColorPicker, "Color Picker", "colorpicker")]
|
||||
public class ColorPickerPropertyEditor : PropertyEditor
|
||||
{
|
||||
@@ -29,7 +53,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
public ColorListPreValueEditor()
|
||||
{
|
||||
Fields = CreatePreValueFields();
|
||||
Fields.AddRange(CreatePreValueFields());
|
||||
//use a custom editor too
|
||||
Fields.First().View = "views/propertyeditors/colorpicker/colorpicker.prevalues.html";
|
||||
//change the description
|
||||
|
||||
@@ -36,15 +36,14 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
public DropDownMultiplePreValueEditor()
|
||||
{
|
||||
var fields = CreatePreValueFields();
|
||||
Fields.AddRange(CreatePreValueFields());
|
||||
//add the multiple field, we'll make it hidden so it is not seen in the pre-value editor
|
||||
fields.Add(new PreValueField
|
||||
Fields.Add(new PreValueField
|
||||
{
|
||||
Key = "multiple",
|
||||
Name = "multiple",
|
||||
View = "hidden"
|
||||
});
|
||||
Fields = fields;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
protected override ValueEditor CreateValueEditor()
|
||||
{
|
||||
var editor = base.CreateValueEditor();
|
||||
editor.Validators.Add(new RegexValidator("^\\d*$"));
|
||||
editor.Validators.Add(new IntegerValidator());
|
||||
return editor;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
|
||||
public ValueListPreValueEditor()
|
||||
{
|
||||
Fields = CreatePreValueFields();
|
||||
Fields.AddRange(CreatePreValueFields());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user