- A text content field in the common module.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-06-15 11:41:35 -07:00
parent 1403b2de67
commit 57991424e5
10 changed files with 105 additions and 10 deletions

View File

@@ -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
};
}
}
}

View 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); }
}
}
}

View File

@@ -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) {}
}
}

View File

@@ -0,0 +1,7 @@
using Orchard.Core.Common.Fields;
namespace Orchard.Core.Common.ViewModels {
public class TextContentFieldDisplayViewModel {
public TextContentField Text { get; set; }
}
}

View File

@@ -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; }
}
}
}

View File

@@ -0,0 +1,3 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TextContentFieldDisplayViewModel>" %>
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
<%=Model.Text %>

View File

@@ -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>

View File

@@ -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" />

View File

@@ -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); }
// }
//}
}

View File

@@ -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);
}