Changing some method names, adding zone helpers for item editor template

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043117
This commit is contained in:
loudej
2009-12-03 22:35:45 +00:00
parent 9f81c16228
commit edcec5a480
46 changed files with 309 additions and 207 deletions

View File

@@ -175,7 +175,7 @@ namespace Orchard.Tests.Models {
[Test] [Test]
public void EditorsShouldBeOrderedByPositionAndDefaultPositionIsSix() { public void EditorsShouldBeOrderedByPositionAndDefaultPositionIsSix() {
var alpha = _manager.New("alpha"); var alpha = _manager.New("alpha");
var templates = _manager.GetDisplays(alpha, null, null).Displays; var templates = _manager.GetDisplayViewModel(alpha, null, null).Displays;
Assert.That(templates.Count(), Is.EqualTo(3)); Assert.That(templates.Count(), Is.EqualTo(3));
var t0 = templates.First(); var t0 = templates.First();

View File

@@ -6,7 +6,7 @@ using Orchard.Models.ViewModels;
namespace Orchard.Tests.Models.Stubs { namespace Orchard.Tests.Models.Stubs {
public class AlphaProvider : ContentProvider { public class AlphaProvider : ContentProvider {
public AlphaProvider() { public AlphaProvider() {
OnGetDisplays<Alpha>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part) { Position = "3" })); OnGetDisplayViewModel<Alpha>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part) { Position = "3" }));
} }
public override IEnumerable<ContentType> GetContentTypes() { public override IEnumerable<ContentType> GetContentTypes() {
return new[] { new ContentType { Name = "alpha" } }; return new[] { new ContentType { Name = "alpha" } };

View File

@@ -4,7 +4,7 @@ using Orchard.Models.ViewModels;
namespace Orchard.Tests.Models.Stubs { namespace Orchard.Tests.Models.Stubs {
public class FlavoredProvider : ContentProvider { public class FlavoredProvider : ContentProvider {
public FlavoredProvider() { public FlavoredProvider() {
OnGetDisplays<Flavored>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part))); OnGetDisplayViewModel<Flavored>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part)));
} }
protected override void Activating(ActivatingContentContext context) { protected override void Activating(ActivatingContentContext context) {
if (context.ContentType == "beta" || context.ContentType == "alpha") { if (context.ContentType == "beta" || context.ContentType == "alpha") {

View File

@@ -4,7 +4,7 @@ using Orchard.Models.ViewModels;
namespace Orchard.Tests.Models.Stubs { namespace Orchard.Tests.Models.Stubs {
public class StyledProvider : ContentProvider { public class StyledProvider : ContentProvider {
public StyledProvider() { public StyledProvider() {
OnGetDisplays<Styled>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part) { Position = "10" })); OnGetDisplayViewModel<Styled>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part) { Position = "10" }));
} }
protected override void Activating(ActivatingContentContext context) { protected override void Activating(ActivatingContentContext context) {

View File

@@ -14,17 +14,17 @@ namespace Orchard.Core.Common.Providers {
public BodyAspectProvider(IRepository<BodyRecord> bodyRepository) { public BodyAspectProvider(IRepository<BodyRecord> bodyRepository) {
Filters.Add(new StorageFilter<BodyRecord>(bodyRepository) { AutomaticallyCreateMissingRecord = true }); Filters.Add(new StorageFilter<BodyRecord>(bodyRepository) { AutomaticallyCreateMissingRecord = true });
OnGetDisplays<BodyAspect>((context, body) => { OnGetDisplayViewModel<BodyAspect>((context, body) => {
var model = new BodyDisplayViewModel { BodyAspect = body }; var model = new BodyDisplayViewModel { BodyAspect = body };
context.AddDisplay(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" }); context.AddDisplay(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" });
}); });
OnGetEditors<BodyAspect>((context, body) => { OnGetEditorViewModel<BodyAspect>((context, body) => {
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate }; var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" }); context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" });
}); });
OnUpdateEditors<BodyAspect>((context, body) => { OnUpdateEditorViewModel<BodyAspect>((context, body) => {
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate }; var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
context.Updater.TryUpdateModel(model, TemplatePrefix, null, null); context.Updater.TryUpdateModel(model, TemplatePrefix, null, null);
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" }); context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" });

View File

@@ -75,7 +75,7 @@ namespace Orchard.Core.Common.Providers {
} }
protected override void UpdateEditors(UpdateContentContext context) { protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context) {
var part = context.ContentItem.As<CommonAspect>(); var part = context.ContentItem.As<CommonAspect>();
if (part == null) if (part == null)
return; return;

View File

@@ -26,14 +26,14 @@ namespace Orchard.Core.Settings.Controllers {
public ActionResult Index(string tabName) { public ActionResult Index(string tabName) {
var model = new Orchard.Core.Settings.ViewModels.SettingsIndexViewModel { var model = new Orchard.Core.Settings.ViewModels.SettingsIndexViewModel {
Site = _siteService.GetSiteSettings().As<SiteSettings>() }; Site = _siteService.GetSiteSettings().As<SiteSettings>() };
model.ItemView = _modelManager.GetEditors(model.Site, tabName); model.ItemView = _modelManager.GetEditorViewModel(model.Site, tabName);
return View(model); return View(model);
} }
[AcceptVerbs(HttpVerbs.Post)] [AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(string tabName, FormCollection input) { public ActionResult Index(string tabName, FormCollection input) {
var viewModel = new SettingsIndexViewModel { Site = _siteService.GetSiteSettings().As<SiteSettings>() }; var viewModel = new SettingsIndexViewModel { Site = _siteService.GetSiteSettings().As<SiteSettings>() };
viewModel.ItemView = _modelManager.UpdateEditors(viewModel.Site.ContentItem, tabName, this); viewModel.ItemView = _modelManager.UpdateEditorViewModel(viewModel.Site.ContentItem, tabName, this);
if (!TryUpdateModel(viewModel, input.ToValueProvider())) { if (!TryUpdateModel(viewModel, input.ToValueProvider())) {
return View(viewModel); return View(viewModel);

View File

@@ -91,7 +91,7 @@ namespace Orchard.Blogs.Controllers {
return new NotFoundResult(); return new NotFoundResult();
var model = new BlogEditViewModel { Blog = blog }; var model = new BlogEditViewModel { Blog = blog };
model.ItemView = _contentManager.GetEditors(model.Blog.ContentItem, ""); model.ItemView = _contentManager.GetEditorViewModel(model.Blog.ContentItem, "");
return View(model); return View(model);
} }
@@ -104,7 +104,7 @@ namespace Orchard.Blogs.Controllers {
return new NotFoundResult(); return new NotFoundResult();
var model = new BlogEditViewModel { Blog = blog }; var model = new BlogEditViewModel { Blog = blog };
model.ItemView = _contentManager.UpdateEditors(model.Blog.ContentItem, "",this); model.ItemView = _contentManager.UpdateEditorViewModel(model.Blog.ContentItem, "",this);
IValueProvider values = input.ToValueProvider(); IValueProvider values = input.ToValueProvider();
if (!TryUpdateModel(model, values)) if (!TryUpdateModel(model, values))

View File

@@ -60,7 +60,7 @@ namespace Orchard.Blogs.Controllers {
if (post == null) if (post == null)
return new NotFoundResult(); return new NotFoundResult();
return View(new BlogPostViewModel { Blog = blog, Post = post, ItemView = _contentManager.GetDisplays(post.ContentItem, null, "detail") }); return View(new BlogPostViewModel { Blog = blog, Post = post, ItemView = _contentManager.GetDisplayViewModel(post.ContentItem, null, "detail") });
} }
public ActionResult Create(string blogSlug) { public ActionResult Create(string blogSlug) {
@@ -70,7 +70,7 @@ namespace Orchard.Blogs.Controllers {
if (blog == null) if (blog == null)
return new NotFoundResult(); return new NotFoundResult();
return View(new CreateBlogPostViewModel { Blog = blog, ItemView = _contentManager.GetEditors(_contentManager.New("blogpost"), null) }); return View(new CreateBlogPostViewModel { Blog = blog, ItemView = _contentManager.GetEditorViewModel(_contentManager.New("blogpost"), null) });
} }
[HttpPost] [HttpPost]
@@ -85,12 +85,12 @@ namespace Orchard.Blogs.Controllers {
return new NotFoundResult(); return new NotFoundResult();
if (ModelState.IsValid == false) { if (ModelState.IsValid == false) {
model.ItemView = _contentManager.UpdateEditors(_contentManager.New("blogpost"), null, this); model.ItemView = _contentManager.UpdateEditorViewModel(_contentManager.New("blogpost"), null, this);
return View(model); return View(model);
} }
BlogPost blogPost = _blogPostService.Create(model.ToCreateBlogPostParams(blog)); BlogPost blogPost = _blogPostService.Create(model.ToCreateBlogPostParams(blog));
model.ItemView = _contentManager.UpdateEditors(blogPost, null, this); model.ItemView = _contentManager.UpdateEditorViewModel(blogPost, null, this);
//TEMP: (erikpo) ensure information has committed for this record //TEMP: (erikpo) ensure information has committed for this record
var session = _sessionLocator.For(typeof(BlogPostRecord)); var session = _sessionLocator.For(typeof(BlogPostRecord));
@@ -115,7 +115,7 @@ namespace Orchard.Blogs.Controllers {
return new NotFoundResult(); return new NotFoundResult();
var model = new BlogPostEditViewModel { Blog = blog, Post = post }; var model = new BlogPostEditViewModel { Blog = blog, Post = post };
model.ItemView = _contentManager.GetEditors(model.Post.ContentItem, null); model.ItemView = _contentManager.GetEditorViewModel(model.Post.ContentItem, null);
return View(model); return View(model);
} }
@@ -136,7 +136,7 @@ namespace Orchard.Blogs.Controllers {
return new NotFoundResult(); return new NotFoundResult();
var model = new BlogPostEditViewModel { Blog = blog, Post = post }; var model = new BlogPostEditViewModel { Blog = blog, Post = post };
model.ItemView = _contentManager.UpdateEditors(model.Post.ContentItem, null, this); model.ItemView = _contentManager.UpdateEditorViewModel(model.Post.ContentItem, null, this);
IValueProvider values = input.ToValueProvider(); IValueProvider values = input.ToValueProvider();
TryUpdateModel(model, values); TryUpdateModel(model, values);

View File

@@ -16,21 +16,21 @@ namespace Orchard.Comments.Models {
Filters.Add(new ActivatingFilter<HasComments>("blogpost")); Filters.Add(new ActivatingFilter<HasComments>("blogpost"));
} }
protected override void GetDisplays(GetDisplaysContext context) { protected override void GetDisplayViewModel(GetDisplayViewModelContext context) {
if (context.ContentItem.Has<HasComments>() == false) { if (context.ContentItem.Has<HasComments>() == false) {
return; return;
} }
context.AddDisplay(new TemplateViewModel(context.ContentItem.Get<HasComments>())); context.AddDisplay(new TemplateViewModel(context.ContentItem.Get<HasComments>()));
} }
protected override void GetEditors(GetEditorsContext context) { protected override void GetEditorViewModel(GetEditorViewModelContext context) {
if (context.ContentItem.Has<HasComments>() == false) { if (context.ContentItem.Has<HasComments>() == false) {
return; return;
} }
context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasComments>())); context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasComments>()));
} }
protected override void UpdateEditors(UpdateContentContext context) { protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context) {
if (context.ContentItem.Has<HasComments>() == false) { if (context.ContentItem.Has<HasComments>() == false) {
return; return;
} }

View File

@@ -36,8 +36,8 @@ namespace Orchard.DevTools.Controllers {
.Select(x => x.GetType()) .Select(x => x.GetType())
.SelectMany(x => AllTypes(x)) .SelectMany(x => AllTypes(x))
.Distinct(); .Distinct();
model.DisplayView = _contentManager.GetDisplays(model.Item, null, null); model.DisplayView = _contentManager.GetDisplayViewModel(model.Item, null, null);
model.EditorView = _contentManager.GetEditors(model.Item, null); model.EditorView = _contentManager.GetEditorViewModel(model.Item, null);
return View(model); return View(model);
} }

View File

@@ -3,10 +3,10 @@ using Orchard.Models.ViewModels;
namespace Orchard.DevTools.Models { namespace Orchard.DevTools.Models {
public class DebugLinkProvider : ContentProvider { public class DebugLinkProvider : ContentProvider {
protected override void GetDisplays(GetDisplaysContext context) { protected override void GetDisplayViewModel(GetDisplayViewModelContext context) {
context.AddDisplay(new TemplateViewModel(new ShowDebugLink { ContentItem = context.ContentItem }) { ZoneName = "last", Position = "10" }); context.AddDisplay(new TemplateViewModel(new ShowDebugLink { ContentItem = context.ContentItem }) { ZoneName = "last", Position = "10" });
} }
protected override void GetEditors(GetEditorsContext context) { protected override void GetEditorViewModel(GetEditorViewModelContext context) {
context.AddEditor(new TemplateViewModel(new ShowDebugLink { ContentItem = context.ContentItem }) { ZoneName = "last", Position = "10" }); context.AddEditor(new TemplateViewModel(new ShowDebugLink { ContentItem = context.ContentItem }) { ZoneName = "last", Position = "10" });
} }
} }

View File

@@ -78,23 +78,6 @@
</li> </li>
<%}%> <%}%>
</ul> </ul>
<h3>
Editors</h3>
<ul>
<%foreach (var editor in Model.Editors) {%>
<li><span style="font-weight: bold">
<%=Html.Encode(editor.Prefix) %></span>
<%=Html.Encode(editor.Model.GetType().Name) %>
(<%=Html.Encode(editor.Model.GetType().Namespace) %>)
Prefix:<%=Html.Encode(editor.Prefix ?? "(null)")%>
Position:<%=Html.Encode(editor.Position??"(null)") %>
<div style="margin-left: 20px; border: solid 1px black;">
<%=Html.EditorFor(x=>editor.Model, editor.TemplateName, editor.Prefix) %>
</div>
</li>
<%
}%>
</ul>
<h3> <h3>
Displays</h3> Displays</h3>
<ul> <ul>
@@ -104,6 +87,7 @@
<%=Html.Encode(display.Model.GetType().Name)%> <%=Html.Encode(display.Model.GetType().Name)%>
(<%=Html.Encode(display.Model.GetType().Namespace)%>) (<%=Html.Encode(display.Model.GetType().Namespace)%>)
Prefix:<%=Html.Encode(display.Prefix ?? "(null)")%> Prefix:<%=Html.Encode(display.Prefix ?? "(null)")%>
Zone:<%=Html.Encode(display.ZoneName ?? "(null)")%>
Position:<%=Html.Encode(display.Position ?? "(null)")%> Position:<%=Html.Encode(display.Position ?? "(null)")%>
<div style="margin-left: 20px; border: solid 1px black;"> <div style="margin-left: 20px; border: solid 1px black;">
<%=Html.DisplayFor(x => display.Model, display.TemplateName, display.Prefix)%> <%=Html.DisplayFor(x => display.Model, display.TemplateName, display.Prefix)%>
@@ -112,6 +96,24 @@
<% <%
}%> }%>
</ul> </ul>
<h3>
Editors</h3>
<ul>
<%foreach (var editor in Model.Editors) {%>
<li><span style="font-weight: bold">
<%=Html.Encode(editor.Prefix) %></span>
<%=Html.Encode(editor.Model.GetType().Name) %>
(<%=Html.Encode(editor.Model.GetType().Namespace) %>)
Prefix:<%=Html.Encode(editor.Prefix ?? "(null)")%>
Zone:<%=Html.Encode(editor.ZoneName ?? "(null)")%>
Position:<%=Html.Encode(editor.Position??"(null)") %>
<div style="margin-left: 20px; border: solid 1px black;">
<%=Html.EditorFor(x=>editor.Model, editor.TemplateName, editor.Prefix) %>
</div>
</li>
<%
}%>
</ul>
</div> </div>
<div id="footer"> <div id="footer">
<% Html.Include("footer"); %> <% Html.Include("footer"); %>

View File

@@ -23,7 +23,7 @@ namespace Orchard.Media.Models {
settings.Record.RootMediaFolder = "~/Media"; settings.Record.RootMediaFolder = "~/Media";
} }
protected override void GetEditors(GetEditorsContext context) { protected override void GetEditorViewModel(GetEditorViewModelContext context) {
var model = context.ContentItem.As<MediaSettings>(); var model = context.ContentItem.As<MediaSettings>();
if (model == null) if (model == null)
return; return;
@@ -31,7 +31,7 @@ namespace Orchard.Media.Models {
context.AddEditor(new TemplateViewModel(model.Record, "MediaSettings")); context.AddEditor(new TemplateViewModel(model.Record, "MediaSettings"));
} }
protected override void UpdateEditors(UpdateContentContext context) { protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context) {
var model = context.ContentItem.As<MediaSettings>(); var model = context.ContentItem.As<MediaSettings>();
if (model == null) if (model == null)
return; return;

View File

@@ -29,7 +29,7 @@ namespace Orchard.Roles.Models {
}); });
} }
protected override void GetEditors(GetEditorsContext context) { protected override void GetEditorViewModel(GetEditorViewModelContext context) {
var userRoles = context.ContentItem.As<UserRoles>(); var userRoles = context.ContentItem.As<UserRoles>();
if (userRoles != null) { if (userRoles != null) {
var roles = var roles =
@@ -50,7 +50,7 @@ namespace Orchard.Roles.Models {
} }
} }
protected override void UpdateEditors(UpdateContentContext context) { protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context) {
var userRoles = context.ContentItem.As<UserRoles>(); var userRoles = context.ContentItem.As<UserRoles>();
if (userRoles != null) { if (userRoles != null) {
var viewModel = new UserRolesViewModel(); var viewModel = new UserRolesViewModel();

View File

@@ -32,7 +32,7 @@ namespace Orchard.Sandbox.Controllers {
Pages = _contentManager.Query<SandboxPage, SandboxPageRecord>() Pages = _contentManager.Query<SandboxPage, SandboxPageRecord>()
.OrderBy(x => x.Name) .OrderBy(x => x.Name)
.List() .List()
.Select(x => _contentManager.GetDisplays(x, null, "SummaryList")) .Select(x => _contentManager.GetDisplayViewModel(x, null, "SummaryList"))
}; };
return View(model); return View(model);
} }
@@ -40,7 +40,7 @@ namespace Orchard.Sandbox.Controllers {
public ActionResult Show(int id) { public ActionResult Show(int id) {
var page = _contentManager.Get<SandboxPage>(id); var page = _contentManager.Get<SandboxPage>(id);
var model = new PageShowViewModel { var model = new PageShowViewModel {
Page = _contentManager.GetDisplays(page, null, "Detail") Page = _contentManager.GetDisplayViewModel(page, null, "Detail")
}; };
return View(model); return View(model);
} }
@@ -80,7 +80,7 @@ namespace Orchard.Sandbox.Controllers {
var page = _contentManager.Get<SandboxPage>(id); var page = _contentManager.Get<SandboxPage>(id);
var model = new PageEditViewModel { var model = new PageEditViewModel {
Page = _contentManager.GetEditors(page, null) Page = _contentManager.GetEditorViewModel(page, null)
}; };
return View(model); return View(model);
} }
@@ -95,7 +95,7 @@ namespace Orchard.Sandbox.Controllers {
var page = _contentManager.Get<SandboxPage>(id); var page = _contentManager.Get<SandboxPage>(id);
var model = new PageEditViewModel { var model = new PageEditViewModel {
Page = _contentManager.UpdateEditors(page, null, this) Page = _contentManager.UpdateEditorViewModel(page, null, this)
}; };
if (!ModelState.IsValid) if (!ModelState.IsValid)
return View(model); return View(model);

View File

@@ -4,6 +4,7 @@ using Orchard.Core.Common.Models;
using Orchard.Data; using Orchard.Data;
using Orchard.Models; using Orchard.Models;
using Orchard.Models.Driver; using Orchard.Models.Driver;
using Orchard.Models.ViewModels;
namespace Orchard.Sandbox.Models { namespace Orchard.Sandbox.Models {
public class SandboxContentProvider : ContentProvider { public class SandboxContentProvider : ContentProvider {
@@ -44,6 +45,8 @@ namespace Orchard.Sandbox.Models {
}); });
}); });
OnGetDisplayViewModel<SandboxPage>((context, page) =>
context.AddDisplay(new TemplateViewModel(page) { TemplateName = "ContentItemTitle", ZoneName = "title" }));

