mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding Zone html helper implementations
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044177
This commit is contained in:
+12
-5
@@ -1,8 +1,10 @@
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Mvc.ViewEngines;
|
using Orchard.Mvc.ViewEngines;
|
||||||
|
using Orchard.Mvc.ViewModels;
|
||||||
|
using Orchard.UI.Zones;
|
||||||
|
|
||||||
namespace Orchard.Mvc.Html {
|
namespace Orchard.Mvc.Html {
|
||||||
public static class LayoutHelperExtensions {
|
public static class LayoutExtensions {
|
||||||
public static void RenderBody(this HtmlHelper html) {
|
public static void RenderBody(this HtmlHelper html) {
|
||||||
OrchardLayoutContext layoutContext = OrchardLayoutContext.From(html.ViewContext);
|
OrchardLayoutContext layoutContext = OrchardLayoutContext.From(html.ViewContext);
|
||||||
html.ViewContext.HttpContext.Response.Output.Write(layoutContext.BodyContent);
|
html.ViewContext.HttpContext.Response.Output.Write(layoutContext.BodyContent);
|
||||||
@@ -23,12 +25,17 @@ namespace Orchard.Mvc.Html {
|
|||||||
return MvcHtmlString.Create(html.Encode(layoutContext.Title));
|
return MvcHtmlString.Create(html.Encode(layoutContext.Title));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RenderZone(this HtmlHelper html, string zoneName) {
|
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, string partitions) where TModel : BaseViewModel {
|
||||||
OrchardLayoutContext layoutContext = OrchardLayoutContext.From(html.ViewContext);
|
//is IoC necessary for this to work properly?
|
||||||
html.ViewContext.HttpContext.Response.Output.Write(layoutContext.Title);
|
var manager = new ZoneManager();
|
||||||
|
manager.Render(html, html.ViewData.Model.Zones, zoneName, partitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RenderZone(this HtmlHelper html, string zoneName, string foo) {}
|
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : BaseViewModel {
|
||||||
|
Zone(html, zoneName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RenderZone(this HtmlHelper html, string zoneName, string foo) { }
|
||||||
|
|
||||||
public static void RegisterStyle(this HtmlHelper html, string styleName) {
|
public static void RegisterStyle(this HtmlHelper html, string styleName) {
|
||||||
//todo: register the style
|
//todo: register the style
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
|
using Orchard.UI.Zones;
|
||||||
|
|
||||||
namespace Orchard.Mvc.ViewModels {
|
namespace Orchard.Mvc.ViewModels {
|
||||||
public class BaseViewModel {
|
public class BaseViewModel {
|
||||||
public BaseViewModel() {
|
public BaseViewModel() {
|
||||||
Messages = new List<NotifyEntry>();
|
Messages = new List<NotifyEntry>();
|
||||||
|
Zones = new ZoneCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IList<NotifyEntry> Messages { get; set; }
|
public IList<NotifyEntry> Messages { get; set; }
|
||||||
public IUser CurrentUser { get; set; }
|
public IUser CurrentUser { get; set; }
|
||||||
|
public ZoneCollection Zones { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@
|
|||||||
<Compile Include="Mvc\Html\ContentItemExtensions.cs" />
|
<Compile Include="Mvc\Html\ContentItemExtensions.cs" />
|
||||||
<Compile Include="Mvc\Html\ItemDisplayExtensions.cs" />
|
<Compile Include="Mvc\Html\ItemDisplayExtensions.cs" />
|
||||||
<Compile Include="Mvc\Html\ItemEditorExtensions.cs" />
|
<Compile Include="Mvc\Html\ItemEditorExtensions.cs" />
|
||||||
<Compile Include="Mvc\Html\LayoutHelperExtensions.cs" />
|
<Compile Include="Mvc\Html\LayoutExtensions.cs" />
|
||||||
<Compile Include="Mvc\Html\MvcFormAntiForgeryPost.cs" />
|
<Compile Include="Mvc\Html\MvcFormAntiForgeryPost.cs" />
|
||||||
<Compile Include="Mvc\MvcModule.cs" />
|
<Compile Include="Mvc\MvcModule.cs" />
|
||||||
<Compile Include="Mvc\Html\HtmlHelperExtensions.cs" />
|
<Compile Include="Mvc\Html\HtmlHelperExtensions.cs" />
|
||||||
@@ -222,6 +222,12 @@
|
|||||||
<Compile Include="Mvc\ViewEngines\WebFormsViewEngineProvider.cs" />
|
<Compile Include="Mvc\ViewEngines\WebFormsViewEngineProvider.cs" />
|
||||||
<Compile Include="Mvc\ViewModels\AdminViewModel.cs" />
|
<Compile Include="Mvc\ViewModels\AdminViewModel.cs" />
|
||||||
<Compile Include="Mvc\ViewModels\BaseViewModel.cs" />
|
<Compile Include="Mvc\ViewModels\BaseViewModel.cs" />
|
||||||
|
<Compile Include="UI\Zones\DelegateZoneItem.cs" />
|
||||||
|
<Compile Include="UI\Zones\ItemDisplayZoneItem.cs" />
|
||||||
|
<Compile Include="UI\Zones\RenderPartialZoneItem.cs" />
|
||||||
|
<Compile Include="UI\Zones\ZoneCollection.cs" />
|
||||||
|
<Compile Include="UI\Zones\ZoneEntry.cs" />
|
||||||
|
<Compile Include="UI\Zones\ZoneItem.cs" />
|
||||||
<Compile Include="Mvc\ViewPage.cs">
|
<Compile Include="Mvc\ViewPage.cs">
|
||||||
<SubType>ASPXCodeBehind</SubType>
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -264,6 +270,7 @@
|
|||||||
<Compile Include="Storage\IStorageFile.cs" />
|
<Compile Include="Storage\IStorageFile.cs" />
|
||||||
<Compile Include="Storage\IStorageFolder.cs" />
|
<Compile Include="Storage\IStorageFolder.cs" />
|
||||||
<Compile Include="Storage\IStorageProvider.cs" />
|
<Compile Include="Storage\IStorageProvider.cs" />
|
||||||
|
<Compile Include="UI\Zones\ZoneManager.cs" />
|
||||||
<Compile Include="Utility\Reflect.cs" />
|
<Compile Include="Utility\Reflect.cs" />
|
||||||
<Compile Include="Utility\ReflectOn.cs" />
|
<Compile Include="Utility\ReflectOn.cs" />
|
||||||
<Compile Include="Validation\JetBrains.Annotations.cs" />
|
<Compile Include="Validation\JetBrains.Annotations.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public class DelegateZoneItem : ZoneItem {
|
||||||
|
public Action<HtmlHelper> Action { get; set; }
|
||||||
|
|
||||||
|
public override void Execute<TModel>(HtmlHelper<TModel> html) {
|
||||||
|
Action(html);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.Models.ViewModels;
|
||||||
|
using Orchard.Mvc.Html;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public class ItemDisplayZoneItem : ZoneItem {
|
||||||
|
public ItemDisplayModel DisplayModel { get; set; }
|
||||||
|
|
||||||
|
public override void Execute<TModel>(HtmlHelper<TModel> html) {
|
||||||
|
html.DisplayForItem(DisplayModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Mvc.Html;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public class RenderPartialZoneItem : ZoneItem {
|
||||||
|
public object Model { get; set; }
|
||||||
|
public string TemplateName { get; set; }
|
||||||
|
|
||||||
|
public override void Execute<TModel>(HtmlHelper<TModel> html) {
|
||||||
|
html.RenderPartial(TemplateName, Model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.Models.ViewModels;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public class ZoneCollection : Dictionary<string, ZoneEntry> {
|
||||||
|
public void AddRenderPartial(string location, string templateName, object model) {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void AddDisplayItem(string location, ItemDisplayModel displayModel) {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void AddAction(string location, Action<HtmlHelper> action) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public class ZoneEntry {
|
||||||
|
public ZoneEntry() {
|
||||||
|
Items = new List<ZoneItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ZoneName { get; set; }
|
||||||
|
public IList<ZoneItem> Items { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public abstract class ZoneItem {
|
||||||
|
public string Position { get; set; }
|
||||||
|
public bool WasExecuted { get; set; }
|
||||||
|
|
||||||
|
public abstract void Execute<TModel>(HtmlHelper<TModel> html);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public class ZoneManager {
|
||||||
|
public void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions) {
|
||||||
|
|
||||||
|
ZoneEntry zone;
|
||||||
|
if (!zones.TryGetValue(zoneName, out zone))
|
||||||
|
return;
|
||||||
|
|
||||||
|
//TODO: partitions
|
||||||
|
foreach (var item in zone.Items) {
|
||||||
|
if (item.WasExecuted)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
item.WasExecuted = true;
|
||||||
|
item.Execute(html);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user