--HG--
branch : dev
This commit is contained in:
Dave Reed
2010-10-18 11:49:26 -07:00
21 changed files with 82 additions and 114 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using JetBrains.Annotations;
@@ -9,7 +8,6 @@ using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Models;
using Orchard.Core.Common.Settings;
using Orchard.Core.Common.ViewModels;
using Orchard.Core.ContentsLocation.Models;
using Orchard.Core.Routable.Models;
using Orchard.Services;
@@ -49,10 +47,6 @@ namespace Orchard.Core.Common.Drivers {
);
}
private string IfThen(bool predicate, string value) {
return predicate ? value : null;
}
protected override DriverResult Editor(BodyPart part, dynamic shapeHelper) {
var model = BuildEditorViewModel(part);
return ContentShape("Parts_Common_Body_Edit",

View File

@@ -2,7 +2,6 @@
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Models;
using Orchard.Core.Common.ViewModels;
using Orchard.Core.ContentsLocation.Models;
using Orchard.Localization;
using Orchard.Security;
using Orchard.Services;
@@ -48,8 +47,8 @@ namespace Orchard.Core.Common.Drivers {
protected override DriverResult Editor(CommonPart part, dynamic shapeHelper) {
return Combined(
OwnerEditor(part, null),
ContainerEditor(part, null));
OwnerEditor(part, null, shapeHelper),
ContainerEditor(part, null, shapeHelper));
}
protected override DriverResult Editor(CommonPart instance, IUpdateModel updater, dynamic shapeHelper) {
@@ -58,11 +57,11 @@ namespace Orchard.Core.Common.Drivers {
instance.VersionModifiedUtc = _clock.UtcNow;
return Combined(
OwnerEditor(instance, updater),
ContainerEditor(instance, updater));
OwnerEditor(instance, updater, shapeHelper),
ContainerEditor(instance, updater, shapeHelper));
}
DriverResult OwnerEditor(CommonPart part, IUpdateModel updater) {
DriverResult OwnerEditor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
var currentUser = _authenticationService.GetAuthenticatedUser();
if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, part)) {
return null;
@@ -87,10 +86,11 @@ namespace Orchard.Core.Common.Drivers {
}
}
return ContentPartTemplate(model, "Parts/Common.Owner", TemplatePrefix).Location(part.GetLocation("Editor"));
return ContentShape("Parts_Common_Owner_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts/Common.Owner", Model: model, Prefix: Prefix));
}
DriverResult ContainerEditor(CommonPart part, IUpdateModel updater) {
DriverResult ContainerEditor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
var currentUser = _authenticationService.GetAuthenticatedUser();
if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, part)) {
return null;
@@ -115,7 +115,8 @@ namespace Orchard.Core.Common.Drivers {
}
}
return ContentPartTemplate(model, "Parts/Common.Container", TemplatePrefix).Location(part.GetLocation("Editor"));
return ContentShape("Parts_Common_Container_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts/Common.Container", Model: model, Prefix: Prefix));
}
}
}

View File

