mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-16 08:37:02 +08:00
Changing item editor model from templates array to zones paradigm
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044983
This commit is contained in:
parent
0329e836bc
commit
4db45c2050
@ -12,6 +12,7 @@ using Orchard.ContentManagement;
|
|||||||
using Orchard.ContentManagement.Drivers;
|
using Orchard.ContentManagement.Drivers;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
using Orchard.ContentManagement.ViewModels;
|
using Orchard.ContentManagement.ViewModels;
|
||||||
|
using Orchard.UI.Zones;
|
||||||
|
|
||||||
namespace Orchard.Tests.ContentManagement {
|
namespace Orchard.Tests.ContentManagement {
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
@ -60,10 +61,11 @@ namespace Orchard.Tests.ContentManagement {
|
|||||||
item.Weld(new StubPart { Foo = new[] { "a", "b", "c" } });
|
item.Weld(new StubPart { Foo = new[] { "a", "b", "c" } });
|
||||||
|
|
||||||
var ctx = new BuildDisplayModelContext(new ItemDisplayModel(item), "");
|
var ctx = new BuildDisplayModelContext(new ItemDisplayModel(item), "");
|
||||||
Assert.That(ctx.DisplayModel.Displays.Count(), Is.EqualTo(0));
|
Assert.That(ctx.DisplayModel.Zones.Count(), Is.EqualTo(0));
|
||||||
contentHandler.BuildDisplayModel(ctx);
|
contentHandler.BuildDisplayModel(ctx);
|
||||||
Assert.That(ctx.DisplayModel.Displays.Count(), Is.EqualTo(1));
|
Assert.That(ctx.DisplayModel.Zones.Count(), Is.EqualTo(1));
|
||||||
Assert.That(ctx.DisplayModel.Displays.Single().Prefix, Is.EqualTo("Stub"));
|
Assert.That(ctx.DisplayModel.Zones.Single().Key, Is.EqualTo("topmeta"));
|
||||||
|
Assert.That(ctx.DisplayModel.Zones.Single().Value.Items.OfType<PartDisplayZoneItem>().Single().Prefix, Is.EqualTo("Stub"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,13 +21,13 @@ namespace Orchard.Core.Common.Providers {
|
|||||||
|
|
||||||
OnGetEditorViewModel<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 = "primary" });
|
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "primary", Position = "5" });
|
||||||
});
|
});
|
||||||
|
|
||||||
OnUpdateEditorViewModel<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 = "primary" });
|
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "primary", Position = "5" });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ namespace Orchard.Core.Common.Providers {
|
|||||||
if (instance.Owner != null)
|
if (instance.Owner != null)
|
||||||
viewModel.Owner = instance.Owner.UserName;
|
viewModel.Owner = instance.Owner.UserName;
|
||||||
|
|
||||||
context.AddEditor(new TemplateViewModel(viewModel, "CommonAspect") { TemplateName = "Parts/Common.Owner", ZoneName = "primary", Position = "999" });
|
context.AddEditor(new TemplateViewModel(viewModel, "CommonAspect") { TemplateName = "Parts/Common.Owner", ZoneName = "primary", Position = "9" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ namespace Orchard.Core.Common.Providers {
|
|||||||
instance.Owner = newOwner;
|
instance.Owner = newOwner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context.AddEditor(new TemplateViewModel(viewModel, "CommonAspect") { TemplateName = "Parts/Common.Owner", ZoneName = "primary", Position = "999" });
|
context.AddEditor(new TemplateViewModel(viewModel, "CommonAspect") { TemplateName = "Parts/Common.Owner", ZoneName = "primary", Position = "9" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -76,6 +76,7 @@
|
|||||||
<Compile Include="Common\ViewModels\BodyEditorViewModel.cs" />
|
<Compile Include="Common\ViewModels\BodyEditorViewModel.cs" />
|
||||||
<Compile Include="Common\ViewModels\OwnerEditorViewModel.cs" />
|
<Compile Include="Common\ViewModels\OwnerEditorViewModel.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Settings\Controllers\SiteSettingsDriver.cs" />
|
||||||
<Compile Include="Themes\Services\AdminThemeSelector.cs" />
|
<Compile Include="Themes\Services\AdminThemeSelector.cs" />
|
||||||
<Compile Include="Themes\Services\SafeModeThemeSelector.cs" />
|
<Compile Include="Themes\Services\SafeModeThemeSelector.cs" />
|
||||||
<Compile Include="Settings\AdminMenu.cs" />
|
<Compile Include="Settings\AdminMenu.cs" />
|
||||||
@ -112,7 +113,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Common\Package.txt" />
|
<Content Include="Common\Package.txt" />
|
||||||
<Content Include="Settings\Package.txt" />
|
<Content Include="Settings\Package.txt" />
|
||||||
<Content Include="Settings\Views\Admin\Index.aspx" />
|
<Content Include="Settings\Views\Admin\Index.ascx" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
<Content Include="XmlRpc\Package.txt" />
|
<Content Include="XmlRpc\Package.txt" />
|
||||||
<Content Include="XmlRpc\Views\Home\Index.aspx" />
|
<Content Include="XmlRpc\Views\Home\Index.aspx" />
|
||||||
@ -138,6 +139,7 @@
|
|||||||
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.ascx" />
|
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.ascx" />
|
||||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.Body.ascx" />
|
<Content Include="Common\Views\EditorTemplates\Parts\Common.Body.ascx" />
|
||||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.Owner.ascx" />
|
<Content Include="Common\Views\EditorTemplates\Parts\Common.Owner.ascx" />
|
||||||
|
<Content Include="Settings\Views\EditorTemplates\Items\Settings.Site.ascx" />
|
||||||
<Content Include="Themes\Styles\site.css" />
|
<Content Include="Themes\Styles\site.css" />
|
||||||
<Content Include="Themes\Views\Admin\Install.aspx" />
|
<Content Include="Themes\Views\Admin\Install.aspx" />
|
||||||
<Content Include="Themes\Views\header.ascx" />
|
<Content Include="Themes\Views\header.ascx" />
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.Core.Settings.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Settings.Controllers {
|
||||||
|
public class SiteSettingsDriver : ItemDriver<SiteSettings> {
|
||||||
|
protected override ContentType GetContentType() {
|
||||||
|
return SiteSettings.ContentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(SiteSettings part) {
|
||||||
|
return ItemTemplate("Items/Settings.Site");
|
||||||
|
}
|
||||||
|
protected override DriverResult Editor(SiteSettings part, IUpdateModel updater) {
|
||||||
|
return ItemTemplate("Items/Settings.Site");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,10 +7,6 @@ using Orchard.ContentManagement.Handlers;
|
|||||||
namespace Orchard.Core.Settings.Models {
|
namespace Orchard.Core.Settings.Models {
|
||||||
public class SiteSettingsHandler : ContentHandler {
|
public class SiteSettingsHandler : ContentHandler {
|
||||||
|
|
||||||
public override IEnumerable<ContentType> GetContentTypes() {
|
|
||||||
return new[] {SiteSettings.ContentType};
|
|
||||||
}
|
|
||||||
|
|
||||||
public SiteSettingsHandler(IRepository<SiteSettingsRecord> repository){
|
public SiteSettingsHandler(IRepository<SiteSettingsRecord> repository){
|
||||||
Filters.Add(new ActivatingFilter<SiteSettings>("site"));
|
Filters.Add(new ActivatingFilter<SiteSettings>("site"));
|
||||||
Filters.Add(new StorageFilter<SiteSettingsRecord>(repository));
|
Filters.Add(new StorageFilter<SiteSettingsRecord>(repository));
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.Core.Settings.ViewModels.SettingsIndexViewModel>" %>
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Core.Settings.ViewModels.SettingsIndexViewModel>" %>
|
||||||
<h2><%=Html.TitleForPage("Edit Settings")%></h2>
|
|
||||||
|
<h2>
|
||||||
|
<%=Html.TitleForPage("Edit Settings")%></h2>
|
||||||
<%using (Html.BeginFormAntiForgeryPost()) { %>
|
<%using (Html.BeginFormAntiForgeryPost()) { %>
|
||||||
<%= Html.ValidationSummary() %>
|
<%= Html.ValidationSummary() %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
@ -21,10 +23,9 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
<%=Html.EditorFor(s=>s.Id) %>
|
<%=Html.EditorFor(s=>s.Id) %>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% foreach (var e in Model.EditorModel.Editors) {
|
|
||||||
var editor = e;
|
<%= Html.EditorForItem(Model.EditorModel) %>
|
||||||
%><%=Html.EditorFor(m => editor.Model, editor.TemplateName, editor.Prefix)%>
|
|
||||||
<% } %>
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<input class="button" type="submit" value="Save" />
|
<input class="button" type="submit" value="Save" />
|
||||||
</fieldset>
|
</fieldset>
|
@ -0,0 +1,5 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorModel<SiteSettings>>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Core.Settings.Models"%>
|
||||||
|
<%@ Import Namespace="Orchard.ContentManagement.ViewModels"%>
|
||||||
|
<% Html.Zone("primary"); %>
|
||||||
|
<% Html.ZonesAny(); %>
|
@ -2,5 +2,5 @@
|
|||||||
<%@ Import Namespace="Orchard.ContentManagement.ViewModels"%>
|
<%@ Import Namespace="Orchard.ContentManagement.ViewModels"%>
|
||||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||||
<% Html.AddTitleParts(Model.Item.Name); %>
|
<% Html.AddTitleParts(Model.Item.Name); %>
|
||||||
<%=Html.EditorZone("primary") %>
|
<% Html.Zone("primary"); %>
|
||||||
<%=Html.EditorZonesAny() %>
|
<% Html.ZonesAny(); %>
|
@ -4,11 +4,11 @@
|
|||||||
<% Html.AddTitleParts(Model.Item.Title); %>
|
<% Html.AddTitleParts(Model.Item.Title); %>
|
||||||
<div class="sections">
|
<div class="sections">
|
||||||
<div class="primary">
|
<div class="primary">
|
||||||
<%=Html.EditorZone("primary") %>
|
<% Html.Zone("primary"); %>
|
||||||
<%=Html.EditorZonesExcept("secondary") %>
|
<% Html.ZonesExcept("secondary"); %>
|
||||||
</div>
|
</div>
|
||||||
<div class="secondary">
|
<div class="secondary">
|
||||||
<%=Html.EditorZone("secondary")%>
|
<% Html.Zone("secondary");%>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<input class="button" type="submit" name="submit.Save" value="Save"/>
|
<input class="button" type="submit" name="submit.Save" value="Save"/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -33,7 +33,20 @@ namespace Orchard.DevTools.ViewModels {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<TemplateViewModel> Editors { get { return EditorModel.Editors; } }
|
public IEnumerable<TemplateViewModel> Editors {
|
||||||
|
get {
|
||||||
|
return EditorModel.Zones
|
||||||
|
.SelectMany(z => z.Value.Items
|
||||||
|
.OfType<PartEditorZoneItem>()
|
||||||
|
.Select(x => new { ZoneName = z.Key, Item = x }))
|
||||||
|
.Select(x => new TemplateViewModel(x.Item.Model, x.Item.Prefix) {
|
||||||
|
Model = x.Item.Model,
|
||||||
|
TemplateName = x.Item.TemplateName,
|
||||||
|
WasUsed = x.Item.WasExecuted,
|
||||||
|
ZoneName = x.ZoneName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public object Locate(Type type) {
|
public object Locate(Type type) {
|
||||||
return Item.ContentItem.Get(type);
|
return Item.ContentItem.Get(type);
|
||||||
|
@ -24,11 +24,11 @@ namespace Orchard.Roles.Controllers {
|
|||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[AcceptVerbs(HttpVerbs.Post)]
|
[HttpPost, ActionName("Index")]
|
||||||
public ActionResult Index(FormCollection input) {
|
public ActionResult IndexPOST() {
|
||||||
try {
|
try {
|
||||||
foreach (string key in input.Keys) {
|
foreach (string key in Request.Form.Keys) {
|
||||||
if (key.StartsWith("Checkbox.") && input[key] == "true") {
|
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||||
int roleId = Convert.ToInt32(key.Substring("Checkbox.".Length));
|
int roleId = Convert.ToInt32(key.Substring("Checkbox.".Length));
|
||||||
_roleService.DeleteRole(roleId);
|
_roleService.DeleteRole(roleId);
|
||||||
}
|
}
|
||||||
@ -46,14 +46,14 @@ namespace Orchard.Roles.Controllers {
|
|||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[AcceptVerbs(HttpVerbs.Post)]
|
[HttpPost, ActionName("Create")]
|
||||||
public ActionResult Create(FormCollection input) {
|
public ActionResult CreatePOST() {
|
||||||
var viewModel = new RoleCreateViewModel();
|
var viewModel = new RoleCreateViewModel();
|
||||||
try {
|
try {
|
||||||
UpdateModel(viewModel, input.ToValueProvider());
|
UpdateModel(viewModel);
|
||||||
_roleService.CreateRole(viewModel.Name);
|
_roleService.CreateRole(viewModel.Name);
|
||||||
foreach (string key in input.Keys) {
|
foreach (string key in Request.Form.Keys) {
|
||||||
if (key.StartsWith("Checkbox.") && input[key] == "true") {
|
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||||
string permissionName = key.Substring("Checkbox.".Length);
|
string permissionName = key.Substring("Checkbox.".Length);
|
||||||
_roleService.CreatePermissionForRole(viewModel.Name,
|
_roleService.CreatePermissionForRole(viewModel.Name,
|
||||||
permissionName);
|
permissionName);
|
||||||
@ -80,16 +80,16 @@ namespace Orchard.Roles.Controllers {
|
|||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[AcceptVerbs(HttpVerbs.Post)]
|
[HttpPost, ActionName("Edit")]
|
||||||
public ActionResult Edit(FormCollection input) {
|
public ActionResult EditPOST() {
|
||||||
var viewModel = new RoleEditViewModel();
|
var viewModel = new RoleEditViewModel();
|
||||||
try {
|
try {
|
||||||
UpdateModel(viewModel, input.ToValueProvider());
|
UpdateModel(viewModel);
|
||||||
// Save
|
// Save
|
||||||
if (!String.IsNullOrEmpty(HttpContext.Request.Form["submit.Save"])) {
|
if (!String.IsNullOrEmpty(HttpContext.Request.Form["submit.Save"])) {
|
||||||
List<string> rolePermissions = new List<string>();
|
List<string> rolePermissions = new List<string>();
|
||||||
foreach (string key in input.Keys) {
|
foreach (string key in Request.Form.Keys) {
|
||||||
if (key.StartsWith("Checkbox.") && input[key] == "true") {
|
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||||
string permissionName = key.Substring("Checkbox.".Length);
|
string permissionName = key.Substring("Checkbox.".Length);
|
||||||
rolePermissions.Add(permissionName);
|
rolePermissions.Add(permissionName);
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,6 @@ using Orchard.ContentManagement.Records;
|
|||||||
namespace Orchard.Sandbox.Models {
|
namespace Orchard.Sandbox.Models {
|
||||||
public class SandboxSettingsRecord : ContentPartRecord {
|
public class SandboxSettingsRecord : ContentPartRecord {
|
||||||
public virtual bool AllowAnonymousEdits { get; set; }
|
public virtual bool AllowAnonymousEdits { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public virtual string NameOfThemeWhenEditingPage { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
<%=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()%>
|
<% Html.ZonesAny(); %>
|
||||||
|
@ -5,8 +5,4 @@
|
|||||||
<%= Html.EditorFor(x=>x.AllowAnonymousEdits) %>
|
<%= Html.EditorFor(x=>x.AllowAnonymousEdits) %>
|
||||||
<%= Html.ValidationMessage("AllowAnonymousEdits", "*")%>
|
<%= Html.ValidationMessage("AllowAnonymousEdits", "*")%>
|
||||||
<br />
|
<br />
|
||||||
<%= Html.LabelFor(x => x.NameOfThemeWhenEditingPage)%>
|
|
||||||
<%= Html.EditorFor(x=>x.NameOfThemeWhenEditingPage) %>
|
|
||||||
<%= Html.ValidationMessage("NameOfThemeWhenEditingPage", "*")%>
|
|
||||||
<br />
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorModel<User>>" %>
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorModel<User>>" %>
|
||||||
<%@ Import Namespace="Orchard.ContentManagement.ViewModels" %>
|
<%@ Import Namespace="Orchard.ContentManagement.ViewModels" %>
|
||||||
<%@ Import Namespace="Orchard.Users.Models" %>
|
<%@ Import Namespace="Orchard.Users.Models" %>
|
||||||
<%=Html.EditorZonesAny() %>
|
<% Html.ZonesAny(); %>
|
||||||
|
@ -293,39 +293,31 @@ namespace Orchard.ContentManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemDisplayModel<TContentPart> BuildDisplayModel<TContentPart>(TContentPart content, string displayType) where TContentPart : IContent {
|
public ItemDisplayModel<TContentPart> BuildDisplayModel<TContentPart>(TContentPart content, string displayType) where TContentPart : IContent {
|
||||||
var itemView = new ItemDisplayModel<TContentPart> { Item = content };
|
var displayModel = new ItemDisplayModel<TContentPart>(content);
|
||||||
var context = new BuildDisplayModelContext(itemView, displayType);
|
var context = new BuildDisplayModelContext(displayModel, displayType);
|
||||||
foreach (var handler in Handlers) {
|
foreach (var handler in Handlers) {
|
||||||
handler.BuildDisplayModel(context);
|
handler.BuildDisplayModel(context);
|
||||||
}
|
}
|
||||||
return itemView;
|
return displayModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemEditorModel<TContentPart> BuildEditorModel<TContentPart>(TContentPart content) where TContentPart : IContent {
|
public ItemEditorModel<TContentPart> BuildEditorModel<TContentPart>(TContentPart content) where TContentPart : IContent {
|
||||||
var itemView = new ItemEditorModel<TContentPart> { Item = content, Editors = Enumerable.Empty<TemplateViewModel>() };
|
var editorModel = new ItemEditorModel<TContentPart>(content);
|
||||||
var context = new BuildEditorModelContext(itemView);
|
var context = new BuildEditorModelContext(editorModel);
|
||||||
foreach (var handler in Handlers) {
|
foreach (var handler in Handlers) {
|
||||||
handler.BuildEditorModel(context);
|
handler.BuildEditorModel(context);
|
||||||
}
|
}
|
||||||
context.EditorModel.Editors = OrderTemplates(context.EditorModel.Editors);
|
return editorModel;
|
||||||
return itemView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemEditorModel<TContentPart> UpdateEditorModel<TContentPart>(TContentPart content, IUpdateModel updater) where TContentPart : IContent {
|
public ItemEditorModel<TContentPart> UpdateEditorModel<TContentPart>(TContentPart content, IUpdateModel updater) where TContentPart : IContent {
|
||||||
var itemView = new ItemEditorModel<TContentPart> { Item = content, Editors = Enumerable.Empty<TemplateViewModel>() };
|
var editorModel = new ItemEditorModel<TContentPart>(content);
|
||||||
|
|
||||||
var context = new UpdateEditorModelContext(itemView, updater);
|
var context = new UpdateEditorModelContext(editorModel, updater);
|
||||||
foreach (var handler in Handlers) {
|
foreach (var handler in Handlers) {
|
||||||
handler.UpdateEditorModel(context);
|
handler.UpdateEditorModel(context);
|
||||||
}
|
}
|
||||||
context.EditorModel.Editors = OrderTemplates(context.EditorModel.Editors);
|
return editorModel;
|
||||||
return itemView;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<TemplateViewModel> OrderTemplates(IEnumerable<TemplateViewModel> templates) {
|
|
||||||
var comparer = new PositionComparer();
|
|
||||||
//TODO: rethink this comparison because it adds a requirement on naming zones.
|
|
||||||
return templates.OrderBy(x => (x.ZoneName ?? "*") + "." + (x.Position ?? "5"), comparer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IContentQuery<ContentItem> Query() {
|
public IContentQuery<ContentItem> Query() {
|
||||||
|
@ -21,11 +21,8 @@ namespace Orchard.ContentManagement.Drivers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Apply(BuildEditorModelContext context) {
|
public override void Apply(BuildEditorModelContext context) {
|
||||||
context.AddEditor(new TemplateViewModel(Model, Prefix) {
|
context.EditorModel.Zones.AddEditorPart(
|
||||||
TemplateName = TemplateName,
|
Zone + ":" + Position, Model, TemplateName, Prefix);
|
||||||
ZoneName = Zone,
|
|
||||||
Position = Position
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PartTemplateResult Location(string zone) {
|
public PartTemplateResult Location(string zone) {
|
||||||
|
@ -11,8 +11,14 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
public ContentItem ContentItem { get; set; }
|
public ContentItem ContentItem { get; set; }
|
||||||
public ItemEditorModel EditorModel { get; set; }
|
public ItemEditorModel EditorModel { get; set; }
|
||||||
|
|
||||||
public void AddEditor(TemplateViewModel editor) {
|
|
||||||
EditorModel.Editors = EditorModel.Editors.Concat(new[] { editor });
|
public void AddEditor(TemplateViewModel display) {
|
||||||
|
//TEMP: (loudej) transition code - from TemplateViewMode to ZoneItem
|
||||||
|
EditorModel.Zones.AddEditorPart(
|
||||||
|
display.ZoneName + ":" + display.Position,
|
||||||
|
display.Model,
|
||||||
|
display.TemplateName,
|
||||||
|
display.Prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,19 +5,26 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
public class TemplateFilterForRecord<TRecord> : TemplateFilterBase<ContentPart<TRecord>> where TRecord : ContentPartRecord, new() {
|
public class TemplateFilterForRecord<TRecord> : TemplateFilterBase<ContentPart<TRecord>> where TRecord : ContentPartRecord, new() {
|
||||||
private readonly string _prefix;
|
private readonly string _prefix;
|
||||||
private readonly string _templateName;
|
private readonly string _templateName;
|
||||||
|
private string _location;
|
||||||
|
|
||||||
public TemplateFilterForRecord(string prefix, string templateName) {
|
public TemplateFilterForRecord(string prefix, string templateName) {
|
||||||
_prefix = prefix;
|
_prefix = prefix;
|
||||||
_templateName = templateName;
|
_templateName = templateName;
|
||||||
|
_location = "primary";
|
||||||
|
}
|
||||||
|
|
||||||
|
public TemplateFilterForRecord<TRecord> Location(string location) {
|
||||||
|
_location = location;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void BuildEditorModel(BuildEditorModelContext context, ContentPart<TRecord> part) {
|
protected override void BuildEditorModel(BuildEditorModelContext context, ContentPart<TRecord> part) {
|
||||||
context.AddEditor(new TemplateViewModel(part.Record, _prefix) { TemplateName = _templateName });
|
context.EditorModel.Zones.AddEditorPart(_location, part.Record, _templateName, _prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateEditorModel(UpdateEditorModelContext context, ContentPart<TRecord> part) {
|
protected override void UpdateEditorModel(UpdateEditorModelContext 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) { TemplateName = _templateName });
|
context.EditorModel.Zones.AddEditorPart(_location, part.Record, _templateName, _prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.UI.Zones;
|
using Orchard.UI.Zones;
|
||||||
|
|
||||||
@ -15,13 +13,13 @@ namespace Orchard.ContentManagement.ViewModels {
|
|||||||
protected ItemDisplayModel(ItemDisplayModel displayModel) {
|
protected ItemDisplayModel(ItemDisplayModel displayModel) {
|
||||||
TemplateName = displayModel.TemplateName;
|
TemplateName = displayModel.TemplateName;
|
||||||
Prefix = displayModel.Prefix;
|
Prefix = displayModel.Prefix;
|
||||||
Zones = displayModel.Zones;
|
|
||||||
Item = displayModel.Item;
|
Item = displayModel.Item;
|
||||||
|
Zones = displayModel.Zones;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemDisplayModel(ContentItem item) {
|
public ItemDisplayModel(ContentItem item) {
|
||||||
Item = item;
|
|
||||||
Zones = new ZoneCollection();
|
Zones = new ZoneCollection();
|
||||||
|
Item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentItem Item {
|
public ContentItem Item {
|
||||||
@ -37,23 +35,6 @@ namespace Orchard.ContentManagement.ViewModels {
|
|||||||
public string TemplateName { get; set; }
|
public string TemplateName { get; set; }
|
||||||
public string Prefix { get; set; }
|
public string Prefix { get; set; }
|
||||||
public ZoneCollection Zones { get; set; }
|
public ZoneCollection Zones { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<TemplateViewModel> Displays {
|
|
||||||
get {
|
|
||||||
return Zones
|
|
||||||
.SelectMany(z => z.Value.Items
|
|
||||||
.OfType<PartDisplayZoneItem>()
|
|
||||||
.Select(x=>new{ZoneName=z.Key,Item=x}))
|
|
||||||
.Select(x => new TemplateViewModel(x.Item.Model,x.Item.Prefix) {
|
|
||||||
Model = x.Item.Model,
|
|
||||||
TemplateName=x.Item.TemplateName,
|
|
||||||
WasUsed=x.Item.WasExecuted,
|
|
||||||
ZoneName=x.ZoneName,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ItemDisplayModel<TPart> : ItemDisplayModel where TPart : IContent {
|
public class ItemDisplayModel<TPart> : ItemDisplayModel where TPart : IContent {
|
||||||
@ -67,6 +48,10 @@ namespace Orchard.ContentManagement.ViewModels {
|
|||||||
: base(displayModel) {
|
: base(displayModel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemDisplayModel(TPart part)
|
||||||
|
: base(part.ContentItem) {
|
||||||
|
}
|
||||||
|
|
||||||
public new TPart Item {
|
public new TPart Item {
|
||||||
get { return _item; }
|
get { return _item; }
|
||||||
set { SetItem(value.ContentItem); }
|
set { SetItem(value.ContentItem); }
|
||||||
|
@ -2,19 +2,26 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using Orchard.UI.Zones;
|
||||||
|
|
||||||
namespace Orchard.ContentManagement.ViewModels {
|
namespace Orchard.ContentManagement.ViewModels {
|
||||||
public class ItemEditorModel {
|
public class ItemEditorModel : IZoneContainer {
|
||||||
private ContentItem _item;
|
private ContentItem _item;
|
||||||
|
|
||||||
protected ItemEditorModel() {
|
protected ItemEditorModel() {
|
||||||
|
Zones = new ZoneCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ItemEditorModel(ItemEditorModel editorModel) {
|
protected ItemEditorModel(ItemEditorModel editorModel) {
|
||||||
TemplateName = editorModel.TemplateName;
|
TemplateName = editorModel.TemplateName;
|
||||||
Prefix = editorModel.Prefix;
|
Prefix = editorModel.Prefix;
|
||||||
Editors = editorModel.Editors.ToArray();
|
|
||||||
Item = editorModel.Item;
|
Item = editorModel.Item;
|
||||||
|
Zones = editorModel.Zones;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemEditorModel(ContentItem item) {
|
||||||
|
Zones = new ZoneCollection();
|
||||||
|
Item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentItem Item {
|
public ContentItem Item {
|
||||||
@ -29,7 +36,7 @@ namespace Orchard.ContentManagement.ViewModels {
|
|||||||
public Func<HtmlHelper, ItemEditorModel, HtmlHelper> Adaptor { get; set; }
|
public Func<HtmlHelper, ItemEditorModel, 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> Editors { get; set; }
|
public ZoneCollection Zones { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ItemEditorModel<TPart> : ItemEditorModel where TPart : IContent {
|
public class ItemEditorModel<TPart> : ItemEditorModel where TPart : IContent {
|
||||||
@ -39,10 +46,15 @@ namespace Orchard.ContentManagement.ViewModels {
|
|||||||
public ItemEditorModel() {
|
public ItemEditorModel() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemEditorModel(ItemEditorModel editorModel)
|
public ItemEditorModel(ItemEditorModel editorModel)
|
||||||
: base(editorModel) {
|
: base(editorModel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemEditorModel(TPart content)
|
||||||
|
: base(content.ContentItem) {
|
||||||
|
}
|
||||||
|
|
||||||
public new TPart Item {
|
public new TPart Item {
|
||||||
get { return _item; }
|
get { return _item; }
|
||||||
set { SetItem(value.ContentItem); }
|
set { SetItem(value.ContentItem); }
|
||||||
|
@ -21,10 +21,5 @@ namespace Orchard.Mvc.Html {
|
|||||||
|
|
||||||
return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? "");
|
return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void DisplayZonesAny<TModel>(this HtmlHelper<TModel> html) where TModel : ItemDisplayModel {
|
|
||||||
html.ZonesAny();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,4 @@
|
|||||||
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;
|
||||||
@ -22,47 +20,5 @@ 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 : ItemEditorModel {
|
|
||||||
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 : ItemEditorModel {
|
|
||||||
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 : ItemEditorModel {
|
|
||||||
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 : ItemEditorModel {
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -119,12 +119,12 @@ namespace Orchard.Mvc.ViewEngines {
|
|||||||
|
|
||||||
|
|
||||||
private static void Monitor(ViewEngineResult result, string viewName) {
|
private static void Monitor(ViewEngineResult result, string viewName) {
|
||||||
//if (result.View == null) {
|
if (result.View == null) {
|
||||||
// Trace.WriteLine("Unable to find " + viewName);
|
Trace.WriteLine("Unable to find " + viewName);
|
||||||
// foreach (var search in result.SearchedLocations) {
|
// foreach (var search in result.SearchedLocations) {
|
||||||
// Trace.WriteLine(" location " + search);
|
// Trace.WriteLine(" location " + search);
|
||||||
// }
|
// }
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReleaseView(ControllerContext controllerContext, IView view) {
|
public void ReleaseView(ControllerContext controllerContext, IView view) {
|
||||||
|
@ -258,6 +258,7 @@
|
|||||||
<Compile Include="UI\Zones\ItemDisplayZoneItem.cs" />
|
<Compile Include="UI\Zones\ItemDisplayZoneItem.cs" />
|
||||||
<Compile Include="UI\Zones\IZoneManager.cs" />
|
<Compile Include="UI\Zones\IZoneManager.cs" />
|
||||||
<Compile Include="UI\Zones\PartDisplayZoneItem.cs" />
|
<Compile Include="UI\Zones\PartDisplayZoneItem.cs" />
|
||||||
|
<Compile Include="UI\Zones\PartEditorZoneItem.cs" />
|
||||||
<Compile Include="UI\Zones\RenderPartialZoneItem.cs" />
|
<Compile Include="UI\Zones\RenderPartialZoneItem.cs" />
|
||||||
<Compile Include="UI\Zones\ZoneCollection.cs" />
|
<Compile Include="UI\Zones\ZoneCollection.cs" />
|
||||||
<Compile Include="UI\Zones\ZoneEntry.cs" />
|
<Compile Include="UI\Zones\ZoneEntry.cs" />
|
||||||
|
15
src/Orchard/UI/Zones/PartEditorZoneItem.cs
Normal file
15
src/Orchard/UI/Zones/PartEditorZoneItem.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Mvc.Html;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public class PartEditorZoneItem : ZoneItem {
|
||||||
|
public object Model { get; set; }
|
||||||
|
public string TemplateName { get; set; }
|
||||||
|
public string Prefix { get; set; }
|
||||||
|
|
||||||
|
public override void Execute<TModel>(HtmlHelper<TModel> html) {
|
||||||
|
html.ViewContext.Writer.Write(
|
||||||
|
html.EditorFor(m => Model, TemplateName, Prefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,17 +9,20 @@ namespace Orchard.UI.Zones {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class ZoneCollection : Dictionary<string, ZoneEntry> {
|
public class ZoneCollection : Dictionary<string, ZoneEntry> {
|
||||||
|
public void AddAction(string location, Action<HtmlHelper> action) {
|
||||||
|
AddZoneItem(location, new DelegateZoneItem { Action = action });
|
||||||
|
}
|
||||||
public void AddRenderPartial(string location, string templateName, object model) {
|
public void AddRenderPartial(string location, string templateName, object model) {
|
||||||
AddZoneItem(location, new RenderPartialZoneItem { Model = model, TemplateName = templateName });
|
AddZoneItem(location, new RenderPartialZoneItem { Model = model, TemplateName = templateName });
|
||||||
}
|
}
|
||||||
public void AddDisplayItem(string location, ItemDisplayModel displayModel) {
|
public void AddDisplayItem(string location, ItemDisplayModel displayModel) {
|
||||||
AddZoneItem(location, new ItemDisplayZoneItem() { DisplayModel = displayModel });
|
AddZoneItem(location, new ItemDisplayZoneItem { DisplayModel = displayModel });
|
||||||
}
|
}
|
||||||
public void AddDisplayPart(string location, object model, string templateName, string prefix) {
|
public void AddDisplayPart(string location, object model, string templateName, string prefix) {
|
||||||
AddZoneItem(location, new PartDisplayZoneItem { Model = model, TemplateName = templateName, Prefix = prefix });
|
AddZoneItem(location, new PartDisplayZoneItem { Model = model, TemplateName = templateName, Prefix = prefix });
|
||||||
}
|
}
|
||||||
public void AddAction(string location, Action<HtmlHelper> action) {
|
public void AddEditorPart(string location, object model, string templateName, string prefix) {
|
||||||
AddZoneItem(location, new DelegateZoneItem { Action = action });
|
AddZoneItem(location, new PartEditorZoneItem { Model = model, TemplateName = templateName, Prefix = prefix });
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddZoneItem(string location, ZoneItem item) {
|
private void AddZoneItem(string location, ZoneItem item) {
|
||||||
|
Loading…
Reference in New Issue
Block a user