Updating the Orchard.Core Common module to use the new shape API

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-10-18 10:13:57 -07:00
parent 1f4145ddd2
commit fedf68e4a4
15 changed files with 39 additions and 90 deletions

View File

@@ -2,7 +2,6 @@
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Models; using Orchard.Core.Common.Models;
using Orchard.Core.Common.ViewModels; using Orchard.Core.Common.ViewModels;
using Orchard.Core.ContentsLocation.Models;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Security; using Orchard.Security;
using Orchard.Services; using Orchard.Services;
@@ -48,8 +47,8 @@ namespace Orchard.Core.Common.Drivers {
protected override DriverResult Editor(CommonPart part, dynamic shapeHelper) { protected override DriverResult Editor(CommonPart part, dynamic shapeHelper) {
return Combined( return Combined(
OwnerEditor(part, null), OwnerEditor(part, null, shapeHelper),
ContainerEditor(part, null)); ContainerEditor(part, null, shapeHelper));
} }
protected override DriverResult Editor(CommonPart instance, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(CommonPart instance, IUpdateModel updater, dynamic shapeHelper) {
@@ -58,11 +57,11 @@ namespace Orchard.Core.Common.Drivers {
instance.VersionModifiedUtc = _clock.UtcNow; instance.VersionModifiedUtc = _clock.UtcNow;
return Combined( return Combined(
OwnerEditor(instance, updater), OwnerEditor(instance, updater, shapeHelper),
ContainerEditor(instance, updater)); ContainerEditor(instance, updater, shapeHelper));
} }
DriverResult OwnerEditor(CommonPart part, IUpdateModel updater) { DriverResult OwnerEditor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
var currentUser = _authenticationService.GetAuthenticatedUser(); var currentUser = _authenticationService.GetAuthenticatedUser();
if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, part)) { if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, part)) {
return null; 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(); var currentUser = _authenticationService.GetAuthenticatedUser();
if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, part)) { if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, part)) {
return null; 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;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Fields; using Orchard.Core.Common.Fields;
using Orchard.Core.ContentsLocation.Models;
namespace Orchard.Core.Common.Drivers { namespace Orchard.Core.Common.Drivers {
[UsedImplicitly] [UsedImplicitly]
public class TextFieldDriver : ContentFieldDriver<TextField> { public class TextFieldDriver : ContentFieldDriver<TextField> {
public IOrchardServices Services { get; set; }
private const string TemplateName = "Fields/Common.TextField";
public TextFieldDriver(IOrchardServices services) { public TextFieldDriver(IOrchardServices services) {
Services = services; Services = services;
} }
public IOrchardServices Services { get; set; }
private static string GetPrefix(TextField field, ContentPart part) { private static string GetPrefix(TextField field, ContentPart part) {
return part.PartDefinition.Name + "." + field.Name; return part.PartDefinition.Name + "." + field.Name;
} }
protected override DriverResult Display(ContentPart part, TextField field, string displayType) { protected override DriverResult Display(ContentPart part, TextField field, string displayType, dynamic shapeHelper) {
var location = field.GetLocation(displayType, "Primary", "1"); return ContentShape("Fields_Common_Text", () => shapeHelper.Fields_Common_Text(ContentField: field, Name: field.Name, Value: field.Value));
return ContentFieldTemplate(field, TemplateName, GetPrefix(field, part))
.Location(location);
} }
protected override DriverResult Editor(ContentPart part, TextField field) { protected override DriverResult Editor(ContentPart part, TextField field, dynamic shapeHelper) {
var location = field.GetLocation("Editor", "Primary", "1"); return ContentShape("Fields_Common_Text_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Fields/Common.Text.Edit", Model: field, Prefix: GetPrefix(field, part)));
return ContentFieldTemplate(field, TemplateName, GetPrefix(field, part))
.Location(location);
} }
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); updater.TryUpdateModel(field, GetPrefix(field, part), null, null);
return Editor(part, field); return Editor(part, field, shapeHelper);
} }
} }
} }

View File

