diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs index 449c89c4a..4e07ef598 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs @@ -4,14 +4,15 @@ using System.Web.Mvc; using System.Linq; using Orchard.ContentManagement; using Orchard.Core.Contents.Controllers; +using Orchard.DisplayManagement; using Orchard.Localization; using Orchard.Logging; +using Orchard.Mvc.Extensions; using Orchard.UI.Admin; using Orchard.UI.Notify; using Orchard.Utility.Extensions; using Orchard.Widgets.Models; using Orchard.Widgets.Services; -using Orchard.Widgets.ViewModels; namespace Orchard.Widgets.Controllers { @@ -24,57 +25,69 @@ namespace Orchard.Widgets.Controllers { public AdminController( IOrchardServices services, - IWidgetsService widgetsService) { + IWidgetsService widgetsService, + IShapeFactory shapeFactory) { Services = services; _widgetsService = widgetsService; T = NullLocalizer.Instance; Logger = NullLogger.Instance; + Shape = shapeFactory; } private IOrchardServices Services { get; set; } public Localizer T { get; set; } public ILogger Logger { get; set; } + dynamic Shape { get; set; } - public ActionResult Index(int? id) { + public ActionResult Index(int? layerId) { IEnumerable layers = _widgetsService.GetLayers(); LayerPart currentLayer; - IEnumerable currentLayerWidgets; + IEnumerable widgets; if (layers.Count() > 0) { - currentLayer = id == null ? + currentLayer = layerId == null ? layers.First() : - layers.FirstOrDefault(layer => layer.Id == id); + layers.FirstOrDefault(layer => layer.Id == layerId); if (currentLayer == null && - id != null) { + layerId != null) { // Incorrect layer id passed - Services.Notifier.Error(T("Layer not found: {0}", id)); + Services.Notifier.Error(T("Layer not found: {0}", layerId)); return RedirectToAction("Index"); } - currentLayerWidgets = _widgetsService.GetWidgets(currentLayer.Id); + widgets = _widgetsService.GetWidgets(); } else { currentLayer = null; - currentLayerWidgets = new List(); + widgets = new List(); } - WidgetsIndexViewModel widgetsIndexViewModel = new WidgetsIndexViewModel { - WidgetTypes = _widgetsService.GetWidgetTypes(), - Layers = layers, - Zones = _widgetsService.GetZones(), - CurrentLayer = currentLayer, - CurrentLayerWidgets = currentLayerWidgets - }; + //WidgetsIndexViewModel widgetsIndexViewModel = new WidgetsIndexViewModel { + // WidgetTypes = _widgetsService.GetWidgetTypes(), + // Layers = layers, + // Zones = _widgetsService.GetZones(), + // CurrentLayer = currentLayer, + // CurrentLayerWidgets = currentLayerWidgets + //}; - return View(widgetsIndexViewModel); + //return View(widgetsIndexViewModel); + + dynamic viewModel = Shape.ViewModel() + .CurrentLayer(currentLayer) + .Layers(layers) + .Widgets(widgets) + .Zones(_widgetsService.GetZones()); + + // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. + return View((object)viewModel); } [HttpPost, ActionName("Index")] - public ActionResult IndexWidgetPOST(int? id) { + public ActionResult IndexWidgetPOST(int? id, string returnUrl) { const string moveDownString = "submit.MoveDown."; const string moveUpString = "submit.MoveUp."; @@ -98,7 +111,7 @@ namespace Orchard.Widgets.Controllers { this.Error(exception, T("Moving widget failed: {0}", exception.Message), Logger, Services.Notifier); } - return RedirectToAction("Index", "Admin", new { id }); + return this.RedirectLocal(returnUrl, () => RedirectToAction("Index")); } public ActionResult AddWidget(int layerId, string widgetType) { @@ -216,7 +229,7 @@ namespace Orchard.Widgets.Controllers { [HttpPost, ActionName("EditLayer")] [FormValueRequired("submit.Save")] - public ActionResult EditLayerSavePOST(int id) { + public ActionResult EditLayerSavePOST(int id, string returnUrl) { if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) return new HttpUnauthorizedResult(); @@ -238,7 +251,7 @@ namespace Orchard.Widgets.Controllers { this.Error(exception, T("Editing layer failed: {0}", exception.Message), Logger, Services.Notifier); } - return RedirectToAction("Index", "Admin", new { id }); + return this.RedirectLocal(returnUrl, () => RedirectToAction("Index")); } [HttpPost, ActionName("EditLayer")] diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Orchard.Widgets.csproj b/src/Orchard.Web/Modules/Orchard.Widgets/Orchard.Widgets.csproj index f1f3be1a7..8c184261f 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Orchard.Widgets.csproj +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Orchard.Widgets.csproj @@ -71,7 +71,6 @@ - diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Styles/orchard-widgets-admin.css b/src/Orchard.Web/Modules/Orchard.Widgets/Styles/orchard-widgets-admin.css index c26226f70..73f60200a 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Styles/orchard-widgets-admin.css +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Styles/orchard-widgets-admin.css @@ -1,114 +1,57 @@ -#main #widgets h2 { - border-bottom:none; +#layout-widgets-placement { +float:left; +width:65%; +} +#widgets-placement { } +#layout-widgets-assistance { +float:right; +width:35%; +} +.widgets-container { +padding:10px; } -h4.widgets-layer-header, h4.widgets-zone-header { - font-weight:600; +#widgets-layers-control { +margin-bottom:-20px; +} +#widgets-layers-control form, #widgets-layers-control fieldset { +display:inline; +} +#widgets-layers-control select, #widgets-layers-control a { +vertical-align:middle; +} +#widgets-layers-control a { +margin-left:10px; } -h4.widgets-layer-header { - float:left; - width:40%; +#widgets-zones { +background:#F3F4F5; +border:1px solid #E4E5E6; +padding:0 5px; } - - -.widgetsbag-editor h5 { - color:#4c4c4c; - font-weight:600; +#widgets-zones ol { +list-style:decimal inside; } - -.widgets-availableWidgets { - float: right; - float: left; - width: 30%; - margin: 0 0 0 2em; +#widgets-zones li { +background:#FFF; +color:#AEC3CE; +border:1px solid #EAEAEA; +margin:5px 0; +padding:0 10px; } - -.widgets-availableWidgets table.items th -{ - background: #f1f1f1; - padding:.5em 0 .3em .2em; +#widgets-zones h2 { +font-size:1.077em; } - -.widgets-availableLayers { - float: left; - margin: 0 0 0 2em; - width: 60%; - min-width: 40%; +#widgets-zones h2, #widgets-zones li li { +color:#333; } - -.widgets-layerZones { - float: left; - float: right; - width: 60%; - border: 1px solid #eaeaea; - border:1px solid #ccc; - background: #fcfcfc; +#widgets-zones li li { +background:#F3F4F5; +border:0; +margin:10px 0; +padding:5px 10px 5px 25px; } - -.widgets-layerZones .widgets-zone { - background:#f5f5f5; - border: 1px solid #f1f1f1; - padding: 1em 2em 1em 2em; - margin: 0 0 .6em 0; +#widgets-zones .widgets-mover { +margin-left:-18px; +vertical-align:-2px; } - -.widgets-layerZones .widgets-zoneWidget { - margin: .6em; - padding: 1em 2em 1em 3em; - background:#ffffff; - border: 1px solid #f1f1f1; - vertical-align: middle; -} - -.widgets-availableLayers fieldset -{ - border: 1px solid #eaeaea; - background: #f1f1f1; - background: -moz-linear-gradient(center top, #f1f1f1, #fcfcfc); - padding: .6em; -} - -.widgets-availableWidgets fieldset { - padding: 0; -} - -.widgets-layers { - border:1px solid #ccc; - border-right:none; -} - -.widgets-layers ul { - background: #f5f5f5; - border: 1px solid #f1f1f1; -} - -.widgets-layers ul li -{ - padding: .6em .4em; - border:1px solid #F1F1F1; -} - -.widgets-layers .widgets-currentLayer { - background: #c3d9ff; -} - -.widgets-layers .widgets-currentLayer a { - color: #333; - font-weight: 600; -} - -.widgets-layerZones ul li ul { - margin: 0; - padding: 0; -} - -.new-layer { - padding: .6em; - background: #F5F5F5; -} - -.new-layer a { - text-decoration: none; - font-weight: 600; -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/ViewModels/WidgetsIndexViewModel.cs b/src/Orchard.Web/Modules/Orchard.Widgets/ViewModels/WidgetsIndexViewModel.cs deleted file mode 100644 index fb24ec294..000000000 --- a/src/Orchard.Web/Modules/Orchard.Widgets/ViewModels/WidgetsIndexViewModel.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Collections.Generic; -using Orchard.Widgets.Models; - -namespace Orchard.Widgets.ViewModels -{ - public class WidgetsIndexViewModel - { - /// - /// The available widget content types. - /// - public IEnumerable WidgetTypes { get; set; } - - /// - /// The available layers. - /// - public IEnumerable Layers { get; set; } - - /// - /// The available zones in the page. - /// - public IEnumerable Zones { get; set; } - - /// - /// The current layer. - /// - public LayerPart CurrentLayer { get; set; } - - /// - /// The current layer widgets. - /// - public IEnumerable CurrentLayerWidgets { get; set; } - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml index 4904bcf69..9f04734f9 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml @@ -1,41 +1,52 @@ -@model WidgetsIndexViewModel +@using Orchard.Utility.Extensions; @using Orchard.Widgets.Models; -@using Orchard.Widgets.ViewModels; @{ Style.Require("WidgetsAdmin"); - Layout.Title = T("Manage Widgets").ToString(); + IEnumerable layers = Model.Layers; + IEnumerable widgets = Model.Widgets; + IEnumerable zones = Model.Zones; + var returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString(); } -@using(Html.BeginFormAntiForgeryPost()) { - Html.ValidationSummary(); - - -
- -
-

Widgets

- -
-

Layers

-

Zones

-
-
    - @foreach (string zone in Model.Zones) { +
    +
    + @if (layers.Count() > 0) { + using (Html.BeginForm("index", "admin", FormMethod.Get, new {area = "Orchard.Widgets"})) { +
    + + + + @Html.Link(T("Edit").Text, Url.Action("EditLayer", "Admin", new { area = "Orchard.Widgets", id = Model.CurrentLayer.Id, returnUrl }), new { @class = "button" }) +
    + } + } + @Html.Link(T("Add a new layer...").Text, Url.Action("AddLayer", "Admin", new { area = "Orchard.Widgets", returnUrl })) +
    +
    +
    +
    +
    +
      + @foreach (string zone in zones) {
    1. -
      @zone
      -
        +

        @zone

        +
          @{ - int count = Model.CurrentLayerWidgets.Where(widgetPart => widgetPart.Zone == zone).Count() - 1; + int count = widgets.Where(w => w.Zone == zone).Count() - 1; int i = 0; } - @foreach (WidgetPart widget in Model.CurrentLayerWidgets.Where(widgetPart => widgetPart.Zone == zone).OrderBy(widgetPart => widgetPart.Position, new Orchard.UI.FlatPositionComparer())) { -
        • + @foreach (WidgetPart widget in widgets.Where(w => w.Zone == zone).OrderBy(w => w.Position, new Orchard.UI.FlatPositionComparer())) { +
        • @if (i > 0) { - + } @if (i < count) { - + } @{ i++; @@ -46,56 +57,17 @@
        } -
      +
    - -
    -
      - @foreach (var layer in Model.Layers) { - var layerClass = "widgets-editLayer"; - if (layer.Id == Model.CurrentLayer.Id) { - layerClass += " widgets-currentLayer"; - } -
    • - - - - @Html.ActionLink(@layer.Name, "Index", new { @layer.Id }) -
    • - } -
    -
    - @Html.ActionLink(T("+ Add a layer").ToString(), "AddLayer", new { }) -
    -
    -
-
- - -
-

Available Widgets

- -
- - - - - - - - - - - - @foreach (string widget in Model.WidgetTypes) { - - - - - } -
@T("Name")
@widget@Html.ActionLink(T("Add to zone").ToString(), "AddWidget", new { layerId = Model.CurrentLayer.Id, widgetType = widget })
- -
+
-} \ No newline at end of file +
+
+
+

[theme preview image]

+

[layer visibility]

+
+
+
+