mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
Adding Zone html helper implementations
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044177
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Mvc.ViewEngines;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.UI.Zones;
|
||||
|
||||
namespace Orchard.Mvc.Html {
|
||||
public static class LayoutHelperExtensions {
|
||||
public static class LayoutExtensions {
|
||||
public static void RenderBody(this HtmlHelper html) {
|
||||
OrchardLayoutContext layoutContext = OrchardLayoutContext.From(html.ViewContext);
|
||||
html.ViewContext.HttpContext.Response.Output.Write(layoutContext.BodyContent);
|
||||
@@ -23,12 +25,17 @@ namespace Orchard.Mvc.Html {
|
||||
return MvcHtmlString.Create(html.Encode(layoutContext.Title));
|
||||
}
|
||||
|
||||
public static void RenderZone(this HtmlHelper html, string zoneName) {
|
||||
OrchardLayoutContext layoutContext = OrchardLayoutContext.From(html.ViewContext);
|
||||
html.ViewContext.HttpContext.Response.Output.Write(layoutContext.Title);
|
||||
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, string partitions) where TModel : BaseViewModel {
|
||||
//is IoC necessary for this to work properly?
|
||||
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) {
|
||||
//todo: register the style
|
@@ -1,14 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.UI.Zones;
|
||||
|
||||
namespace Orchard.Mvc.ViewModels {
|
||||
public class BaseViewModel {
|
||||
public BaseViewModel() {
|
||||
Messages = new List<NotifyEntry>();
|
||||
Zones = new ZoneCollection();
|
||||
}
|
||||
|
||||
public IList<NotifyEntry> Messages { 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\ItemDisplayExtensions.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\MvcModule.cs" />
|
||||
<Compile Include="Mvc\Html\HtmlHelperExtensions.cs" />
|
||||
@@ -222,6 +222,12 @@
|
||||
<Compile Include="Mvc\ViewEngines\WebFormsViewEngineProvider.cs" />
|
||||
<Compile Include="Mvc\ViewModels\AdminViewModel.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">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
@@ -264,6 +270,7 @@
|
||||
<Compile Include="Storage\IStorageFile.cs" />
|
||||
<Compile Include="Storage\IStorageFolder.cs" />
|
||||
<Compile Include="Storage\IStorageProvider.cs" />
|
||||
<Compile Include="UI\Zones\ZoneManager.cs" />
|
||||
<Compile Include="Utility\Reflect.cs" />
|
||||
<Compile Include="Utility\ReflectOn.cs" />
|
||||
<Compile Include="Validation\JetBrains.Annotations.cs" />
|
||||
|
12
src/Orchard/UI/Zones/DelegateZoneItem.cs
Normal file
12
src/Orchard/UI/Zones/DelegateZoneItem.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
13
src/Orchard/UI/Zones/ItemDisplayZoneItem.cs
Normal file
13
src/Orchard/UI/Zones/ItemDisplayZoneItem.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
13
src/Orchard/UI/Zones/RenderPartialZoneItem.cs
Normal file
13
src/Orchard/UI/Zones/RenderPartialZoneItem.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
18
src/Orchard/UI/Zones/ZoneCollection.cs
Normal file
18
src/Orchard/UI/Zones/ZoneCollection.cs
Normal file
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
12
src/Orchard/UI/Zones/ZoneEntry.cs
Normal file
12
src/Orchard/UI/Zones/ZoneEntry.cs
Normal file
@@ -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; }
|
||||
}
|
||||
}
|
10
src/Orchard/UI/Zones/ZoneItem.cs
Normal file
10
src/Orchard/UI/Zones/ZoneItem.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
25
src/Orchard/UI/Zones/ZoneManager.cs
Normal file
25
src/Orchard/UI/Zones/ZoneManager.cs
Normal file
@@ -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