Roughing out a model aspect for body text. The format property will eventually determine the chain of output filters the text passes through, and which editor template is used for the text itself.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042796
This commit is contained in:
loudej
2009-12-01 05:30:10 +00:00
parent cd39efe610
commit 15b6b7116a
15 changed files with 171 additions and 20 deletions

View File

@@ -1,18 +1,34 @@
using System;
using Orchard.Core.Common.Models;
using Orchard.Core.Common.Records;
using Orchard.Core.Common.ViewModels;
using Orchard.Data;
using Orchard.Models.Driver;
using Orchard.UI.Models;
namespace Orchard.Core.Common.Providers {
public class BodyAspectProvider : ContentProvider {
public BodyAspectProvider(IRepository<BodyRecord> bodyRepository) {
Filters.Add(new StorageFilter<BodyRecord>(bodyRepository));
OnGetEditors<BodyAspect>();
}
private const string TemplatePrefix = "Body";
private const string TemplateName = "BodyAspect";
private const string DefaultTextEditorTemplate = "TinyMceTextEditor";
private void OnGetEditors<TPart>() {
public BodyAspectProvider(IRepository<BodyRecord> bodyRepository) {
Filters.Add(new StorageFilter<BodyRecord>(bodyRepository) { AutomaticallyCreateMissingRecord = true });
OnGetDisplays<BodyAspect>((context, body) => {
var model = new BodyDisplayViewModel { BodyAspect = body };
context.Displays.Add(new ModelTemplate(model, TemplatePrefix) { TemplateName = TemplateName });
});
OnGetEditors<BodyAspect>((context, body) => {
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
context.Editors.Add(new ModelTemplate(model, TemplatePrefix) { TemplateName = TemplateName });
});
OnUpdateEditors<BodyAspect>((context, body) => {
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
context.Updater.TryUpdateModel(model, TemplatePrefix, null, null);
context.Editors.Add(new ModelTemplate(model, TemplatePrefix) { TemplateName = TemplateName });
});
}
}
}
}

View File

@@ -2,7 +2,7 @@ using Orchard.Models.Records;
namespace Orchard.Core.Common.Records {
public class BodyRecord : ContentPartRecord {
public virtual string Body { get; set; }
public virtual string Text { get; set; }
public virtual string Format { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Core.Common.Models;
namespace Orchard.Core.Common.ViewModels {
public class BodyDisplayViewModel {
public BodyAspect BodyAspect { get; set; }
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Core.Common.Models;
namespace Orchard.Core.Common.ViewModels {
public class BodyEditorViewModel {
public BodyAspect BodyAspect { get; set; }
public string Text {
get { return BodyAspect.Record.Text; }
set { BodyAspect.Record.Text = value; }
}
public string Format {
get { return BodyAspect.Record.Format; }
set { BodyAspect.Record.Format = value; }
}
public string TextEditorTemplate { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BodyDisplayViewModel>" %>
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Core.Settings.ViewModels"%>
<%@ Import Namespace="Orchard.Utility" %>
<%= Model.BodyAspect.Record.Text %>

View File

@@ -0,0 +1,7 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BodyEditorViewModel>" %>
<%@ Import Namespace="Orchard.Core.Common.ViewModels" %>
<%@ Import Namespace="Orchard.Core.Common.Models" %>
<%@ Import Namespace="Orchard.Core.Settings.ViewModels" %>
<%@ Import Namespace="Orchard.Utility" %>
<h3>Body</h3>
<ul><li><%=Html.EditorFor(m=>m.Text, Model.TextEditorTemplate) %></li></ul>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
</handlers>
</system.webServer>
</configuration>

View File

@@ -71,6 +71,8 @@
<Compile Include="Common\Records\BodyRecord.cs" />
<Compile Include="Common\Records\CommonRecord.cs" />
<Compile Include="Common\Records\RoutableRecord.cs" />
<Compile Include="Common\ViewModels\BodyDisplayViewModel.cs" />
<Compile Include="Common\ViewModels\BodyEditorViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings\AdminMenu.cs" />
<Compile Include="Settings\Controllers\AdminController.cs" />
@@ -110,9 +112,14 @@
<Content Include="Settings\Views\Web.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Common\Views\Models\DisplayTemplates\BodyAspect.ascx" />
<Content Include="Common\Views\Models\EditorTemplates\BodyAspect.ascx" />
<Content Include="Settings\Views\Admin\EditorTemplates\SettingsIndexViewModel.ascx" />
<Content Include="XmlRpc\Views\Web.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Common\Views\Web.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.