Adding ShapeMenuItem

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-02-10 15:32:38 -08:00
parent 9673ea7aea
commit 8651e33326
10 changed files with 149 additions and 6 deletions

View File

@@ -0,0 +1,53 @@
using System;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models;
using Orchard.Localization;
namespace Orchard.Core.Navigation.Drivers {
public class ShapeMenuItemPartDriver : ContentPartDriver<ShapeMenuItemPart> {
private const string TemplateName = "Parts.ShapeMenuItemPart.Edit";
public ShapeMenuItemPartDriver(IOrchardServices services) {
T = NullLocalizer.Instance;
Services = services;
}
public Localizer T { get; set; }
public IOrchardServices Services { get; set; }
protected override string Prefix { get { return "ShapeMenuItemPart"; } }
protected override DriverResult Editor(ShapeMenuItemPart part, dynamic shapeHelper) {
return ContentShape("Parts_ShapeMenuItemPart_Edit", () => {
return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix);
});
}
protected override DriverResult Editor(ShapeMenuItemPart part, IUpdateModel updater, dynamic shapeHelper) {
if (updater.TryUpdateModel(part, Prefix, null, null)) {
if (String.IsNullOrWhiteSpace(part.ShapeType)) {
updater.AddModelError("ShapeType", T("The Shape Type is mandatory."));
}
}
return Editor(part, shapeHelper);
}
protected override void Importing(ShapeMenuItemPart part, ImportContentContext context) {
IfNotNull(context.Attribute(part.PartDefinition.Name, "ShapeType"), x => part.Record.ShapeType = x);
}
private static void IfNotNull<T>(T value, Action<T> then) where T : class {
if(value != null) {
then(value);
}
}
protected override void Exporting(ShapeMenuItemPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("ShapeType", part.Record.ShapeType);
}
}
}

View File

@@ -0,0 +1,11 @@
using Orchard.Core.Navigation.Models;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Core.Navigation.Handlers {
public class ShapeMenuItemPartHandler : ContentHandler {
public ShapeMenuItemPartHandler(IRepository<ShapeMenuItemPartRecord> repository) {
Filters.Add(StorageFilter.For(repository));
}
}
}

View File

@@ -93,7 +93,22 @@ namespace Orchard.Core.Navigation {
.WithSetting("Stereotype", "MenuItem")
);
return 3;
SchemaBuilder.CreateTable("ShapeMenuItemPartRecord",
table => table.ContentPartRecord()
.Column<string>("ShapeType")
);
ContentDefinitionManager.AlterTypeDefinition("ShapeMenuItem",
cfg => cfg
.WithPart("ShapeMenuItemPart")
.WithPart("MenuPart")
.WithPart("CommonPart")
.DisplayedAs("Shape Link")
.WithSetting("Description", "Injects menu items from a Shape")
.WithSetting("Stereotype", "MenuItem")
);
return 4;
}
public int UpdateFrom1() {
@@ -177,5 +192,24 @@ namespace Orchard.Core.Navigation {
return 3;
}
public int UpdateFrom3() {
SchemaBuilder.CreateTable("ShapeMenuItemPartRecord",
table => table.ContentPartRecord()
.Column<string>("ShapeType")
);
ContentDefinitionManager.AlterTypeDefinition("ShapeMenuItem",
cfg => cfg
.WithPart("ShapeMenuItemPart")
.WithPart("MenuPart")
.WithPart("CommonPart")
.DisplayedAs("Shape Link")
.WithSetting("Description", "Injects menu items from a Shape")
.WithSetting("Stereotype", "MenuItem")
);
return 4;
}
}
}

View File

@@ -0,0 +1,13 @@
using Orchard.ContentManagement;
namespace Orchard.Core.Navigation.Models {
public class ShapeMenuItemPart : ContentPart<ShapeMenuItemPartRecord> {
/// <summary>
/// Maximum number of items to retrieve from db
/// </summary>
public virtual string ShapeType {
get { return Record.ShapeType; }
set { Record.ShapeType = value; }
}
}
}

