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

61 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>
/// Represents the configuration editor for a multiple textstring value editor.
2018-01-24 11:44:44 +01:00
/// </summary>
internal class MultipleTextStringConfigurationEditor : ConfigurationEditor<MultipleTextStringConfiguration>
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(MultipleTextStringConfiguration.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(MultipleTextStringConfiguration.Maximum)
2018-01-24 11:44:44 +01:00
});
}
2018-01-24 13:37:14 +01:00
/// <inheritdoc />
public override MultipleTextStringConfiguration FromConfigurationEditor(IDictionary<string, object> editorValues, MultipleTextStringConfiguration configuration)
2018-01-24 11:44:44 +01:00
{
// TODO: this isn't pretty
//the values from the editor will be min/max fields 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
return new MultipleTextStringConfiguration
2018-01-24 13:37:14 +01:00
{
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 />
public override Dictionary<string, object> ToConfigurationEditor(MultipleTextStringConfiguration 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
}
}
2019-01-21 15:57:48 +01:00
}