Getting the "add layer" hint hooked up for published content.

Hint notification message appears anytime the content is published, not just on
creation. Need to recognize an existing layer for the to be hinted layer rule so
we don't send the user down the path of duplicate layer creation.

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2011-03-23 11:04:51 -07:00
parent 8f77ef608e
commit 4703aa1429
3 changed files with 23 additions and 7 deletions

View File

@@ -175,7 +175,7 @@ namespace Orchard.Widgets.Controllers {
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index")); return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
} }
public ActionResult AddLayer() { public ActionResult AddLayer(string name, string description, string layerRule) { // <- hints for a new layer
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
@@ -185,6 +185,15 @@ namespace Orchard.Widgets.Controllers {
return HttpNotFound(); return HttpNotFound();
dynamic model = Services.ContentManager.BuildEditor(layerPart); dynamic model = Services.ContentManager.BuildEditor(layerPart);
// only messing with the hints if they're given
if (!string.IsNullOrWhiteSpace(name))
model.Name = name;
if (!string.IsNullOrWhiteSpace(description))
model.Description = description;
if (!string.IsNullOrWhiteSpace(layerRule))
model.LayerRule = layerRule;
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
return View((object)model); return View((object)model);
} catch (Exception exception) { } catch (Exception exception) {
@@ -225,9 +234,8 @@ namespace Orchard.Widgets.Controllers {
try { try {
LayerPart layerPart = _widgetsService.GetLayer(id); LayerPart layerPart = _widgetsService.GetLayer(id);
if (layerPart == null) { if (layerPart == null)
return HttpNotFound(); return HttpNotFound();
}
dynamic model = Services.ContentManager.BuildEditor(layerPart); dynamic model = Services.ContentManager.BuildEditor(layerPart);
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.

View File

@@ -12,15 +12,23 @@ using Orchard.Localization;
using Orchard.UI.Notify; using Orchard.UI.Notify;
namespace Orchard.Widgets.Drivers { namespace Orchard.Widgets.Drivers {
public class LayerHintHandlerDriver : ContentHandler { public class LayerHintHandler : ContentHandler {
public LayerHintHandlerDriver(IOrchardServices services, RequestContext requestContext) { public LayerHintHandler(IOrchardServices services, RequestContext requestContext) {
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
OnPublished<RoutePart>((context, part) => { OnPublished<RoutePart>((context, part) => {
if (string.IsNullOrWhiteSpace(part.Path)) // only going to help in creating a layer if the content has a path if (string.IsNullOrWhiteSpace(part.Path)) // only going to help in creating a layer if the content has a path
return; return;
var urlHelper = new UrlHelper(requestContext); var urlHelper = new UrlHelper(requestContext);
services.Notifier.Information(T("Would you like to <a href=\"{0}\">add a widget layer</a> for this page?", urlHelper.Action("AddLayer", "Admin", new { area = "Orchard.Widgets", rule = "url ~/" + part.Path }))); var pathForLayer = "~/" + part.Path;
services.Notifier.Information(T("Would you like to <a href=\"{0}\">add a widget layer</a> for \"{1}\"?",
urlHelper.Action("AddLayer", "Admin", new {
area = "Orchard.Widgets",
name = part.Title,
layerRule = string.Format("url \"{0}\"", pathForLayer),
description = T("A widget layer for \"{0}\" at \"{1}\".", part.Title, pathForLayer)
}),
part.Title));
}); });
} }

View File

@@ -51,7 +51,7 @@
<Compile Include="Commands\WidgetCommands.cs" /> <Compile Include="Commands\WidgetCommands.cs" />
<Compile Include="Controllers\AdminController.cs" /> <Compile Include="Controllers\AdminController.cs" />
<Compile Include="Drivers\LayerPartDriver.cs" /> <Compile Include="Drivers\LayerPartDriver.cs" />
<Compile Include="Drivers\LayerHintHandlerDriver.cs" /> <Compile Include="Drivers\LayerHintHandler.cs" />
<Compile Include="Drivers\WidgetPartDriver.cs" /> <Compile Include="Drivers\WidgetPartDriver.cs" />
<Compile Include="Migrations.cs" /> <Compile Include="Migrations.cs" />
<Compile Include="Handlers\LayerPartHandler.cs" /> <Compile Include="Handlers\LayerPartHandler.cs" />