Adding MenuItemLink alternates

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2012-05-21 17:04:01 -07:00
parent cf4411a644
commit f1d3458afa
16 changed files with 95 additions and 14 deletions

View File

@@ -8,5 +8,9 @@
/// Used to determine if this content type supports draft versions
/// </summary>
public bool Draftable { get; set; }
/// <summary>
/// Defines the stereotype of the type
/// </summary>
public string Stereotype { get; set; }
}
}

View File

@@ -60,6 +60,16 @@ namespace Orchard.Core.Navigation {
.Column<bool>("OnAdminMenu")
);
ContentDefinitionManager.AlterTypeDefinition("HtmlMenuItem", cfg => cfg
.WithPart("MenuPart")
.WithPart("BodyPart")
.WithPart("CommonPart")
.DisplayedAs("Html Menu Item")
.WithSetting("Description", "Renders some custom HTML in the menu.")
.WithSetting("BodyPartSettings.FlavorDefault", "html")
.WithSetting("Stereotype", "MenuItem")
);
ContentDefinitionManager.AlterPartDefinition("AdminMenuPart", builder => builder.Attachable());
return 3;
@@ -112,6 +122,16 @@ namespace Orchard.Core.Navigation {
.AlterTable("MenuPartRecord", table => table.AddColumn<int>("MenuRecord_id"))
;
ContentDefinitionManager.AlterTypeDefinition("HtmlMenuItem", cfg => cfg
.WithPart("MenuPart")
.WithPart("BodyPart")
.WithPart("CommonPart")
.DisplayedAs("Html Menu Item")
.WithSetting("Description", "Renders some custom HTML in the menu.")
.WithSetting("BodyPartSettings.FlavorDefault", "html")
.WithSetting("Stereotype", "MenuItem")
);
return 3;
}
}

View File

@@ -1,7 +1,5 @@
using System.Web;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Common.Models;
using Orchard.Core.Navigation.Models;
using Orchard.Localization;
using Orchard.UI.Navigation;
@@ -26,9 +24,9 @@ namespace Orchard.Core.Navigation.Services {
var part = menuPart;
if (part.Is<MenuItemPart>())
builder.Add(new LocalizedString(HttpUtility.HtmlEncode(part.MenuText)), part.MenuPosition, item => item.Url(part.As<MenuItemPart>().Url));
builder.Add(new LocalizedString(HttpUtility.HtmlEncode(part.MenuText)), part.MenuPosition, item => item.Url(part.As<MenuItemPart>().Url).Content(part));
else
builder.Add(new LocalizedString(HttpUtility.HtmlEncode(part.MenuText)), part.MenuPosition, item => item.Action(_contentManager.GetItemMetadata(part.ContentItem).DisplayRouteValues));
builder.Add(new LocalizedString(HttpUtility.HtmlEncode(part.MenuText)), part.MenuPosition, item => item.Action(_contentManager.GetItemMetadata(part.ContentItem).DisplayRouteValues).Content(part));
}
}
}

View File