View File

@@ -0,0 +1,10 @@
using Orchard.ContentManagement.Records;
namespace Orchard.Core.Navigation.Models {
public class ShapeMenuItemPartRecord : ContentPartRecord {
/// <summary>
/// The shape to display
/// </summary>
public virtual string ShapeType { get; set; }
}
}

View File

@@ -6,4 +6,5 @@
<Place Parts_ContentMenuItem_Edit="Content:10"/>
<Place Parts_MenuWidget_Edit="Content:10"/>
<Place Parts_MenuWidget="Content"/>
<Place Parts_ShapeMenuItemPart_Edit="Content:10"/>
</Placement>

View File

@@ -0,0 +1,8 @@
@model Orchard.Core.Navigation.Models.ShapeMenuItemPart
<fieldset>
<div>
@Html.LabelFor(m => m.ShapeType, T("Type of the shape to display"))
@Html.TextBoxFor(m => m.ShapeType, new { @class = "text textMedium" })
</div>
</fieldset>

View File

@@ -0,0 +1,4 @@
@{
string type = Model.Content.ShapeMenuItemPart.ShapeType;
}
@Display(New.Create(type).MenuItem(Model))

View File

@@ -135,11 +135,13 @@
<Compile Include="Navigation\Drivers\NavigationPartDriver.cs" />
<Compile Include="Navigation\Drivers\MenuItemPartDriver.cs" />
<Compile Include="Navigation\Drivers\MenuWidgetPartDriver.cs" />
<Compile Include="Navigation\Drivers\ShapeMenuItemPartDriver.cs" />
<Compile Include="Navigation\Handlers\AdminMenuPartHandler.cs" />
<Compile Include="Navigation\Handlers\ContentMenuItemPartHandler.cs" />
<Compile Include="Navigation\Handlers\NavigationPartHandler.cs" />
<Compile Include="Navigation\Handlers\MenuHandler.cs" />
<Compile Include="Navigation\Handlers\MenuWidgetPartHandler.cs" />
<Compile Include="Navigation\Handlers\ShapeMenuItemPartHandler.cs" />
<Compile Include="Navigation\Models\AdminMenuPart.cs" />
<Compile Include="Navigation\Models\AdminMenuPartRecord.cs" />
<Compile Include="Navigation\Models\ContentMenuItemPartRecord.cs" />
@@ -147,6 +149,8 @@
<Compile Include="Navigation\Models\NavigationPart.cs" />
<Compile Include="Navigation\Models\MenuWidgetPartRecord.cs" />
<Compile Include="Navigation\Models\MenuWidgetPart.cs" />
<Compile Include="Navigation\Models\ShapeMenuItemPart.cs" />
<Compile Include="Navigation\Models\ShapeMenuItemPartRecord.cs" />
<Compile Include="Navigation\Security\ContentMenuItemAuthorizationEventHandler.cs" />
<Compile Include="Navigation\Services\AdminMenuNavigationProvider.cs" />
<Compile Include="Navigation\Services\DefaultMenuManager.cs" />
@@ -556,6 +560,12 @@
<ItemGroup>
<Content Include="Navigation\Views\Menu.Edit.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Navigation\Views\EditorTemplates\Parts.ShapeMenuItemPart.Edit.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Navigation\Views\MenuItemLink-ShapeMenuItem.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@@ -6,11 +6,10 @@
if (!HasText(Model.Text)) {
@DisplayChildren(Model)
} else {
string requestUrl = Request.Path.Replace(Request.ApplicationPath, string.Empty).TrimEnd('/').ToUpperInvariant();
string modelUrl = Model.Href.Replace(Request.ApplicationPath, string.Empty).TrimEnd('/').ToUpperInvariant();
if (requestUrl == modelUrl || (!string.IsNullOrEmpty(modelUrl) && requestUrl.StartsWith(modelUrl + "/"))) {
Model.Classes.Add("current");
if((bool)Model.Selected) {
Model.Classes.Add("current");
}
if(items.Any()) {
Model.Classes.Add("dropdown");
}