From cb368b4335492e90e7bcd8a2b22489d16118fef4 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 28 Aug 2013 13:30:05 +1000 Subject: [PATCH] Implemented the numeric property editor --- src/Umbraco.Core/CoreBootManager.cs | 6 +- .../Manifest/ManifestValidatorConverter.cs | 6 +- ....cs => DelimitedManifestValueValidator.cs} | 134 +++++++++--------- ...ValidatorBase.cs => IPropertyValidator.cs} | 52 +++---- ...idator.cs => ManifestPropertyValidator.cs} | 126 ++++++++-------- ...Validator.cs => ManifestValueValidator.cs} | 88 ++++++------ .../PropertyEditors/PreValueField.cs | 6 +- .../PropertyEditors/RegexValidator.cs | 66 +++++++++ .../PropertyEditors/RegexValueValidator.cs | 31 ---- ...r.cs => RequiredManifestValueValidator.cs} | 62 ++++---- .../PropertyEditors/ValidatorsResolver.cs | 6 +- .../PropertyEditors/ValueEditor.cs | 14 +- src/Umbraco.Core/Umbraco.Core.csproj | 12 +- .../prevalueeditors/multivalues.controller.js | 2 +- .../propertyeditors/integer/integer.html | 9 ++ .../PropertyEditors/PostcodeValidator.cs | 4 +- .../ColorPickerPropertyEditor.cs | 4 +- .../PropertyEditors/DateTimeValidator.cs | 4 +- .../PropertyEditors/IntegerPropertyEditor.cs | 21 +++ .../PropertyEditors/MediaPicker.cs | 7 + ...ertyEditor.cs => TextboxPropertyEditor.cs} | 2 +- .../ValueListPreValueEditor.cs | 4 +- src/Umbraco.Web/Umbraco.Web.csproj | 3 +- 23 files changed, 371 insertions(+), 298 deletions(-) rename src/Umbraco.Core/PropertyEditors/{DelimitedValueValidator.cs => DelimitedManifestValueValidator.cs} (95%) rename src/Umbraco.Core/PropertyEditors/{ValidatorBase.cs => IPropertyValidator.cs} (83%) rename src/Umbraco.Core/PropertyEditors/{ManifestValidator.cs => ManifestPropertyValidator.cs} (81%) rename src/Umbraco.Core/PropertyEditors/{ValueValidator.cs => ManifestValueValidator.cs} (94%) create mode 100644 src/Umbraco.Core/PropertyEditors/RegexValidator.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/RegexValueValidator.cs rename src/Umbraco.Core/PropertyEditors/{RequiredValueValidator.cs => RequiredManifestValueValidator.cs} (90%) create mode 100644 src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html create mode 100644 src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs rename src/Umbraco.Web/PropertyEditors/{TextStringPropertyEditor.cs => TextboxPropertyEditor.cs} (86%) diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 51317049e1..99fa936d1f 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -260,9 +260,9 @@ namespace Umbraco.Core //setup the validators resolver with our predefined validators ValidatorsResolver.Current = new ValidatorsResolver(new[] { - new Lazy(() => typeof (RequiredValueValidator)), - new Lazy(() => typeof (RegexValueValidator)), - new Lazy(() => typeof (DelimitedValueValidator)) + new Lazy(() => typeof (RequiredManifestValueValidator)), + new Lazy(() => typeof (RegexValidator)), + new Lazy(() => typeof (DelimitedManifestValueValidator)) }); //by default we'll use the standard configuration based sync diff --git a/src/Umbraco.Core/Manifest/ManifestValidatorConverter.cs b/src/Umbraco.Core/Manifest/ManifestValidatorConverter.cs index 2e73da4e30..a92abfbeb3 100644 --- a/src/Umbraco.Core/Manifest/ManifestValidatorConverter.cs +++ b/src/Umbraco.Core/Manifest/ManifestValidatorConverter.cs @@ -9,11 +9,11 @@ namespace Umbraco.Core.Manifest /// Used when deserialing the validation collection, any serialized property editors are from a manifest and thus the /// validators are manifest validators. /// - internal class ManifestValidatorConverter : JsonCreationConverter + internal class ManifestValidatorConverter : JsonCreationConverter { - protected override ValidatorBase Create(Type objectType, JObject jObject) + protected override IPropertyValidator Create(Type objectType, JObject jObject) { - return new ManifestValidator(); + return new ManifestPropertyValidator(); } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/DelimitedValueValidator.cs b/src/Umbraco.Core/PropertyEditors/DelimitedManifestValueValidator.cs similarity index 95% rename from src/Umbraco.Core/PropertyEditors/DelimitedValueValidator.cs rename to src/Umbraco.Core/PropertyEditors/DelimitedManifestValueValidator.cs index c2c13aa9af..752668064b 100644 --- a/src/Umbraco.Core/PropertyEditors/DelimitedValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/DelimitedManifestValueValidator.cs @@ -1,68 +1,68 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Text.RegularExpressions; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// A validator that validates a delimited set of values against a common regex - /// - [ValueValidator("Delimited")] - internal sealed class DelimitedValueValidator : ValueValidator - { - /// - /// Performs the validation - /// - /// - /// Can be a json formatted string containing properties: 'delimiter' and 'pattern' - /// The current pre-values stored for the data type - /// - /// - public override IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor) - { - //TODO: localize these! - if (value != null) - { - var delimiter = ","; - Regex regex = null; - if (config.IsNullOrWhiteSpace() == false) - { - var json = JsonConvert.DeserializeObject(config); - if (json["delimiter"] != null) - { - delimiter = json["delimiter"].ToString(); - } - if (json["pattern"] != null) - { - var regexPattern = json["pattern"].ToString(); - regex = new Regex(regexPattern); - } - } - - var stringVal = value.ToString(); - var split = stringVal.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); - for (var i = 0; i < split.Length; i++) - { - var s = split[i]; - //next if we have a regex statement validate with that - if (regex != null) - { - if (regex.IsMatch(s) == false) - { - yield return new ValidationResult("The item at index " + i + " did not match the expression " + regex, - new[] - { - //make the field name called 'value0' where 0 is the index - "value" + i - }); - } - } - } - } - - } - } +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// A validator that validates a delimited set of values against a common regex + /// + [ValueValidator("Delimited")] + internal sealed class DelimitedManifestValueValidator : ManifestValueValidator + { + /// + /// Performs the validation + /// + /// + /// Can be a json formatted string containing properties: 'delimiter' and 'pattern' + /// The current pre-values stored for the data type + /// + /// + public override IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor) + { + //TODO: localize these! + if (value != null) + { + var delimiter = ","; + Regex regex = null; + if (config.IsNullOrWhiteSpace() == false) + { + var json = JsonConvert.DeserializeObject(config); + if (json["delimiter"] != null) + { + delimiter = json["delimiter"].ToString(); + } + if (json["pattern"] != null) + { + var regexPattern = json["pattern"].ToString(); + regex = new Regex(regexPattern); + } + } + + var stringVal = value.ToString(); + var split = stringVal.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); + for (var i = 0; i < split.Length; i++) + { + var s = split[i]; + //next if we have a regex statement validate with that + if (regex != null) + { + if (regex.IsMatch(s) == false) + { + yield return new ValidationResult("The item at index " + i + " did not match the expression " + regex, + new[] + { + //make the field name called 'value0' where 0 is the index + "value" + i + }); + } + } + } + } + + } + } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ValidatorBase.cs b/src/Umbraco.Core/PropertyEditors/IPropertyValidator.cs similarity index 83% rename from src/Umbraco.Core/PropertyEditors/ValidatorBase.cs rename to src/Umbraco.Core/PropertyEditors/IPropertyValidator.cs index 7f3c4f0c0d..94e09d9bb1 100644 --- a/src/Umbraco.Core/PropertyEditors/ValidatorBase.cs +++ b/src/Umbraco.Core/PropertyEditors/IPropertyValidator.cs @@ -1,27 +1,27 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// An abstract class defining a validator - /// - public abstract class ValidatorBase - { - /// - /// Validates the object with the resolved ValueValidator found for this type - /// - /// - /// Depending on what is being validated, this value can be a json structure (JObject, JArray, etc...) representing an editor's model, it could be a single - /// string representing an editor's model, this class structure is also used to validate pre-values and in that case this value - /// could be a json structure or a single value representing a pre-value field. - /// - /// - /// When validating a property editor value (not a pre-value), this is the current pre-values stored for the data type. - /// When validating a pre-value field, this is the name of that field. - /// - /// The property editor instance that we are validating for - /// - public abstract IEnumerable Validate(object value, string preValues, PropertyEditor editor); - } +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// An interface defining a validator + /// + public interface IPropertyValidator + { + /// + /// Validates the object with the resolved ValueValidator found for this type + /// + /// + /// Depending on what is being validated, this value can be a json structure (JObject, JArray, etc...) representing an editor's model, it could be a single + /// string representing an editor's model, this class structure is also used to validate pre-values and in that case this value + /// could be a json structure or a single value representing a pre-value field. + /// + /// + /// When validating a property editor value (not a pre-value), this is the current pre-values stored for the data type. + /// When validating a pre-value field, this is the name of that field. + /// + /// The property editor instance that we are validating for + /// + IEnumerable Validate(object value, string preValues, PropertyEditor editor); + } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ManifestValidator.cs b/src/Umbraco.Core/PropertyEditors/ManifestPropertyValidator.cs similarity index 81% rename from src/Umbraco.Core/PropertyEditors/ManifestValidator.cs rename to src/Umbraco.Core/PropertyEditors/ManifestPropertyValidator.cs index c8938be9d4..768492695b 100644 --- a/src/Umbraco.Core/PropertyEditors/ManifestValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/ManifestPropertyValidator.cs @@ -1,64 +1,64 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using Newtonsoft.Json; -using Umbraco.Core.Serialization; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// Represents a validator found in a package manifest - /// - internal class ManifestValidator : ValidatorBase - { - /// - /// The validator type name - /// - [JsonProperty("type", Required = Required.Always)] - public string Type { get; set; } - - /// - /// The configuration defined for this validator in the manifest - /// - /// - /// This is NOT the pre-value for this data type - /// - [JsonProperty("config")] - [JsonConverter(typeof(JsonToStringConverter))] - public string Config { get; set; } - - private ValueValidator _validatorInstance; - - /// - /// Gets the ValueValidator instance - /// - internal ValueValidator ValidatorInstance - { - get - { - if (_validatorInstance == null) - { - var val = ValidatorsResolver.Current.GetValidator(Type); - if (val == null) - { - throw new InvalidOperationException("No " + typeof(ValueValidator) + " could be found for the type name of " + Type); - } - _validatorInstance = val; - } - return _validatorInstance; - } - } - - /// - /// Validates the object with the resolved ValueValidator found for this type - /// - /// - /// The current pre-values stored for the data type - /// The property editor instance that we are validating for - /// - public override IEnumerable Validate(object value, string preValues, PropertyEditor editor) - { - return ValidatorInstance.Validate(value, Config, preValues, editor); - } - } +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; +using Umbraco.Core.Serialization; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Represents a validator found in a package manifest + /// + internal class ManifestPropertyValidator : IPropertyValidator + { + /// + /// The validator type name + /// + [JsonProperty("type", Required = Required.Always)] + public string Type { get; set; } + + /// + /// The configuration defined for this validator in the manifest + /// + /// + /// This is NOT the pre-value for this data type + /// + [JsonProperty("config")] + [JsonConverter(typeof(JsonToStringConverter))] + public string Config { get; set; } + + private ManifestValueValidator _validatorInstance; + + /// + /// Gets the ValueValidator instance + /// + internal ManifestValueValidator ValidatorInstance + { + get + { + if (_validatorInstance == null) + { + var val = ValidatorsResolver.Current.GetValidator(Type); + if (val == null) + { + throw new InvalidOperationException("No " + typeof(ManifestValueValidator) + " could be found for the type name of " + Type); + } + _validatorInstance = val; + } + return _validatorInstance; + } + } + + /// + /// Validates the object with the resolved ValueValidator found for this type + /// + /// + /// The current pre-values stored for the data type + /// The property editor instance that we are validating for + /// + public IEnumerable Validate(object value, string preValues, PropertyEditor editor) + { + return ValidatorInstance.Validate(value, Config, preValues, editor); + } + } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ValueValidator.cs b/src/Umbraco.Core/PropertyEditors/ManifestValueValidator.cs similarity index 94% rename from src/Umbraco.Core/PropertyEditors/ValueValidator.cs rename to src/Umbraco.Core/PropertyEditors/ManifestValueValidator.cs index 830dc026d8..2b6348d491 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/ManifestValueValidator.cs @@ -1,45 +1,45 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// A validator used to validate a value based on a validator name defined in a package manifest - /// - internal abstract class ValueValidator - { - protected ValueValidator() - { - var att = this.GetType().GetCustomAttribute(false); - if (att == null) - { - throw new InvalidOperationException("The class " + GetType() + " is not attributed with the " + typeof(ValueValidatorAttribute) + " attribute"); - } - TypeName = att.TypeName; - } - - public string TypeName { get; private set; } - - /// - /// Performs the validation against the value - /// - /// - /// Depending on what is being validated, this value can be a json structure (JObject, JArray, etc...) representing an editor's model, it could be a single - /// string representing an editor's model. - /// - /// - /// An object that is used to configure the validator. An example could be a regex - /// expression if the validator was a regex validator. This is defined in the manifest along with - /// the definition of the validator. - /// - /// The current pre-values stored for the data type - /// The property editor instance that is being validated - /// - /// Returns a list of validation results. If a result does not have a field name applied to it then then we assume that - /// the validation message applies to the entire property type being validated. If there is a field name applied to a - /// validation result we will try to match that field name up with a field name on the item itself. - /// - public abstract IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor); - } +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// A validator used to validate a value based on a validator name defined in a package manifest + /// + internal abstract class ManifestValueValidator + { + protected ManifestValueValidator() + { + var att = this.GetType().GetCustomAttribute(false); + if (att == null) + { + throw new InvalidOperationException("The class " + GetType() + " is not attributed with the " + typeof(ValueValidatorAttribute) + " attribute"); + } + TypeName = att.TypeName; + } + + public string TypeName { get; private set; } + + /// + /// Performs the validation against the value + /// + /// + /// Depending on what is being validated, this value can be a json structure (JObject, JArray, etc...) representing an editor's model, it could be a single + /// string representing an editor's model. + /// + /// + /// An object that is used to configure the validator. An example could be a regex + /// expression if the validator was a regex validator. This is defined in the manifest along with + /// the definition of the validator. + /// + /// The current pre-values stored for the data type + /// The property editor instance that is being validated + /// + /// Returns a list of validation results. If a result does not have a field name applied to it then then we assume that + /// the validation message applies to the entire property type being validated. If there is a field name applied to a + /// validation result we will try to match that field name up with a field name on the item itself. + /// + public abstract IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor); + } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/PreValueField.cs b/src/Umbraco.Core/PropertyEditors/PreValueField.cs index c5938fe2f3..deaaa75ee3 100644 --- a/src/Umbraco.Core/PropertyEditors/PreValueField.cs +++ b/src/Umbraco.Core/PropertyEditors/PreValueField.cs @@ -14,7 +14,7 @@ namespace Umbraco.Core.PropertyEditors /// public PreValueField() { - Validators = new List(); + Validators = new List(); //check for an attribute and fill the values var att = GetType().GetCustomAttribute(false); @@ -32,7 +32,7 @@ namespace Umbraco.Core.PropertyEditors /// Constructor used to set validators instead of adding them later /// /// - public PreValueField(params ValidatorBase[] validators) + public PreValueField(params IPropertyValidator[] validators) : this() { foreach (var v in validators) @@ -78,6 +78,6 @@ namespace Umbraco.Core.PropertyEditors /// A collection of validators for the pre value field /// [JsonProperty("validation", ItemConverterType = typeof(ManifestValidatorConverter))] - public List Validators { get; private set; } + public List Validators { get; private set; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/RegexValidator.cs b/src/Umbraco.Core/PropertyEditors/RegexValidator.cs new file mode 100644 index 0000000000..b04b979fdb --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/RegexValidator.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text.RegularExpressions; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// A validator that validates that the value against a Regex expression + /// + [ValueValidator("Regex")] + internal sealed class RegexValidator : ManifestValueValidator, IPropertyValidator + { + private readonly string _regex; + + /// + /// Normally used when configured as a ManifestValueValidator + /// + public RegexValidator() + { + } + + /// + /// Normally used when configured as an IPropertyValidator + /// + /// + public RegexValidator(string regex) + { + if (regex == null) throw new ArgumentNullException("regex"); + _regex = regex; + } + + public override IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor) + { + //TODO: localize these! + if (config.IsNullOrWhiteSpace() == false && value != null) + { + var asString = value.ToString(); + + var regex = new Regex(config); + + if (regex.IsMatch(asString) == false) + { + yield return new ValidationResult("Value is invalid, it does not match the correct pattern", new[] { "value" }); + } + } + + } + + /// + /// Used when configured as an IPropertyValidator + /// + /// + /// + /// + /// + public IEnumerable Validate(object value, string preValues, PropertyEditor editor) + { + if (_regex == null) + { + throw new InvalidOperationException("This validator is not configured as a " + typeof(IPropertyValidator)); + } + return Validate(value, _regex, preValues, editor); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/RegexValueValidator.cs b/src/Umbraco.Core/PropertyEditors/RegexValueValidator.cs deleted file mode 100644 index 10ac6842dd..0000000000 --- a/src/Umbraco.Core/PropertyEditors/RegexValueValidator.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Text.RegularExpressions; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// A validator that validates that the value against a Regex expression - /// - [ValueValidator("Regex")] - internal sealed class RegexValueValidator : ValueValidator - { - public override IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor) - { - //TODO: localize these! - if (config.IsNullOrWhiteSpace() == false && value != null) - { - var asString = value.ToString(); - - var regex = new Regex(config); - - if (regex.IsMatch(asString) == false) - { - yield return new ValidationResult("Value is invalid, it does not match the correct pattern", new[] { "value" }); - } - } - - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/RequiredValueValidator.cs b/src/Umbraco.Core/PropertyEditors/RequiredManifestValueValidator.cs similarity index 90% rename from src/Umbraco.Core/PropertyEditors/RequiredValueValidator.cs rename to src/Umbraco.Core/PropertyEditors/RequiredManifestValueValidator.cs index 362952243f..d226b3ae18 100644 --- a/src/Umbraco.Core/PropertyEditors/RequiredValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/RequiredManifestValueValidator.cs @@ -1,32 +1,32 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// A validator that validates that the value is not null or empty (if it is a string) - /// - [ValueValidator("Required")] - internal sealed class RequiredValueValidator : ValueValidator - { - public override IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor) - { - //TODO: localize these! - - if (value == null) - { - yield return new ValidationResult("Value cannot be null", new[] {"value"}); - } - else - { - var asString = value.ToString(); - if (asString.IsNullOrWhiteSpace()) - { - yield return new ValidationResult("Value cannot be empty", new[] { "value" }); - } - } - - - } - } +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// A validator that validates that the value is not null or empty (if it is a string) + /// + [ValueValidator("Required")] + internal sealed class RequiredManifestValueValidator : ManifestValueValidator + { + public override IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor) + { + //TODO: localize these! + + if (value == null) + { + yield return new ValidationResult("Value cannot be null", new[] {"value"}); + } + else + { + var asString = value.ToString(); + if (asString.IsNullOrWhiteSpace()) + { + yield return new ValidationResult("Value cannot be empty", new[] { "value" }); + } + } + + + } + } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ValidatorsResolver.cs b/src/Umbraco.Core/PropertyEditors/ValidatorsResolver.cs index a23c6a3c2c..4b1f0b7c28 100644 --- a/src/Umbraco.Core/PropertyEditors/ValidatorsResolver.cs +++ b/src/Umbraco.Core/PropertyEditors/ValidatorsResolver.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.PropertyEditors /// /// A resolver to resolve all registered validators /// - internal class ValidatorsResolver : LazyManyObjectsResolverBase + internal class ValidatorsResolver : LazyManyObjectsResolverBase { public ValidatorsResolver(IEnumerable> lazyTypeList) : base(lazyTypeList, ObjectLifetimeScope.Application) @@ -18,7 +18,7 @@ namespace Umbraco.Core.PropertyEditors /// /// Returns the validators /// - public IEnumerable Validators + public IEnumerable Validators { get { return Values; } } @@ -28,7 +28,7 @@ namespace Umbraco.Core.PropertyEditors /// /// /// - public ValueValidator GetValidator(string name) + public ManifestValueValidator GetValidator(string name) { return Values.FirstOrDefault(x => x.TypeName == name); } diff --git a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs b/src/Umbraco.Core/PropertyEditors/ValueEditor.cs index aebc11c851..4682f28323 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueEditor.cs @@ -23,7 +23,7 @@ namespace Umbraco.Core.PropertyEditors { ValueType = "string"; //set a default for validators - Validators = new List(); + Validators = new List(); } /// @@ -31,7 +31,7 @@ namespace Umbraco.Core.PropertyEditors /// /// /// Allows adding custom validators during construction instead of specifying them later - public ValueEditor(string view, params ValidatorBase[] validators) + public ValueEditor(string view, params IPropertyValidator[] validators) : this() { View = view; @@ -60,7 +60,7 @@ namespace Umbraco.Core.PropertyEditors /// A collection of validators for the pre value editor /// [JsonProperty("validation", ItemConverterType = typeof(ManifestValidatorConverter))] - public List Validators { get; private set; } + public List Validators { get; private set; } /// /// Returns the validator used for the required field validation which is specified on the PropertyType @@ -71,9 +71,9 @@ namespace Umbraco.Core.PropertyEditors /// The default validator used is the RequiredValueValidator but this can be overridden by property editors /// if they need to do some custom validation, or if the value being validated is a json object. /// - internal virtual ValueValidator RequiredValidator + internal virtual ManifestValueValidator RequiredValidator { - get { return new RequiredValueValidator(); } + get { return new RequiredManifestValueValidator(); } } /// @@ -85,9 +85,9 @@ namespace Umbraco.Core.PropertyEditors /// The default validator used is the RegexValueValidator but this can be overridden by property editors /// if they need to do some custom validation, or if the value being validated is a json object. /// - internal virtual ValueValidator RegexValidator + internal virtual ManifestValueValidator RegexValidator { - get { return new RegexValueValidator(); } + get { return new RegexValidator(); } } /// diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 89503b5bdc..1d5fa08454 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -581,18 +581,18 @@ - - + + - + - - - + + + diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/multivalues.controller.js b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/multivalues.controller.js index ac6d3ad1c9..e4a6f3e3c7 100644 --- a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/multivalues.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/multivalues.controller.js @@ -9,7 +9,7 @@ angular.module("umbraco").controller("Umbraco.Editors.MultiValuesController", if (!angular.isArray($scope.model.value)) { //make an array from the dictionary var items = []; - for (var i in $scope.model.value) { + for (var i in $scope.model.value) { items.push({value: $scope.model.value[i]}); } //now make the editor model the array diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html new file mode 100644 index 0000000000..e10f1d6828 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html @@ -0,0 +1,9 @@ +
+ + + Invalid integer value + {{propertyForm.requiredField.errorMsg}} +
diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/PostcodeValidator.cs b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/PostcodeValidator.cs index 05eed35a79..0a1a638885 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/PostcodeValidator.cs +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/PostcodeValidator.cs @@ -10,10 +10,10 @@ namespace Umbraco.Web.UI.App_Plugins.MyPackage.PropertyEditors /// /// Validates a postcode /// - internal class PostcodeValidator : ValidatorBase + internal class PostcodeValidator : IPropertyValidator { - public override IEnumerable Validate(object value, string preValues, PropertyEditor editor) + public IEnumerable Validate(object value, string preValues, PropertyEditor editor) { if (value != null) { diff --git a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs index 1b3eb62b10..c40bf09d95 100644 --- a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs @@ -38,9 +38,9 @@ namespace Umbraco.Web.PropertyEditors Fields.First().Validators.Add(new ColorListValidator()); } - internal class ColorListValidator : ValidatorBase + internal class ColorListValidator : IPropertyValidator { - public override IEnumerable Validate(object value, string preValues, PropertyEditor editor) + public IEnumerable Validate(object value, string preValues, PropertyEditor editor) { var json = value as JArray; if (json == null) yield break; diff --git a/src/Umbraco.Web/PropertyEditors/DateTimeValidator.cs b/src/Umbraco.Web/PropertyEditors/DateTimeValidator.cs index 694434357e..50fb9057d8 100644 --- a/src/Umbraco.Web/PropertyEditors/DateTimeValidator.cs +++ b/src/Umbraco.Web/PropertyEditors/DateTimeValidator.cs @@ -9,9 +9,9 @@ namespace Umbraco.Web.PropertyEditors /// /// Used to validate if the value is a valid date/time /// - internal class DateTimeValidator : ValidatorBase + internal class DateTimeValidator : IPropertyValidator { - public override IEnumerable Validate(object value, string preValues, PropertyEditor editor) + public IEnumerable Validate(object value, string preValues, PropertyEditor editor) { DateTime dt; if (value != null && DateTime.TryParse(value.ToString(), out dt) == false) diff --git a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs new file mode 100644 index 0000000000..a9705ee5f5 --- /dev/null +++ b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs @@ -0,0 +1,21 @@ +using Umbraco.Core; +using Umbraco.Core.PropertyEditors; + +namespace Umbraco.Web.PropertyEditors +{ + [PropertyEditor(Constants.PropertyEditors.Integer, "Numeric", "integer")] + public class IntegerPropertyEditor : PropertyEditor + { + /// + /// Overridden to ensure that the value is validated + /// + /// + protected override ValueEditor CreateValueEditor() + { + var editor = base.CreateValueEditor(); + editor.Validators.Add(new RegexValidator("^\\d*$")); + return editor; + } + + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/MediaPicker.cs b/src/Umbraco.Web/PropertyEditors/MediaPicker.cs index fca582eb1f..d79fb36ad2 100644 --- a/src/Umbraco.Web/PropertyEditors/MediaPicker.cs +++ b/src/Umbraco.Web/PropertyEditors/MediaPicker.cs @@ -12,5 +12,12 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MediaPicker, "Media Picker", "mediapicker")] public class MediaPickerPropertyEditor : PropertyEditor { + protected override ValueEditor CreateValueEditor() + { + //TODO: Need to add some validation to the ValueEditor to ensure that any media chosen actually exists! + + return base.CreateValueEditor(); + } + } } diff --git a/src/Umbraco.Web/PropertyEditors/TextStringPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs similarity index 86% rename from src/Umbraco.Web/PropertyEditors/TextStringPropertyEditor.cs rename to src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs index 32b283b0c3..1c22312663 100644 --- a/src/Umbraco.Web/PropertyEditors/TextStringPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs @@ -11,7 +11,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { [PropertyEditor(Constants.PropertyEditors.Textbox, "Textbox", "textbox")] - public class TextStringPropertyEditor : PropertyEditor + public class TextboxPropertyEditor : PropertyEditor { } } diff --git a/src/Umbraco.Web/PropertyEditors/ValueListPreValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ValueListPreValueEditor.cs index 5b06759f24..06f2146cc9 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueListPreValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueListPreValueEditor.cs @@ -113,9 +113,9 @@ namespace Umbraco.Web.PropertyEditors /// /// A custom validator to ensure that all values in the list are unique /// - internal class EnsureUniqueValuesValidator : ValidatorBase + internal class EnsureUniqueValuesValidator : IPropertyValidator { - public override IEnumerable Validate(object value, string preValues, PropertyEditor editor) + public IEnumerable Validate(object value, string preValues, PropertyEditor editor) { var json = value as JArray; if (json == null) yield break; diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index f82bc1dc96..beab9ac756 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -322,6 +322,7 @@ + @@ -381,7 +382,7 @@ - +