@@ -107,7 +107,7 @@
.menu-items-zone {
background:#F3F4F5;
border:1px solid #E4E5E6;
padding:5px;
padding:0px;
}
.menu-items-zone h2 {
@@ -118,8 +118,9 @@
.menu-items-zone li {
background:#FFF;
border:1px solid #EAEAEA;
margin: 2px;
padding: 5px;
padding-right:60px;
padding-right:65px;
display: block;
position:relative;
}

View File

@@ -29,6 +29,8 @@ else {
<label for="MenuText">@T("Menu text")</label>
@Html.TextBoxFor(m => m.MenuText, new { @class = "textMedium", autofocus = "autofocus" })
<span class="hint">@T("The text that should appear in the menu.")</span>
@Html.HiddenFor(m => m.OnMenu, true)
@Html.HiddenFor(m => m.CurrentMenuId, Request["menuId"])
</fieldset>
}

View File

@@ -0,0 +1 @@
<span class="raw">@Html.Raw(Model.Content.BodyPart.Text)</span>

View File

@@ -525,6 +525,9 @@
<ItemGroup>
<Content Include="Shapes\Views\MenuItemLink.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Navigation\Views\MenuItemLink-HtmlMenuItem.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -94,6 +94,18 @@ namespace Orchard.Core.Shapes {
menuItem.Metadata.Alternates.Add("MenuItem__" + menu.MenuName);
});
builder.Describe("MenuItemLink")
.OnDisplaying(displaying => {
var menuItem = displaying.Shape;
var menu = menuItem.Menu;
menuItem.Metadata.Alternates.Add("MenuItemLink__" + menu.MenuName);
string contentType = menuItem.Content.ContentItem.ContentType;
if(contentType != null) {
menuItem.Metadata.Alternates.Add("MenuItemLink__" + contentType);
}
});
builder.Describe("LocalMenu")
.OnDisplaying(displaying => {
var menu = displaying.Shape;

View File

@@ -59,6 +59,7 @@
<Compile Include="Services\ContentDefinitionService.cs" />
<Compile Include="Services\IContentDefinitionService.cs" />
<Compile Include="ViewModels\AddFieldViewModel.cs" />
<Compile Include="ViewModels\ContentTypeSettingsViewModel.cs" />
<Compile Include="ViewModels\EditFieldNameViewModel.cs" />
<Compile Include="ViewModels\CreatePartViewModel.cs" />
<Compile Include="ViewModels\EditFieldViewModel.cs" />
@@ -122,7 +123,7 @@
<Content Include="Views\Admin\EditField.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\DefinitionTemplates\ContentTypeSettings.cshtml" />
<Content Include="Views\DefinitionTemplates\ContentTypeSettingsViewModel.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

View File

@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.ViewModels;
using Orchard.ContentTypes.ViewModels;
using Orchard.Core.Contents.Extensions;
using Orchard.Core.Contents.Settings;
@@ -11,15 +13,26 @@ namespace Orchard.ContentTypes.Settings {
public class EditorEvents : ContentDefinitionEditorEventsBase {
public override IEnumerable<TemplateViewModel> TypeEditor(ContentTypeDefinition definition) {
var model = definition.Settings.GetModel<ContentTypeSettings>();
var settings = definition.Settings.GetModel<ContentTypeSettings>();
var model = new ContentTypeSettingsViewModel {
Creatable = settings.Creatable,
Draftable = settings.Draftable,
};
if(definition.Settings.ContainsKey("Stereotype")) {
model.Stereotype = definition.Settings["Stereotype"] ?? String.Empty;
}
yield return DefinitionTemplate(model);
}
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) {
var model = new ContentTypeSettings();
updateModel.TryUpdateModel(model, "ContentTypeSettings", null, null);
var model = new ContentTypeSettingsViewModel();
updateModel.TryUpdateModel(model, "ContentTypeSettingsViewModel", null, null);
builder.Creatable(model.Creatable);
builder.Draftable(model.Draftable);
builder.WithSetting("Stereotype", model.Stereotype);
yield return DefinitionTemplate(model);
}

View File

@@ -0,0 +1,7 @@
namespace Orchard.ContentTypes.ViewModels {
public class ContentTypeSettingsViewModel {
public bool Creatable { get; set; }
public bool Draftable{ get; set; }
public string Stereotype { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
@model Orchard.Core.Contents.Settings.ContentTypeSettings
@model Orchard.ContentTypes.ViewModels.ContentTypeSettingsViewModel
<fieldset>
@Html.EditorFor(m => m.Creatable)
@@ -12,4 +12,11 @@
<label for="@Html.FieldIdFor(m => m.Draftable)" class="forcheckbox">@T("Draftable")</label>
@Html.ValidationMessageFor(m => m.Draftable)
<span class="hint">@T("Determines if this content type supports draft versions.")</span>
</fieldset>
<fieldset>
<label for="@Html.FieldIdFor(m => m.Stereotype)">@T("Stereotype")</label>
@Html.TextBoxFor(m => m.Stereotype, new { @class = "textMedium"})
@Html.ValidationMessageFor(m => m.Stereotype)
<span class="hint">@T("(Optional) The stereotype of the content type. e.g., Widget, MenuItem, ...")</span>
</fieldset>

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Security.Permissions;
@@ -24,6 +25,7 @@ namespace Orchard.UI.Navigation {
public RouteValueDictionary RouteValues { get; set; }
public IEnumerable<MenuItem> Items { get; set; }
public IEnumerable<Permission> Permissions { get; set; }
public IContent Content { get; set; }
public IList<string> Classes {
get { return _classes; }
set {

View File

@@ -151,7 +151,8 @@ namespace Orchard.UI.Navigation {
.RouteValues(menuItem.RouteValues)
.Item(menuItem)
.Menu(menu)
.Parent(parentShape);
.Parent(parentShape)
.Content(menuItem.Content);
foreach (var className in menuItem.Classes)
menuItemShape.Classes.Add(className);

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Security.Permissions;
@@ -26,11 +27,17 @@ namespace Orchard.UI.Navigation {
_item.MenuId = menuId;
return this;
}
public NavigationItemBuilder Url(string url) {
_item.Url = url;
return this;
}
public NavigationItemBuilder Content(IContent content) {
_item.Content = content;
return this;
}
public NavigationItemBuilder IdHint(string idHint) {
_item.IdHint = idHint;
return this;

View File

@@ -96,7 +96,8 @@ namespace Orchard.UI.Navigation {
Url = item.Url,
LinkToFirstChild = item.LinkToFirstChild,
Href = item.Href,
MenuId = item.MenuId
MenuId = item.MenuId,
Content = item.Content
};
}
}
@@ -225,6 +226,7 @@ namespace Orchard.UI.Navigation {
Position = SelectBestPositionValue(items.Select(x => x.Position)),
Permissions = items.SelectMany(x => x.Permissions).Distinct(),
MenuId = items.First().MenuId,
Content = items.First().Content
};
return joined;
}