View File

@@ -75,6 +75,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Package.txt" /> <Content Include="Package.txt" />
<Content Include="Views\Models\DisplayTemplates\ContentItemTitle.ascx" />
<Content Include="Views\Models\DisplayTemplates\SandboxPageSummary.ascx" /> <Content Include="Views\Models\DisplayTemplates\SandboxPageSummary.ascx" />
<Content Include="Views\Models\DisplayTemplates\SandboxPage.ascx" /> <Content Include="Views\Models\DisplayTemplates\SandboxPage.ascx" />
<Content Include="Views\Models\EditorTemplates\SandboxPage.ascx" /> <Content Include="Views\Models\EditorTemplates\SandboxPage.ascx" />

View File

@@ -0,0 +1,6 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IContent>" %>
<%@ Import Namespace="Orchard.Mvc.Html" %>
<%@ Import Namespace="Orchard.Sandbox.Models" %>
<%@ Import Namespace="Orchard.Models.ViewModels" %>
<%@ Import Namespace="Orchard.Models" %>
<h1><%=Html.ItemDisplayLink(Model) %></h1>

View File

@@ -2,21 +2,23 @@
<%@ Import Namespace="Orchard.Mvc.Html" %> <%@ Import Namespace="Orchard.Mvc.Html" %>
<%@ Import Namespace="Orchard.Sandbox.Models" %> <%@ Import Namespace="Orchard.Sandbox.Models" %>
<%@ Import Namespace="Orchard.Models.ViewModels" %> <%@ Import Namespace="Orchard.Models.ViewModels" %>
<%@ Import Namespace="Orchard.Models" %>
<%=Html.DisplayZone("before")%>
<div class="item"> <div class="item">
<%=Html.DisplayZone("first")%> <%=Html.DisplayZone("first")%>
<h1> <div class="title">
<%=Html.Encode(Model.Item.Record.Name) %></h1> <%=Html.DisplayZone("title")%>
</div>
<%=Html.DisplayZone("metatop")%> <%=Html.DisplayZone("metatop")%>
<div class="body">
<%=Html.DisplayZone("body")%></div>
<%=Html.DisplayZone("metabottom")%>
<div class="actions"> <div class="actions">
<%=Html.ItemEditLink("Edit this page", Model.Item) %>, <%=Html.ItemEditLink("Edit this page", Model.Item) %>
<%=Html.ActionLink("Return to list", "index") %> <%=Html.ActionLink("Return to list", "index") %>
<%=Html.DisplayZone("actions") %></div> <%=Html.DisplayZone("actions") %>
<%=Html.DisplayZonesExcept("last","after") %> </div>
<div class="body">
<%=Html.DisplayZone("body")%>
</div>
<%=Html.DisplayZone("metabottom")%>
<div class="footer">
<%=Html.DisplayZonesExcept("last") %>
<%=Html.DisplayZone("last")%> <%=Html.DisplayZone("last")%>
</div> </div>
<%=Html.DisplayZone("after")%> </div>

