From a01b7dde239bb7bbb6f4a6a1676208ea4223af2f Mon Sep 17 00:00:00 2001 From: Jamie Phillips Date: Wed, 30 Sep 2015 21:35:44 -0400 Subject: [PATCH 1/9] URL Field for Dynamic Forms Created this because I was binding to a content type that had a URL field. Need to do this validation when submitting the dynamic form. --- .../Drivers/UrlFieldElementDriver.cs | 79 +++++++++++++++++++ .../Orchard.DynamicForms/Elements/UrlField.cs | 9 +++ .../Orchard.DynamicForms.csproj | 11 +++ .../ValidationRules/UrlAddress.cs | 40 ++++++++++ .../Settings/UrlFieldValidationSettings.cs | 8 ++ .../Validators/UrlFieldValidator.cs | 28 +++++++ .../Views/Elements/UrlField.Design.cshtml | 21 +++++ .../Views/Elements/UrlField.cshtml | 25 ++++++ 8 files changed, 221 insertions(+) create mode 100644 src/Orchard.Web/Modules/Orchard.DynamicForms/Drivers/UrlFieldElementDriver.cs create mode 100644 src/Orchard.Web/Modules/Orchard.DynamicForms/Elements/UrlField.cs create mode 100644 src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs create mode 100644 src/Orchard.Web/Modules/Orchard.DynamicForms/Validators/Settings/UrlFieldValidationSettings.cs create mode 100644 src/Orchard.Web/Modules/Orchard.DynamicForms/Validators/UrlFieldValidator.cs create mode 100644 src/Orchard.Web/Modules/Orchard.DynamicForms/Views/Elements/UrlField.Design.cshtml create mode 100644 src/Orchard.Web/Modules/Orchard.DynamicForms/Views/Elements/UrlField.cshtml diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Drivers/UrlFieldElementDriver.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Drivers/UrlFieldElementDriver.cs new file mode 100644 index 000000000..7c121254d --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Drivers/UrlFieldElementDriver.cs @@ -0,0 +1,79 @@ +using Orchard.DynamicForms.Elements; +using Orchard.Forms.Services; +using Orchard.Layouts.Framework.Drivers; +using Orchard.Layouts.Framework.Display; +using Orchard.Layouts.Helpers; +using Orchard.Tokens; +using DescribeContext = Orchard.Forms.Services.DescribeContext; + +namespace Orchard.DynamicForms.Drivers { + public class UrlFieldElementDriver : FormsElementDriver { + private readonly ITokenizer _tokenizer; + + public UrlFieldElementDriver(IFormManager formManager, ITokenizer tokenizer) : base(formManager) { + _tokenizer = tokenizer; + } + + protected override EditorResult OnBuildEditor(UrlField element, ElementEditorContext context) { + var autoLabelEditor = BuildForm(context, "AutoLabel"); + var webAddressFieldEditor = BuildForm(context, "UrlField"); + var webAddressFieldValidation = BuildForm(context, "UrlFieldValidation", "Validation:10"); + + return Editor(context, autoLabelEditor, webAddressFieldEditor, webAddressFieldValidation); + } + + protected override void DescribeForm(DescribeContext context) { + context.Form("UrlField", factory => { + var shape = (dynamic) factory; + var form = shape.Fieldset( + Id: "UrlField", + _Value: shape.Textbox( + Id: "Value", + Name: "Value", + Title: "Value", + Classes: new[] {"text", "medium", "tokenized"}, + Description: T("The value of this URL field."))); + + return form; + }); + + context.Form("UrlFieldValidation", factory => { + var shape = (dynamic) factory; + var form = shape.Fieldset( + Id: "UrlFieldValidation", + _IsRequired: shape.Checkbox( + Id: "IsRequired", + Name: "IsRequired", + Title: "Required", + Value: "true", + Description: T("Tick this checkbox to make this email field a required field.")), + _MaximumLength: shape.Textbox( + Id: "MaximumLength", + Name: "MaximumLength", + Title: "Maximum Length", + Classes: new[] {"text", "medium", "tokenized"}, + Description: T("The maximum length allowed.")), + _CustomValidationMessage: shape.Textbox( + Id: "CustomValidationMessage", + Name: "CustomValidationMessage", + Title: "Custom Validation Message", + Classes: new[] {"text", "large", "tokenized"}, + Description: T("Optionally provide a custom validation message.")), + _ShowValidationMessage: shape.Checkbox( + Id: "ShowValidationMessage", + Name: "ShowValidationMessage", + Title: "Show Validation Message", + Value: "true", + Description: T("Autogenerate a validation message when a validation error occurs for the current field. Alternatively, to control the placement of the validation message you can use the ValidationMessage element instead."))); + + return form; + }); + } + + protected override void OnDisplaying(UrlField element, ElementDisplayContext context) { + context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData()); + context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData()); + context.ElementShape.ProcessedValue = _tokenizer.Replace(element.RuntimeValue, context.GetTokenData()); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Elements/UrlField.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Elements/UrlField.cs new file mode 100644 index 000000000..83e24971d --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Elements/UrlField.cs @@ -0,0 +1,9 @@ +using Orchard.DynamicForms.Validators.Settings; + +namespace Orchard.DynamicForms.Elements { + public class UrlField : LabeledFormElement { + public UrlFieldValidationSettings ValidationSettings { + get { return Data.GetModel(""); } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Orchard.DynamicForms.csproj b/src/Orchard.Web/Modules/Orchard.DynamicForms/Orchard.DynamicForms.csproj index b16e3c705..b6075865d 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/Orchard.DynamicForms.csproj +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Orchard.DynamicForms.csproj @@ -167,7 +167,9 @@ + + @@ -217,7 +219,9 @@ + + @@ -271,6 +275,7 @@ + @@ -506,6 +511,12 @@ + + + + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs new file mode 100644 index 000000000..664f6e3a8 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs @@ -0,0 +1,40 @@ +using System; +using System.Text.RegularExpressions; +using Orchard.DynamicForms.Helpers; +using Orchard.DynamicForms.Services; +using Orchard.DynamicForms.Services.Models; +using Orchard.Localization; + +namespace Orchard.DynamicForms.ValidationRules +{ + public class UrlAddress : ValidationRule + { + public UrlAddress() { + RegexOptions = RegexOptions.Singleline | RegexOptions.IgnoreCase; + Pattern = @"^http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$"; + } + + public string Pattern { get; set; } + public RegexOptions RegexOptions { get; set; } + + public override void Validate(ValidateInputContext context) + { + if (!Regex.IsMatch(context.AttemptedValue, Pattern, RegexOptions)) + { + var message = GetValidationMessage(context); + context.ModelState.AddModelError(context.FieldName, message.Text); + } + } + + public override void RegisterClientAttributes(RegisterClientValidationAttributesContext context) + { + context.ClientAttributes["data-val-regex"] = GetValidationMessage(context).Text; + context.ClientAttributes["data-val-regex-pattern"] = Pattern; + } + + private LocalizedString GetValidationMessage(ValidationContext context) + { + return T(Tokenize(ErrorMessage.WithDefault(String.Format("{0} is not a valid url.", context.FieldName)), context)); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Validators/Settings/UrlFieldValidationSettings.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Validators/Settings/UrlFieldValidationSettings.cs new file mode 100644 index 000000000..b8325a47d --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Validators/Settings/UrlFieldValidationSettings.cs @@ -0,0 +1,8 @@ +using Orchard.DynamicForms.Services.Models; + +namespace Orchard.DynamicForms.Validators.Settings { + public class UrlFieldValidationSettings : ValidationSettingsBase { + public bool? IsRequired { get; set; } + public int? MaximumLength { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Validators/UrlFieldValidator.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Validators/UrlFieldValidator.cs new file mode 100644 index 000000000..2d8959f43 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Validators/UrlFieldValidator.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using Orchard.DynamicForms.Elements; +using Orchard.DynamicForms.Services; +using Orchard.DynamicForms.ValidationRules; + +namespace Orchard.DynamicForms.Validators { + public class UrlFieldValidator : ElementValidator { + private readonly IValidationRuleFactory _validationRuleFactory; + + public UrlFieldValidator(IValidationRuleFactory validationRuleFactory) { + _validationRuleFactory = validationRuleFactory; + } + + protected override IEnumerable GetValidationRules(UrlField element) { + var settings = element.ValidationSettings; + + if (settings.IsRequired == true) + yield return _validationRuleFactory.Create(settings.CustomValidationMessage); + + if (settings.MaximumLength != null) { + yield return _validationRuleFactory.Create(r => { + r.Maximum = settings.MaximumLength; + r.ErrorMessage = settings.CustomValidationMessage; + }); + } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Views/Elements/UrlField.Design.cshtml b/src/Orchard.Web/Modules/Orchard.DynamicForms/Views/Elements/UrlField.Design.cshtml new file mode 100644 index 000000000..aad86e6c3 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Views/Elements/UrlField.Design.cshtml @@ -0,0 +1,21 @@ +@using Orchard.DynamicForms.Elements +@using Orchard.Layouts.Helpers +@{ + var element = (UrlField)Model.Element; + var tagBuilder = TagBuilderExtensions.CreateElementTagBuilder(Model, "input"); + + tagBuilder.AddCssClass("text design"); + tagBuilder.Attributes["type"] = "url"; + tagBuilder.Attributes["value"] = element.Value; + tagBuilder.Attributes["name"] = element.Name; +} + +@if (element.ShowLabel) { +
+ + @tagBuilder.ToHtmlString(TagRenderMode.SelfClosing) +
+} +else { + @tagBuilder.ToHtmlString(TagRenderMode.SelfClosing) +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Views/Elements/UrlField.cshtml b/src/Orchard.Web/Modules/Orchard.DynamicForms/Views/Elements/UrlField.cshtml new file mode 100644 index 000000000..a205053dc --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Views/Elements/UrlField.cshtml @@ -0,0 +1,25 @@ +@using Orchard.DisplayManagement.Shapes +@using Orchard.DynamicForms.Elements +@using Orchard.Layouts.Helpers +@{ + var element = (UrlField)Model.Element; + var tagBuilder = (OrchardTagBuilder)TagBuilderExtensions.CreateElementTagBuilder(Model, "input"); + + tagBuilder.AddCssClass("text"); + tagBuilder.Attributes["type"] = "url"; + tagBuilder.Attributes["value"] = Model.ProcessedValue; + tagBuilder.Attributes["name"] = Model.ProcessedName; + tagBuilder.AddClientValidationAttributes((IDictionary)Model.ClientValidationAttributes); + + if (!ViewData.ModelState.IsValidField(Model.ProcessedName)) { + tagBuilder.AddCssClass("input-validation-error"); + } +} + +@if (element.ShowLabel) { + +} +@tagBuilder.ToHtmlString(TagRenderMode.SelfClosing) +@if (element.ValidationSettings.ShowValidationMessage == true) { + @Html.ValidationMessage((string)Model.ProcessedName) +} \ No newline at end of file From 9ae372a9208755cf81b2bfba8ffd623c7f3e7fff Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Wed, 21 Oct 2015 00:11:42 +0100 Subject: [PATCH 2/9] revamp and update version to 1.9.2 It was still talking about the project in the context of v1 and had a duplicate section about getting involved --- README.md | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7d9717ccf..4e644eb26 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # Orchard + Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform. +[![Join the chat at https://gitter.im/OrchardCMS/Orchard](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/OrchardCMS/Orchard?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +You can try it for free on [Dotnest.com](https://dotnest.com) or on Microsoft Azure by clicking on this button + +[![Deploy to Azure](https://azuredeploy.net/deploybutton.png)](https://ms.portal.azure.com/#create/OutercurveFoundation.OrchardCMS.0.5.9) + ## About The Orchard Project #### Please visit our website at http://orchardproject.net for the most current information about this project. @@ -13,26 +20,29 @@ Orchard is delivered under the [.NET Foundation](http://www.dotnetfoundation.org Our mission is to empower our users and foster a dedicated and diverse community that builds the CMS that we all want to use. -There are many ways you can [contribute to Orchard](http://orchardproject.net/contribution): you can [fix bugs](https://github.com/OrchardCMS/Orchard/issues), contribute modules and themes to [our gallery](http://gallery.orchardproject.net/), [write documentation](https://github.com/OrchardCMS/OrchardDoc), [translate Orchard](http://orchardproject.net/localize), or answer questions [on our forums](http://orchard.codeplex.com/discussions) and [on Stack Overflow](http://stackoverflow.com/questions/tagged/orchardcms). - ## Project Status -Orchard is currently in version 1.9.1. We invite participation by the developer community in shaping the project’s direction, so that we can publicly validate our designs and development approach. -Our 1.9.1 release is available from our Downloads page, and is easy to [Install Orchard using the Web Platform Installer](http://www.orchardproject.net/docs/Installing-Orchard.ashx). We encourage interested developers to check out the source code on the Orchard Github site and get involved with the project. +Orchard is currently in version 1.9.2. We invite participation by the developer community in shaping the project’s direction, so that we can publicly validate our designs and development approach. +Our 1.9.2 release is available from our Downloads page, and is easy to [Install Orchard using the Web Platform Installer](http://docs.orchardproject.net/Documentation/Installing-Orchard). We encourage interested developers to check out the source code on the Orchard Github site and get involved with the project. * [Download the latest release](https://github.com/OrchardCMS/Orchard/releases) -* [Feature roadmap](http://www.orchardproject.net/docs/feature-roadmap.ashx) +* [Feature roadmap](http://docs.orchardproject.net/Documentation/feature-roadmap) * [Docs and designs/specs](http://www.orchardproject.net/docs) * [About us](http://www.orchardproject.net/about) * [Contact us](mailto:ofeedbk@microsoft.com) ## How To Get Involved -We hope that by engaging with the community in the very early stages of the project that we will be able to shape Orchard into a valuable set of tools and applications for the community. The Orchard team is committed to open community participation and accepts code contributions today. We encourage community participation at all levels from general project feedback to bug fixes and patches. +We hope that by engaging with the community we will continue to shape Orchard into a valuable set of tools and applications. The Orchard team is committed to open community participation and accepts code contributions. We encourage community participation at all levels from general project feedback to bug fixes and patches. + +There are many ways you can [contribute to Orchard](http://orchardproject.net/contribution): * [Check out the code](https://github.com/OrchardCMS/Orchard) -* [Check out the docs](http://orchardproject.net/docs) +* [Write documentation](https://github.com/OrchardCMS/OrchardDoc) * [Find and file a bug](https://github.com/OrchardCMS/Orchard/issues) * [Propose a feature idea](http://orchard.uservoice.com) -* [Ask and answer questions](http://www.orchardproject.net/discussions) +* [Ask and answer questions in our forums](http://www.orchardproject.net/discussions) and [on Stack Overflow](http://stackoverflow.com/questions/tagged/orchardcms) +* [Participate in our gitter.im chatroom](https://gitter.im/OrchardCMS/Orchard) * [Participate in forum discussions](http://orchard.codeplex.com/discussions) -* [Submit a patch](http://www.orchardproject.net/docs/Contributing-patches.ashx) +* [Submit a pull request](http://docs.orchardproject.net/Documentation/Contributing-patches) +* [Translate Orchard](http://orchardproject.net/localize) +* [Contribute modules and themes to our gallery](http://gallery.orchardproject.net/) * [Send us feedback](mailto:ofeedbk@microsoft.com) From 14c2ee794409382ef13ae225b54cddfd5ebd55ba Mon Sep 17 00:00:00 2001 From: Jamie Phillips Date: Tue, 20 Oct 2015 20:34:23 -0400 Subject: [PATCH 3/9] Updating Validation Message for URL Field This change is made to now be in sync with the recent changes to how validation messages are being handled. --- .../Orchard.DynamicForms/ValidationRules/UrlAddress.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs index 664f6e3a8..3ee7e985d 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs @@ -34,7 +34,9 @@ namespace Orchard.DynamicForms.ValidationRules private LocalizedString GetValidationMessage(ValidationContext context) { - return T(Tokenize(ErrorMessage.WithDefault(String.Format("{0} is not a valid url.", context.FieldName)), context)); + return String.IsNullOrWhiteSpace(ErrorMessage) + ? T("{0} is not a valid URL.", context.FieldName) + : new LocalizedString(Tokenize(ErrorMessage, context)); } } -} \ No newline at end of file +} From 0d5cff66a9a32fef1254855cd52044c46d948e86 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Wed, 21 Oct 2015 14:41:41 -0700 Subject: [PATCH 4/9] Fixing Azure Portal integration --- lib/msdeploy/parameters.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/msdeploy/parameters.xml b/lib/msdeploy/parameters.xml index db78a9991..95b029f92 100644 --- a/lib/msdeploy/parameters.xml +++ b/lib/msdeploy/parameters.xml @@ -23,19 +23,20 @@ - + - + + - +