Files
Umbraco-CMS/src/Umbraco.Web/PropertyEditors/MultipleTextStringConfigurationEditor.cs
T

60 lines
2.4 KiB
C#
Raw Normal View History

2018-01-24 13:37:14 +01:00
using System.Collections.Generic;
2018-01-24 11:44:44 +01:00
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.Validators;
namespace Umbraco.Web.PropertyEditors
{
/// <summary>
2018-01-24 13:37:14 +01:00
/// Represents the configuration editor for a multiple testring value editor.
2018-01-24 11:44:44 +01:00
/// </summary>
2018-01-24 13:37:14 +01:00
internal class MultipleTextStringConfigurationEditor : ConfigurationEditor<MultipleTestStringConfiguration>
2018-01-24 11:44:44 +01:00
{
2018-01-24 13:37:14 +01:00
public MultipleTextStringConfigurationEditor()
2018-01-24 11:44:44 +01:00
{
Fields.Add(new ConfigurationField(new IntegerValidator())
{
Description = "Enter the minimum amount of text boxes to be displayed",
Key = "min",
View = "requiredfield",
2018-01-24 13:37:14 +01:00
Name = "Minimum",
PropertyName = nameof(MultipleTestStringConfiguration.Minimum)
2018-01-24 11:44:44 +01:00
});
Fields.Add(new ConfigurationField(new IntegerValidator())
{
Description = "Enter the maximum amount of text boxes to be displayed, enter 0 for unlimited",
Key = "max",
View = "requiredfield",
2018-01-24 13:37:14 +01:00
Name = "Maximum",
PropertyName = nameof(MultipleTestStringConfiguration.Maximum)
2018-01-24 11:44:44 +01:00
});
}
2018-01-24 13:37:14 +01:00
/// <inheritdoc />
public override MultipleTestStringConfiguration FromConfigurationEditor(IDictionary<string, object> editorValues, MultipleTestStringConfiguration configuration)
2018-01-24 11:44:44 +01:00
{
2018-01-24 13:37:14 +01:00
// fixme this isn't pretty
2018-01-24 11:44:44 +01:00
//the values from the editor will be min/max fieds and we need to format to json in one field
2018-01-24 13:37:14 +01:00
// is the editor sending strings or ints or?!
2018-02-05 17:48:54 +01:00
var min = (editorValues.ContainsKey("min") ? editorValues["min"].ToString() : "0").TryConvertTo<int>();
var max = (editorValues.ContainsKey("max") ? editorValues["max"].ToString() : "0").TryConvertTo<int>();
2018-01-24 11:44:44 +01:00
2018-01-24 13:37:14 +01:00
return new MultipleTestStringConfiguration
{
Minimum = min ? min.Result : 0,
Maximum = max ? max.Result : 0
};
2018-01-24 11:44:44 +01:00
}
2018-01-24 13:37:14 +01:00
/// <inheritdoc />
2018-02-05 17:48:54 +01:00
public override Dictionary<string, object> ToConfigurationEditor(MultipleTestStringConfiguration configuration)
2018-01-24 11:44:44 +01:00
{
2018-01-24 13:37:14 +01:00
return new Dictionary<string, object>
2018-01-24 11:44:44 +01:00
{
2018-01-24 13:37:14 +01:00
{ "min", configuration.Minimum },
{ "max", configuration.Maximum }
};
2018-01-24 11:44:44 +01:00
}
}
}