View File

@@ -2,9 +2,9 @@
<%@ Import Namespace="Orchard.Mvc.Html"%> <%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Sandbox.Models" %> <%@ Import Namespace="Orchard.Sandbox.Models" %>
<%@ Import Namespace="Orchard.Models.ViewModels" %> <%@ Import Namespace="Orchard.Models.ViewModels" %>
<%@ Import Namespace="Orchard.Models" %>
<h2><%=Html.ItemDisplayLink(Model.Item) %></h2> <div class="item">
<%--<%foreach (var display in Model.Displays) { %> <%=Html.DisplayZone("title") %>
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix??"") %> <%=Html.DisplayZone("metatop")%>
<%} %> <%=Html.DisplayZone("body") %>
--%> </div>

View File

@@ -1,14 +1,10 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorViewModel<SandboxPage>>" %> <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorViewModel<SandboxPage>>" %>
<%@ Import Namespace="Orchard.Mvc.Html" %>
<%@ Import Namespace="Orchard.Sandbox.Models" %> <%@ Import Namespace="Orchard.Sandbox.Models" %>
<%@ Import Namespace="Orchard.Models.ViewModels" %> <%@ Import Namespace="Orchard.Models.ViewModels" %>
<%@ Import Namespace="Orchard.Models" %>
<li> <li>
<%=Html.LabelFor(m => m.Item.Record.Name)%> <%=Html.LabelFor(m => m.Item.Record.Name)%>
<%=Html.EditorFor(m => m.Item.Record.Name)%> <%=Html.EditorFor(m => m.Item.Record.Name)%>
</li> </li>
<%=Html.EditorZonesAny()%>
<%foreach (var e in Model.Editors) { %>
<%=Html.EditorFor(m=>e.Model, e.TemplateName, e.Prefix??"") %>
<%} %>

