Completes: U4-3261 Ensure label/readonly displays pre-values

This commit is contained in:
Shannon
2013-10-29 19:14:15 +11:00
parent 3d7f7db396
commit 968a94f281
2 changed files with 45 additions and 1 deletions

View File

@@ -0,0 +1,7 @@
<div ng-show="model.value.length > 0">
<ul>
<li ng-repeat="preVal in model.value">
<i>{{preVal.Key}}</i>&nbsp;:&nbsp;<strong>{{preVal.Value}}</strong>
</li>
</ul>
</div>

View File

@@ -1,6 +1,9 @@
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
@@ -14,5 +17,39 @@ namespace Umbraco.Web.PropertyEditors
return new LabelPropertyValueEditor(base.CreateValueEditor());
}
protected override PreValueEditor CreatePreValueEditor()
{
return new LabelPreValueEditor();
}
internal class LabelPreValueEditor : PreValueEditor
{
public LabelPreValueEditor()
{
Fields.Add(new PreValueField()
{
HideLabel = true,
View = "readonly",
Key = "values"
});
}
/// <summary>
/// Chuck all the values into one field so devs can see what is stored there - we want this in case we've converted a legacy proeprty editor over to a label
/// we should still show the pre-values stored for the data type.
/// </summary>
/// <param name="defaultPreVals"></param>
/// <param name="persistedPreVals"></param>
/// <returns></returns>
public override IDictionary<string, object> ConvertDbToEditor(IDictionary<string, object> defaultPreVals, PreValueCollection persistedPreVals)
{
var existing = base.ConvertDbToEditor(defaultPreVals, persistedPreVals);
//convert to a list, easier to enumerate on the editor
var asList = existing.Select(e => new KeyValuePair<string, object>(e.Key, e.Value)).ToList();
var result = new Dictionary<string, object> { { "values", asList } };
return result;
}
}
}
}