Fixes U4-2702 Ensure the new file uploader has consistent pre-values pre previous versions

This commit is contained in:
Shannon
2013-10-28 16:01:07 +11:00
parent 025e7eba1d
commit 7c9f742b4d
2 changed files with 53 additions and 4 deletions

View File

@@ -11,14 +11,19 @@ namespace Umbraco.Web.PropertyEditors
{
internal class ColorListPreValueEditor : ValueListPreValueEditor
{
public ColorListPreValueEditor()
{
var field = Fields.First();
//use a custom editor too
Fields.First().View = "views/propertyeditors/colorpicker/colorpicker.prevalues.html";
field.View = "views/propertyeditors/colorpicker/colorpicker.prevalues.html";
//change the description
Fields.First().Description = "Add and remove colors in HEX format without a prefixed '#'";
field.Description = "Add and remove colors in HEX format without a prefixed '#'";
//change the label
field.Name = "Add color";
//need to have some custom validation happening here
Fields.First().Validators.Add(new ColorListValidator());
field.Validators.Add(new ColorListValidator());
}
internal class ColorListValidator : IPropertyValidator

View File

@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
@@ -126,6 +129,16 @@ namespace Umbraco.Web.PropertyEditors
/// </summary>
internal class FileUploadPreValueEditor : ValueListPreValueEditor
{
public FileUploadPreValueEditor()
: base()
{
var field = Fields.First();
field.Description = "Enter a max width/height for each thumbnail";
field.Name = "Add thumbnail size";
//need to have some custom validation happening here
field.Validators.Add(new ThumbnailListValidator());
}
/// <summary>
/// Format the persisted value to work with our multi-val editor.
/// </summary>
@@ -164,12 +177,43 @@ namespace Umbraco.Web.PropertyEditors
//this should just be a dictionary of values, we want to re-format this so that it is just one value in the dictionary that is
// semi-colon delimited
var values = result.Select(item => item.Value).ToList();
var values = result.Select(item => item.Value.Value).ToList();
result.Clear();
result.Add("thumbs", new PreValue(string.Join(";", values)));
return result;
}
internal class ThumbnailListValidator : IPropertyValidator
{
public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor)
{
var json = value as JArray;
if (json == null) yield break;
//validate each item which is a json object
for (var index = 0; index < json.Count; index++)
{
var i = json[index];
var jItem = i as JObject;
if (jItem == null || jItem["value"] == null) continue;
//NOTE: we will be removing empty values when persisting so no need to validate
var asString = jItem["value"].ToString();
if (asString.IsNullOrWhiteSpace()) continue;
int parsed;
if (int.TryParse(asString, out parsed) == false)
{
yield return new ValidationResult("The value " + asString + " is not a valid number", new[]
{
//we'll make the server field the index number of the value so it can be wired up to the view
"item_" + index.ToInvariantString()
});
}
}
}
}
}
}