- Adding an item reference content field.

- Moving text content field editor from parts to fields folder.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-06-22 13:00:42 -07:00
parent 5db91c1689
commit e8c5addc2d
9 changed files with 101 additions and 1 deletions

View File

@@ -0,0 +1,46 @@
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 ItemReferenceContentFieldDriver : ContentFieldDriver<ItemReferenceContentField> {
public IOrchardServices Services { get; set; }
private const string TemplateName = "Fields/Common.ItemReferenceContentField";
public ItemReferenceContentFieldDriver(IOrchardServices services) {
Services = services;
}
protected override string Prefix {
get { return "ItemReferenceContentField"; }
}
protected override DriverResult Display(ItemReferenceContentField field, string displayType) {
var model = new ItemReferenceContentFieldDisplayViewModel {
Item = Services.ContentManager.Get(field.ContentItemReference.Id)
};
return ContentFieldTemplate(model, TemplateName, Prefix);
}
protected override DriverResult Editor(ItemReferenceContentField field) {
var model = BuildEditorViewModel(field);
return ContentFieldTemplate(model, TemplateName, Prefix).Location("primary", "6");
}
protected override DriverResult Editor(ItemReferenceContentField field, IUpdateModel updater) {
var model = BuildEditorViewModel(field);
updater.TryUpdateModel(model, Prefix, null, null);
return ContentFieldTemplate(model, TemplateName, Prefix).Location("primary", "6");
}
private ItemReferenceContentFieldEditorViewModel BuildEditorViewModel(ItemReferenceContentField field) {
return new ItemReferenceContentFieldEditorViewModel {
Item = Services.ContentManager.Get(field.ContentItemReference.Id)
};
}
}
}

View File

@@ -0,0 +1,8 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
namespace Orchard.Core.Common.Fields {
public class ItemReferenceContentField : ContentField {
public ContentItemRecord ContentItemReference { get; set; }
}
}

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 ItemReferenceContentFieldHandler : ContentFieldHandler {
public ItemReferenceContentFieldHandler(IEnumerable<IContentFieldDriver> contentFieldDrivers) : base(contentFieldDrivers) { }
}
}

View File

@@ -0,0 +1,12 @@
using Orchard.ContentManagement;
namespace Orchard.Core.Common.ViewModels {
public class ItemReferenceContentFieldDisplayViewModel {
private ContentItem _item;
public ContentItem Item {
get { return _item; }
set { _item = value; }
}
}
}

View File

@@ -0,0 +1,12 @@
using Orchard.ContentManagement;
namespace Orchard.Core.Common.ViewModels {
public class ItemReferenceContentFieldEditorViewModel {
private ContentItem _item;
public ContentItem Item {
get { return _item; }
set { _item = value; }
}
}
}

View File

@@ -0,0 +1,3 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemReferenceContentFieldDisplayViewModel>" %>
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
<%= Html.ItemDisplayLink(Model.Item) %>

View File

@@ -0,0 +1,3 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ItemReferenceContentFieldEditorViewModel>" %>
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
<%= Html.ItemEditLink(Model.Item) %>

View File

@@ -63,13 +63,18 @@
<ItemGroup>
<Compile Include="Common\Drivers\BodyDriver.cs" />
<Compile Include="Common\Drivers\CommonDriver.cs" />
<Compile Include="Common\Drivers\ItemReferenceContentFieldDriver.cs" />
<Compile Include="Common\Drivers\RoutableDriver.cs" />
<Compile Include="Common\Controllers\RoutableController.cs" />
<Compile Include="Common\Drivers\TextContentFieldDriver.cs" />
<Compile Include="Common\Fields\ItemReferenceContentField.cs" />
<Compile Include="Common\Fields\TextContentField.cs" />
<Compile Include="Common\Handlers\ItemReferenceContentFieldHandler.cs" />
<Compile Include="Common\Handlers\RoutableAspectHandler.cs" />
<Compile Include="Common\Handlers\TextContentFieldHandler.cs" />
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
<Compile Include="Common\ViewModels\ItemReferenceContentFieldDisplayModel.cs" />
<Compile Include="Common\ViewModels\ItemReferenceContentFieldEditorViewModel.cs" />
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
<Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" />
<Compile Include="Contents\Controllers\ItemController.cs" />
@@ -203,9 +208,11 @@
</ItemGroup>
<ItemGroup>
<Content Include="Common\Module.txt" />
<Content Include="Common\Views\DisplayTemplates\Fields\Common.ItemReferenceContentField.ascx" />
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextContentField.ascx" />
<Content Include="Common\Views\EditorTemplates\Fields\Common.ItemReferenceContentField.ascx" />
<Content Include="Common\Views\EditorTemplates\Parts\Common.Container.ascx" />
<Content Include="Common\Views\EditorTemplates\Parts\Common.TextContentField.ascx" />
<Content Include="Common\Views\EditorTemplates\Fields\Common.TextContentField.ascx" />
<Content Include="Contents\Module.txt" />
<Content Include="Contents\Styles\admin.css" />
<Content Include="Contents\Views\Admin\EditType.ascx" />