View File

@@ -20,7 +20,6 @@
</div> </div>
<div id="main"> <div id="main">
<% Html.RenderPartial("Messages", Model.Messages); %> <% Html.RenderPartial("Messages", Model.Messages); %>
<%= Html.DisplayForItem(m => m.Page) %> <%= Html.DisplayForItem(m => m.Page) %>
</div> </div>
<div id="footer"> <div id="footer">

View File

@@ -17,11 +17,14 @@ namespace Orchard.Tags.Controllers {
public class HomeController : Controller { public class HomeController : Controller {
private readonly ITagService _tagService; private readonly ITagService _tagService;
private readonly IAuthorizer _authorizer; private readonly IAuthorizer _authorizer;
private readonly IContentManager _contentManager;
private readonly INotifier _notifier; private readonly INotifier _notifier;
public HomeController(ITagService tagService, INotifier notifier, IAuthorizer authorizer) { public HomeController(ITagService tagService, INotifier notifier, IAuthorizer authorizer,
IContentManager contentManager) {
_tagService = tagService; _tagService = tagService;
_authorizer = authorizer; _authorizer = authorizer;
_contentManager = contentManager;
_notifier = notifier; _notifier = notifier;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
@@ -110,7 +113,7 @@ namespace Orchard.Tags.Controllers {
IEnumerable<IContent> contents = _tagService.GetTaggedContentItems(tag.Id).ToList(); IEnumerable<IContent> contents = _tagService.GetTaggedContentItems(tag.Id).ToList();
var viewModel = new TagsSearchViewModel { var viewModel = new TagsSearchViewModel {
TagName = tag.TagName, TagName = tag.TagName,
Contents = contents, Contents = contents.Select(x=>_contentManager.GetDisplayViewModel(x, null, "SummaryTag")),
}; };
return View(viewModel); return View(viewModel);

View File

@@ -30,20 +30,20 @@ namespace Orchard.Tags.Models {
Filters.Add(new ActivatingFilter<HasTags>("sandboxpage")); Filters.Add(new ActivatingFilter<HasTags>("sandboxpage"));
Filters.Add(new ActivatingFilter<HasTags>("blogpost")); Filters.Add(new ActivatingFilter<HasTags>("blogpost"));
OnGetDisplays<HasTags>((context, hasTags) => { OnGetDisplayViewModel<HasTags>((context, hasTags) => {
context.AddDisplay(new TemplateViewModel(hasTags) { ZoneName="metatop", Position = "2", TemplateName = "HasTagsList" }); context.AddDisplay(new TemplateViewModel(hasTags) { ZoneName="metatop", Position = "2", TemplateName = "HasTagsList" });
context.AddDisplay(new TemplateViewModel(hasTags) { ZoneName = "metabottom", Position = "5" }); context.AddDisplay(new TemplateViewModel(hasTags) { ZoneName = "metabottom", Position = "5" });
}); });
} }
protected override void GetEditors(GetEditorsContext context) { protected override void GetEditorViewModel(GetEditorViewModelContext context) {
if (context.ContentItem.Has<HasTags>() == false) { if (context.ContentItem.Has<HasTags>() == false) {
return; return;
} }
context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasTags>())); context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasTags>()));
} }
protected override void UpdateEditors(UpdateContentContext context) { protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context) {
if (context.ContentItem.Has<HasTags>() == false) { if (context.ContentItem.Has<HasTags>() == false) {
return; return;
} }

View File

@@ -1,10 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.Models; using Orchard.Models;
using Orchard.Models.ViewModels;
using Orchard.Mvc.ViewModels; using Orchard.Mvc.ViewModels;
namespace Orchard.Tags.ViewModels { namespace Orchard.Tags.ViewModels {
public class TagsSearchViewModel : BaseViewModel { public class TagsSearchViewModel : BaseViewModel {
public string TagName { get; set; } public string TagName { get; set; }
public IEnumerable<IContent> Contents { get; set; } public IEnumerable<ItemDisplayViewModel<IContent>> Contents { get; set; }
} }
} }

View File

@@ -6,6 +6,6 @@
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h2>List of contents tagged with <%= Model.TagName %></h2><% <h2>List of contents tagged with <%= Model.TagName %></h2><%
foreach (var contentItem in Model.Contents) { %> foreach (var contentItem in Model.Contents) { %>
<%=Html.ItemDisplayLink(contentItem)%><% <%=Html.DisplayForItem(x=>contentItem)%><%
} %> } %>
</asp:Content> </asp:Content>

View File

@@ -2,7 +2,7 @@
<%@ Import Namespace="Orchard.Mvc.Html"%> <%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Tags.Models"%> <%@ Import Namespace="Orchard.Tags.Models"%>
<h3>Tags</h3> <h3>Tags</h3>
<div class="yui-g"> <% Html.BeginForm("Update", "Home", new { area = "Orchard.Tags" }); %><%= Html.ValidationSummary() %> <div class="yui-g">
<h2 class="separator">Edit Tags</h2> <h2 class="separator">Edit Tags</h2>
<% <%
string tags = ""; string tags = "";

View File

@@ -49,7 +49,7 @@ namespace Orchard.Users.Controllers {
public ActionResult Create() { public ActionResult Create() {
var user = _contentManager.New("user"); var user = _contentManager.New("user");
var model = new UserCreateViewModel { var model = new UserCreateViewModel {
ItemView = _contentManager.GetEditors(user, null) ItemView = _contentManager.GetEditorViewModel(user, null)
}; };
return View(model); return View(model);
} }
@@ -61,7 +61,7 @@ namespace Orchard.Users.Controllers {
ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").ToString()); ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").ToString());
} }
if (ModelState.IsValid == false) { if (ModelState.IsValid == false) {
model.ItemView = _contentManager.UpdateEditors(_contentManager.New("user"), null, this); model.ItemView = _contentManager.UpdateEditorViewModel(_contentManager.New("user"), null, this);
return View(model); return View(model);
} }
var user = _membershipService.CreateUser(new CreateUserParams( var user = _membershipService.CreateUser(new CreateUserParams(
@@ -69,7 +69,7 @@ namespace Orchard.Users.Controllers {
model.Password, model.Password,
model.Email, model.Email,
null, null, true)); null, null, true));
model.ItemView = _contentManager.UpdateEditors(user, null, this); model.ItemView = _contentManager.UpdateEditorViewModel(user, null, this);
if (ModelState.IsValid == false) { if (ModelState.IsValid == false) {
//TODO: rollback transaction //TODO: rollback transaction
return View(model); return View(model);
@@ -80,14 +80,14 @@ namespace Orchard.Users.Controllers {
public ActionResult Edit(int id) { public ActionResult Edit(int id) {
var model = new UserEditViewModel { User = _contentManager.Get<User>(id) }; var model = new UserEditViewModel { User = _contentManager.Get<User>(id) };
model.ItemView = _contentManager.GetEditors(model.User.ContentItem, null); model.ItemView = _contentManager.GetEditorViewModel(model.User.ContentItem, null);
return View(model); return View(model);
} }
[HttpPost] [HttpPost]
public ActionResult Edit(int id, FormCollection input) { public ActionResult Edit(int id, FormCollection input) {
var model = new UserEditViewModel { User = _contentManager.Get<User>(id) }; var model = new UserEditViewModel { User = _contentManager.Get<User>(id) };
model.ItemView = _contentManager.UpdateEditors(model.User.ContentItem, null, this); model.ItemView = _contentManager.UpdateEditorViewModel(model.User.ContentItem, null, this);
if (!TryUpdateModel(model, input.ToValueProvider())) { if (!TryUpdateModel(model, input.ToValueProvider())) {
return View(model); return View(model);

View File

@@ -136,34 +136,34 @@ namespace Orchard.Models {
return context.Metadata; return context.Metadata;
} }
public ItemDisplayViewModel<TContentPart> GetDisplays<TContentPart>(TContentPart content, string groupName, string displayType) where TContentPart : IContent { public ItemDisplayViewModel<TContentPart> GetDisplayViewModel<TContentPart>(TContentPart content, string groupName, string displayType) where TContentPart : IContent {
var itemView = new ItemDisplayViewModel<TContentPart> {Item = content, Displays = Enumerable.Empty<TemplateViewModel>()}; var itemView = new ItemDisplayViewModel<TContentPart> {Item = content, Displays = Enumerable.Empty<TemplateViewModel>()};
var context = new GetDisplaysContext(itemView, groupName, displayType); var context = new GetDisplayViewModelContext(itemView, groupName, displayType);
foreach (var driver in Drivers) { foreach (var driver in Drivers) {
driver.GetDisplays(context); driver.GetDisplayViewModel(context);
} }
context.ItemView.Displays = OrderTemplates(context.ItemView.Displays); context.ViewModel.Displays = OrderTemplates(context.ViewModel.Displays);
return itemView; return itemView;
} }
public ItemEditorViewModel<TContentPart> GetEditors<TContentPart>(TContentPart content, string groupName) where TContentPart : IContent { public ItemEditorViewModel<TContentPart> GetEditorViewModel<TContentPart>(TContentPart content, string groupName) where TContentPart : IContent {
var itemView = new ItemEditorViewModel<TContentPart> { Item = content, Editors = Enumerable.Empty<TemplateViewModel>() }; var itemView = new ItemEditorViewModel<TContentPart> { Item = content, Editors = Enumerable.Empty<TemplateViewModel>() };
var context = new GetEditorsContext(itemView, groupName); var context = new GetEditorViewModelContext(itemView, groupName);
foreach (var driver in Drivers) { foreach (var driver in Drivers) {
driver.GetEditors(context); driver.GetEditorViewModel(context);
} }
context.ItemView.Editors = OrderTemplates(context.ItemView.Editors); context.ViewModel.Editors = OrderTemplates(context.ViewModel.Editors);
return itemView; return itemView;
} }
public ItemEditorViewModel<TContentPart> UpdateEditors<TContentPart>(TContentPart content, string groupName, IUpdateModel updater) where TContentPart : IContent { public ItemEditorViewModel<TContentPart> UpdateEditorViewModel<TContentPart>(TContentPart content, string groupName, IUpdateModel updater) where TContentPart : IContent {
var itemView = new ItemEditorViewModel<TContentPart> { Item = content, Editors = Enumerable.Empty<TemplateViewModel>() }; var itemView = new ItemEditorViewModel<TContentPart> { Item = content, Editors = Enumerable.Empty<TemplateViewModel>() };
var context = new UpdateContentContext(itemView, groupName, updater); var context = new UpdateEditorViewModelContext(itemView, groupName, updater);
foreach (var driver in Drivers) { foreach (var driver in Drivers) {
driver.UpdateEditors(context); driver.UpdateEditorViewModel(context);
} }
context.ItemView.Editors = OrderTemplates(context.ItemView.Editors); context.ViewModel.Editors = OrderTemplates(context.ViewModel.Editors);
return itemView; return itemView;
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Web.Mvc;
using Orchard.Models.ViewModels; using Orchard.Models.ViewModels;
namespace Orchard.Models.Driver { namespace Orchard.Models.Driver {
@@ -7,7 +8,7 @@ namespace Orchard.Models.Driver {
private readonly string _templateName; private readonly string _templateName;
private readonly string _prefix; private readonly string _prefix;
private readonly string[] _displayTypes; private readonly string[] _displayTypes;
private Action<UpdateContentContext, ItemEditorViewModel<TContent>> _updater; private Action<UpdateEditorViewModelContext, ItemEditorViewModel<TContent>> _updater;
public ContentItemTemplates(string templateName, params string[] displayTypes) { public ContentItemTemplates(string templateName, params string[] displayTypes) {
_templateName = templateName; _templateName = templateName;
@@ -15,31 +16,47 @@ namespace Orchard.Models.Driver {
_updater = (context, viewModel) => context.Updater.TryUpdateModel(viewModel, "", null, null); _updater = (context, viewModel) => context.Updater.TryUpdateModel(viewModel, "", null, null);
} }
protected override void GetDisplays(GetDisplaysContext context, TContent instance) { protected override void GetDisplayViewModel(GetDisplayViewModelContext context, TContent instance) {
var longestMatch = LongestMatch(context.DisplayType); var longestMatch = LongestMatch(context.DisplayType);
context.ItemView.TemplateName = _templateName + longestMatch; context.ViewModel.TemplateName = _templateName + longestMatch;
context.ItemView.Prefix = _prefix; context.ViewModel.Prefix = _prefix;
if (context.ViewModel.GetType() != typeof(ItemDisplayViewModel<TContent>)) {
context.ViewModel.Adaptor = (html, viewModel) => {
return new HtmlHelper<ItemDisplayViewModel<TContent>>(
html.ViewContext,
new ViewDataContainer { ViewData = new ViewDataDictionary(new ItemDisplayViewModel<TContent>(viewModel)) },
html.RouteCollection);
};
}
}
class ViewDataContainer : IViewDataContainer {
public ViewDataDictionary ViewData { get; set; }
} }
private string LongestMatch(string displayType) { private string LongestMatch(string displayType) {
if (string.IsNullOrEmpty(displayType))
return displayType;
return _displayTypes.Aggregate("", (best, x) => { return _displayTypes.Aggregate("", (best, x) => {
if (displayType.StartsWith(x) && x.Length > best.Length) return x; if (displayType.StartsWith(x) && x.Length > best.Length) return x;
return best; return best;
}); });
} }
protected override void GetEditors(GetEditorsContext context, TContent instance) { protected override void GetEditorViewModel(GetEditorViewModelContext context, TContent instance) {
context.ItemView.TemplateName = _templateName; context.ViewModel.TemplateName = _templateName;
context.ItemView.Prefix = _prefix; context.ViewModel.Prefix = _prefix;
} }
protected override void UpdateEditors(UpdateContentContext context, TContent instance) { protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context, TContent instance) {
_updater(context, (ItemEditorViewModel<TContent>)context.ItemView); _updater(context, (ItemEditorViewModel<TContent>)context.ViewModel);
context.ItemView.TemplateName = _templateName; context.ViewModel.TemplateName = _templateName;
context.ItemView.Prefix = _prefix; context.ViewModel.Prefix = _prefix;
} }
public void Updater(Action<UpdateContentContext, ItemEditorViewModel<TContent>> updater) { public void Updater(Action<UpdateEditorViewModelContext, ItemEditorViewModel<TContent>> updater) {
_updater = updater; _updater = updater;
} }
} }

View File

@@ -36,16 +36,16 @@ namespace Orchard.Models.Driver {
protected void OnGetItemMetadata<TPart>(Action<GetItemMetadataContext, TPart> handler) where TPart : class, IContent { protected void OnGetItemMetadata<TPart>(Action<GetItemMetadataContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineTemplateFilter<TPart> { OnGetItemMetadata = handler }); Filters.Add(new InlineTemplateFilter<TPart> { OnGetItemMetadata = handler });
} }
protected void OnGetDisplays<TPart>(Action<GetDisplaysContext, TPart> handler) where TPart : class, IContent { protected void OnGetDisplayViewModel<TPart>(Action<GetDisplayViewModelContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineTemplateFilter<TPart> { OnGetDisplays = handler }); Filters.Add(new InlineTemplateFilter<TPart> { OnGetDisplayViewModel = handler });
} }
protected void OnGetEditors<TPart>(Action<GetEditorsContext, TPart> handler) where TPart : class, IContent { protected void OnGetEditorViewModel<TPart>(Action<GetEditorViewModelContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineTemplateFilter<TPart> { OnGetEditors = handler }); Filters.Add(new InlineTemplateFilter<TPart> { OnGetEditorViewModel = handler });
} }
protected void OnUpdateEditors<TPart>(Action<UpdateContentContext, TPart> handler) where TPart : class, IContent { protected void OnUpdateEditorViewModel<TPart>(Action<UpdateEditorViewModelContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineTemplateFilter<TPart> { OnUpdateEditors = handler }); Filters.Add(new InlineTemplateFilter<TPart> { OnUpdateEditorViewModel = handler });
} }
class InlineStorageFilter<TPart> : StorageFilterBase<TPart> where TPart : class, IContent { class InlineStorageFilter<TPart> : StorageFilterBase<TPart> where TPart : class, IContent {
@@ -73,20 +73,20 @@ namespace Orchard.Models.Driver {
class InlineTemplateFilter<TPart> : TemplateFilterBase<TPart> where TPart : class, IContent { class InlineTemplateFilter<TPart> : TemplateFilterBase<TPart> where TPart : class, IContent {
public Action<GetItemMetadataContext, TPart> OnGetItemMetadata { get; set; } public Action<GetItemMetadataContext, TPart> OnGetItemMetadata { get; set; }
public Action<GetDisplaysContext, TPart> OnGetDisplays { get; set; } public Action<GetDisplayViewModelContext, TPart> OnGetDisplayViewModel { get; set; }
public Action<GetEditorsContext, TPart> OnGetEditors { get; set; } public Action<GetEditorViewModelContext, TPart> OnGetEditorViewModel { get; set; }
public Action<UpdateContentContext, TPart> OnUpdateEditors { get; set; } public Action<UpdateEditorViewModelContext, TPart> OnUpdateEditorViewModel { get; set; }
protected override void GetItemMetadata(GetItemMetadataContext context, TPart instance) { protected override void GetItemMetadata(GetItemMetadataContext context, TPart instance) {
if (OnGetItemMetadata != null) OnGetItemMetadata(context, instance); if (OnGetItemMetadata != null) OnGetItemMetadata(context, instance);
} }
protected override void GetDisplays(GetDisplaysContext context, TPart instance) { protected override void GetDisplayViewModel(GetDisplayViewModelContext context, TPart instance) {
if (OnGetDisplays != null) OnGetDisplays(context, instance); if (OnGetDisplayViewModel != null) OnGetDisplayViewModel(context, instance);
} }
protected override void GetEditors(GetEditorsContext context, TPart instance) { protected override void GetEditorViewModel(GetEditorViewModelContext context, TPart instance) {
if (OnGetEditors != null) OnGetEditors(context, instance); if (OnGetEditorViewModel != null) OnGetEditorViewModel(context, instance);
} }
protected override void UpdateEditors(UpdateContentContext context, TPart instance) { protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context, TPart instance) {
if (OnUpdateEditors != null) OnUpdateEditors(context, instance); if (OnUpdateEditorViewModel != null) OnUpdateEditorViewModel(context, instance);
} }
} }
@@ -136,20 +136,20 @@ namespace Orchard.Models.Driver {
filter.GetItemMetadata(context); filter.GetItemMetadata(context);
GetItemMetadata(context); GetItemMetadata(context);
} }
void IContentProvider.GetDisplays(GetDisplaysContext context) { void IContentProvider.GetDisplayViewModel(GetDisplayViewModelContext context) {
foreach (var filter in Filters.OfType<IContentTemplateFilter>()) foreach (var filter in Filters.OfType<IContentTemplateFilter>())
filter.GetDisplays(context); filter.GetDisplayViewModel(context);
GetDisplays(context); GetDisplayViewModel(context);
} }
void IContentProvider.GetEditors(GetEditorsContext context) { void IContentProvider.GetEditorViewModel(GetEditorViewModelContext context) {
foreach (var filter in Filters.OfType<IContentTemplateFilter>()) foreach (var filter in Filters.OfType<IContentTemplateFilter>())
filter.GetEditors(context); filter.GetEditorViewModel(context);
GetEditors(context); GetEditorViewModel(context);
} }
void IContentProvider.UpdateEditors(UpdateContentContext context) { void IContentProvider.UpdateEditorViewModel(UpdateEditorViewModelContext context) {
foreach (var filter in Filters.OfType<IContentTemplateFilter>()) foreach (var filter in Filters.OfType<IContentTemplateFilter>())
filter.UpdateEditors(context); filter.UpdateEditorViewModel(context);
UpdateEditors(context); UpdateEditorViewModel(context);
} }
protected virtual void Activating(ActivatingContentContext context) { } protected virtual void Activating(ActivatingContentContext context) { }
@@ -162,8 +162,8 @@ namespace Orchard.Models.Driver {
protected virtual void Created(CreateContentContext context) { } protected virtual void Created(CreateContentContext context) { }
protected virtual void GetItemMetadata(GetItemMetadataContext context) { } protected virtual void GetItemMetadata(GetItemMetadataContext context) { }
protected virtual void GetDisplays(GetDisplaysContext context) { } protected virtual void GetDisplayViewModel(GetDisplayViewModelContext context) { }
protected virtual void GetEditors(GetEditorsContext context) { } protected virtual void GetEditorViewModel(GetEditorViewModelContext context) { }
protected virtual void UpdateEditors(UpdateContentContext context) {} protected virtual void UpdateEditorViewModel(UpdateEditorViewModelContext context) {}
} }
} }

View File

@@ -4,22 +4,22 @@ using System.Linq;
using Orchard.Models.ViewModels; using Orchard.Models.ViewModels;
namespace Orchard.Models.Driver { namespace Orchard.Models.Driver {
public class GetDisplaysContext { public class GetDisplayViewModelContext {
public GetDisplaysContext(ItemDisplayViewModel itemView, string groupName, string displayType) { public GetDisplayViewModelContext(ItemDisplayViewModel viewModel, string groupName, string displayType) {
ContentItem = itemView.Item; ContentItem = viewModel.Item;
GroupName = groupName; GroupName = groupName;
DisplayType = displayType; DisplayType = displayType;
ItemView = itemView; ViewModel = viewModel;
} }
public ContentItem ContentItem { get; set; } public ContentItem ContentItem { get; set; }
public string GroupName { get; set; } public string GroupName { get; set; }
public string DisplayType { get; set; } public string DisplayType { get; set; }
public ItemDisplayViewModel ItemView { get; set; } public ItemDisplayViewModel ViewModel { get; set; }
public void AddDisplay(TemplateViewModel display) { public void AddDisplay(TemplateViewModel display) {
ItemView.Displays = ItemView.Displays.Concat(new[] { display }); ViewModel.Displays = ViewModel.Displays.Concat(new[] { display });
} }
} }
} }

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Models.ViewModels;
namespace Orchard.Models.Driver {
public class GetEditorViewModelContext {
public GetEditorViewModelContext(ItemEditorViewModel viewModel, string groupName) {
ContentItem = viewModel.Item;
GroupName = groupName;
ViewModel = viewModel;
}
public ContentItem ContentItem { get; set; }
public string GroupName { get; set; }
public ItemEditorViewModel ViewModel { get; set; }
public void AddEditor(TemplateViewModel editor) {
ViewModel.Editors = ViewModel.Editors.Concat(new[] { editor });
}
}
}

View File

@@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Models.ViewModels;
namespace Orchard.Models.Driver {
public class GetEditorsContext {
public GetEditorsContext(ItemEditorViewModel itemView, string groupName) {
ContentItem = itemView.Item;
GroupName = groupName;
ItemView = itemView;
}
public ContentItem ContentItem { get; set; }
public string GroupName { get; set; }
public ItemEditorViewModel ItemView { get; set; }
public void AddEditor(TemplateViewModel editor) {
ItemView.Editors = ItemView.Editors.Concat(new[] { editor });
}
}
}

View File

@@ -12,8 +12,8 @@ namespace Orchard.Models.Driver {
void Loaded(LoadContentContext context); void Loaded(LoadContentContext context);
void GetItemMetadata(GetItemMetadataContext context); void GetItemMetadata(GetItemMetadataContext context);
void GetDisplays(GetDisplaysContext context); void GetDisplayViewModel(GetDisplayViewModelContext context);
void GetEditors(GetEditorsContext context); void GetEditorViewModel(GetEditorViewModelContext context);
void UpdateEditors(UpdateContentContext context); void UpdateEditorViewModel(UpdateEditorViewModelContext context);
} }
} }

View File

@@ -6,8 +6,8 @@ using System.Text;
namespace Orchard.Models.Driver { namespace Orchard.Models.Driver {
interface IContentTemplateFilter : IContentFilter { interface IContentTemplateFilter : IContentFilter {
void GetItemMetadata(GetItemMetadataContext context); void GetItemMetadata(GetItemMetadataContext context);
void GetDisplays(GetDisplaysContext context); void GetDisplayViewModel(GetDisplayViewModelContext context);
void GetEditors(GetEditorsContext context); void GetEditorViewModel(GetEditorViewModelContext context);
void UpdateEditors(UpdateContentContext context); void UpdateEditorViewModel(UpdateEditorViewModelContext context);
} }
} }

View File

@@ -7,28 +7,28 @@ namespace Orchard.Models.Driver {
public abstract class TemplateFilterBase<TPart> : IContentTemplateFilter where TPart : class, IContent { public abstract class TemplateFilterBase<TPart> : IContentTemplateFilter where TPart : class, IContent {
protected virtual void GetItemMetadata(GetItemMetadataContext context, TPart instance) { } protected virtual void GetItemMetadata(GetItemMetadataContext context, TPart instance) { }
protected virtual void GetDisplays(GetDisplaysContext context, TPart instance) { } protected virtual void GetDisplayViewModel(GetDisplayViewModelContext context, TPart instance) { }
protected virtual void GetEditors(GetEditorsContext context, TPart instance) { } protected virtual void GetEditorViewModel(GetEditorViewModelContext context, TPart instance) { }
protected virtual void UpdateEditors(UpdateContentContext context, TPart instance) { } protected virtual void UpdateEditorViewModel(UpdateEditorViewModelContext context, TPart instance) { }
void IContentTemplateFilter.GetItemMetadata(GetItemMetadataContext context) { void IContentTemplateFilter.GetItemMetadata(GetItemMetadataContext context) {
if (context.ContentItem.Is<TPart>()) if (context.ContentItem.Is<TPart>())
GetItemMetadata(context, context.ContentItem.As<TPart>()); GetItemMetadata(context, context.ContentItem.As<TPart>());
} }
void IContentTemplateFilter.GetDisplays(GetDisplaysContext context) { void IContentTemplateFilter.GetDisplayViewModel(GetDisplayViewModelContext context) {
if (context.ContentItem.Is<TPart>()) if (context.ContentItem.Is<TPart>())
GetDisplays(context, context.ContentItem.As<TPart>()); GetDisplayViewModel(context, context.ContentItem.As<TPart>());
} }
void IContentTemplateFilter.GetEditors(GetEditorsContext context) { void IContentTemplateFilter.GetEditorViewModel(GetEditorViewModelContext context) {
if (context.ContentItem.Is<TPart>()) if (context.ContentItem.Is<TPart>())
GetEditors(context, context.ContentItem.As<TPart>()); GetEditorViewModel(context, context.ContentItem.As<TPart>());
} }
void IContentTemplateFilter.UpdateEditors(UpdateContentContext context) { void IContentTemplateFilter.UpdateEditorViewModel(UpdateEditorViewModelContext context) {
if (context.ContentItem.Is<TPart>()) if (context.ContentItem.Is<TPart>())
UpdateEditors(context, context.ContentItem.As<TPart>()); UpdateEditorViewModel(context, context.ContentItem.As<TPart>());
} }
} }

View File

@@ -9,11 +9,11 @@ namespace Orchard.Models.Driver {
_prefix = prefix; _prefix = prefix;
} }
protected override void GetEditors(GetEditorsContext context, ContentPart<TRecord> part) { protected override void GetEditorViewModel(GetEditorViewModelContext context, ContentPart<TRecord> part) {
context.AddEditor(new TemplateViewModel(part.Record, _prefix)); context.AddEditor(new TemplateViewModel(part.Record, _prefix));
} }
protected override void UpdateEditors(UpdateContentContext context, ContentPart<TRecord> part) { protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context, ContentPart<TRecord> part) {
context.Updater.TryUpdateModel(part.Record, _prefix, null, null); context.Updater.TryUpdateModel(part.Record, _prefix, null, null);
context.AddEditor(new TemplateViewModel(part.Record, _prefix)); context.AddEditor(new TemplateViewModel(part.Record, _prefix));
} }

View File

@@ -1,12 +0,0 @@
using Orchard.Models.ViewModels;
namespace Orchard.Models.Driver {
public class UpdateContentContext : GetEditorsContext {
public UpdateContentContext(ItemEditorViewModel itemView, string groupName, IUpdateModel updater)
: base(itemView, groupName) {
Updater = updater;
}
public IUpdateModel Updater { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using Orchard.Models.ViewModels;
namespace Orchard.Models.Driver {
public class UpdateEditorViewModelContext : GetEditorViewModelContext {
public UpdateEditorViewModelContext(ItemEditorViewModel viewModel, string groupName, IUpdateModel updater)
: base(viewModel, groupName) {
Updater = updater;
}
public IUpdateModel Updater { get; set; }
}
}

View File

@@ -15,8 +15,9 @@ namespace Orchard.Models {
IContentQuery<ContentItem> Query(); IContentQuery<ContentItem> Query();
ContentItemMetadata GetItemMetadata(IContent contentItem); ContentItemMetadata GetItemMetadata(IContent contentItem);
ItemDisplayViewModel<TContentPart> GetDisplays<TContentPart>(TContentPart contentItem, string groupName, string displayType) where TContentPart : IContent;
ItemEditorViewModel<TContentPart> GetEditors<TContentPart>(TContentPart contentItem, string groupName) where TContentPart : IContent; ItemDisplayViewModel<TContent> GetDisplayViewModel<TContent>(TContent content, string groupName, string displayType) where TContent : IContent;
ItemEditorViewModel<TContentPart> UpdateEditors<TContentPart>(TContentPart contentItem, string groupName, IUpdateModel updater) where TContentPart : IContent; ItemEditorViewModel<TContent> GetEditorViewModel<TContent>(TContent content, string groupName) where TContent : IContent;
ItemEditorViewModel<TContent> UpdateEditorViewModel<TContent>(TContent content, string groupName, IUpdateModel updater) where TContent : IContent;
} }
} }

View File

@@ -1,9 +1,22 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace Orchard.Models.ViewModels { namespace Orchard.Models.ViewModels {
public class ItemDisplayViewModel { public class ItemDisplayViewModel {
private ContentItem _item; private ContentItem _item;
protected ItemDisplayViewModel() {
}
protected ItemDisplayViewModel(ItemDisplayViewModel viewModel) {
TemplateName = viewModel.TemplateName;
Prefix = viewModel.Prefix;
Displays = viewModel.Displays.ToArray();
Item = viewModel.Item;
}
public ContentItem Item { public ContentItem Item {
get { return _item; } get { return _item; }
set { SetItem(value); } set { SetItem(value); }
@@ -13,6 +26,7 @@ namespace Orchard.Models.ViewModels {
_item = value; _item = value;
} }
public Func<HtmlHelper, ItemDisplayViewModel, HtmlHelper> Adaptor { get; set; }
public string TemplateName { get; set; } public string TemplateName { get; set; }
public string Prefix { get; set; } public string Prefix { get; set; }
public IEnumerable<TemplateViewModel> Displays { get; set; } public IEnumerable<TemplateViewModel> Displays { get; set; }
@@ -20,6 +34,14 @@ namespace Orchard.Models.ViewModels {
public class ItemDisplayViewModel<TPart> : ItemDisplayViewModel where TPart : IContent { public class ItemDisplayViewModel<TPart> : ItemDisplayViewModel where TPart : IContent {
private TPart _item; private TPart _item;
public ItemDisplayViewModel() {
}
public ItemDisplayViewModel(ItemDisplayViewModel viewModel)
: base(viewModel) {
}
public new TPart Item { public new TPart Item {
get { return _item; } get { return _item; }
set { SetItem(value.ContentItem); } set { SetItem(value.ContentItem); }

View File

@@ -13,9 +13,14 @@ namespace Orchard.Mvc.Html {
var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData); var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
var model = (TItemViewModel)metadata.Model; var model = (TItemViewModel)metadata.Model;
if (model.Adaptor != null) {
return model.Adaptor(html, model).DisplayForModel(model.TemplateName, model.Prefix ?? "");
}
return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? ""); return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? "");
} }
public static MvcHtmlString DisplayZone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : ItemDisplayViewModel { public static MvcHtmlString DisplayZone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : ItemDisplayViewModel {
var templates = html.ViewData.Model.Displays.Where(x => x.ZoneName == zoneName && x.WasUsed == false); var templates = html.ViewData.Model.Displays.Where(x => x.ZoneName == zoneName && x.WasUsed == false);
return DisplayZoneImplementation(html, templates); return DisplayZoneImplementation(html, templates);

View File

@@ -1,4 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Mvc.Html; using System.Web.Mvc.Html;
@@ -13,5 +15,47 @@ namespace Orchard.Mvc.Html {
return html.EditorFor(expression, model.TemplateName, model.Prefix ?? ""); return html.EditorFor(expression, model.TemplateName, model.Prefix ?? "");
} }
public static MvcHtmlString EditorZone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : ItemEditorViewModel {
var templates = html.ViewData.Model.Editors.Where(x => x.ZoneName == zoneName && x.WasUsed == false);
return EditorZoneImplementation(html, templates);
}
public static MvcHtmlString EditorZonesAny<TModel>(this HtmlHelper<TModel> html) where TModel : ItemEditorViewModel {
var templates = html.ViewData.Model.Editors.Where(x => x.WasUsed == false);
return EditorZoneImplementation(html, templates);
}
public static MvcHtmlString EditorZones<TModel>(this HtmlHelper<TModel> html, params string[] include) where TModel : ItemEditorViewModel {
var templates = html.ViewData.Model.Editors.Where(x => include.Contains(x.ZoneName) && x.WasUsed == false);
return EditorZoneImplementation(html, templates);
}
public static MvcHtmlString EditorZonesExcept<TModel>(this HtmlHelper<TModel> html, params string[] exclude) where TModel : ItemEditorViewModel {
var templates = html.ViewData.Model.Editors.Where(x => !exclude.Contains(x.ZoneName) && x.WasUsed == false);
return EditorZoneImplementation(html, templates);
}
private static MvcHtmlString EditorZoneImplementation<TModel>(HtmlHelper<TModel> html, IEnumerable<TemplateViewModel> templates) {
var count = templates.Count();
if (count == 0)
return null;
if (count == 1) {
var t = templates.Single();
t.WasUsed = true;
return html.EditorFor(m => t.Model, t.TemplateName, t.Prefix ?? "");
}
var strings = new List<MvcHtmlString>();
foreach (var template in templates) {
var t = template;
t.WasUsed = true;
strings.Add(html.EditorFor(m => t.Model, t.TemplateName, t.Prefix ?? ""));
}
return MvcHtmlString.Create(string.Concat(strings.ToArray()));
}
} }
} }

View File

@@ -135,7 +135,7 @@
<Compile Include="Models\Driver\ActivatedContentContext.cs" /> <Compile Include="Models\Driver\ActivatedContentContext.cs" />
<Compile Include="Models\Driver\ActivatingFilter.cs" /> <Compile Include="Models\Driver\ActivatingFilter.cs" />
<Compile Include="Models\Driver\ContentItemTemplates.cs" /> <Compile Include="Models\Driver\ContentItemTemplates.cs" />
<Compile Include="Models\Driver\GetDisplaysContext.cs" /> <Compile Include="Models\Driver\GetDisplayViewModelContext.cs" />
<Compile Include="Models\Driver\GetItemMetadataContext.cs" /> <Compile Include="Models\Driver\GetItemMetadataContext.cs" />
<Compile Include="Models\Driver\IContentActivatingFilter.cs" /> <Compile Include="Models\Driver\IContentActivatingFilter.cs" />
<Compile Include="Models\Driver\IContentFilter.cs" /> <Compile Include="Models\Driver\IContentFilter.cs" />
@@ -157,7 +157,7 @@
<Compile Include="Models\Driver\ContentItemBuilder.cs" /> <Compile Include="Models\Driver\ContentItemBuilder.cs" />
<Compile Include="Models\Driver\ContentProvider.cs" /> <Compile Include="Models\Driver\ContentProvider.cs" />
<Compile Include="Models\Driver\ActivatingContentContext.cs" /> <Compile Include="Models\Driver\ActivatingContentContext.cs" />
<Compile Include="Models\Driver\GetEditorsContext.cs" /> <Compile Include="Models\Driver\GetEditorViewModelContext.cs" />
<Compile Include="Models\Driver\StorageFilter.cs" /> <Compile Include="Models\Driver\StorageFilter.cs" />
<Compile Include="Models\Driver\StorageFilterBase.cs" /> <Compile Include="Models\Driver\StorageFilterBase.cs" />
<Compile Include="Models\Driver\TemplateFilterBase.cs" /> <Compile Include="Models\Driver\TemplateFilterBase.cs" />
@@ -174,7 +174,7 @@
<Compile Include="Models\Records\ContentPartRecordAlteration.cs" /> <Compile Include="Models\Records\ContentPartRecordAlteration.cs" />
<Compile Include="Models\Records\ContentTypeRecord.cs" /> <Compile Include="Models\Records\ContentTypeRecord.cs" />
<Compile Include="Models\Records\ContentItemRecord.cs" /> <Compile Include="Models\Records\ContentItemRecord.cs" />
<Compile Include="Models\Driver\UpdateContentContext.cs" /> <Compile Include="Models\Driver\UpdateEditorViewModelContext.cs" />
<Compile Include="Models\ViewModels\TemplateViewModel.cs" /> <Compile Include="Models\ViewModels\TemplateViewModel.cs" />
<Compile Include="Models\ViewModels\ItemDisplayViewModel.cs" /> <Compile Include="Models\ViewModels\ItemDisplayViewModel.cs" />
<Compile Include="Models\ViewModels\ItemEditorViewModel.cs" /> <Compile Include="Models\ViewModels\ItemEditorViewModel.cs" />