-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added MaxLength setting for TextField # Conflicts: # src/Orchard.Web/Modules/Orchard.Taxonomies/Settings/TaxonomyFieldEditorEvents.cs * added MaxLength setting for TitlePart * added missing files * Removed where clause * changed title length to a constant and updated the recipe * added comment to remind people to update the migration when they change the constant introduced previously * fixed hint text for title * fixed maxLength initialization in TitlePartSettings.cshtml * MaxTitleLength constant is now Pascal case * Correction on constant spelling in TitlePartSettings shape. --------- Co-authored-by: Andrea Piovanelli <[email protected]>
- Loading branch information
1 parent
eb09ab7
commit 44bfa39
Showing
18 changed files
with
193 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
src/Orchard.Web/Core/Common/Views/Body-Large.Editor.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
src/Orchard.Web/Core/Common/Views/Body-Small.Editor.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 15 additions & 4 deletions
19
src/Orchard.Web/Core/Common/Views/EditorTemplates/Fields.Common.Text.Edit.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
@model Orchard.Core.Common.ViewModels.TextFieldDriverViewModel | ||
@{ | ||
var maxLength = Model.Settings.MaxLength > 0 ? Model.Settings.MaxLength.ToString() : ""; | ||
} | ||
|
||
<fieldset> | ||
<label for="@Html.FieldIdFor(m => m.Text)" @if(Model.Settings.Required) { <text>class="required"</text> }>@Model.Field.DisplayName</label> | ||
<label for="@Html.FieldIdFor(m => m.Text)" @if (Model.Settings.Required) { <text> class="required" </text> }>@Model.Field.DisplayName</label> | ||
@if (String.IsNullOrWhiteSpace(Model.Settings.Flavor)) { | ||
@(Model.Settings.Required ? Html.TextBoxFor(m => m.Text, new {@class = "text", required = "required"}) : Html.TextBoxFor(m => m.Text, new {@class = "text"})) | ||
@(Model.Settings.Required | ||
? Html.TextBoxFor(m => m.Text, new {@class = "text", required = "required", maxlength = maxLength}) | ||
: Html.TextBoxFor(m => m.Text, new {@class = "text", maxlength = maxLength })) | ||
@Html.ValidationMessageFor(m => m.Text) | ||
} | ||
else { | ||
@Display.Body_Editor(Text: Model.Text, EditorFlavor: Model.Settings.Flavor, Required: Model.Settings.Required, ContentItem: Model.ContentItem, Field: Model.Field) | ||
|
||
var htmlAttributes = new Dictionary<string, object> { | ||
{"maxlength", maxLength} | ||
}; | ||
|
||
@Display.Body_Editor(Text: Model.Text, EditorFlavor: Model.Settings.Flavor, Required: Model.Settings.Required, | ||
ContentItem: Model.ContentItem, Field: Model.Field, HtmlAttributes: htmlAttributes) | ||
} | ||
@if (HasText(Model.Settings.Hint)) { | ||
<span class="hint">@Model.Settings.Hint</span> | ||
<span class="hint">@Model.Settings.Hint</span> | ||
} | ||
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace Orchard.Core.Title.Settings { | ||
|
||
|
||
public class TitlePartSettings { | ||
// Whenever this constant is changed a new migration step must be created to update the length of the field on the DB | ||
public const int MaxTitleLength = 1024; | ||
[Range(0, MaxTitleLength)] | ||
[DisplayName("Maximum Length")] | ||
public int MaxLength {get; set;} | ||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Orchard.Web/Core/Title/Settings/TitlePartSettingsEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using Orchard.ContentManagement; | ||
using Orchard.ContentManagement.MetaData; | ||
using Orchard.ContentManagement.MetaData.Builders; | ||
using Orchard.ContentManagement.MetaData.Models; | ||
using Orchard.ContentManagement.ViewModels; | ||
|
||
namespace Orchard.Core.Title.Settings { | ||
public class TitlePartSettingsEvents : ContentDefinitionEditorEventsBase { | ||
|
||
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition) { | ||
if (definition.PartDefinition.Name != "TitlePart") { | ||
yield break; | ||
} | ||
|
||
var settings = definition | ||
.Settings | ||
.GetModel<TitlePartSettings>() | ||
?? new TitlePartSettings(); | ||
|
||
yield return DefinitionTemplate(settings); | ||
} | ||
|
||
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) { | ||
|
||
if (builder.Name != "TitlePart") { | ||
yield break; | ||
} | ||
|
||
var model = new TitlePartSettings(); | ||
|
||
if (updateModel.TryUpdateModel(model, "TitlePartSettings", null, null)) { | ||
builder.WithSetting("TitlePartSettings.MaxLength", model.MaxLength.ToString()); | ||
|
||
} | ||
yield return DefinitionTemplate(model); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Orchard.Web/Core/Title/Views/DefinitionTemplates/TitlePartSettings.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@using Orchard.Core.Title.Settings; | ||
@model TitlePartSettings | ||
@{ | ||
var maxLength = TitlePartSettings.MaxTitleLength; | ||
} | ||
|
||
<fieldset> | ||
<label for="@Html.FieldIdFor(m => m.MaxLength)">@T("Maximum length")</label> | ||
@Html.EditorFor(m => m.MaxLength, new { htmlAttributes = new { min = 0, max = maxLength } }) | ||
<span class="hint">@T("Maximum length allowed for the title. Setting the value to 0 means the maximum allowed length is {0} characters.", maxLength)</span> | ||
@Html.ValidationMessageFor(m => m.MaxLength) | ||
</fieldset> |
10 changes: 7 additions & 3 deletions
10
src/Orchard.Web/Core/Title/Views/EditorTemplates/Parts.Title.TitlePart.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
@model Orchard.Core.Title.Models.TitlePart | ||
@using Orchard.Core.Title.Settings | ||
@model Orchard.Core.Title.Models.TitlePart | ||
@{ | ||
var maxLength = Model.Settings.GetModel<TitlePartSettings>().MaxLength > 0 ? Model.Settings.GetModel<TitlePartSettings>().MaxLength.ToString() : ""; | ||
} | ||
|
||
<fieldset> | ||
<label for="@Html.FieldIdFor(m => m.Title)" class="required">@T("Title")</label> | ||
@Html.TextBoxFor(m => m.Title, new { @class = "text large", autofocus = "autofocus" }) | ||
<label for="@Html.FieldIdFor(m => m.Title)" class="required">@T("Title")</label> | ||
@Html.TextBoxFor(m => m.Title, new { @class = "text large", autofocus = "autofocus", maxlength = maxLength }) | ||
<span class="hint">@T("You must provide a title for this content item")</span> | ||
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters