--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-02-12 12:00:24 -08:00
16 changed files with 219 additions and 10 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");
}

View File

@@ -24,9 +24,15 @@
var url = baseUrl
+ "/Admin/Orchard.ContentPicker?"
+ "callback=" + callbackName
+ "&" + (new Date() - 0)
+ "&part=" + encodeURIComponent(data.part)
+ "&field=" + encodeURIComponent(data.field);
+ "&" + (new Date() - 0);
if (data.part) {
url += "&part=" + encodeURIComponent(data.part);
}
if (data.field) {
url += "&field=" + encodeURIComponent(data.field);
}
var w = window.open(url, "_blank", data.windowFeatures || "width=685,height=700,status=no,toolbar=no,location=no,menubar=no,resizable=no,scrollbars=yes");
});

View File

@@ -72,6 +72,16 @@
link = link + "?callback=" + query("callback");
self.attr("href", link);
}
if (url.length == 1 || query("part", "?" + url[1]).length == 0) {
link = link + "&part=" + query("part");
self.attr("href", link);
}
if (url.length == 1 || query("field", "?" + url[1]).length == 0) {
link = link + "&field=" + query("field");
self.attr("href", link);
}
});
// get a querystring value

View File

@@ -2,7 +2,7 @@
<fieldset>
<div>
@Html.CheckBoxFor(m => m.ShowSearchTab) <label for="@Html.FieldIdFor(m => m.ShowSearchTab)" class="forcheckbox">@T("Show Content tab")</label>
@Html.CheckBoxFor(m => m.ShowSearchTab) <label for="@Html.FieldIdFor(m => m.ShowSearchTab)" class="forcheckbox">@T("Show Search tab")</label>
<span class="hint">@T("Uncheck to hide the Search tab from the picker window.")</span>
</div>
</fieldset>

View File

@@ -0,0 +1,25 @@
using System.Collections.ObjectModel;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Widgets.Handlers {
/// <summary>
/// Saves references to content items which have been displayed during a request
/// </summary>
public class DisplayedContentItemDetailHandler : ContentHandler, IDisplayedContentItemHandler {
private readonly Collection<string> _contentTypes = new Collection<string>();
protected override void BuildDisplayShape(BuildDisplayContext context) {
if (context.DisplayType == "Detail") {
_contentTypes.Add(context.ContentItem.ContentType);
}
}
public bool IsDisplayed(string contentType) {
return _contentTypes.Contains(contentType);
}
}
public interface IDisplayedContentItemHandler: IDependency {
bool IsDisplayed(string contentType);
}
}

View File

@@ -63,6 +63,7 @@
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="ControlWrapper.cs" />
<Compile Include="Drivers\LayerPartDriver.cs" />
<Compile Include="Handlers\DisplayedContentItemHandler.cs" />
<Compile Include="Handlers\LayerHintHandler.cs" />
<Compile Include="Drivers\WidgetPartDriver.cs" />
<Compile Include="Migrations.cs" />
@@ -78,6 +79,7 @@
<Compile Include="ResourceManifest.cs" />
<Compile Include="RuleEngine\AuthenticatedRuleProvider.cs" />
<Compile Include="RuleEngine\BuiltinRuleProvider.cs" />
<Compile Include="RuleEngine\ContentDisplayedRuleProvider.cs" />
<Compile Include="RuleEngine\RuleManager.cs" />
<Compile Include="RuleEngine\UrlRuleProvider.cs" />
<Compile Include="Services\IRuleManager.cs" />

View File

@@ -0,0 +1,23 @@
using System;
using Orchard.Widgets.Handlers;
using Orchard.Widgets.Services;
namespace Orchard.Widgets.RuleEngine {
public class ContentDisplayedRuleProvider : IRuleProvider {
private readonly IDisplayedContentItemHandler _displayedContentItemHandler;
public ContentDisplayedRuleProvider(IDisplayedContentItemHandler displayedContentItemHandler) {
_displayedContentItemHandler = displayedContentItemHandler;
}
public void Process(RuleContext ruleContext) {
if (!String.Equals(ruleContext.FunctionName, "contenttype", StringComparison.OrdinalIgnoreCase)) {
return;
}
var contentType = Convert.ToString(ruleContext.Arguments[0]);
ruleContext.Result = _displayedContentItemHandler.IsDisplayed(contentType);
}
}
}