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>
|
2019-01-26 10:52:19 -05:00
|
|
|
/// Represents the configuration editor for a multiple textstring value editor.
|
2018-01-24 11:44:44 +01:00
|
|
|
/// </summary>
|
2018-05-20 18:14:31 +01:00
|
|
|
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",
|
2018-05-20 18:14:31 +01:00
|
|
|
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",
|
2018-05-20 18:14:31 +01:00
|
|
|
PropertyName = nameof(MultipleTextStringConfiguration.Maximum)
|
2018-01-24 11:44:44 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 13:37:14 +01:00
|
|
|
/// <inheritdoc />
|
2018-05-20 18:14:31 +01:00
|
|
|
public override MultipleTextStringConfiguration FromConfigurationEditor(IDictionary<string, object> editorValues, MultipleTextStringConfiguration configuration)
|
2018-01-24 11:44:44 +01:00
|
|
|
{
|
2019-01-27 01:17:32 -05:00
|
|
|
// TODO: this isn't pretty
|
2019-01-26 10:52:19 -05:00
|
|
|
//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
|
|
|
|
2018-05-20 18:14:31 +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 />
|
2018-05-20 18:14:31 +01:00
|
|
|
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
|
|
|
}
|