mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 03:58:13 +08:00
Preparing for display/editor content chrome structuring
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042906
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);
|
||||
var templates = _manager.GetDisplays(alpha, null, null).Displays;
|
||||
Assert.That(templates.Count(), Is.EqualTo(3));
|
||||
|
||||
var t0 = templates.First();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Tests.Models.Stubs {
|
||||
public class AlphaProvider : ContentProvider {
|
||||
public AlphaProvider() {
|
||||
OnGetDisplays<Alpha>((ctx, part) => ctx.Displays.Add(new ModelTemplate(part) { Position = "3" }));
|
||||
OnGetDisplays<Alpha>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part) { Position = "3" }));
|
||||
}
|
||||
public override IEnumerable<ContentType> GetContentTypes() {
|
||||
return new[] { new ContentType { Name = "alpha" } };
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Tests.Models.Stubs {
|
||||
public class FlavoredProvider : ContentProvider {
|
||||
public FlavoredProvider() {
|
||||
OnGetDisplays<Flavored>((ctx, part) => ctx.Displays.Add(new ModelTemplate(part)));
|
||||
OnGetDisplays<Flavored>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part)));
|
||||
}
|
||||
protected override void Activating(ActivatingContentContext context) {
|
||||
if (context.ContentType == "beta" || context.ContentType == "alpha") {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Tests.Models.Stubs {
|
||||
public class StyledProvider : ContentProvider {
|
||||
public StyledProvider() {
|
||||
OnGetDisplays<Styled>((ctx, part) => ctx.Displays.Add(new ModelTemplate(part) { Position = "10" }));
|
||||
OnGetDisplays<Styled>((ctx, part) => ctx.AddDisplay(new TemplateViewModel(part) { Position = "10" }));
|
||||
}
|
||||
|
||||
protected override void Activating(ActivatingContentContext context) {
|
||||
|
||||
@@ -3,7 +3,7 @@ using Orchard.Core.Common.Records;
|
||||
using Orchard.Core.Common.ViewModels;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Core.Common.Providers {
|
||||
public class BodyAspectProvider : ContentProvider {
|
||||
@@ -16,18 +16,18 @@ namespace Orchard.Core.Common.Providers {
|
||||
|
||||
OnGetDisplays<BodyAspect>((context, body) => {
|
||||
var model = new BodyDisplayViewModel { BodyAspect = body };
|
||||
context.Displays.Add(new ModelTemplate(model, TemplatePrefix) { TemplateName = TemplateName, Position = "3" });
|
||||
context.AddDisplay(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, Position = "3" });
|
||||
});
|
||||
|
||||
OnGetEditors<BodyAspect>((context, body) => {
|
||||
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
|
||||
context.Editors.Add(new ModelTemplate(model, TemplatePrefix) { TemplateName = TemplateName, Position = "3" });
|
||||
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, Position = "3" });
|
||||
});
|
||||
|
||||
OnUpdateEditors<BodyAspect>((context, body) => {
|
||||
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
|
||||
context.Updater.TryUpdateModel(model, TemplatePrefix, null, null);
|
||||
context.Editors.Add(new ModelTemplate(model, TemplatePrefix) { TemplateName = TemplateName, Position = "3" });
|
||||
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, Position = "3" });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,17 +23,17 @@ namespace Orchard.Core.Settings.Controllers {
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
public ActionResult Index(string tabName) {
|
||||
var model = new Orchard.Core.Settings.ViewModels.SettingsIndexViewModel {
|
||||
Site = _siteService.GetSiteSettings().As<SiteSettings>() };
|
||||
model.Editors = _modelManager.GetEditors(model.Site.ContentItem);
|
||||
model.ItemView = _modelManager.GetEditors(model.Site, tabName);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[AcceptVerbs(HttpVerbs.Post)]
|
||||
public ActionResult Index(FormCollection input) {
|
||||
public ActionResult Index(string tabName, FormCollection input) {
|
||||
var viewModel = new SettingsIndexViewModel { Site = _siteService.GetSiteSettings().As<SiteSettings>() };
|
||||
viewModel.Editors = _modelManager.UpdateEditors(viewModel.Site.ContentItem, this);
|
||||
viewModel.ItemView = _modelManager.UpdateEditors(viewModel.Site.ContentItem, tabName, this);
|
||||
|
||||
if (!TryUpdateModel(viewModel, input.ToValueProvider())) {
|
||||
return View(viewModel);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Core.Settings.Models;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Core.Settings.ViewModels {
|
||||
public class SettingsIndexViewModel : AdminViewModel {
|
||||
public SiteSettings Site { get; set; }
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id {
|
||||
|
||||
@@ -18,6 +18,6 @@
|
||||
</ol>
|
||||
|
||||
|
||||
<% foreach(var e in Model.Editors) {%>
|
||||
<% foreach(var e in Model.ItemView.Editors) {%>
|
||||
<%=Html.EditorFor(m => e.Model, e.TemplateName, e.Prefix)%>
|
||||
<%} %>
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult ListForAdmin() {
|
||||
return View(new BlogsViewModel {Blogs = _blogService.Get()});
|
||||
return View(new BlogsViewModel { Blogs = _blogService.Get() });
|
||||
}
|
||||
|
||||
//TODO: (erikpo) Should move the slug parameter and get call and null check up into a model binder
|
||||
@@ -45,7 +45,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
IEnumerable<BlogPost> posts = _blogPostService.Get(blog);
|
||||
|
||||
return View(new BlogViewModel {Blog = blog, Posts = posts});
|
||||
return View(new BlogViewModel { Blog = blog, Posts = posts });
|
||||
}
|
||||
|
||||
public ActionResult Create() {
|
||||
@@ -58,7 +58,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return View(model);
|
||||
|
||||
Blog blog = _blogService.Create(model.ToCreateBlogParams());
|
||||
|
||||
|
||||
//TEMP: (erikpo) ensure information has committed for this record
|
||||
var session = _sessionLocator.For(typeof(BlogRecord));
|
||||
session.Flush();
|
||||
@@ -74,7 +74,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogEditViewModel { Blog = blog };
|
||||
model.Editors = _contentManager.GetEditors(model.Blog.ContentItem);
|
||||
model.ItemView = _contentManager.GetEditors(model.Blog.ContentItem, "");
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogEditViewModel { Blog = blog };
|
||||
model.Editors = _contentManager.UpdateEditors(model.Blog.ContentItem, this);
|
||||
model.ItemView = _contentManager.UpdateEditors(model.Blog.ContentItem, "",this);
|
||||
|
||||
IValueProvider values = input.ToValueProvider();
|
||||
if (!TryUpdateModel(model, values))
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (post == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
return View(new BlogPostViewModel {Blog = blog, Post = post, Displays = _contentManager.GetDisplays(post.ContentItem)});
|
||||
return View(new BlogPostViewModel { Blog = blog, Post = post, ItemView = _contentManager.GetDisplays(post.ContentItem, null, "detail") });
|
||||
}
|
||||
|
||||
public ActionResult Create(string blogSlug) {
|
||||
@@ -62,7 +62,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
return View(new CreateBlogPostViewModel {Blog = blog});
|
||||
return View(new CreateBlogPostViewModel { Blog = blog });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -98,7 +98,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogPostEditViewModel { Blog = blog, Post = post };
|
||||
model.Editors = _contentManager.GetEditors(model.Post.ContentItem);
|
||||
model.ItemView = _contentManager.GetEditors(model.Post.ContentItem, null);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogPostEditViewModel { Blog = blog, Post = post };
|
||||
model.Editors = _contentManager.UpdateEditors(model.Post.ContentItem, this);
|
||||
model.ItemView = _contentManager.UpdateEditors(model.Post.ContentItem, null, this);
|
||||
|
||||
IValueProvider values = input.ToValueProvider();
|
||||
if (!TryUpdateModel(model, values))
|
||||
|
||||
@@ -4,13 +4,13 @@ using System.Web.Mvc;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class BlogEditViewModel : AdminViewModel {
|
||||
public Blog Blog { get; set; }
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id {
|
||||
|
||||
@@ -5,14 +5,14 @@ using System.Web.Mvc;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class BlogPostEditViewModel : AdminViewModel {
|
||||
public Blog Blog { get; set; }
|
||||
public BlogPost Post { get; set; }
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class BlogPostViewModel : BaseViewModel {
|
||||
public Blog Blog { get; set; }
|
||||
public BlogPost Post { get; set; }
|
||||
public IEnumerable<ModelTemplate> Displays { get; set; }
|
||||
public ItemDisplayViewModel ItemView { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,10 @@
|
||||
<%=Html.EditorForModel() %>
|
||||
<fieldset><input class="button" type="submit" value="Save" /></fieldset>
|
||||
<% } %>
|
||||
<%foreach (var editor in Model.Editors) { %>
|
||||
<%foreach (var editor in Model.ItemView.Editors) { %>
|
||||
<%-- TODO: why is Body in editors? --%>
|
||||
<%-- TODO: because any content type using the body editor doesn't need
|
||||
to re-implement the rich editor, media extensions, format filter chain selection, etc --%>
|
||||
<% if (!String.Equals(editor.Prefix, "Body")) { %>
|
||||
<%=Html.EditorFor(m=>editor.Model, editor.TemplateName, editor.Prefix) %>
|
||||
<% } %>
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
|
||||
<h1><%=Html.Encode(Model.Post.Title) %></h1>
|
||||
<div class="metadata">
|
||||
<div class="posted">Posted by <%=Html.Encode(Model.Post.Creator.UserName) %> <%=Html.Published(Model.Post) %></div>
|
||||
<%if (Model.Post.Creator != null) {%>
|
||||
<div class="posted">Posted by <%=Html.Encode(Model.Post.Creator.UserName)%> <%=Html.Published(Model.Post)%></div>
|
||||
<%}%>
|
||||
<div><a href="<%=Url.BlogPostEdit(Model.Blog.Slug, Model.Post.Slug) %>">(edit)</a></div>
|
||||
</div>
|
||||
|
||||
<%foreach (var display in Model.Displays) { %>
|
||||
<%foreach (var display in Model.ItemView.Displays) { %>
|
||||
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
|
||||
<%} %>
|
||||
</asp:Content>
|
||||
@@ -2,7 +2,7 @@
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Comments.Models {
|
||||
public class HasCommentsProvider : ContentProvider {
|
||||
@@ -20,21 +20,21 @@ namespace Orchard.Comments.Models {
|
||||
if (context.ContentItem.Has<HasComments>() == false) {
|
||||
return;
|
||||
}
|
||||
context.Displays.Add(new ModelTemplate(context.ContentItem.Get<HasComments>()));
|
||||
context.AddDisplay(new TemplateViewModel(context.ContentItem.Get<HasComments>()));
|
||||
}
|
||||
|
||||
protected override void GetEditors(GetEditorsContext context) {
|
||||
if (context.ContentItem.Has<HasComments>() == false) {
|
||||
return;
|
||||
}
|
||||
context.Editors.Add(new ModelTemplate(context.ContentItem.Get<HasComments>()));
|
||||
context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasComments>()));
|
||||
}
|
||||
|
||||
protected override void UpdateEditors(UpdateContentContext context) {
|
||||
if (context.ContentItem.Has<HasComments>() == false) {
|
||||
return;
|
||||
}
|
||||
context.Editors.Add(new ModelTemplate(context.ContentItem.Get<HasComments>()));
|
||||
context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasComments>()));
|
||||
}
|
||||
|
||||
protected override void Loading(LoadContentContext context) {
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace Orchard.DevTools.Controllers {
|
||||
.Select(x => x.GetType())
|
||||
.SelectMany(x => AllTypes(x))
|
||||
.Distinct();
|
||||
model.Displays = _contentManager.GetDisplays(model.Item);
|
||||
model.Editors = _contentManager.GetEditors(model.Item);
|
||||
model.DisplayView = _contentManager.GetDisplays(model.Item, null, null);
|
||||
model.EditorView = _contentManager.GetEditors(model.Item, null);
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.DevTools.Models {
|
||||
public class DebugLinkProvider : ContentProvider {
|
||||
protected override void GetDisplays(GetDisplaysContext context) {
|
||||
context.Displays.Add(new ModelTemplate(new ShowDebugLink { ContentItem = context.ContentItem }) { Position = "10" });
|
||||
context.AddDisplay(new TemplateViewModel(new ShowDebugLink { ContentItem = context.ContentItem }) { Position = "10" });
|
||||
}
|
||||
protected override void GetEditors(GetEditorsContext context) {
|
||||
context.Editors.Add(new ModelTemplate(new ShowDebugLink { ContentItem = context.ContentItem }) { Position = "10" });
|
||||
context.AddEditor(new TemplateViewModel(new ShowDebugLink { ContentItem = context.ContentItem }) { Position = "10" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Records;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.DevTools.ViewModels {
|
||||
public class ContentDetailsViewModel : BaseViewModel {
|
||||
@@ -13,9 +13,13 @@ namespace Orchard.DevTools.ViewModels {
|
||||
|
||||
public IEnumerable<Type> PartTypes { get; set; }
|
||||
|
||||
public IEnumerable<ModelTemplate> Displays { get; set; }
|
||||
public ItemDisplayViewModel DisplayView { get; set; }
|
||||
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
public ItemEditorViewModel EditorView { get; set; }
|
||||
|
||||
public IEnumerable<TemplateViewModel> Displays { get { return DisplayView.Displays; } }
|
||||
|
||||
public IEnumerable<TemplateViewModel> Editors { get { return EditorView.Editors; } }
|
||||
|
||||
public object Locate(Type type) {
|
||||
return Item.ContentItem.Get(type);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.Records;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Media.Models {
|
||||
public class MediaSettings : ContentPart<MediaSettingsRecord> {
|
||||
@@ -28,7 +28,7 @@ namespace Orchard.Media.Models {
|
||||
if (model == null)
|
||||
return;
|
||||
|
||||
context.Editors.Add(new ModelTemplate(model.Record, "MediaSettings"));
|
||||
context.AddEditor(new TemplateViewModel(model.Record, "MediaSettings"));
|
||||
}
|
||||
|
||||
protected override void UpdateEditors(UpdateContentContext context) {
|
||||
@@ -37,7 +37,7 @@ namespace Orchard.Media.Models {
|
||||
return;
|
||||
|
||||
context.Updater.TryUpdateModel(model.Record, "MediaSettings", null, null);
|
||||
context.Editors.Add(new ModelTemplate(model.Record, "MediaSettings"));
|
||||
context.AddEditor(new TemplateViewModel(model.Record, "MediaSettings"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Roles.Models.NoRecord;
|
||||
using Orchard.Roles.Records;
|
||||
using Orchard.Roles.Services;
|
||||
using Orchard.Roles.ViewModels;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Roles.Models {
|
||||
@@ -46,7 +46,7 @@ namespace Orchard.Roles.Models {
|
||||
Roles = roles.ToList(),
|
||||
};
|
||||
|
||||
context.Editors.Add(new ModelTemplate(viewModel, "UserRoles"));
|
||||
context.AddEditor(new TemplateViewModel(viewModel, "UserRoles"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace Orchard.Roles.Models {
|
||||
}
|
||||
|
||||
}
|
||||
context.Editors.Add(new ModelTemplate(viewModel, "UserRoles"));
|
||||
context.AddEditor(new TemplateViewModel(viewModel, "UserRoles"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Orchard.Sandbox.Controllers {
|
||||
var page = _contentManager.Get<SandboxPage>(id);
|
||||
var model = new PageShowViewModel {
|
||||
Page = page,
|
||||
Displays = _contentManager.GetDisplays(page)
|
||||
ItemView = _contentManager.GetDisplays(page, null, null)
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ namespace Orchard.Sandbox.Controllers {
|
||||
}
|
||||
|
||||
var model = new PageEditViewModel { Page = _contentManager.Get<SandboxPage>(id) };
|
||||
model.Editors = _contentManager.GetEditors(model.Page);
|
||||
model.ItemView = _contentManager.GetEditors(model.Page, null);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Orchard.Sandbox.Controllers {
|
||||
}
|
||||
|
||||
var model = new PageEditViewModel { Page = _contentManager.Get<SandboxPage>(id) };
|
||||
model.Editors = _contentManager.UpdateEditors(model.Page, this);
|
||||
model.ItemView = _contentManager.UpdateEditors(model.Page, null, this);
|
||||
if (!TryUpdateModel(model, input.ToValueProvider()))
|
||||
return View(model);
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Sandbox.Models;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Sandbox.ViewModels {
|
||||
public class PageEditViewModel : BaseViewModel {
|
||||
public SandboxPage Page { get; set; }
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Sandbox.Models;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Sandbox.ViewModels {
|
||||
public class PageShowViewModel : BaseViewModel {
|
||||
public SandboxPage Page { get; set; }
|
||||
public IEnumerable<ModelTemplate> Displays { get; set; }
|
||||
public ItemDisplayViewModel ItemView { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<ul>
|
||||
<li>
|
||||
<%=Html.LabelFor(x => x.Page.Record.Name)%><%=Html.EditorFor(x => x.Page.Record.Name)%></li>
|
||||
<%foreach (var x in Model.Editors) { %>
|
||||
<%foreach (var x in Model.ItemView.Editors) { %>
|
||||
<%=Html.EditorFor(m=>x.Model, x.TemplateName, x.Prefix) %>
|
||||
<%} %>
|
||||
<li>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<div id="main">
|
||||
<% Html.RenderPartial("Messages", Model.Messages); %>
|
||||
<h1><%=Html.Encode(Model.Page.Record.Name) %></h1>
|
||||
<%foreach (var display in Model.Displays) { %>
|
||||
<%foreach (var display in Model.ItemView.Displays) { %>
|
||||
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
|
||||
<%} %>
|
||||
<p>
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Linq;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Tags.Models {
|
||||
public class HasTags : ContentPart {
|
||||
@@ -27,8 +27,8 @@ namespace Orchard.Tags.Models {
|
||||
Filters.Add(new ActivatingFilter<HasTags>("blogpost"));
|
||||
|
||||
OnGetDisplays<HasTags>((context, hasTags) => {
|
||||
context.Displays.Add(new ModelTemplate(hasTags) { Position = "2", TemplateName = "HasTagsList" });
|
||||
context.Displays.Add(new ModelTemplate(hasTags) { Position = "5" });
|
||||
context.AddDisplay(new TemplateViewModel(hasTags) { Position = "2", TemplateName = "HasTagsList" });
|
||||
context.AddDisplay(new TemplateViewModel(hasTags) { Position = "5" });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,14 +36,14 @@ namespace Orchard.Tags.Models {
|
||||
if (context.ContentItem.Has<HasTags>() == false) {
|
||||
return;
|
||||
}
|
||||
context.Editors.Add(new ModelTemplate(context.ContentItem.Get<HasTags>()));
|
||||
context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasTags>()));
|
||||
}
|
||||
|
||||
protected override void UpdateEditors(UpdateContentContext context) {
|
||||
if (context.ContentItem.Has<HasTags>() == false) {
|
||||
return;
|
||||
}
|
||||
context.Editors.Add(new ModelTemplate(context.ContentItem.Get<HasTags>()));
|
||||
context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasTags>()));
|
||||
}
|
||||
|
||||
protected override void Loading(LoadContentContext context) {
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Orchard.Users.Controllers {
|
||||
public ActionResult Create() {
|
||||
var user = _contentManager.New("user");
|
||||
var model = new UserCreateViewModel {
|
||||
Editors = _contentManager.GetEditors(user)
|
||||
ItemView = _contentManager.GetEditors(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.Editors = _contentManager.UpdateEditors(_contentManager.New("user"), this);
|
||||
model.ItemView = _contentManager.UpdateEditors(_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.Editors = _contentManager.UpdateEditors(user, this);
|
||||
model.ItemView = _contentManager.UpdateEditors(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.Editors = _contentManager.GetEditors(model.User.ContentItem);
|
||||
model.ItemView = _contentManager.GetEditors(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.Editors = _contentManager.UpdateEditors(model.User.ContentItem, this);
|
||||
model.ItemView = _contentManager.UpdateEditors(model.User.ContentItem, null, this);
|
||||
|
||||
if (!TryUpdateModel(model, input.ToValueProvider())) {
|
||||
return View(model);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Users.ViewModels {
|
||||
public class UserCreateViewModel : AdminViewModel {
|
||||
@@ -17,7 +18,6 @@ namespace Orchard.Users.ViewModels {
|
||||
[Required, DataType(DataType.Password)]
|
||||
public string ConfirmPassword { get; set; }
|
||||
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Users.Models;
|
||||
|
||||
namespace Orchard.Users.ViewModels {
|
||||
public class UserEditViewModel : AdminViewModel {
|
||||
public User User { get; set; }
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id {
|
||||
@@ -27,5 +29,6 @@ namespace Orchard.Users.ViewModels {
|
||||
get { return User.As<User>().Record.Email; }
|
||||
set { User.As<User>().Record.Email = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,6 @@
|
||||
<%=Html.EditorFor(m=>m.ConfirmPassword, "inputPasswordLarge") %>
|
||||
</ol>
|
||||
|
||||
<% foreach(var e in Model.Editors) {%>
|
||||
<% foreach(var e in Model.ItemView.Editors) {%>
|
||||
<%=Html.EditorFor(m => e.Model, e.TemplateName, e.Prefix)%>
|
||||
<%} %>
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
<%=Html.EditorFor(m=>m.Email, "inputTextLarge") %>
|
||||
</ol>
|
||||
|
||||
<% foreach(var e in Model.Editors) {%>
|
||||
<% foreach(var e in Model.ItemView.Editors) {%>
|
||||
<%=Html.EditorFor(m => e.Model, e.TemplateName, e.Prefix)%>
|
||||
<%} %>
|
||||
|
||||
@@ -5,7 +5,7 @@ using Autofac;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.Records;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Models {
|
||||
@@ -136,34 +136,37 @@ namespace Orchard.Models {
|
||||
return context.Metadata;
|
||||
}
|
||||
|
||||
public IEnumerable<ModelTemplate> GetDisplays(IContent content) {
|
||||
public ItemDisplayViewModel GetDisplays(IContent content, string tabName, string displayType) {
|
||||
var context = new GetDisplaysContext(content);
|
||||
foreach (var driver in Drivers) {
|
||||
driver.GetDisplays(context);
|
||||
}
|
||||
return OrderTemplates(context.Displays);
|
||||
context.ItemView.Displays = OrderTemplates(context.ItemView.Displays);
|
||||
return context.ItemView;
|
||||
}
|
||||
|
||||
public IEnumerable<ModelTemplate> GetEditors(IContent content) {
|
||||
public ItemEditorViewModel GetEditors(IContent content, string tabName) {
|
||||
var context = new GetEditorsContext(content);
|
||||
foreach (var driver in Drivers) {
|
||||
driver.GetEditors(context);
|
||||
}
|
||||
return OrderTemplates(context.Editors);
|
||||
context.ItemView.Editors = OrderTemplates(context.ItemView.Editors);
|
||||
return context.ItemView;
|
||||
}
|
||||
|
||||
public IEnumerable<ModelTemplate> UpdateEditors(IContent content, IUpdateModel updater) {
|
||||
public ItemEditorViewModel UpdateEditors(IContent content, string tabName, IUpdateModel updater) {
|
||||
|
||||
var context = new UpdateContentContext(content, updater);
|
||||
foreach (var driver in Drivers) {
|
||||
driver.UpdateEditors(context);
|
||||
}
|
||||
return OrderTemplates(context.Editors);
|
||||
context.ItemView.Editors = OrderTemplates(context.ItemView.Editors);
|
||||
return context.ItemView;
|
||||
}
|
||||
|
||||
private static IEnumerable<ModelTemplate> OrderTemplates(IEnumerable<ModelTemplate> templates) {
|
||||
private static IEnumerable<TemplateViewModel> OrderTemplates(IEnumerable<TemplateViewModel> templates) {
|
||||
var comparer = new PositionComparer();
|
||||
return templates.OrderBy(x => x.Position ?? "6", comparer);
|
||||
|
||||
return templates.OrderBy(x => (x.ZoneName ?? "*") + "." + (x.Position ?? "5"), comparer);
|
||||
}
|
||||
|
||||
public IContentQuery<ContentItem> Query() {
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.UI.Models;
|
||||
using System.Linq;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public class GetDisplaysContext {
|
||||
public GetDisplaysContext(IContent content) {
|
||||
ContentItem = content.ContentItem;
|
||||
Displays = new List<ModelTemplate>();
|
||||
ItemView = new ItemDisplayViewModel {
|
||||
ContentItem = ContentItem,
|
||||
Displays = Enumerable.Empty<TemplateViewModel>(),
|
||||
};
|
||||
}
|
||||
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public IList<ModelTemplate> Displays { get; set; }
|
||||
public ItemDisplayViewModel ItemView { get; set; }
|
||||
|
||||
public void AddDisplay(TemplateViewModel display) {
|
||||
ItemView.Displays = ItemView.Displays.Concat(new[] { display });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.UI.Models;
|
||||
using System.Linq;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public class GetEditorsContext {
|
||||
public GetEditorsContext(IContent content) {
|
||||
ContentItem = content.ContentItem;
|
||||
Editors= new List<ModelTemplate>();
|
||||
ItemView = new ItemEditorViewModel {
|
||||
ContentItem = ContentItem,
|
||||
Editors = Enumerable.Empty<TemplateViewModel>(),
|
||||
};
|
||||
}
|
||||
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public IList<ModelTemplate> Editors { get; set; }
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
|
||||
public void AddEditor(TemplateViewModel editor) {
|
||||
ItemView.Editors = ItemView.Editors.Concat(new[] { editor });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using Orchard.Models.Records;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public class TemplateFilterForRecord<TRecord> : TemplateFilterBase<ContentPart<TRecord>> where TRecord : ContentPartRecord, new() {
|
||||
@@ -10,12 +10,12 @@ namespace Orchard.Models.Driver {
|
||||
}
|
||||
|
||||
protected override void GetEditors(GetEditorsContext context, ContentPart<TRecord> part) {
|
||||
context.Editors.Add(new ModelTemplate(part.Record, _prefix));
|
||||
context.AddEditor(new TemplateViewModel(part.Record, _prefix));
|
||||
}
|
||||
|
||||
protected override void UpdateEditors(UpdateContentContext context, ContentPart<TRecord> part) {
|
||||
context.Updater.TryUpdateModel(part.Record, _prefix, null, null);
|
||||
context.Editors.Add(new ModelTemplate(part.Record, _prefix));
|
||||
context.AddEditor(new TemplateViewModel(part.Record, _prefix));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.Records;
|
||||
using Orchard.UI.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Models {
|
||||
public interface IContentManager : IDependency {
|
||||
@@ -15,8 +15,8 @@ namespace Orchard.Models {
|
||||
IContentQuery<ContentItem> Query();
|
||||
|
||||
ContentItemMetadata GetItemMetadata(IContent contentItem);
|
||||
IEnumerable<ModelTemplate> GetDisplays(IContent contentItem);
|
||||
IEnumerable<ModelTemplate> GetEditors(IContent contentItem);
|
||||
IEnumerable<ModelTemplate> UpdateEditors(IContent contentItem, IUpdateModel updater);
|
||||
ItemDisplayViewModel GetDisplays(IContent contentItem, string tabName, string displayType);
|
||||
ItemEditorViewModel GetEditors(IContent contentItem, string tabName);
|
||||
ItemEditorViewModel UpdateEditors(IContent contentItem, string tabName, IUpdateModel updater);
|
||||
}
|
||||
}
|
||||
|
||||
9
src/Orchard/Models/ViewModels/ItemDisplayViewModel.cs
Normal file
9
src/Orchard/Models/ViewModels/ItemDisplayViewModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Models.ViewModels {
|
||||
public class ItemDisplayViewModel {
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public string TemplateName { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Displays { get; set; }
|
||||
}
|
||||
}
|
||||
9
src/Orchard/Models/ViewModels/ItemEditorViewModel.cs
Normal file
9
src/Orchard/Models/ViewModels/ItemEditorViewModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Models.ViewModels {
|
||||
public class ItemEditorViewModel {
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public string TemplateName { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Editors { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
namespace Orchard.UI.Models {
|
||||
public class ModelTemplate {
|
||||
public ModelTemplate(object model)
|
||||
namespace Orchard.Models.ViewModels {
|
||||
public class TemplateViewModel {
|
||||
public TemplateViewModel(object model)
|
||||
: this(model, string.Empty) {
|
||||
}
|
||||
public ModelTemplate(object model, string prefix) {
|
||||
public TemplateViewModel(object model, string prefix) {
|
||||
Model = model;
|
||||
Prefix = prefix;
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
public string Prefix { get; set; }
|
||||
public string TemplateName { get; set; }
|
||||
|
||||
public string ZoneName { get; set; }
|
||||
public string Position { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,7 @@
|
||||
<Compile Include="Models\Records\ContentTypeRecord.cs" />
|
||||
<Compile Include="Models\Records\ContentItemRecord.cs" />
|
||||
<Compile Include="Models\Driver\UpdateContentContext.cs" />
|
||||
<Compile Include="Models\ViewModels\ContentViewModel.cs" />
|
||||
<Compile Include="Mvc\Html\ContentItemExtensions.cs" />
|
||||
<Compile Include="Mvc\MvcModule.cs" />
|
||||
<Compile Include="Mvc\Html\HtmlHelperExtensions.cs" />
|
||||
@@ -209,7 +210,6 @@
|
||||
<Compile Include="Tasks\IBackgroundTask.cs" />
|
||||
<Compile Include="Tasks\SweepGenerator.cs" />
|
||||
<Compile Include="UI\Menus\AdminMenuFilter.cs" />
|
||||
<Compile Include="UI\Models\ModelTemplate.cs" />
|
||||
<Compile Include="UI\Navigation\NavigationBuilder.cs" />
|
||||
<Compile Include="UI\Navigation\INavigationProvider.cs" />
|
||||
<Compile Include="UI\Navigation\MenuItem.cs" />
|
||||
@@ -245,6 +245,9 @@
|
||||
<ItemGroup>
|
||||
<None Include="Models\Diagram.cd" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="UI\Models\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
Reference in New Issue
Block a user