rough concept work around some item template zones

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043037
This commit is contained in:
loudej
2009-12-03 06:30:11 +00:00
parent 320ce0e94c
commit 7248d34812
7 changed files with 69 additions and 19 deletions

View File

@@ -16,18 +16,18 @@ namespace Orchard.Core.Common.Providers {
OnGetDisplays<BodyAspect>((context, body) => {
var model = new BodyDisplayViewModel { BodyAspect = body };
context.AddDisplay(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, Position = "3" });
context.AddDisplay(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" });
});
OnGetEditors<BodyAspect>((context, body) => {
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, Position = "3" });
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" });
});
OnUpdateEditors<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, Position = "3" });
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" });
});
}
}

View File

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

View File

@@ -1,14 +1,22 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemDisplayViewModel<SandboxPage>>" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Mvc.Html" %>
<%@ Import Namespace="Orchard.Sandbox.Models" %>
<%@ Import Namespace="Orchard.Models.ViewModels" %>
<%@ Import Namespace="Orchard.Models" %>
<h1><%=Html.Encode(Model.Item.Record.Name) %></h1>
<%foreach (var display in Model.Displays) { %>
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
<%} %>
<p>
<%=Html.ItemEditLink("Edit this page", Model.Item) %>, <%=Html.ActionLink("Return to list", "index") %></p>
<%=Html.DisplayZone("before")%>
<div class="item">
<%=Html.DisplayZone("first")%>
<h1>
<%=Html.Encode(Model.Item.Record.Name) %></h1>
<%=Html.DisplayZone("metatop")%>
<div class="body">
<%=Html.DisplayZone("body")%></div>
<%=Html.DisplayZone("metabottom")%>
<div class="actions">
<%=Html.ItemEditLink("Edit this page", Model.Item) %>,
<%=Html.ActionLink("Return to list", "index") %>
<%=Html.DisplayZone("actions") %></div>
<%=Html.DisplayZonesExcept("last","after") %>
<%=Html.DisplayZone("last")%>
</div>
<%=Html.DisplayZone("after")%>

View File

@@ -20,8 +20,7 @@
</div>
<div id="main">
<% Html.RenderPartial("Messages", Model.Messages); %>
<h3>
Edit Page</h3>
<h3>Edit Page</h3>
<%using (Html.BeginForm()) { %>
<%=Html.EditorForItem(m=>m.Page) %>
<input type="submit" name="submit" value="Save" />

View File

@@ -27,8 +27,8 @@ namespace Orchard.Tags.Models {
Filters.Add(new ActivatingFilter<HasTags>("blogpost"));
OnGetDisplays<HasTags>((context, hasTags) => {
context.AddDisplay(new TemplateViewModel(hasTags) { Position = "2", TemplateName = "HasTagsList" });
context.AddDisplay(new TemplateViewModel(hasTags) { Position = "5" });
context.AddDisplay(new TemplateViewModel(hasTags) { ZoneName="metatop", Position = "2", TemplateName = "HasTagsList" });
context.AddDisplay(new TemplateViewModel(hasTags) { ZoneName = "metabottom", Position = "5" });
});
}

View File

@@ -15,5 +15,6 @@
public string ZoneName { get; set; }
public string Position { get; set; }
public bool WasUsed { get; set; }
}
}

View File

@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;
@@ -13,5 +15,45 @@ namespace Orchard.Mvc.Html {
return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? "");
}
public static MvcHtmlString DisplayZone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : ItemDisplayViewModel {
var templates = html.ViewData.Model.Displays.Where(x => x.ZoneName == zoneName && x.WasUsed == false);
return DisplayZoneImplementation(html, templates);
}
public static MvcHtmlString DisplayZonesAny<TModel>(this HtmlHelper<TModel> html) where TModel : ItemDisplayViewModel {
var templates = html.ViewData.Model.Displays.Where(x => x.WasUsed == false);
return DisplayZoneImplementation(html, templates);
}
public static MvcHtmlString DisplayZones<TModel>(this HtmlHelper<TModel> html, params string[] include) where TModel : ItemDisplayViewModel {
var templates = html.ViewData.Model.Displays.Where(x => include.Contains(x.ZoneName) && x.WasUsed == false);
return DisplayZoneImplementation(html, templates);
}
public static MvcHtmlString DisplayZonesExcept<TModel>(this HtmlHelper<TModel> html, params string[] exclude) where TModel : ItemDisplayViewModel {
var templates = html.ViewData.Model.Displays.Where(x => !exclude.Contains(x.ZoneName) && x.WasUsed == false);
return DisplayZoneImplementation(html, templates);
}
private static MvcHtmlString DisplayZoneImplementation<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.DisplayFor(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.DisplayFor(m => t.Model, t.TemplateName, t.Prefix ?? ""));
}
return MvcHtmlString.Create(string.Concat(strings.ToArray()));
}
}
}