mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
- A text content field in the common module.
--HG-- branch : dev
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Fields;
|
||||
using Orchard.Core.Common.ViewModels;
|
||||
|
||||
namespace Orchard.Core.Common.Drivers {
|
||||
[UsedImplicitly]
|
||||
public class TextContentFieldDriver : ContentFieldDriver<TextContentField> {
|
||||
public IOrchardServices Services { get; set; }
|
||||
private const string TemplateName = "Fields/Common.TextContentField";
|
||||
|
||||
public TextContentFieldDriver(IOrchardServices services) {
|
||||
Services = services;
|
||||
}
|
||||
|
||||
protected override string Prefix {
|
||||
get { return "TextContentField"; }
|
||||
}
|
||||
|
||||
protected override DriverResult Display(TextContentField field, string displayType) {
|
||||
var model = new TextContentFieldDisplayViewModel { Text = field };
|
||||
|
||||
return ContentFieldTemplate(model, TemplateName, Prefix);
|
||||
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(TextContentField field) {
|
||||
var model = BuildEditorViewModel(field);
|
||||
return ContentFieldTemplate(model, TemplateName, Prefix).Location("primary", "5");
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(TextContentField field, IUpdateModel updater) {
|
||||
var model = BuildEditorViewModel(field);
|
||||
updater.TryUpdateModel(model, Prefix, null, null);
|
||||
return ContentFieldTemplate(model, TemplateName, Prefix).Location("primary", "5");
|
||||
}
|
||||
|
||||
private static TextContentFieldEditorViewModel BuildEditorViewModel(TextContentField field) {
|
||||
return new TextContentFieldEditorViewModel {
|
||||
TextContentField = field
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/Orchard.Web/Core/Common/Fields/TextContentField.cs
Normal file
10
src/Orchard.Web/Core/Common/Fields/TextContentField.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Core.Common.Fields {
|
||||
public class TextContentField : ContentField {
|
||||
public string TextField {
|
||||
get { return Getter("text"); }
|
||||
set { Setter("text", value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
|
||||
namespace Orchard.Core.Common.Handlers {
|
||||
public class TextContentFieldHandler : ContentFieldHandler {
|
||||
public TextContentFieldHandler(IEnumerable<IContentFieldDriver> contentFieldDrivers) : base(contentFieldDrivers) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using Orchard.Core.Common.Fields;
|
||||
|
||||
namespace Orchard.Core.Common.ViewModels {
|
||||
public class TextContentFieldDisplayViewModel {
|
||||
public TextContentField Text { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Core.Common.Fields;
|
||||
|
||||
namespace Orchard.Core.Common.ViewModels {
|
||||
public class TextContentFieldEditorViewModel {
|
||||
public TextContentField TextContentField { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Text {
|
||||
get { return TextContentField.TextField; }
|
||||
set { TextContentField.TextField = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TextContentFieldDisplayViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||
<%=Model.Text %>
|
||||
@@ -0,0 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TextContentFieldEditorViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||
<fieldset>
|
||||
<%: Html.LabelFor(m=>m.Text) %>
|
||||
<%: Html.EditorFor(m=>m.Text) %>
|
||||
<%: Html.ValidationMessageFor(m=>m.Text) %>
|
||||
</fieldset>
|
||||
@@ -69,8 +69,13 @@
|
||||
<Compile Include="Common\Drivers\CommonDriver.cs" />
|
||||
<Compile Include="Common\Drivers\RoutableDriver.cs" />
|
||||
<Compile Include="Common\Controllers\RoutableController.cs" />
|
||||
<Compile Include="Common\Drivers\TextContentFieldDriver.cs" />
|
||||
<Compile Include="Common\Fields\TextContentField.cs" />
|
||||
<Compile Include="Common\Handlers\RoutableAspectHandler.cs" />
|
||||
<Compile Include="Common\Handlers\TextContentFieldHandler.cs" />
|
||||
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
|
||||
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
|
||||
<Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" />
|
||||
<Compile Include="Contents\Controllers\ItemController.cs" />
|
||||
<Compile Include="Contents\Handlers\ContentsModuleHandler.cs" />
|
||||
<Compile Include="Localization\Drivers\LocalizedDriver.cs" />
|
||||
@@ -207,7 +212,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Module.txt" />
|
||||
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextContentField.ascx" />
|
||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.Container.ascx" />
|
||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.TextContentField.ascx" />
|
||||
<Content Include="Contents\Module.txt" />
|
||||
<Content Include="Contents\Views\Admin\Types.aspx" />
|
||||
<Content Include="Contents\Views\Admin\List.aspx" />
|
||||
|
||||
@@ -15,11 +15,4 @@ namespace Orchard.ContentManagement {
|
||||
public Func<string, string> Getter { get; set; }
|
||||
public Action<string, string> Setter { get; set; }
|
||||
}
|
||||
|
||||
//public class AddressField : ContentField {
|
||||
// public string Zip {
|
||||
// get {return Getter("zip");}
|
||||
// set { Setter("zip", value); }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -54,15 +54,15 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
protected virtual DriverResult Editor(TField field, IUpdateModel updater) { return null; }
|
||||
|
||||
|
||||
public ContentTemplateResult ContentPartTemplate(object model) {
|
||||
public ContentTemplateResult ContentFieldTemplate(object model) {
|
||||
return new ContentTemplateResult(model, null, Prefix).Location(Zone);
|
||||
}
|
||||
|
||||
public ContentTemplateResult ContentPartTemplate(object model, string template) {
|
||||
public ContentTemplateResult ContentFieldTemplate(object model, string template) {
|
||||
return new ContentTemplateResult(model, template, Prefix).Location(Zone);
|
||||
}
|
||||
|
||||
public ContentTemplateResult ContentPartTemplate(object model, string template, string prefix) {
|
||||
public ContentTemplateResult ContentFieldTemplate(object model, string template, string prefix) {
|
||||
return new ContentTemplateResult(model, template, prefix).Location(Zone);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user