diff --git a/src/Orchard.Web/Modules/Orchard.Templates/Drivers/ShapePartDriver.cs b/src/Orchard.Web/Modules/Orchard.Templates/Drivers/ShapePartDriver.cs index 40a2d8dc1..a9b34b7a8 100644 --- a/src/Orchard.Web/Modules/Orchard.Templates/Drivers/ShapePartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Templates/Drivers/ShapePartDriver.cs @@ -8,7 +8,6 @@ using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Handlers; using Orchard.Data; using Orchard.Localization; -using Orchard.Templates.Helpers; using Orchard.Templates.Models; using Orchard.Templates.Services; using Orchard.Templates.ViewModels; @@ -38,14 +37,12 @@ namespace Orchard.Templates.Drivers { protected override DriverResult Editor(ShapePart part, IUpdateModel updater, dynamic shapeHelper) { var viewModel = new ShapePartViewModel { - Name = part.Name, Template = part.Template }; if (updater != null && updater.TryUpdateModel(viewModel, Prefix, null, new[] { "AvailableLanguages" }) - && ValidateShapeName(viewModel.Name, updater)) { - part.Name = viewModel.Name.TrimSafe(); + && ValidateShapeName(part, updater)) { part.Template = viewModel.Template; try { @@ -62,27 +59,34 @@ namespace Orchard.Templates.Drivers { } protected override void Exporting(ShapePart part, ExportContentContext context) { - context.Element(part.PartDefinition.Name).SetAttributeValue("Name", part.Name); context.Element(part.PartDefinition.Name).Add(new XCData(part.Template)); } protected override void Importing(ShapePart part, ImportContentContext context) { - context.ImportAttribute(part.PartDefinition.Name, "Name", x => part.Name = x); var shapeElement = context.Data.Element(part.PartDefinition.Name); if(shapeElement != null) part.Template = shapeElement.Value; } - private bool ValidateShapeName(string name, IUpdateModel updater) { + private bool ValidateShapeName(ShapePart part, IUpdateModel updater) { + var titleViewModel = new TitleViewModel(); + if (!updater.TryUpdateModel(titleViewModel, "Title", null, null)) + return false; + + var name = titleViewModel.Title; if (!string.IsNullOrWhiteSpace(name) && name[0].IsLetter() && name.All(c => c.IsLetter() || Char.IsDigit(c) || c == '.' || c == '-' )) { return true; } - updater.AddModelError("Name", T("Shape names can only contain alphanumerical, dot (.) or dash (-) characters and have to start with a letter.")); + updater.AddModelError("Title", T("{0} names can only contain alphanumerical, dot (.) or dash (-) characters and have to start with a letter.", part.ContentItem.TypeDefinition.DisplayName)); return false; } + + private class TitleViewModel { + public string Title { get; set; } + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Templates/Handlers/ShapePartHandler.cs b/src/Orchard.Web/Modules/Orchard.Templates/Handlers/ShapePartHandler.cs index 86093169d..e966d4c04 100644 --- a/src/Orchard.Web/Modules/Orchard.Templates/Handlers/ShapePartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Templates/Handlers/ShapePartHandler.cs @@ -1,7 +1,6 @@ using Orchard.Caching; using Orchard.Compilation.Razor; using Orchard.ContentManagement.Handlers; -using Orchard.Data; using Orchard.Templates.Models; using Orchard.Templates.Services; @@ -9,12 +8,8 @@ namespace Orchard.Templates.Handlers { public class ShapePartHandler : ContentHandler { private readonly IRazorTemplateHolder _razorTemplateHolder; - public ShapePartHandler( - ISignals signals, - IRepository repository, - IRazorTemplateHolder razorTemplateHolder) { + public ShapePartHandler(ISignals signals, IRazorTemplateHolder razorTemplateHolder) { _razorTemplateHolder = razorTemplateHolder; - Filters.Add(StorageFilter.For(repository)); OnGetContentItemMetadata((ctx, part) => ctx.Metadata.DisplayText = part.Name); OnUpdated((ctx, part) => _razorTemplateHolder.Set(part.Name, part.Template)); diff --git a/src/Orchard.Web/Modules/Orchard.Templates/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Templates/Migrations.cs index 73e32c5db..4f75a0da3 100644 --- a/src/Orchard.Web/Modules/Orchard.Templates/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Templates/Migrations.cs @@ -5,10 +5,6 @@ using Orchard.Data.Migration; namespace Orchard.Templates { public class Migrations : DataMigrationImpl { public int Create() { - SchemaBuilder.CreateTable("ShapePartRecord", table => table - .ContentPartRecord() - .Column("Name", c => c.WithLength(100)) - .Column("Template", c => c.Unlimited())); ContentDefinitionManager.AlterPartDefinition("ShapePart", part => part .Attachable() @@ -17,6 +13,7 @@ namespace Orchard.Templates { ContentDefinitionManager.AlterTypeDefinition("Template", type => type .WithPart("CommonPart") .WithPart("IdentityPart") + .WithPart("TitlePart") .WithPart("ShapePart", p => p .WithSetting("ShapePartSettings.Processor", "Razor")) .Draftable()); diff --git a/src/Orchard.Web/Modules/Orchard.Templates/Models/ShapePart.cs b/src/Orchard.Web/Modules/Orchard.Templates/Models/ShapePart.cs index 1f73ec074..668b86878 100644 --- a/src/Orchard.Web/Modules/Orchard.Templates/Models/ShapePart.cs +++ b/src/Orchard.Web/Modules/Orchard.Templates/Models/ShapePart.cs @@ -1,11 +1,11 @@ using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; using Orchard.Templates.Settings; namespace Orchard.Templates.Models { - public class ShapePart : ContentPart { + public class ShapePart : ContentPart { public string Name { - get { return Retrieve(x => x.Name); } - set { Store(x => x.Name, value); } + get { return this.As().Title; } } public string ProcessorName { @@ -13,8 +13,8 @@ namespace Orchard.Templates.Models { } public string Template { - get { return Retrieve(x => x.Template); } - set { Store(x => x.Template, value); } + get { return this.Retrieve(x => x.Template); } + set { this.Store(x => x.Template, value); } } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Templates/Models/ShapePartRecord.cs b/src/Orchard.Web/Modules/Orchard.Templates/Models/ShapePartRecord.cs deleted file mode 100644 index 7af59594c..000000000 --- a/src/Orchard.Web/Modules/Orchard.Templates/Models/ShapePartRecord.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Orchard.ContentManagement.Records; -using Orchard.Data.Conventions; - -namespace Orchard.Templates.Models { - public class ShapePartRecord : ContentPartRecord { - public virtual string Name { get; set; } - - [StringLengthMax] - public virtual string Template { get; set; } - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Templates/Orchard.Templates.csproj b/src/Orchard.Web/Modules/Orchard.Templates/Orchard.Templates.csproj index a56a79f17..de3c207f5 100644 --- a/src/Orchard.Web/Modules/Orchard.Templates/Orchard.Templates.csproj +++ b/src/Orchard.Web/Modules/Orchard.Templates/Orchard.Templates.csproj @@ -167,7 +167,6 @@ - diff --git a/src/Orchard.Web/Modules/Orchard.Templates/ViewModels/ShapePartViewModel.cs b/src/Orchard.Web/Modules/Orchard.Templates/ViewModels/ShapePartViewModel.cs index 76fe2dc0d..44b2b22fa 100644 --- a/src/Orchard.Web/Modules/Orchard.Templates/ViewModels/ShapePartViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.Templates/ViewModels/ShapePartViewModel.cs @@ -1,9 +1,5 @@ -using System.ComponentModel.DataAnnotations; - -namespace Orchard.Templates.ViewModels { +namespace Orchard.Templates.ViewModels { public class ShapePartViewModel { - [StringLength(100)] - public string Name { get; set; } public string Template { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Templates/Views/EditorTemplates/Parts.Shape.cshtml b/src/Orchard.Web/Modules/Orchard.Templates/Views/EditorTemplates/Parts.Shape.cshtml index 034390711..92c116c02 100644 --- a/src/Orchard.Web/Modules/Orchard.Templates/Views/EditorTemplates/Parts.Shape.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Templates/Views/EditorTemplates/Parts.Shape.cshtml @@ -11,13 +11,6 @@ Script.Include("codemirror/mode/htmlembedded/htmlembedded.js"); Script.Include("template-editor.js", "template-editor.min.js"); } -
-
- @Html.LabelFor(m => m.Name, T("Name")) - @Html.TextBoxFor(m => m.Name, new { @class = "text medium" }) - @T("The name of this template, which can be used to reference from code (as when using shape type names) and tokens.") -
-
@Html.TextAreaFor(m => m.Template, new { @class = "text large code-editor" })