mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 13:33:34 +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.Models;
|
||||||
using Orchard.Core.Common.Records;
|
using Orchard.Core.Common.Records;
|
||||||
|
using Orchard.Core.Common.ViewModels;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
|
using Orchard.UI.Models;
|
||||||
|
|
||||||
namespace Orchard.Core.Common.Providers {
|
namespace Orchard.Core.Common.Providers {
|
||||||
public class BodyAspectProvider : ContentProvider {
|
public class BodyAspectProvider : ContentProvider {
|
||||||
public BodyAspectProvider(IRepository<BodyRecord> bodyRepository) {
|
private const string TemplatePrefix = "Body";
|
||||||
Filters.Add(new StorageFilter<BodyRecord>(bodyRepository));
|
private const string TemplateName = "BodyAspect";
|
||||||
OnGetEditors<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 {
|
namespace Orchard.Core.Common.Records {
|
||||||
public class BodyRecord : ContentPartRecord {
|
public class BodyRecord : ContentPartRecord {
|
||||||
public virtual string Body { get; set; }
|
public virtual string Text { get; set; }
|
||||||
public virtual string Format { 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\BodyRecord.cs" />
|
||||||
<Compile Include="Common\Records\CommonRecord.cs" />
|
<Compile Include="Common\Records\CommonRecord.cs" />
|
||||||
<Compile Include="Common\Records\RoutableRecord.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="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Settings\AdminMenu.cs" />
|
<Compile Include="Settings\AdminMenu.cs" />
|
||||||
<Compile Include="Settings\Controllers\AdminController.cs" />
|
<Compile Include="Settings\Controllers\AdminController.cs" />
|
||||||
@@ -110,9 +112,14 @@
|
|||||||
<Content Include="Settings\Views\Web.config" />
|
<Content Include="Settings\Views\Web.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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="Settings\Views\Admin\EditorTemplates\SettingsIndexViewModel.ascx" />
|
||||||
<Content Include="XmlRpc\Views\Web.config" />
|
<Content Include="XmlRpc\Views\Web.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Common\Views\Web.config" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.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.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
@@ -9,7 +9,7 @@ namespace Orchard.Blogs.Models {
|
|||||||
|
|
||||||
public Blog Blog { get; set; }
|
public Blog Blog { get; set; }
|
||||||
public string Title { get { return this.As<RoutableAspect>().Title; } }
|
public string Title { get { return this.As<RoutableAspect>().Title; } }
|
||||||
public string Body { get { return this.As<BodyAspect>().Record.Body; } }
|
public string Body { get { return this.As<BodyAspect>().Record.Text; } }
|
||||||
public string Slug { get { return this.As<RoutableAspect>().Slug; } }
|
public string Slug { get { return this.As<RoutableAspect>().Slug; } }
|
||||||
public IUser Creator { get { return this.As<CommonAspect>().OwnerField.Value; } }
|
public IUser Creator { get { return this.As<CommonAspect>().OwnerField.Value; } }
|
||||||
public DateTime? Published { get { return Record.Published; } }
|
public DateTime? Published { get { return Record.Published; } }
|
||||||
|
@@ -83,7 +83,7 @@ namespace Orchard.Sandbox.Controllers {
|
|||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost, ValidateInput(false)]
|
||||||
public ActionResult Edit(int id, FormCollection input) {
|
public ActionResult Edit(int id, FormCollection input) {
|
||||||
var settings = CurrentSite.Get<ContentPart<SandboxSettingsRecord>>();
|
var settings = CurrentSite.Get<ContentPart<SandboxSettingsRecord>>();
|
||||||
if (settings.Record.AllowAnonymousEdits == false && CurrentUser == null) {
|
if (settings.Record.AllowAnonymousEdits == false && CurrentUser == null) {
|
||||||
|
@@ -20,11 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<% Html.RenderPartial("Messages", Model.Messages); %>
|
<% Html.RenderPartial("Messages", Model.Messages); %>
|
||||||
<h3>
|
<h1><%=Html.Encode(Model.Page.Record.Name) %></h1>
|
||||||
<%=Html.Encode(Model.Page.Record.Name) %></h3>
|
|
||||||
<div>
|
|
||||||
TODO: page body
|
|
||||||
</div>
|
|
||||||
<%foreach (var display in Model.Displays) { %>
|
<%foreach (var display in Model.Displays) { %>
|
||||||
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
|
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
|
||||||
<%} %>
|
<%} %>
|
||||||
|
@@ -42,6 +42,10 @@
|
|||||||
<Reference Include="System.Data.DataSetExtensions">
|
<Reference Include="System.Data.DataSetExtensions">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\..\lib\aspnetmvc\System.Web.Mvc.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Xml.Linq">
|
<Reference Include="System.Xml.Linq">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
</Reference>
|
</Reference>
|
||||||
@@ -116,10 +120,14 @@
|
|||||||
<Content Include="Scripts\utils\form_utils.js" />
|
<Content Include="Scripts\utils\form_utils.js" />
|
||||||
<Content Include="Scripts\utils\mctabs.js" />
|
<Content Include="Scripts\utils\mctabs.js" />
|
||||||
<Content Include="Scripts\utils\validate.js" />
|
<Content Include="Scripts\utils\validate.js" />
|
||||||
|
<Content Include="Views\Models\EditorTemplates\TinyMceTextEditor.ascx" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Views\Web.config" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.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.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
@@ -0,0 +1,11 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
|
||||||
|
<%@ Import Namespace="System.Web.Mvc.Html" %>
|
||||||
|
|
||||||
|
<script src="<%=ResolveUrl("~/Packages/TinyMce/scripts/tiny_mce.js") %>" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<%=Html.TextArea("", Model, 25, 80, new {}) %>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
tinyMCE.init({ theme: "advanced", mode: "textareas", plugins: "fullscreen,autoresize", theme_advanced_toolbar_location: "top", theme_advanced_toolbar_align: "left", theme_advanced_buttons3_add: "fullscreen" });
|
||||||
|
</script>
|
||||||
|
|
34
src/Orchard.Web/Packages/TinyMce/Views/Web.config
Normal file
34
src/Orchard.Web/Packages/TinyMce/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>
|
@@ -1,17 +1,14 @@
|
|||||||
namespace Orchard.UI.Models {
|
namespace Orchard.UI.Models {
|
||||||
public class ModelTemplate {
|
public class ModelTemplate {
|
||||||
public ModelTemplate()
|
|
||||||
: this(null) {
|
|
||||||
}
|
|
||||||
public ModelTemplate(object model)
|
public ModelTemplate(object model)
|
||||||
: this(model, string.Empty) {
|
: this(model, string.Empty) {
|
||||||
|
|
||||||
}
|
}
|
||||||
public ModelTemplate(object model, string prefix) {
|
public ModelTemplate(object model, string prefix) {
|
||||||
Model = model;
|
Model = model;
|
||||||
Prefix = prefix;
|
Prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public object Model { get; set; }
|
public object Model { get; set; }
|
||||||
public string Prefix { get; set; }
|
public string Prefix { get; set; }
|
||||||
public string TemplateName { get; set; }
|
public string TemplateName { get; set; }
|
||||||
|
Reference in New Issue
Block a user