mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-15 18:55:14 +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.Handlers;
|
||||
using Orchard.ContentManagement.ViewModels;
|
||||
using Orchard.UI.Zones;
|
||||
|
||||
namespace Orchard.Tests.ContentManagement {
|
||||
[TestFixture]
|
||||
@ -60,10 +61,11 @@ namespace Orchard.Tests.ContentManagement {
|
||||
item.Weld(new StubPart { Foo = new[] { "a", "b", "c" } });
|
||||
|
||||
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);
|
||||
Assert.That(ctx.DisplayModel.Displays.Count(), Is.EqualTo(1));
|
||||
Assert.That(ctx.DisplayModel.Displays.Single().Prefix, Is.EqualTo("Stub"));
|
||||
Assert.That(ctx.DisplayModel.Zones.Count(), Is.EqualTo(1));
|
||||
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) => {
|
||||
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) => {
|
||||
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
|
||||
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)
|
||||
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;
|
||||
}
|
||||
}
|
||||
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\OwnerEditorViewModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Settings\Controllers\SiteSettingsDriver.cs" />
|
||||
<Compile Include="Themes\Services\AdminThemeSelector.cs" />
|
||||
<Compile Include="Themes\Services\SafeModeThemeSelector.cs" />
|
||||
<Compile Include="Settings\AdminMenu.cs" />
|
||||
@ -112,7 +113,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Common\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="XmlRpc\Package.txt" />
|
||||
<Content Include="XmlRpc\Views\Home\Index.aspx" />
|
||||
@ -138,6 +139,7 @@
|
||||
<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.Owner.ascx" />
|
||||
<Content Include="Settings\Views\EditorTemplates\Items\Settings.Site.ascx" />
|
||||
<Content Include="Themes\Styles\site.css" />
|
||||
<Content Include="Themes\Views\Admin\Install.aspx" />
|
||||
<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 {
|
||||
public class SiteSettingsHandler : ContentHandler {
|
||||
|
||||
public override IEnumerable<ContentType> GetContentTypes() {
|
||||
return new[] {SiteSettings.ContentType};
|
||||
}
|
||||
|
||||
public SiteSettingsHandler(IRepository<SiteSettingsRecord> repository){
|
||||
Filters.Add(new ActivatingFilter<SiteSettings>("site"));
|
||||
Filters.Add(new StorageFilter<SiteSettingsRecord>(repository));
|
||||
|
@ -1,5 +1,7 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.Core.Settings.ViewModels.SettingsIndexViewModel>" %>
|
||||
<h2><%=Html.TitleForPage("Edit Settings")%></h2>
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Core.Settings.ViewModels.SettingsIndexViewModel>" %>
|
||||
|
||||
<h2>
|
||||
<%=Html.TitleForPage("Edit Settings")%></h2>
|
||||
<%using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%= Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
@ -21,10 +23,9 @@
|
||||
</fieldset>
|
||||
<%=Html.EditorFor(s=>s.Id) %>
|
||||
</fieldset>
|
||||
<% foreach (var e in Model.EditorModel.Editors) {
|
||||
var editor = e;
|
||||
%><%=Html.EditorFor(m => editor.Model, editor.TemplateName, editor.Prefix)%>
|
||||
<% } %>
|
||||
|
||||
<%= Html.EditorForItem(Model.EditorModel) %>
|
||||
|
||||
<fieldset>
|
||||
<input class="button" type="submit" value="Save" />
|
||||
</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.Blogs.Models"%>
|
||||
<% Html.AddTitleParts(Model.Item.Name); %>
|
||||
<%=Html.EditorZone("primary") %>
|
||||
<%=Html.EditorZonesAny() %>
|
||||
<% Html.Zone("primary"); %>
|
||||
<% Html.ZonesAny(); %>
|
@ -4,11 +4,11 @@
|
||||
<% Html.AddTitleParts(Model.Item.Title); %>
|
||||
<div class="sections">
|
||||
<div class="primary">
|
||||
<%=Html.EditorZone("primary") %>
|
||||
<%=Html.EditorZonesExcept("secondary") %>
|
||||
<% Html.Zone("primary"); %>
|
||||
<% Html.ZonesExcept("secondary"); %>
|
||||
</div>
|
||||
<div class="secondary">
|
||||
<%=Html.EditorZone("secondary")%>
|
||||
<% Html.Zone("secondary");%>
|
||||
<fieldset>
|
||||
<input class="button" type="submit" name="submit.Save" value="Save"/>
|
||||
</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) {
|
||||
return Item.ContentItem.Get(type);
|
||||
|
@ -24,11 +24,11 @@ namespace Orchard.Roles.Controllers {
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[AcceptVerbs(HttpVerbs.Post)]
|
||||
public ActionResult Index(FormCollection input) {
|
||||
[HttpPost, ActionName("Index")]
|
||||
public ActionResult IndexPOST() {
|
||||
try {
|
||||
foreach (string key in input.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && input[key] == "true") {
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
int roleId = Convert.ToInt32(key.Substring("Checkbox.".Length));
|
||||
_roleService.DeleteRole(roleId);
|
||||
}
|
||||
@ -46,14 +46,14 @@ namespace Orchard.Roles.Controllers {
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[AcceptVerbs(HttpVerbs.Post)]
|
||||
public ActionResult Create(FormCollection input) {
|
||||
[HttpPost, ActionName("Create")]
|
||||
public ActionResult CreatePOST() {
|
||||
var viewModel = new RoleCreateViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel, input.ToValueProvider());
|
||||
UpdateModel(viewModel);
|
||||
_roleService.CreateRole(viewModel.Name);
|
||||
foreach (string key in input.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && input[key] == "true") {
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
string permissionName = key.Substring("Checkbox.".Length);
|
||||
_roleService.CreatePermissionForRole(viewModel.Name,
|
||||
permissionName);
|
||||
@ -80,16 +80,16 @@ namespace Orchard.Roles.Controllers {
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[AcceptVerbs(HttpVerbs.Post)]
|
||||
public ActionResult Edit(FormCollection input) {
|
||||
[HttpPost, ActionName("Edit")]
|
||||
public ActionResult EditPOST() {
|
||||
var viewModel = new RoleEditViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel, input.ToValueProvider());
|
||||
UpdateModel(viewModel);
|
||||
// Save
|
||||
if (!String.IsNullOrEmpty(HttpContext.Request.Form["submit.Save"])) {
|
||||
List<string> rolePermissions = new List<string>();
|
||||
foreach (string key in input.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && input[key] == "true") {
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
string permissionName = key.Substring("Checkbox.".Length);
|
||||
rolePermissions.Add(permissionName);
|
||||
}
|
||||
|
@ -7,9 +7,6 @@ using Orchard.ContentManagement.Records;
|
||||
namespace Orchard.Sandbox.Models {
|
||||
public class SandboxSettingsRecord : ContentPartRecord {
|
||||
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.EditorFor(m => m.Item.Record.Name)%>
|
||||
</li>
|
||||
<%=Html.EditorZonesAny()%>
|
||||
<% Html.ZonesAny(); %>
|
||||
|
@ -5,8 +5,4 @@
|
||||
<%= Html.EditorFor(x=>x.AllowAnonymousEdits) %>
|
||||
<%= Html.ValidationMessage("AllowAnonymousEdits", "*")%>
|
||||
<br />
|
||||
<%= Html.LabelFor(x => x.NameOfThemeWhenEditingPage)%>
|
||||
<%= Html.EditorFor(x=>x.NameOfThemeWhenEditingPage) %>
|
||||
<%= Html.ValidationMessage("NameOfThemeWhenEditingPage", "*")%>
|
||||
<br />
|
||||
</fieldset>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorModel<User>>" %>
|
||||
<%@ Import Namespace="Orchard.ContentManagement.ViewModels" %>
|
||||
<%@ 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 {
|
||||
var itemView = new ItemDisplayModel<TContentPart> { Item = content };
|
||||
var context = new BuildDisplayModelContext(itemView, displayType);
|
||||
var displayModel = new ItemDisplayModel<TContentPart>(content);
|
||||
var context = new BuildDisplayModelContext(displayModel, displayType);
|
||||
foreach (var handler in Handlers) {
|
||||
handler.BuildDisplayModel(context);
|
||||
}
|
||||
return itemView;
|
||||
return displayModel;
|
||||
}
|
||||
|
||||
public ItemEditorModel<TContentPart> BuildEditorModel<TContentPart>(TContentPart content) where TContentPart : IContent {
|
||||
var itemView = new ItemEditorModel<TContentPart> { Item = content, Editors = Enumerable.Empty<TemplateViewModel>() };
|
||||
var context = new BuildEditorModelContext(itemView);
|
||||
var editorModel = new ItemEditorModel<TContentPart>(content);
|
||||
var context = new BuildEditorModelContext(editorModel);
|
||||
foreach (var handler in Handlers) {
|
||||
handler.BuildEditorModel(context);
|
||||
}
|
||||
context.EditorModel.Editors = OrderTemplates(context.EditorModel.Editors);
|
||||
return itemView;
|
||||
return editorModel;
|
||||
}
|
||||
|
||||
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) {
|
||||
handler.UpdateEditorModel(context);
|
||||
}
|
||||
context.EditorModel.Editors = OrderTemplates(context.EditorModel.Editors);
|
||||
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);
|
||||
return editorModel;
|
||||
}
|
||||
|
||||
public IContentQuery<ContentItem> Query() {
|
||||
|
@ -21,11 +21,8 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
}
|
||||
|
||||
public override void Apply(BuildEditorModelContext context) {
|
||||
context.AddEditor(new TemplateViewModel(Model, Prefix) {
|
||||
TemplateName = TemplateName,
|
||||
ZoneName = Zone,
|
||||
Position = Position
|
||||
});
|
||||
context.EditorModel.Zones.AddEditorPart(
|
||||
Zone + ":" + Position, Model, TemplateName, Prefix);
|
||||
}
|
||||
|
||||
public PartTemplateResult Location(string zone) {
|
||||
|
@ -11,8 +11,14 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
public ContentItem ContentItem { 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() {
|
||||
private readonly string _prefix;
|
||||
private readonly string _templateName;
|
||||
private string _location;
|
||||
|
||||
public TemplateFilterForRecord(string prefix, string templateName) {
|
||||
_prefix = prefix;
|
||||
_templateName = templateName;
|
||||
_location = "primary";
|
||||
}
|
||||
|
||||
public TemplateFilterForRecord<TRecord> Location(string location) {
|
||||
_location = location;
|
||||
return this;
|
||||
}
|
||||
|
||||
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) {
|
||||
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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.UI.Zones;
|
||||
|
||||
@ -15,13 +13,13 @@ namespace Orchard.ContentManagement.ViewModels {
|
||||
protected ItemDisplayModel(ItemDisplayModel displayModel) {
|
||||
TemplateName = displayModel.TemplateName;
|
||||
Prefix = displayModel.Prefix;
|
||||
Zones = displayModel.Zones;
|
||||
Item = displayModel.Item;
|
||||
Zones = displayModel.Zones;
|
||||
}
|
||||
|
||||
public ItemDisplayModel(ContentItem item) {
|
||||
Item = item;
|
||||
Zones = new ZoneCollection();
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public ContentItem Item {
|
||||
@ -37,23 +35,6 @@ namespace Orchard.ContentManagement.ViewModels {
|
||||
public string TemplateName { get; set; }
|
||||
public string Prefix { 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 {
|
||||
@ -67,6 +48,10 @@ namespace Orchard.ContentManagement.ViewModels {
|
||||
: base(displayModel) {
|
||||
}
|
||||
|
||||
public ItemDisplayModel(TPart part)
|
||||
: base(part.ContentItem) {
|
||||
}
|
||||
|
||||
public new TPart Item {
|
||||
get { return _item; }
|
||||
set { SetItem(value.ContentItem); }
|
||||
|
@ -2,19 +2,26 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.UI.Zones;
|
||||
|
||||
namespace Orchard.ContentManagement.ViewModels {
|
||||
public class ItemEditorModel {
|
||||
public class ItemEditorModel : IZoneContainer {
|
||||
private ContentItem _item;
|
||||
|
||||
protected ItemEditorModel() {
|
||||
Zones = new ZoneCollection();
|
||||
}
|
||||
|
||||
protected ItemEditorModel(ItemEditorModel editorModel) {
|
||||
TemplateName = editorModel.TemplateName;
|
||||
Prefix = editorModel.Prefix;
|
||||
Editors = editorModel.Editors.ToArray();
|
||||
Item = editorModel.Item;
|
||||
Zones = editorModel.Zones;
|
||||
}
|
||||
|
||||
public ItemEditorModel(ContentItem item) {
|
||||
Zones = new ZoneCollection();
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public ContentItem Item {
|
||||
@ -29,7 +36,7 @@ namespace Orchard.ContentManagement.ViewModels {
|
||||
public Func<HtmlHelper, ItemEditorModel, HtmlHelper> Adaptor { get; set; }
|
||||
public string TemplateName { 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 {
|
||||
@ -39,10 +46,15 @@ namespace Orchard.ContentManagement.ViewModels {
|
||||
public ItemEditorModel() {
|
||||
|
||||
}
|
||||
|
||||
public ItemEditorModel(ItemEditorModel editorModel)
|
||||
: base(editorModel) {
|
||||
}
|
||||
|
||||
public ItemEditorModel(TPart content)
|
||||
: base(content.ContentItem) {
|
||||
}
|
||||
|
||||
public new TPart Item {
|
||||
get { return _item; }
|
||||
set { SetItem(value.ContentItem); }
|
||||
|
@ -21,10 +21,5 @@ namespace Orchard.Mvc.Html {
|
||||
|
||||
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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
@ -22,47 +20,5 @@ 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 : 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) {
|
||||
//if (result.View == null) {
|
||||
// Trace.WriteLine("Unable to find " + viewName);
|
||||
if (result.View == null) {
|
||||
Trace.WriteLine("Unable to find " + viewName);
|
||||
// foreach (var search in result.SearchedLocations) {
|
||||
// Trace.WriteLine(" location " + search);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
public void ReleaseView(ControllerContext controllerContext, IView view) {
|
||||
|
@ -258,6 +258,7 @@
|
||||
<Compile Include="UI\Zones\ItemDisplayZoneItem.cs" />
|
||||
<Compile Include="UI\Zones\IZoneManager.cs" />
|
||||
<Compile Include="UI\Zones\PartDisplayZoneItem.cs" />
|
||||
<Compile Include="UI\Zones\PartEditorZoneItem.cs" />
|
||||
<Compile Include="UI\Zones\RenderPartialZoneItem.cs" />
|
||||
<Compile Include="UI\Zones\ZoneCollection.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 void AddAction(string location, Action<HtmlHelper> action) {
|
||||
AddZoneItem(location, new DelegateZoneItem { Action = action });
|
||||
}
|
||||
public void AddRenderPartial(string location, string templateName, object model) {
|
||||
AddZoneItem(location, new RenderPartialZoneItem { Model = model, TemplateName = templateName });
|
||||
}
|
||||
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) {
|
||||
AddZoneItem(location, new PartDisplayZoneItem { Model = model, TemplateName = templateName, Prefix = prefix });
|
||||
}
|
||||
public void AddAction(string location, Action<HtmlHelper> action) {
|
||||
AddZoneItem(location, new DelegateZoneItem { Action = action });
|
||||
public void AddEditorPart(string location, object model, string templateName, string prefix) {
|
||||
AddZoneItem(location, new PartEditorZoneItem { Model = model, TemplateName = templateName, Prefix = prefix });
|
||||
}
|
||||
|
||||
private void AddZoneItem(string location, ZoneItem item) {
|
||||
|
Loading…
Reference in New Issue
Block a user