mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
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:
@@ -175,7 +175,7 @@ namespace Orchard.Tests.Models {
|
||||
[Test]
|
||||
public void EditorsShouldBeOrderedByPositionAndDefaultPositionIsSix() {
|
||||
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));
|
||||
|
||||
var t0 = templates.First();
|
||||
|
@@ -6,7 +6,7 @@ using Orchard.Models.ViewModels;
|
||||
namespace Orchard.Tests.Models.Stubs {
|
||||
public class AlphaProvider : ContentProvider {
|
||||
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() {
|
||||
return new[] { new ContentType { Name = "alpha" } };
|
||||
|
@@ -4,7 +4,7 @@ using Orchard.Models.ViewModels;
|
||||
namespace Orchard.Tests.Models.Stubs {
|
||||
public class FlavoredProvider : ContentProvider {
|
||||
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) {
|
||||
if (context.ContentType == "beta" || context.ContentType == "alpha") {
|
||||
|
@@ -4,7 +4,7 @@ using Orchard.Models.ViewModels;
|
||||
namespace Orchard.Tests.Models.Stubs {
|
||||
public class StyledProvider : ContentProvider {
|
||||
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) {
|
||||
|
@@ -14,17 +14,17 @@ namespace Orchard.Core.Common.Providers {
|
||||
public BodyAspectProvider(IRepository<BodyRecord> bodyRepository) {
|
||||
Filters.Add(new StorageFilter<BodyRecord>(bodyRepository) { AutomaticallyCreateMissingRecord = true });
|
||||
|
||||
OnGetDisplays<BodyAspect>((context, body) => {
|
||||
OnGetDisplayViewModel<BodyAspect>((context, body) => {
|
||||
var model = new BodyDisplayViewModel { BodyAspect = 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 };
|
||||
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 };
|
||||
context.Updater.TryUpdateModel(model, TemplatePrefix, null, null);
|
||||
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" });
|
||||
|
@@ -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>();
|
||||
if (part == null)
|
||||
return;
|
||||
|
@@ -26,14 +26,14 @@ namespace Orchard.Core.Settings.Controllers {
|
||||
public ActionResult Index(string tabName) {
|
||||
var model = new Orchard.Core.Settings.ViewModels.SettingsIndexViewModel {
|
||||
Site = _siteService.GetSiteSettings().As<SiteSettings>() };
|
||||
model.ItemView = _modelManager.GetEditors(model.Site, tabName);
|
||||
model.ItemView = _modelManager.GetEditorViewModel(model.Site, tabName);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[AcceptVerbs(HttpVerbs.Post)]
|
||||
public ActionResult Index(string tabName, FormCollection input) {
|
||||
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())) {
|
||||
return View(viewModel);
|
||||
|
@@ -91,7 +91,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogEditViewModel { Blog = blog };
|
||||
model.ItemView = _contentManager.GetEditors(model.Blog.ContentItem, "");
|
||||
model.ItemView = _contentManager.GetEditorViewModel(model.Blog.ContentItem, "");
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
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();
|
||||
if (!TryUpdateModel(model, values))
|
||||
|
@@ -60,7 +60,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (post == null)
|
||||
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) {
|
||||
@@ -70,7 +70,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (blog == null)
|
||||
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]
|
||||
@@ -85,12 +85,12 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
var session = _sessionLocator.For(typeof(BlogPostRecord));
|
||||
@@ -115,7 +115,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
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();
|
||||
TryUpdateModel(model, values);
|
||||
|
@@ -16,21 +16,21 @@ namespace Orchard.Comments.Models {
|
||||
Filters.Add(new ActivatingFilter<HasComments>("blogpost"));
|
||||
}
|
||||
|
||||
protected override void GetDisplays(GetDisplaysContext context) {
|
||||
protected override void GetDisplayViewModel(GetDisplayViewModelContext context) {
|
||||
if (context.ContentItem.Has<HasComments>() == false) {
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
@@ -36,8 +36,8 @@ namespace Orchard.DevTools.Controllers {
|
||||
.Select(x => x.GetType())
|
||||
.SelectMany(x => AllTypes(x))
|
||||
.Distinct();
|
||||
model.DisplayView = _contentManager.GetDisplays(model.Item, null, null);
|
||||
model.EditorView = _contentManager.GetEditors(model.Item, null);
|
||||
model.DisplayView = _contentManager.GetDisplayViewModel(model.Item, null, null);
|
||||
model.EditorView = _contentManager.GetEditorViewModel(model.Item, null);
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
@@ -3,10 +3,10 @@ using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.DevTools.Models {
|
||||
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" });
|
||||
}
|
||||
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" });
|
||||
}
|
||||
}
|
||||
|
@@ -78,23 +78,6 @@
|
||||
</li>
|
||||
<%}%>
|
||||
</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>
|
||||
Displays</h3>
|
||||
<ul>
|
||||
@@ -104,6 +87,7 @@
|
||||
<%=Html.Encode(display.Model.GetType().Name)%>
|
||||
(<%=Html.Encode(display.Model.GetType().Namespace)%>)
|
||||
Prefix:<%=Html.Encode(display.Prefix ?? "(null)")%>
|
||||
Zone:<%=Html.Encode(display.ZoneName ?? "(null)")%>
|
||||
Position:<%=Html.Encode(display.Position ?? "(null)")%>
|
||||
<div style="margin-left: 20px; border: solid 1px black;">
|
||||
<%=Html.DisplayFor(x => display.Model, display.TemplateName, display.Prefix)%>
|
||||
@@ -112,6 +96,24 @@
|
||||
<%
|
||||
}%>
|
||||
</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 id="footer">
|
||||
<% Html.Include("footer"); %>
|
||||
|
@@ -23,7 +23,7 @@ namespace Orchard.Media.Models {
|
||||
settings.Record.RootMediaFolder = "~/Media";
|
||||
}
|
||||
|
||||
protected override void GetEditors(GetEditorsContext context) {
|
||||
protected override void GetEditorViewModel(GetEditorViewModelContext context) {
|
||||
var model = context.ContentItem.As<MediaSettings>();
|
||||
if (model == null)
|
||||
return;
|
||||
@@ -31,7 +31,7 @@ namespace Orchard.Media.Models {
|
||||
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>();
|
||||
if (model == null)
|
||||
return;
|
||||
|
@@ -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>();
|
||||
if (userRoles != null) {
|
||||
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>();
|
||||
if (userRoles != null) {
|
||||
var viewModel = new UserRolesViewModel();
|
||||
|
@@ -32,7 +32,7 @@ namespace Orchard.Sandbox.Controllers {
|
||||
Pages = _contentManager.Query<SandboxPage, SandboxPageRecord>()
|
||||
.OrderBy(x => x.Name)
|
||||
.List()
|
||||
.Select(x => _contentManager.GetDisplays(x, null, "SummaryList"))
|
||||
.Select(x => _contentManager.GetDisplayViewModel(x, null, "SummaryList"))
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ namespace Orchard.Sandbox.Controllers {
|
||||
public ActionResult Show(int id) {
|
||||
var page = _contentManager.Get<SandboxPage>(id);
|
||||
var model = new PageShowViewModel {
|
||||
Page = _contentManager.GetDisplays(page, null, "Detail")
|
||||
Page = _contentManager.GetDisplayViewModel(page, null, "Detail")
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace Orchard.Sandbox.Controllers {
|
||||
|
||||
var page = _contentManager.Get<SandboxPage>(id);
|
||||
var model = new PageEditViewModel {
|
||||
Page = _contentManager.GetEditors(page, null)
|
||||
Page = _contentManager.GetEditorViewModel(page, null)
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ namespace Orchard.Sandbox.Controllers {
|
||||
|
||||
var page = _contentManager.Get<SandboxPage>(id);
|
||||
var model = new PageEditViewModel {
|
||||
Page = _contentManager.UpdateEditors(page, null, this)
|
||||
Page = _contentManager.UpdateEditorViewModel(page, null, this)
|
||||
};
|
||||
if (!ModelState.IsValid)
|
||||
return View(model);
|
||||
|
@@ -4,6 +4,7 @@ using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Sandbox.Models {
|
||||
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" }));
|
||||
|
||||
|
||||
|
||||
|
@@ -75,6 +75,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Package.txt" />
|
||||
<Content Include="Views\Models\DisplayTemplates\ContentItemTitle.ascx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\SandboxPageSummary.ascx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\SandboxPage.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\SandboxPage.ascx" />
|
||||
|
@@ -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>
|
@@ -2,21 +2,23 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<%@ Import Namespace="Orchard.Sandbox.Models" %>
|
||||
<%@ Import Namespace="Orchard.Models.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.Models" %>
|
||||
<%=Html.DisplayZone("before")%>
|
||||
<div class="item">
|
||||
<%=Html.DisplayZone("first")%>
|
||||
<h1>
|
||||
<%=Html.Encode(Model.Item.Record.Name) %></h1>
|
||||
<div class="title">
|
||||
<%=Html.DisplayZone("title")%>
|
||||
</div>
|
||||
<%=Html.DisplayZone("metatop")%>
|
||||
<div class="body">
|
||||
<%=Html.DisplayZone("body")%></div>
|
||||
<%=Html.DisplayZone("metabottom")%>
|
||||
<div class="actions">
|
||||
<%=Html.ItemEditLink("Edit this page", Model.Item) %>,
|
||||
<%=Html.ItemEditLink("Edit this page", Model.Item) %>
|
||||
<%=Html.ActionLink("Return to list", "index") %>
|
||||
<%=Html.DisplayZone("actions") %></div>
|
||||
<%=Html.DisplayZonesExcept("last","after") %>
|
||||
<%=Html.DisplayZone("last")%>
|
||||
<%=Html.DisplayZone("actions") %>
|
||||
</div>
|
||||
<div class="body">
|
||||
<%=Html.DisplayZone("body")%>
|
||||
</div>
|
||||
<%=Html.DisplayZone("metabottom")%>
|
||||
<div class="footer">
|
||||
<%=Html.DisplayZonesExcept("last") %>
|
||||
<%=Html.DisplayZone("last")%>
|
||||
</div>
|
||||
</div>
|
||||
<%=Html.DisplayZone("after")%>
|
||||
|
@@ -2,9 +2,9 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Sandbox.Models" %>
|
||||
<%@ Import Namespace="Orchard.Models.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.Models" %>
|
||||
<h2><%=Html.ItemDisplayLink(Model.Item) %></h2>
|
||||
<%--<%foreach (var display in Model.Displays) { %>
|
||||
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix??"") %>
|
||||
<%} %>
|
||||
--%>
|
||||
|
||||
<div class="item">
|
||||
<%=Html.DisplayZone("title") %>
|
||||
<%=Html.DisplayZone("metatop")%>
|
||||
<%=Html.DisplayZone("body") %>
|
||||
</div>
|
||||
|
@@ -1,14 +1,10 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorViewModel<SandboxPage>>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<%@ Import Namespace="Orchard.Sandbox.Models" %>
|
||||
<%@ Import Namespace="Orchard.Models.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.Models" %>
|
||||
|
||||
|
||||
<li>
|
||||
<%=Html.LabelFor(m => m.Item.Record.Name)%>
|
||||
<%=Html.EditorFor(m => m.Item.Record.Name)%>
|
||||
<%=Html.LabelFor(m => m.Item.Record.Name)%>
|
||||
<%=Html.EditorFor(m => m.Item.Record.Name)%>
|
||||
</li>
|
||||
|
||||
<%foreach (var e in Model.Editors) { %>
|
||||
<%=Html.EditorFor(m=>e.Model, e.TemplateName, e.Prefix??"") %>
|
||||
<%} %>
|
||||
<%=Html.EditorZonesAny()%>
|
||||
|
@@ -20,7 +20,6 @@
|
||||
</div>
|
||||
<div id="main">
|
||||
<% Html.RenderPartial("Messages", Model.Messages); %>
|
||||
|
||||
<%= Html.DisplayForItem(m => m.Page) %>
|
||||
</div>
|
||||
<div id="footer">
|
||||
|
@@ -17,11 +17,14 @@ namespace Orchard.Tags.Controllers {
|
||||
public class HomeController : Controller {
|
||||
private readonly ITagService _tagService;
|
||||
private readonly IAuthorizer _authorizer;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public HomeController(ITagService tagService, INotifier notifier, IAuthorizer authorizer) {
|
||||
public HomeController(ITagService tagService, INotifier notifier, IAuthorizer authorizer,
|
||||
IContentManager contentManager) {
|
||||
_tagService = tagService;
|
||||
_authorizer = authorizer;
|
||||
_contentManager = contentManager;
|
||||
_notifier = notifier;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
@@ -110,7 +113,7 @@ namespace Orchard.Tags.Controllers {
|
||||
IEnumerable<IContent> contents = _tagService.GetTaggedContentItems(tag.Id).ToList();
|
||||
var viewModel = new TagsSearchViewModel {
|
||||
TagName = tag.TagName,
|
||||
Contents = contents,
|
||||
Contents = contents.Select(x=>_contentManager.GetDisplayViewModel(x, null, "SummaryTag")),
|
||||
};
|
||||
return View(viewModel);
|
||||
|
||||
|
@@ -30,20 +30,20 @@ namespace Orchard.Tags.Models {
|
||||
Filters.Add(new ActivatingFilter<HasTags>("sandboxpage"));
|
||||
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 = "metabottom", Position = "5" });
|
||||
});
|
||||
}
|
||||
|
||||
protected override void GetEditors(GetEditorsContext context) {
|
||||
protected override void GetEditorViewModel(GetEditorViewModelContext context) {
|
||||
if (context.ContentItem.Has<HasTags>() == false) {
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
@@ -1,10 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Tags.ViewModels {
|
||||
public class TagsSearchViewModel : BaseViewModel {
|
||||
public string TagName { get; set; }
|
||||
public IEnumerable<IContent> Contents { get; set; }
|
||||
public IEnumerable<ItemDisplayViewModel<IContent>> Contents { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,6 @@
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
|
||||
<h2>List of contents tagged with <%= Model.TagName %></h2><%
|
||||
foreach (var contentItem in Model.Contents) { %>
|
||||
<%=Html.ItemDisplayLink(contentItem)%><%
|
||||
<%=Html.DisplayForItem(x=>contentItem)%><%
|
||||
} %>
|
||||
</asp:Content>
|
@@ -2,7 +2,7 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Tags.Models"%>
|
||||
<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>
|
||||
<%
|
||||
string tags = "";
|
||||
|
@@ -49,7 +49,7 @@ namespace Orchard.Users.Controllers {
|
||||
public ActionResult Create() {
|
||||
var user = _contentManager.New("user");
|
||||
var model = new UserCreateViewModel {
|
||||
ItemView = _contentManager.GetEditors(user, null)
|
||||
ItemView = _contentManager.GetEditorViewModel(user, null)
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace Orchard.Users.Controllers {
|
||||
ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").ToString());
|
||||
}
|
||||
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);
|
||||
}
|
||||
var user = _membershipService.CreateUser(new CreateUserParams(
|
||||
@@ -69,7 +69,7 @@ namespace Orchard.Users.Controllers {
|
||||
model.Password,
|
||||
model.Email,
|
||||
null, null, true));
|
||||
model.ItemView = _contentManager.UpdateEditors(user, null, this);
|
||||
model.ItemView = _contentManager.UpdateEditorViewModel(user, null, this);
|
||||
if (ModelState.IsValid == false) {
|
||||
//TODO: rollback transaction
|
||||
return View(model);
|
||||
@@ -80,14 +80,14 @@ namespace Orchard.Users.Controllers {
|
||||
|
||||
public ActionResult Edit(int 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);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Edit(int id, FormCollection input) {
|
||||
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())) {
|
||||
return View(model);
|
||||
|
@@ -136,34 +136,34 @@ namespace Orchard.Models {
|
||||
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 context = new GetDisplaysContext(itemView, groupName, displayType);
|
||||
var context = new GetDisplayViewModelContext(itemView, groupName, displayType);
|
||||
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;
|
||||
}
|
||||
|
||||
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 context = new GetEditorsContext(itemView, groupName);
|
||||
var context = new GetEditorViewModelContext(itemView, groupName);
|
||||
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;
|
||||
}
|
||||
|
||||
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 context = new UpdateContentContext(itemView, groupName, updater);
|
||||
var context = new UpdateEditorViewModelContext(itemView, groupName, updater);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
@@ -7,7 +8,7 @@ namespace Orchard.Models.Driver {
|
||||
private readonly string _templateName;
|
||||
private readonly string _prefix;
|
||||
private readonly string[] _displayTypes;
|
||||
private Action<UpdateContentContext, ItemEditorViewModel<TContent>> _updater;
|
||||
private Action<UpdateEditorViewModelContext, ItemEditorViewModel<TContent>> _updater;
|
||||
|
||||
public ContentItemTemplates(string templateName, params string[] displayTypes) {
|
||||
_templateName = templateName;
|
||||
@@ -15,31 +16,47 @@ namespace Orchard.Models.Driver {
|
||||
_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);
|
||||
context.ItemView.TemplateName = _templateName + longestMatch;
|
||||
context.ItemView.Prefix = _prefix;
|
||||
context.ViewModel.TemplateName = _templateName + longestMatch;
|
||||
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) {
|
||||
if (string.IsNullOrEmpty(displayType))
|
||||
return displayType;
|
||||
|
||||
return _displayTypes.Aggregate("", (best, x) => {
|
||||
if (displayType.StartsWith(x) && x.Length > best.Length) return x;
|
||||
return best;
|
||||
});
|
||||
if (displayType.StartsWith(x) && x.Length > best.Length) return x;
|
||||
return best;
|
||||
});
|
||||
}
|
||||
|
||||
protected override void GetEditors(GetEditorsContext context, TContent instance) {
|
||||
context.ItemView.TemplateName = _templateName;
|
||||
context.ItemView.Prefix = _prefix;
|
||||
protected override void GetEditorViewModel(GetEditorViewModelContext context, TContent instance) {
|
||||
context.ViewModel.TemplateName = _templateName;
|
||||
context.ViewModel.Prefix = _prefix;
|
||||
}
|
||||
|
||||
protected override void UpdateEditors(UpdateContentContext context, TContent instance) {
|
||||
_updater(context, (ItemEditorViewModel<TContent>)context.ItemView);
|
||||
context.ItemView.TemplateName = _templateName;
|
||||
context.ItemView.Prefix = _prefix;
|
||||
protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context, TContent instance) {
|
||||
_updater(context, (ItemEditorViewModel<TContent>)context.ViewModel);
|
||||
context.ViewModel.TemplateName = _templateName;
|
||||
context.ViewModel.Prefix = _prefix;
|
||||
}
|
||||
|
||||
public void Updater(Action<UpdateContentContext, ItemEditorViewModel<TContent>> updater) {
|
||||
public void Updater(Action<UpdateEditorViewModelContext, ItemEditorViewModel<TContent>> updater) {
|
||||
_updater = updater;
|
||||
}
|
||||
}
|
||||
|
@@ -36,16 +36,16 @@ namespace Orchard.Models.Driver {
|
||||
protected void OnGetItemMetadata<TPart>(Action<GetItemMetadataContext, TPart> handler) where TPart : class, IContent {
|
||||
Filters.Add(new InlineTemplateFilter<TPart> { OnGetItemMetadata = handler });
|
||||
}
|
||||
protected void OnGetDisplays<TPart>(Action<GetDisplaysContext, TPart> handler) where TPart : class, IContent {
|
||||
Filters.Add(new InlineTemplateFilter<TPart> { OnGetDisplays = handler });
|
||||
protected void OnGetDisplayViewModel<TPart>(Action<GetDisplayViewModelContext, TPart> handler) where TPart : class, IContent {
|
||||
Filters.Add(new InlineTemplateFilter<TPart> { OnGetDisplayViewModel = handler });
|
||||
}
|
||||
|
||||
protected void OnGetEditors<TPart>(Action<GetEditorsContext, TPart> handler) where TPart : class, IContent {
|
||||
Filters.Add(new InlineTemplateFilter<TPart> { OnGetEditors = handler });
|
||||
protected void OnGetEditorViewModel<TPart>(Action<GetEditorViewModelContext, TPart> handler) where TPart : class, IContent {
|
||||
Filters.Add(new InlineTemplateFilter<TPart> { OnGetEditorViewModel = handler });
|
||||
}
|
||||
|
||||
protected void OnUpdateEditors<TPart>(Action<UpdateContentContext, TPart> handler) where TPart : class, IContent {
|
||||
Filters.Add(new InlineTemplateFilter<TPart> { OnUpdateEditors = handler });
|
||||
protected void OnUpdateEditorViewModel<TPart>(Action<UpdateEditorViewModelContext, TPart> handler) where TPart : class, IContent {
|
||||
Filters.Add(new InlineTemplateFilter<TPart> { OnUpdateEditorViewModel = handler });
|
||||
}
|
||||
|
||||
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 {
|
||||
public Action<GetItemMetadataContext, TPart> OnGetItemMetadata { get; set; }
|
||||
public Action<GetDisplaysContext, TPart> OnGetDisplays { get; set; }
|
||||
public Action<GetEditorsContext, TPart> OnGetEditors { get; set; }
|
||||
public Action<UpdateContentContext, TPart> OnUpdateEditors { get; set; }
|
||||
public Action<GetDisplayViewModelContext, TPart> OnGetDisplayViewModel { get; set; }
|
||||
public Action<GetEditorViewModelContext, TPart> OnGetEditorViewModel { get; set; }
|
||||
public Action<UpdateEditorViewModelContext, TPart> OnUpdateEditorViewModel { get; set; }
|
||||
protected override void GetItemMetadata(GetItemMetadataContext context, TPart instance) {
|
||||
if (OnGetItemMetadata != null) OnGetItemMetadata(context, instance);
|
||||
}
|
||||
protected override void GetDisplays(GetDisplaysContext context, TPart instance) {
|
||||
if (OnGetDisplays != null) OnGetDisplays(context, instance);
|
||||
protected override void GetDisplayViewModel(GetDisplayViewModelContext context, TPart instance) {
|
||||
if (OnGetDisplayViewModel != null) OnGetDisplayViewModel(context, instance);
|
||||
}
|
||||
protected override void GetEditors(GetEditorsContext context, TPart instance) {
|
||||
if (OnGetEditors != null) OnGetEditors(context, instance);
|
||||
protected override void GetEditorViewModel(GetEditorViewModelContext context, TPart instance) {
|
||||
if (OnGetEditorViewModel != null) OnGetEditorViewModel(context, instance);
|
||||
}
|
||||
protected override void UpdateEditors(UpdateContentContext context, TPart instance) {
|
||||
if (OnUpdateEditors != null) OnUpdateEditors(context, instance);
|
||||
protected override void UpdateEditorViewModel(UpdateEditorViewModelContext context, TPart instance) {
|
||||
if (OnUpdateEditorViewModel != null) OnUpdateEditorViewModel(context, instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,20 +136,20 @@ namespace Orchard.Models.Driver {
|
||||
filter.GetItemMetadata(context);
|
||||
GetItemMetadata(context);
|
||||
}
|
||||
void IContentProvider.GetDisplays(GetDisplaysContext context) {
|
||||
void IContentProvider.GetDisplayViewModel(GetDisplayViewModelContext context) {
|
||||
foreach (var filter in Filters.OfType<IContentTemplateFilter>())
|
||||
filter.GetDisplays(context);
|
||||
GetDisplays(context);
|
||||
filter.GetDisplayViewModel(context);
|
||||
GetDisplayViewModel(context);
|
||||
}
|
||||
void IContentProvider.GetEditors(GetEditorsContext context) {
|
||||
void IContentProvider.GetEditorViewModel(GetEditorViewModelContext context) {
|
||||
foreach (var filter in Filters.OfType<IContentTemplateFilter>())
|
||||
filter.GetEditors(context);
|
||||
GetEditors(context);
|
||||
filter.GetEditorViewModel(context);
|
||||
GetEditorViewModel(context);
|
||||
}
|
||||
void IContentProvider.UpdateEditors(UpdateContentContext context) {
|
||||
void IContentProvider.UpdateEditorViewModel(UpdateEditorViewModelContext context) {
|
||||
foreach (var filter in Filters.OfType<IContentTemplateFilter>())
|
||||
filter.UpdateEditors(context);
|
||||
UpdateEditors(context);
|
||||
filter.UpdateEditorViewModel(context);
|
||||
UpdateEditorViewModel(context);
|
||||
}
|
||||
|
||||
protected virtual void Activating(ActivatingContentContext context) { }
|
||||
@@ -162,8 +162,8 @@ namespace Orchard.Models.Driver {
|
||||
protected virtual void Created(CreateContentContext context) { }
|
||||
|
||||
protected virtual void GetItemMetadata(GetItemMetadataContext context) { }
|
||||
protected virtual void GetDisplays(GetDisplaysContext context) { }
|
||||
protected virtual void GetEditors(GetEditorsContext context) { }
|
||||
protected virtual void UpdateEditors(UpdateContentContext context) {}
|
||||
protected virtual void GetDisplayViewModel(GetDisplayViewModelContext context) { }
|
||||
protected virtual void GetEditorViewModel(GetEditorViewModelContext context) { }
|
||||
protected virtual void UpdateEditorViewModel(UpdateEditorViewModelContext context) {}
|
||||
}
|
||||
}
|
@@ -4,22 +4,22 @@ using System.Linq;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public class GetDisplaysContext {
|
||||
public GetDisplaysContext(ItemDisplayViewModel itemView, string groupName, string displayType) {
|
||||
ContentItem = itemView.Item;
|
||||
public class GetDisplayViewModelContext {
|
||||
public GetDisplayViewModelContext(ItemDisplayViewModel viewModel, string groupName, string displayType) {
|
||||
ContentItem = viewModel.Item;
|
||||
GroupName = groupName;
|
||||
DisplayType = displayType;
|
||||
ItemView = itemView;
|
||||
ViewModel = viewModel;
|
||||
}
|
||||
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public string GroupName { get; set; }
|
||||
public string DisplayType { get; set; }
|
||||
public ItemDisplayViewModel ItemView { get; set; }
|
||||
public ItemDisplayViewModel ViewModel { get; set; }
|
||||
|
||||
|
||||
public void AddDisplay(TemplateViewModel display) {
|
||||
ItemView.Displays = ItemView.Displays.Concat(new[] { display });
|
||||
ViewModel.Displays = ViewModel.Displays.Concat(new[] { display });
|
||||
}
|
||||
}
|
||||
}
|
22
src/Orchard/Models/Driver/GetEditorViewModelContext.cs
Normal file
22
src/Orchard/Models/Driver/GetEditorViewModelContext.cs
Normal 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 });
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
@@ -12,8 +12,8 @@ namespace Orchard.Models.Driver {
|
||||
void Loaded(LoadContentContext context);
|
||||
|
||||
void GetItemMetadata(GetItemMetadataContext context);
|
||||
void GetDisplays(GetDisplaysContext context);
|
||||
void GetEditors(GetEditorsContext context);
|
||||
void UpdateEditors(UpdateContentContext context);
|
||||
void GetDisplayViewModel(GetDisplayViewModelContext context);
|
||||
void GetEditorViewModel(GetEditorViewModelContext context);
|
||||
void UpdateEditorViewModel(UpdateEditorViewModelContext context);
|
||||
}
|
||||
}
|
||||
|
@@ -6,8 +6,8 @@ using System.Text;
|
||||
namespace Orchard.Models.Driver {
|
||||
interface IContentTemplateFilter : IContentFilter {
|
||||
void GetItemMetadata(GetItemMetadataContext context);
|
||||
void GetDisplays(GetDisplaysContext context);
|
||||
void GetEditors(GetEditorsContext context);
|
||||
void UpdateEditors(UpdateContentContext context);
|
||||
void GetDisplayViewModel(GetDisplayViewModelContext context);
|
||||
void GetEditorViewModel(GetEditorViewModelContext context);
|
||||
void UpdateEditorViewModel(UpdateEditorViewModelContext context);
|
||||
}
|
||||
}
|
||||
|
@@ -7,28 +7,28 @@ namespace Orchard.Models.Driver {
|
||||
public abstract class TemplateFilterBase<TPart> : IContentTemplateFilter where TPart : class, IContent {
|
||||
|
||||
protected virtual void GetItemMetadata(GetItemMetadataContext context, TPart instance) { }
|
||||
protected virtual void GetDisplays(GetDisplaysContext context, TPart instance) { }
|
||||
protected virtual void GetEditors(GetEditorsContext context, TPart instance) { }
|
||||
protected virtual void UpdateEditors(UpdateContentContext context, TPart instance) { }
|
||||
protected virtual void GetDisplayViewModel(GetDisplayViewModelContext context, TPart instance) { }
|
||||
protected virtual void GetEditorViewModel(GetEditorViewModelContext context, TPart instance) { }
|
||||
protected virtual void UpdateEditorViewModel(UpdateEditorViewModelContext context, TPart instance) { }
|
||||
|
||||
void IContentTemplateFilter.GetItemMetadata(GetItemMetadataContext context) {
|
||||
if (context.ContentItem.Is<TPart>())
|
||||
GetItemMetadata(context, context.ContentItem.As<TPart>());
|
||||
}
|
||||
|
||||
void IContentTemplateFilter.GetDisplays(GetDisplaysContext context) {
|
||||
void IContentTemplateFilter.GetDisplayViewModel(GetDisplayViewModelContext context) {
|
||||
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>())
|
||||
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>())
|
||||
UpdateEditors(context, context.ContentItem.As<TPart>());
|
||||
UpdateEditorViewModel(context, context.ContentItem.As<TPart>());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -9,11 +9,11 @@ namespace Orchard.Models.Driver {
|
||||
_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));
|
||||
}
|
||||
|
||||
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.AddEditor(new TemplateViewModel(part.Record, _prefix));
|
||||
}
|
||||
|
@@ -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; }
|
||||
}
|
||||
}
|
12
src/Orchard/Models/Driver/UpdateEditorViewModelContext.cs
Normal file
12
src/Orchard/Models/Driver/UpdateEditorViewModelContext.cs
Normal 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; }
|
||||
}
|
||||
}
|
@@ -15,8 +15,9 @@ namespace Orchard.Models {
|
||||
IContentQuery<ContentItem> Query();
|
||||
|
||||
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;
|
||||
ItemEditorViewModel<TContentPart> UpdateEditors<TContentPart>(TContentPart contentItem, string groupName, IUpdateModel updater) where TContentPart : IContent;
|
||||
|
||||
ItemDisplayViewModel<TContent> GetDisplayViewModel<TContent>(TContent content, string groupName, string displayType) where TContent : 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.Models.ViewModels {
|
||||
public class ItemDisplayViewModel {
|
||||
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 {
|
||||
get { return _item; }
|
||||
set { SetItem(value); }
|
||||
@@ -13,6 +26,7 @@ namespace Orchard.Models.ViewModels {
|
||||
_item = value;
|
||||
}
|
||||
|
||||
public Func<HtmlHelper, ItemDisplayViewModel, HtmlHelper> Adaptor { get; set; }
|
||||
public string TemplateName { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Displays { get; set; }
|
||||
@@ -20,6 +34,14 @@ namespace Orchard.Models.ViewModels {
|
||||
|
||||
public class ItemDisplayViewModel<TPart> : ItemDisplayViewModel where TPart : IContent {
|
||||
private TPart _item;
|
||||
|
||||
public ItemDisplayViewModel() {
|
||||
|
||||
}
|
||||
public ItemDisplayViewModel(ItemDisplayViewModel viewModel)
|
||||
: base(viewModel) {
|
||||
}
|
||||
|
||||
public new TPart Item {
|
||||
get { return _item; }
|
||||
set { SetItem(value.ContentItem); }
|
||||
|
@@ -13,9 +13,14 @@ namespace Orchard.Mvc.Html {
|
||||
var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
|
||||
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 ?? "");
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
return DisplayZoneImplementation(html, templates);
|
||||
|
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
@@ -13,5 +15,47 @@ namespace Orchard.Mvc.Html {
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -135,7 +135,7 @@
|
||||
<Compile Include="Models\Driver\ActivatedContentContext.cs" />
|
||||
<Compile Include="Models\Driver\ActivatingFilter.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\IContentActivatingFilter.cs" />
|
||||
<Compile Include="Models\Driver\IContentFilter.cs" />
|
||||
@@ -157,7 +157,7 @@
|
||||
<Compile Include="Models\Driver\ContentItemBuilder.cs" />
|
||||
<Compile Include="Models\Driver\ContentProvider.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\StorageFilterBase.cs" />
|
||||
<Compile Include="Models\Driver\TemplateFilterBase.cs" />
|
||||
@@ -174,7 +174,7 @@
|
||||
<Compile Include="Models\Records\ContentPartRecordAlteration.cs" />
|
||||
<Compile Include="Models\Records\ContentTypeRecord.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\ItemDisplayViewModel.cs" />
|
||||
<Compile Include="Models\ViewModels\ItemEditorViewModel.cs" />
|
||||
|
Reference in New Issue
Block a user