mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Hooking the widget movement arrows back up.
--HG-- branch : dev
This commit is contained in:
@@ -69,27 +69,17 @@ namespace Orchard.Widgets.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost, ActionName("Index")]
|
[HttpPost, ActionName("Index")]
|
||||||
public ActionResult IndexWidgetPOST(int? id, string returnUrl) {
|
public ActionResult IndexWidgetPOST(int? moveUp, int? moveDown, string returnUrl) {
|
||||||
const string moveDownString = "submit.MoveDown.";
|
|
||||||
const string moveUpString = "submit.MoveUp.";
|
|
||||||
|
|
||||||
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
|
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
string moveDownAction = HttpContext.Request.Form.AllKeys.FirstOrDefault(key => key.StartsWith(moveDownString));
|
if (moveUp.HasValue)
|
||||||
if (moveDownAction != null) {
|
_widgetsService.MoveWidgetUp(moveUp.Value);
|
||||||
moveDownAction = moveDownAction.Substring(moveDownString.Length, moveDownAction.IndexOf(".", moveDownString.Length) - moveDownString.Length);
|
if (moveDown.HasValue)
|
||||||
_widgetsService.MoveWidgetDown(int.Parse(moveDownAction));
|
_widgetsService.MoveWidgetDown(moveDown.Value);
|
||||||
}
|
}
|
||||||
else {
|
catch (Exception exception) {
|
||||||
string moveUpAction = HttpContext.Request.Form.AllKeys.FirstOrDefault(key => key.StartsWith(moveUpString));
|
|
||||||
if (moveUpAction != null) {
|
|
||||||
moveUpAction = moveUpAction.Substring(moveUpString.Length, moveUpAction.IndexOf(".", moveUpString.Length) - moveUpString.Length);
|
|
||||||
_widgetsService.MoveWidgetUp(int.Parse(moveUpAction));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception exception) {
|
|
||||||
this.Error(exception, T("Moving widget failed: {0}", exception.Message), Logger, Services.Notifier);
|
this.Error(exception, T("Moving widget failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +130,7 @@ namespace Orchard.Widgets.Controllers {
|
|||||||
if (widgetPart == null)
|
if (widgetPart == null)
|
||||||
return HttpNotFound();
|
return HttpNotFound();
|
||||||
|
|
||||||
int widgetPosition = _widgetsService.GetWidgets(layerId).Count() + 1;
|
int widgetPosition = _widgetsService.GetWidgets().Where(widget => widget.Zone == widgetPart.Zone).Count() + 1;
|
||||||
widgetPart.Position = widgetPosition.ToString();
|
widgetPart.Position = widgetPosition.ToString();
|
||||||
widgetPart.Zone = zone;
|
widgetPart.Zone = zone;
|
||||||
widgetPart.LayerPart = _widgetsService.GetLayer(layerId);
|
widgetPart.LayerPart = _widgetsService.GetLayer(layerId);
|
||||||
|
|||||||
@@ -127,10 +127,20 @@ namespace Orchard.Widgets.Services {
|
|||||||
_contentManager.Remove(GetWidget(widgetId).ContentItem);
|
_contentManager.Remove(GetWidget(widgetId).ContentItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int ParsePosition(WidgetPart widgetPart) {
|
||||||
|
int value;
|
||||||
|
if (!int.TryParse(widgetPart.Record.Position, out value))
|
||||||
|
return 0;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveWidgetUp(int widgetId) {
|
||||||
|
return MoveWidgetUp(GetWidget(widgetId));
|
||||||
|
}
|
||||||
public bool MoveWidgetUp(WidgetPart widgetPart) {
|
public bool MoveWidgetUp(WidgetPart widgetPart) {
|
||||||
int currentPosition = ParsePosition(widgetPart);
|
int currentPosition = ParsePosition(widgetPart);
|
||||||
|
|
||||||
WidgetPart widgetBefore = GetWidgets(widgetPart.LayerPart.Id)
|
WidgetPart widgetBefore = GetWidgets()
|
||||||
.Where(widget => widget.Zone == widgetPart.Zone)
|
.Where(widget => widget.Zone == widgetPart.Zone)
|
||||||
.OrderByDescending(widget => widget.Position, new UI.FlatPositionComparer())
|
.OrderByDescending(widget => widget.Position, new UI.FlatPositionComparer())
|
||||||
.FirstOrDefault(widget => ParsePosition(widget) < currentPosition);
|
.FirstOrDefault(widget => ParsePosition(widget) < currentPosition);
|
||||||
@@ -144,21 +154,13 @@ namespace Orchard.Widgets.Services {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ParsePosition(WidgetPart widgetPart) {
|
public bool MoveWidgetDown(int widgetId) {
|
||||||
int value;
|
return MoveWidgetDown(GetWidget(widgetId));
|
||||||
if (!int.TryParse(widgetPart.Record.Position, out value))
|
|
||||||
return 0;
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MoveWidgetUp(int widgetId) {
|
|
||||||
return MoveWidgetUp(GetWidget(widgetId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool MoveWidgetDown(WidgetPart widgetPart) {
|
public bool MoveWidgetDown(WidgetPart widgetPart) {
|
||||||
int currentPosition = ParsePosition(widgetPart);
|
int currentPosition = ParsePosition(widgetPart);
|
||||||
|
|
||||||
WidgetPart widgetAfter = GetWidgets(widgetPart.LayerPart.Id)
|
WidgetPart widgetAfter = GetWidgets()
|
||||||
.Where(widget => widget.Zone == widgetPart.Zone)
|
.Where(widget => widget.Zone == widgetPart.Zone)
|
||||||
.OrderBy(widget => widget.Position, new UI.FlatPositionComparer())
|
.OrderBy(widget => widget.Position, new UI.FlatPositionComparer())
|
||||||
.FirstOrDefault(widget => ParsePosition(widget) > currentPosition);
|
.FirstOrDefault(widget => ParsePosition(widget) > currentPosition);
|
||||||
@@ -172,9 +174,6 @@ namespace Orchard.Widgets.Services {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MoveWidgetDown(int widgetId) {
|
|
||||||
return MoveWidgetDown(GetWidget(widgetId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SwitchWidgetPositions(WidgetPart sourceWidget, WidgetPart targetWidget) {
|
private static void SwitchWidgetPositions(WidgetPart sourceWidget, WidgetPart targetWidget) {
|
||||||
string tempPosition = sourceWidget.Record.Position;
|
string tempPosition = sourceWidget.Record.Position;
|
||||||
|
|||||||
@@ -33,14 +33,15 @@
|
|||||||
<div id="widgets-placement">
|
<div id="widgets-placement">
|
||||||
<div id="widgets-layers" class="widgets-container detail-view switchable">
|
<div id="widgets-layers" class="widgets-container detail-view switchable">
|
||||||
<div id="widgets-zones">
|
<div id="widgets-zones">
|
||||||
|
@using (Html.BeginFormAntiForgeryPost()) {
|
||||||
<ol>
|
<ol>
|
||||||
@foreach (string zone in zones) {
|
@foreach (string zone in zones) {
|
||||||
int count = widgets.Where(w => w.Zone == zone).Count();
|
int count = widgets.Where(w => w.Zone == zone).Count();
|
||||||
MvcHtmlString classA = null;
|
MvcHtmlString classAttr = null;
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
classA = new MvcHtmlString(" class=\"widgets-none\"");
|
classAttr = new MvcHtmlString(" class=\"widgets-none\"");
|
||||||
}
|
}
|
||||||
<li@(classA)>
|
<li@(classAttr)>
|
||||||
<h2>@zone</h2>
|
<h2>@zone</h2>
|
||||||
<div class="widgets-actions">@Html.ActionLink(T("Add").Text, "ChooseWidget", new { layerId = Model.CurrentLayer.Id, zone, returnUrl }, new { @class = "button" })</div>
|
<div class="widgets-actions">@Html.ActionLink(T("Add").Text, "ChooseWidget", new { layerId = Model.CurrentLayer.Id, zone, returnUrl }, new { @class = "button" })</div>
|
||||||
<ul class="widgets-zone-widgets">
|
<ul class="widgets-zone-widgets">
|
||||||
@@ -49,10 +50,10 @@
|
|||||||
foreach (WidgetPart widget in widgets.Where(w => w.Zone == zone).OrderBy(w => w.Position, new Orchard.UI.FlatPositionComparer())) {
|
foreach (WidgetPart widget in widgets.Where(w => w.Zone == zone).OrderBy(w => w.Position, new Orchard.UI.FlatPositionComparer())) {
|
||||||
<li>
|
<li>
|
||||||
@if (i > 0) {
|
@if (i > 0) {
|
||||||
<input class="widgets-mover" type="image" name="submit.MoveUp.@widget.Id" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/moveup.gif")" alt="Move up" value="@widget.Id" />
|
<input class="widgets-mover" type="image" name="moveUp" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/moveup.gif")" alt="Move up" value="@widget.Id" />
|
||||||
}
|
}
|
||||||
@if (++i < count) {
|
@if (++i < count) {
|
||||||
<input class="widgets-mover" type="image" name="submit.MoveDown.@widget.Id" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/movedown.gif")" alt="Move down" value="@widget.Id" />
|
<input class="widgets-mover" type="image" name="moveDown" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/movedown.gif")" alt="Move down" value="@widget.Id" />
|
||||||
}
|
}
|
||||||
@Html.ActionLink(HasText(widget.Title) ? widget.Title : widget.TypeDefinition.DisplayName, "EditWidget", new { @widget.Id })
|
@Html.ActionLink(HasText(widget.Title) ? widget.Title : widget.TypeDefinition.DisplayName, "EditWidget", new { @widget.Id })
|
||||||
</li>
|
</li>
|
||||||
@@ -62,6 +63,7 @@
|
|||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
</ol>
|
</ol>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user