@@ -2,39 +2,32 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Fields;
using Orchard.Core.ContentsLocation.Models;
namespace Orchard.Core.Common.Drivers {
[UsedImplicitly]
public class TextFieldDriver : ContentFieldDriver<TextField> {
public IOrchardServices Services { get; set; }
private const string TemplateName = "Fields/Common.TextField";
public TextFieldDriver(IOrchardServices services) {
Services = services;
}
public IOrchardServices Services { get; set; }
private static string GetPrefix(TextField field, ContentPart part) {
return part.PartDefinition.Name + "." + field.Name;
}
protected override DriverResult Display(ContentPart part, TextField field, string displayType) {
var location = field.GetLocation(displayType, "Primary", "1");
return ContentFieldTemplate(field, TemplateName, GetPrefix(field, part))
.Location(location);
protected override DriverResult Display(ContentPart part, TextField field, string displayType, dynamic shapeHelper) {
return ContentShape("Fields_Common_Text", () => shapeHelper.Fields_Common_Text(ContentField: field, Name: field.Name, Value: field.Value));
}
protected override DriverResult Editor(ContentPart part, TextField field) {
var location = field.GetLocation("Editor", "Primary", "1");
return ContentFieldTemplate(field, TemplateName, GetPrefix(field, part))
.Location(location);
protected override DriverResult Editor(ContentPart part, TextField field, dynamic shapeHelper) {
return ContentShape("Fields_Common_Text_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Fields/Common.Text.Edit", Model: field, Prefix: GetPrefix(field, part)));
}
protected override DriverResult Editor(ContentPart part, TextField field, IUpdateModel updater) {
protected override DriverResult Editor(ContentPart part, TextField field, IUpdateModel updater, dynamic shapeHelper) {
updater.TryUpdateModel(field, GetPrefix(field, part), null, null);
return Editor(part, field);
return Editor(part, field, shapeHelper);
}
}
}
}

View File

@@ -1,16 +1,24 @@
<Placement>
<!-- available display shapes -->
<!--
Parts_Common_Body
Parts_Common_Body_Summary
Parts_Common_Metadata
Parts_Common_Metadata_Summary
Parts_Common_Metadata_SummaryAdmin
Fields_Common_Text
-->
<!-- edit shape just get default placement -->
<!-- edit shapes getting default placements -->
<!-- edit "shape" -->
<Place Parts_Common_Body_Edit="Primary:2"/>
<Place Parts_Common_Owner_Edit="Primary:20"/>
<Place Parts_Common_Container_Edit="Primary:20"/>
<Place Fields_Common_Text_Edit="Primary:2.5"/>
<!-- default positioning -->
<!-- show summary for all DisplayType by default -->
<Place Parts_Common_Body_Summary="Content:5"/>
<!-- with text fields a little before -->
<Place Fields_Common_Text="Content:2.5"/>
<Match DisplayType="Detail">
<!-- hide summary, show full content, for Detail -->
<Place Parts_Common_Body_Summary="-"

View File

@@ -1,9 +0,0 @@
using System.Web;
using Orchard.Core.Common.Models;
namespace Orchard.Core.Common.ViewModels {
public class BodyDisplayViewModel {
public BodyPart BodyPart { get; set; }
public IHtmlString Html { get; set; }
}
}

View File

@@ -1,23 +0,0 @@
using System;
using Orchard.Core.Common.Models;
using Orchard.Security;
namespace Orchard.Core.Common.ViewModels {
public class CommonMetadataViewModel {
private readonly CommonPart _commonPart;
public CommonMetadataViewModel(CommonPart commonPart) {
_commonPart = commonPart;
}
public IUser Creator { get { return _commonPart.Owner; } }
public DateTime? CreatedUtc { get { return _commonPart.CreatedUtc; } }
public DateTime? PublishedUtc { get { return _commonPart.PublishedUtc; } }
public DateTime? ModifiedUtc { get { return _commonPart.ModifiedUtc; } }
public DateTime? VersionCreatedUtc { get { return _commonPart.VersionCreatedUtc; } }
public DateTime? VersionPublishedUtc { get { return _commonPart.VersionPublishedUtc; } }
public DateTime? VersionModifiedUtc { get { return _commonPart.VersionModifiedUtc; } }
}
}

View File

@@ -1,3 +0,0 @@
@model Orchard.Core.Common.Fields.TextField
@using Orchard.Utility.Extensions;
<p class="text-field"><span class="name">@Model.Name.CamelFriendly():</span> @Model.Value</p>

View File

@@ -1 +0,0 @@
@model Orchard.Core.Common.ViewModels.BodyDisplayViewModel

View File

@@ -1,5 +0,0 @@
@model BodyDisplayViewModel
@using Orchard.Core.Common.ViewModels;
<div class="manage">
@Html.ItemEditLinkWithReturnUrl(T("Edit").ToString(), Model.BodyPart.ContentItem)
</div>

View File

@@ -1 +0,0 @@
@model Orchard.Core.Common.ViewModels.BodyDisplayViewModel

View File

@@ -1,7 +0,0 @@
@model BodyDisplayViewModel
@using Orchard.Core.Common.ViewModels;
@* begin: knowingly broken HTML (hence the ManageWrapperPre and ManageWrapperPost templates)
we need "wrapper templates" (among other functionality) in the future of UI composition
please do not delete or the front end will be broken when the user is authenticated. *@
</div>
@* begin: knowingly broken HTML *@

View File

@@ -1 +0,0 @@
@model Orchard.Core.Common.ViewModels.BodyDisplayViewModel

View File

@@ -1,3 +0,0 @@
@model BodyDisplayViewModel
@using Orchard.Core.Common.ViewModels;
<div class="managewrapper">

View File

@@ -0,0 +1,8 @@
@using Orchard.Utility.Extensions;
@{
string name = Model.Name;
string value = Model.Value;
}
@if (HasText(name) && HasText(value)) {
<p class="text-field"><span class="name">@name.CamelFriendly():</span> <span class="value">@value</span></p>
}

View File

@@ -82,7 +82,6 @@
<Compile Include="ContentsLocation\Models\LocationSettings.cs" />
<Compile Include="ContentsLocation\Settings\LocationSettingsEditorEvents.cs" />
<Compile Include="ContentsLocation\ViewModels\LocationSettingsViewModel.cs" />
<Compile Include="Common\ViewModels\CommonMetadataViewModel.cs" />
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
<Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" />
@@ -148,7 +147,6 @@
<Compile Include="Common\Models\BodyPart.cs" />
<Compile Include="Common\Models\BodyPartRecord.cs" />
<Compile Include="Common\Models\CommonPartRecord.cs" />
<Compile Include="Common\ViewModels\BodyDisplayViewModel.cs" />
<Compile Include="Common\ViewModels\BodyEditorViewModel.cs" />
<Compile Include="Common\ViewModels\OwnerEditorViewModel.cs" />
<Compile Include="Contents\AdminMenu.cs" />
@@ -255,11 +253,8 @@
<Content Include="Common\Module.txt" />
<Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.cshtml" />
<Content Include="Common\Views\DefinitionTemplates\BodyPartSettings.cshtml" />
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextField.cshtml" />
<Content Include="Common\Views\Fields\Common.Text.cshtml" />
<Content Include="Common\Views\Parts\Common.Body.SummaryAdmin.cshtml" />
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.Manage.SummaryAdmin.cshtml" />
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.ManageWrapperPost.SummaryAdmin.cshtml" />
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.ManageWrapperPre.SummaryAdmin.cshtml" />
<Content Include="Common\Views\Parts\Common.Metadata.cshtml" />
<Content Include="Common\Views\Parts\Common.Metadata.SummaryAdmin.cshtml" />
<Content Include="ContentsLocation\Module.txt" />
@@ -281,7 +276,7 @@
<Content Include="PublishLater\Content\Admin\images\scheduled.gif" />
<Content Include="PublishLater\Views\Parts\PublishLater.Metadata.cshtml" />
<Content Include="PublishLater\Views\Parts\PublishLater.Metadata.SummaryAdmin.cshtml" />
<Content Include="Common\Views\EditorTemplates\Fields\Common.TextField.cshtml" />
<Content Include="Common\Views\EditorTemplates\Fields\Common.Text.Edit.cshtml" />
<Content Include="Common\Views\EditorTemplates\Parts\Common.Container.cshtml" />
<Content Include="Common\Views\EditorTemplates\PlainTextEditor.cshtml" />
<Content Include="Contents\Module.txt" />
@@ -359,9 +354,6 @@
</ItemGroup>
<ItemGroup>
<Content Include="Common\Views\Parts\Common.Body.Summary.cshtml" />
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.ManageWrapperPost.cshtml" />
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.ManageWrapperPre.cshtml" />
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.Manage.cshtml" />
<Content Include="Dashboard\Views\Web.config" />
</ItemGroup>
<ItemGroup />

View File

@@ -47,7 +47,7 @@ namespace Orchard.Blogs.Drivers {
}
protected override DriverResult Editor(RecentBlogPostsPart part, dynamic shapeHelper) {
return ContentShape("Parts_Blogs_RecentBlogPosts_Editor",
return ContentShape("Parts_Blogs_RecentBlogPosts_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts/Blogs.RecentBlogPosts", Model: part, Prefix: Prefix));
}

View File

@@ -20,13 +20,13 @@ namespace Orchard.Email.Drivers {
protected override string Prefix { get { return "SmtpSettings"; } }
protected override DriverResult Editor(SmtpSettingsPart part, dynamic shapeHelper) {
return ContentShape("Parts_SmtpSettings_Editor",
return ContentShape("Parts_SmtpSettings_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix));
}
protected override DriverResult Editor(SmtpSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
updater.TryUpdateModel(part, Prefix, null, null);
return ContentShape("Parts_SmtpSettings_Editor",
return ContentShape("Parts_SmtpSettings_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix));
}
}

View File

@@ -36,7 +36,7 @@ namespace Orchard.Tags.Drivers {
if (!_authorizationService.TryCheckAccess(Permissions.ApplyTag, CurrentUser, part))
return null;
return ContentShape("Parts_Tags_Editor",
return ContentShape("Parts_Tags_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: BuildEditorViewModel(part), Prefix: Prefix));
}
@@ -52,7 +52,7 @@ namespace Orchard.Tags.Drivers {
_tagService.UpdateTagsForContentItem(part.ContentItem.Id, tagNames);
}
return ContentShape("Parts_Tags_Editor",
return ContentShape("Parts_Tags_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
}

View File

@@ -3,22 +3,23 @@ using System.Collections.Generic;
using System.Linq;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
using Orchard.DisplayManagement;
namespace Orchard.ContentManagement.Drivers {
public abstract class ContentFieldDriver<TField> : IContentFieldDriver where TField : ContentField, new() {
protected virtual string Prefix { get { return ""; } }
protected virtual string Zone { get { return "body"; } }
protected virtual string Zone { get { return "Content"; } }
DriverResult IContentFieldDriver.BuildDisplayShape(BuildDisplayContext context) {
return Process(context.ContentItem, (part, field) => Display(part, field, context.DisplayType));
return Process(context.ContentItem, (part, field) => Display(part, field, context.DisplayType, context.New));
}
DriverResult IContentFieldDriver.BuildEditorShape(BuildEditorContext context) {
return Process(context.ContentItem, Editor);
return Process(context.ContentItem, (part, field) => Editor(part, field, context.New));
}
DriverResult IContentFieldDriver.UpdateEditorShape(UpdateEditorContext context) {
return Process(context.ContentItem, (part, field) => Editor(part, field, context.Updater));
return Process(context.ContentItem, (part, field) => Editor(part, field, context.Updater, context.New));
}
DriverResult Process(ContentItem item, Func<ContentPart, TField, DriverResult> effort) {
@@ -43,19 +44,44 @@ namespace Orchard.ContentManagement.Drivers {
}
protected virtual DriverResult Display(ContentPart part, TField field, string displayType) { return null; }
protected virtual DriverResult Editor(ContentPart part, TField field) { return null; }
protected virtual DriverResult Editor(ContentPart part, TField field, IUpdateModel updater) { return null; }
protected virtual DriverResult Display(ContentPart part, TField field, string displayType, dynamic shapeHelper) { return null; }
protected virtual DriverResult Editor(ContentPart part, TField field, dynamic shapeHelper) { return null; }
protected virtual DriverResult Editor(ContentPart part, TField field, IUpdateModel updater, dynamic shapeHelper) { return null; }
public ContentShapeResult ContentShape(string shapeType, Func<dynamic> factory) {
return ContentShapeImplementation(shapeType, null, ctx => factory());
}
public ContentShapeResult ContentShape(string shapeType, string defaultLocation, Func<dynamic> factory) {
return ContentShapeImplementation(shapeType, defaultLocation, ctx => factory());
}
public ContentShapeResult ContentShape(string shapeType, Func<dynamic, dynamic> factory) {
return ContentShapeImplementation(shapeType, null, ctx=>factory(CreateShape(ctx, shapeType)));
}
public ContentShapeResult ContentShape(string shapeType, string defaultLocation, Func<dynamic, dynamic> factory) {
return ContentShapeImplementation(shapeType, defaultLocation, factory);
}
private ContentShapeResult ContentShapeImplementation(string shapeType, string defaultLocation, Func<BuildShapeContext, object> shapeBuilder) {
return new ContentShapeResult(shapeType, Prefix, shapeBuilder).Location(defaultLocation);
}
private object CreateShape(BuildShapeContext context, string shapeType) {
IShapeFactory shapeFactory = context.New;
return shapeFactory.Create(shapeType);
}
[Obsolete]
public ContentTemplateResult ContentFieldTemplate(object model) {
return new ContentTemplateResult(model, null, Prefix).Location(Zone);
}
[Obsolete]
public ContentTemplateResult ContentFieldTemplate(object model, string template) {
return new ContentTemplateResult(model, template, Prefix).Location(Zone);
}
[Obsolete]
public ContentTemplateResult ContentFieldTemplate(object model, string template, string prefix) {
return new ContentTemplateResult(model, template, prefix).Location(Zone);
}
@@ -64,4 +90,4 @@ namespace Orchard.ContentManagement.Drivers {
return new CombinedResult(results);
}
}
}
}

View File

@@ -7,7 +7,7 @@ using Orchard.DisplayManagement;
namespace Orchard.ContentManagement.Drivers {
public abstract class ContentPartDriver<TContent> : IContentPartDriver where TContent : ContentPart, new() {
protected virtual string Prefix { get { return ""; } }
protected virtual string Zone { get { return "Primary"; } }
protected virtual string Zone { get { return "Content"; } }
DriverResult IContentPartDriver.BuildDisplay(BuildDisplayContext context) {
var part = context.ContentItem.As<TContent>();
@@ -45,7 +45,6 @@ namespace Orchard.ContentManagement.Drivers {
return ContentShapeImplementation(shapeType, null, ctx=>factory(CreateShape(ctx, shapeType)));
}
public ContentShapeResult ContentShape(string shapeType, string defaultLocation, Func<dynamic, dynamic> factory) {
return ContentShapeImplementation(shapeType, defaultLocation, factory);
}