mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
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:
@@ -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 });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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; }
|
||||
}
|
||||
}
|
@@ -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; }
|
||||
}
|
||||
}
|
@@ -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; }
|
||||
}
|
||||
}
|
@@ -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 %>
|
@@ -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>
|
34
src/Orchard.Web/Core/Common/Views/Web.config
Normal file
34
src/Orchard.Web/Core/Common/Views/Web.config
Normal 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>
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user