mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 13:33:34 +08:00
Updating the Orchard.Core Common module to use the new shape API
--HG-- branch : dev
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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="-"
|
||||
|
@@ -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; }
|
||||
}
|
||||
}
|
@@ -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; } }
|
||||
}
|
||||
}
|
@@ -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>
|
@@ -1 +0,0 @@
|
||||
@model Orchard.Core.Common.ViewModels.BodyDisplayViewModel
|
@@ -1,5 +0,0 @@
|
||||
@model BodyDisplayViewModel
|
||||
@using Orchard.Core.Common.ViewModels;
|
||||
<div class="manage">
|
||||
@Html.ItemEditLinkWithReturnUrl(T("Edit").ToString(), Model.BodyPart.ContentItem)
|
||||
</div>
|
@@ -1 +0,0 @@
|
||||
@model Orchard.Core.Common.ViewModels.BodyDisplayViewModel
|
@@ -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 *@
|
@@ -1 +0,0 @@
|
||||
@model Orchard.Core.Common.ViewModels.BodyDisplayViewModel
|
@@ -1,3 +0,0 @@
|
||||
@model BodyDisplayViewModel
|
||||
@using Orchard.Core.Common.ViewModels;
|
||||
<div class="managewrapper">
|
@@ -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>
|
||||
}
|
@@ -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 />
|
||||
|
Reference in New Issue
Block a user