@@ -1,16 +1,24 @@
<Placement> <Placement>
<!-- available display shapes --> <!-- available display shapes -->
<!-- <!--
Parts_Common_Body
Parts_Common_Body_Summary
Parts_Common_Metadata Parts_Common_Metadata
Parts_Common_Metadata_Summary Parts_Common_Metadata_Summary
Parts_Common_Metadata_SummaryAdmin Parts_Common_Metadata_SummaryAdmin
Fields_Common_Text
--> -->
<!-- edit shape just get default placement --> <!-- edit shapes getting default placements -->
<!-- edit "shape" --> <!-- edit "shape" -->
<Place Parts_Common_Body_Edit="Primary:2"/> <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 --> <!-- default positioning -->
<!-- show summary for all DisplayType by default --> <!-- show summary for all DisplayType by default -->
<Place Parts_Common_Body_Summary="Content:5"/> <Place Parts_Common_Body_Summary="Content:5"/>
<!-- with text fields a little before -->
<Place Fields_Common_Text="Content:2.5"/>
<Match DisplayType="Detail"> <Match DisplayType="Detail">
<!-- hide summary, show full content, for Detail --> <!-- hide summary, show full content, for Detail -->
<Place Parts_Common_Body_Summary="-" <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\Models\LocationSettings.cs" />
<Compile Include="ContentsLocation\Settings\LocationSettingsEditorEvents.cs" /> <Compile Include="ContentsLocation\Settings\LocationSettingsEditorEvents.cs" />
<Compile Include="ContentsLocation\ViewModels\LocationSettingsViewModel.cs" /> <Compile Include="ContentsLocation\ViewModels\LocationSettingsViewModel.cs" />
<Compile Include="Common\ViewModels\CommonMetadataViewModel.cs" />
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" /> <Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" /> <Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
<Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" /> <Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" />
@@ -148,7 +147,6 @@
<Compile Include="Common\Models\BodyPart.cs" /> <Compile Include="Common\Models\BodyPart.cs" />
<Compile Include="Common\Models\BodyPartRecord.cs" /> <Compile Include="Common\Models\BodyPartRecord.cs" />
<Compile Include="Common\Models\CommonPartRecord.cs" /> <Compile Include="Common\Models\CommonPartRecord.cs" />
<Compile Include="Common\ViewModels\BodyDisplayViewModel.cs" />
<Compile Include="Common\ViewModels\BodyEditorViewModel.cs" /> <Compile Include="Common\ViewModels\BodyEditorViewModel.cs" />
<Compile Include="Common\ViewModels\OwnerEditorViewModel.cs" /> <Compile Include="Common\ViewModels\OwnerEditorViewModel.cs" />
<Compile Include="Contents\AdminMenu.cs" /> <Compile Include="Contents\AdminMenu.cs" />
@@ -255,11 +253,8 @@
<Content Include="Common\Module.txt" /> <Content Include="Common\Module.txt" />
<Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.cshtml" /> <Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.cshtml" />
<Content Include="Common\Views\DefinitionTemplates\BodyPartSettings.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\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.cshtml" />
<Content Include="Common\Views\Parts\Common.Metadata.SummaryAdmin.cshtml" /> <Content Include="Common\Views\Parts\Common.Metadata.SummaryAdmin.cshtml" />
<Content Include="ContentsLocation\Module.txt" /> <Content Include="ContentsLocation\Module.txt" />
@@ -281,7 +276,7 @@
<Content Include="PublishLater\Content\Admin\images\scheduled.gif" /> <Content Include="PublishLater\Content\Admin\images\scheduled.gif" />
<Content Include="PublishLater\Views\Parts\PublishLater.Metadata.cshtml" /> <Content Include="PublishLater\Views\Parts\PublishLater.Metadata.cshtml" />
<Content Include="PublishLater\Views\Parts\PublishLater.Metadata.SummaryAdmin.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\Parts\Common.Container.cshtml" />
<Content Include="Common\Views\EditorTemplates\PlainTextEditor.cshtml" /> <Content Include="Common\Views\EditorTemplates\PlainTextEditor.cshtml" />
<Content Include="Contents\Module.txt" /> <Content Include="Contents\Module.txt" />
@@ -359,9 +354,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Common\Views\Parts\Common.Body.Summary.cshtml" /> <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" /> <Content Include="Dashboard\Views\Web.config" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />