// Copyright (c) Umbraco. // See LICENSE for more details. using System.Collections.Generic; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.PropertyEditors.Validators; using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors { /// /// Represents the configuration editor for a multiple textstring value editor. /// internal class MultipleTextStringConfigurationEditor : ConfigurationEditor { public MultipleTextStringConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) { Fields.Add(new ConfigurationField(new IntegerValidator()) { Description = "Enter the minimum amount of text boxes to be displayed", Key = "min", View = "requiredfield", Name = "Minimum", PropertyName = nameof(MultipleTextStringConfiguration.Minimum) }); 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", Name = "Maximum", PropertyName = nameof(MultipleTextStringConfiguration.Maximum) }); } /// public override MultipleTextStringConfiguration FromConfigurationEditor(IDictionary editorValues, MultipleTextStringConfiguration configuration) { // 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 // is the editor sending strings or ints or?! var min = (editorValues.ContainsKey("min") ? editorValues["min"].ToString() : "0").TryConvertTo(); var max = (editorValues.ContainsKey("max") ? editorValues["max"].ToString() : "0").TryConvertTo(); return new MultipleTextStringConfiguration { Minimum = min ? min.Result : 0, Maximum = max ? max.Result : 0 }; } /// public override Dictionary ToConfigurationEditor(MultipleTextStringConfiguration configuration) { return new Dictionary { { "min", configuration.Minimum }, { "max", configuration.Maximum } }; } } }