Got all drop down editors working: normal, multiple, normal publishing keys, multiple publishing keys and should be backwards compatible.

This commit is contained in:
Shannon
2013-08-26 19:00:04 +10:00
parent a6f70619eb
commit 86a82a666f
13 changed files with 312 additions and 153 deletions

View File

@@ -0,0 +1,66 @@
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
/// <summary>
/// A property editor to allow multiple selection of pre-defined items
/// </summary>
/// <remarks>
/// Due to maintaining backwards compatibility this data type stores the value as a string which is a comma separated value of the
/// ids of the individual items so we have logic in here to deal with that.
/// </remarks>
[PropertyEditor(Constants.PropertyEditors.DropdownlistMultiplePublishKeys, "Dropdown list multiple, publish keys", "dropdown")]
public class DropDownMultipleWithKeysPropertyEditor : DropDownPropertyEditor
{
protected override ValueEditor CreateValueEditor()
{
return new DropDownMultipleValueEditor(true, base.CreateValueEditor());
}
protected override PreValueEditor CreatePreValueEditor()
{
return new DropDownMultiplePreValueEditor();
}
/// <summary>
/// A pre-value editor for the 'drop down list multiple' property editor that ensures that 'multiple' is saved for the config in the db but is not
/// rendered as a pre-value field.
/// </summary>
/// <remarks>
/// This is mostly to maintain backwards compatibility with old property editors. Devs can now simply use the Drop down property editor and check the multiple pre-value checkbox
/// </remarks>
internal class DropDownMultiplePreValueEditor : DropDownPreValueEditor
{
public DropDownMultiplePreValueEditor()
{
var fields = CreatePreValueFields();
//add the multiple field, we'll make it hidden so it is not seen in the pre-value editor
fields.Add(new PreValueField
{
Key = "multiple",
Name = "multiple",
View = "hidden"
});
Fields = fields;
}
/// <summary>
/// Always
/// </summary>
/// <param name="defaultPreVals"></param>
/// <param name="persistedPreVals"></param>
/// <returns></returns>
public override IDictionary<string, object> FormatDataForEditor(IDictionary<string, object> defaultPreVals, PreValueCollection persistedPreVals)
{
var returnVal = base.FormatDataForEditor(defaultPreVals, persistedPreVals);
//always add the multiple param to true
returnVal["multiple"] = "1";
return returnVal;
}
}
}
}