Fixing small redirect bugs on widget admin.

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2010-10-13 13:39:38 -07:00
parent b58103b78a
commit d81707ba6e
2 changed files with 105 additions and 90 deletions

View File

@@ -106,7 +106,7 @@ namespace Orchard.Widgets.Controllers {
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message)); Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message));
return RedirectToAction("Index"); return RedirectToAction("Index", "Admin", new { id = layerId });
} }
} }
@@ -128,12 +128,12 @@ namespace Orchard.Widgets.Controllers {
} }
Services.Notifier.Information(T("Your {0} has been created.", widgetPart.TypeDefinition.DisplayName)); Services.Notifier.Information(T("Your {0} has been created.", widgetPart.TypeDefinition.DisplayName));
return RedirectToAction("Index");
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message)); Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message));
return RedirectToAction("Index");
} }
return RedirectToAction("Index", "Admin", new { id = layerId });
} }
public ActionResult AddLayer() { public ActionResult AddLayer() {
@@ -171,7 +171,7 @@ namespace Orchard.Widgets.Controllers {
} }
Services.Notifier.Information(T("Your {0} has been created.", layerPart.TypeDefinition.DisplayName)); Services.Notifier.Information(T("Your {0} has been created.", layerPart.TypeDefinition.DisplayName));
return RedirectToAction("Index"); return RedirectToAction("Index", "Admin", new { id = layerPart.Id });
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Creating layer failed: {0}", exception.Message)); Services.Notifier.Error(T("Creating layer failed: {0}", exception.Message));
@@ -194,7 +194,7 @@ namespace Orchard.Widgets.Controllers {
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Editing layer failed: {0}", exception.Message)); Services.Notifier.Error(T("Editing layer failed: {0}", exception.Message));
return RedirectToAction("Index"); return RedirectToAction("Index", "Admin", new { id });
} }
} }
@@ -216,12 +216,12 @@ namespace Orchard.Widgets.Controllers {
} }
Services.Notifier.Information(T("Your {0} has been saved.", layerPart.TypeDefinition.DisplayName)); Services.Notifier.Information(T("Your {0} has been saved.", layerPart.TypeDefinition.DisplayName));
return RedirectToAction("Index");
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Editing layer failed: {0}", exception.Message)); Services.Notifier.Error(T("Editing layer failed: {0}", exception.Message));
return RedirectToAction("Index");
} }
return RedirectToAction("Index", "Admin", new { id });
} }
[HttpPost, ActionName("EditLayer")] [HttpPost, ActionName("EditLayer")]
@@ -238,15 +238,16 @@ namespace Orchard.Widgets.Controllers {
Services.Notifier.Error(T("Removing Layer failed: {0}", exception.Message)); Services.Notifier.Error(T("Removing Layer failed: {0}", exception.Message));
} }
return RedirectToAction("Index"); return RedirectToAction("Index", "Admin", new { id });
} }
public ActionResult EditWidget(int id) { public ActionResult EditWidget(int id) {
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
WidgetPart widgetPart = null;
try { try {
WidgetPart widgetPart = _widgetsService.GetWidget(id); widgetPart = _widgetsService.GetWidget(id);
if (widgetPart == null) { if (widgetPart == null) {
Services.Notifier.Error(T("Widget not found: {1}", id)); Services.Notifier.Error(T("Widget not found: {1}", id));
return RedirectToAction("Index"); return RedirectToAction("Index");
@@ -257,6 +258,10 @@ namespace Orchard.Widgets.Controllers {
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message)); Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message));
if (widgetPart != null)
return RedirectToAction("Index", "Admin", new { id = widgetPart.LayerPart.Id });
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
} }
@@ -267,11 +272,12 @@ namespace Orchard.Widgets.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
WidgetPart widgetPart = null;
try { try {
WidgetPart widgetPart = _widgetsService.GetWidget(id); widgetPart = _widgetsService.GetWidget(id);
if (widgetPart == null) if (widgetPart == null)
return new NotFoundResult(); return new NotFoundResult();
var model = Services.ContentManager.UpdateEditor(widgetPart, this); var model = Services.ContentManager.UpdateEditor(widgetPart, this);
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
Services.TransactionManager.Cancel(); Services.TransactionManager.Cancel();
@@ -279,12 +285,14 @@ namespace Orchard.Widgets.Controllers {
} }
Services.Notifier.Information(T("Your {0} has been saved.", widgetPart.TypeDefinition.DisplayName)); Services.Notifier.Information(T("Your {0} has been saved.", widgetPart.TypeDefinition.DisplayName));
return RedirectToAction("Index");
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message)); Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message));
return RedirectToAction("Index");
} }
return widgetPart != null ?
RedirectToAction("Index", "Admin", new { id = widgetPart.LayerPart.Id }) :
RedirectToAction("Index");
} }
[HttpPost, ActionName("EditWidget")] [HttpPost, ActionName("EditWidget")]
@@ -293,15 +301,22 @@ namespace Orchard.Widgets.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
WidgetPart widgetPart = null;
try { try {
_widgetsService.DeleteWidget(id); widgetPart = _widgetsService.GetWidget(id);
if (widgetPart == null)
return new NotFoundResult();
_widgetsService.DeleteWidget(widgetPart.Id);
Services.Notifier.Information(T("Widget was successfully deleted")); Services.Notifier.Information(T("Widget was successfully deleted"));
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Removing Widget failed: {0}", exception.Message)); Services.Notifier.Error(T("Removing Widget failed: {0}", exception.Message));
} }
return RedirectToAction("Index"); return widgetPart != null ?
RedirectToAction("Index", "Admin", new { id = widgetPart.LayerPart.Id }) :
RedirectToAction("Index");
} }
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {

View File

@@ -8,85 +8,85 @@
@using(Html.BeginFormAntiForgeryPost()) { @using(Html.BeginFormAntiForgeryPost()) {
Html.ValidationSummary(); Html.ValidationSummary();
<div class="manage">@Html.ActionLink(T("Add a layer").ToString(), "AddLayer", new { }, new { @class = "button primaryAction" })</div> <div class="manage">@Html.ActionLink(T("Add a layer").ToString(), "AddLayer", new { }, new { @class = "button primaryAction" })</div>
<div id="widgets"> <div id="widgets">
<div class="widgets-availableWidgets">
<h2>Available Widgets</h2>
<fieldset> <div class="widgets-availableWidgets">
<table class="items" summary="@T("This is a table of the widgets currently available for use in your application.")"> <h2>Available Widgets</h2>
<colgroup>
<col id="Col1" />
<col id="Col2" />
</colgroup>
<thead>
<tr>
<th scope="col">@T("Name")</th>
<th scope="col"></th>
</tr>
</thead>
@foreach (string widget in Model.WidgetTypes) {
<tr>
<td>@widget</td>
<td>@Html.ActionLink(T("Add").ToString(), "AddWidget", new { layerId = Model.CurrentLayer.Id, widgetType = widget })</td>
</tr>
}
</table>
</fieldset> <fieldset>
</div> <table class="items" summary="@T("This is a table of the widgets currently available for use in your application.")">
<colgroup>
<col id="Col1" />
<col id="Col2" />
</colgroup>
<thead>
<tr>
<th scope="col">@T("Name")</th>
<th scope="col"></th>
</tr>
</thead>
@foreach (string widget in Model.WidgetTypes) {
<tr>
<td>@widget</td>
<td>@Html.ActionLink(T("Add").ToString(), "AddWidget", new { layerId = Model.CurrentLayer.Id, widgetType = widget })</td>
</tr>
}
</table>
<div class="widgets-availableLayers"> </fieldset>
<h2>Widget Layers</h2> </div>
<fieldset> <div class="widgets-availableLayers">
<div> <h2>Widget Layers</h2>
<ul class="widgets-layerZones">
@foreach (string zone in Model.Zones) {
<li>
<div class="widgets-zone">@zone</div>
<ul>
@foreach (WidgetPart widget in Model.CurrentLayerWidgets.Where(widgetPart => widgetPart.Zone == zone).OrderBy(widgetPart => widgetPart.Position, new Orchard.UI.FlatPositionComparer())) {
<li class="widgets-zoneWidget">
@if (widget.Position != "1") {
<input type="image" name="submit.MoveUp.@widget.Id" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/moveup.gif")" alt="Move up" value="@widget.Id" />
}
@if (int.Parse(widget.Position) < Model.CurrentLayerWidgets.Where(widgetPart => widgetPart.Zone == zone).Count()) {
<input type="image" name="submit.MoveDown.@widget.Id" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/movedown.gif")" alt="Move down" value="@widget.Id" />
}
@Html.ActionLink(@widget.Title, "EditWidget", new { @widget.Id })
</li>
}
</ul>
</li>
}
</ul>
</div>
<div class="widgets-layers"> <fieldset>
<ul> <div>
@foreach (var layer in Model.Layers) { <ul class="widgets-layerZones">
if (layer.Id == Model.CurrentLayer.Id) { @foreach (string zone in Model.Zones) {
<li class="widgets-currentLayer widgets-editLayer"> <li>
@Html.ActionLink(@layer.Name, "Index", new { @layer.Id }) <div class="widgets-zone">@zone</div>
<a href="@Url.Action("EditLayer", new { @layer.Id })"> <ul>
<img width="15" height="15" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/edit.gif")" /> @foreach (WidgetPart widget in Model.CurrentLayerWidgets.Where(widgetPart => widgetPart.Zone == zone).OrderBy(widgetPart => widgetPart.Position, new Orchard.UI.FlatPositionComparer())) {
</a> <li class="widgets-zoneWidget">
</li> @if (widget.Position != "1") {
} else { <input type="image" name="submit.MoveUp.@widget.Id" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/moveup.gif")" alt="Move up" value="@widget.Id" />
<li class="widgets-editLayer"> }
@Html.ActionLink(@layer.Name, "Index", new { @layer.Id }) @if (int.Parse(widget.Position) < Model.CurrentLayerWidgets.Where(widgetPart => widgetPart.Zone == zone).Count()) {
<a href="@Url.Action("EditLayer", new { @layer.Id })"> <input type="image" name="submit.MoveDown.@widget.Id" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/movedown.gif")" alt="Move down" value="@widget.Id" />
<img width="15" height="15" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/edit.gif")" /> }
</a> @Html.ActionLink(@widget.Title, "EditWidget", new { @widget.Id })
</li> </li>
} }
} </ul>
<ul> </li>
</div> }
</fieldset> </ul>
</div> </div>
</div>
<div class="widgets-layers">
<ul>
@foreach (var layer in Model.Layers) {
if (layer.Id == Model.CurrentLayer.Id) {
<li class="widgets-currentLayer widgets-editLayer">
@Html.ActionLink(@layer.Name, "Index", new { @layer.Id })
<a href="@Url.Action("EditLayer", new { @layer.Id })">
<img width="15" height="15" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/edit.gif")" />
</a>
</li>
} else {
<li class="widgets-editLayer">
@Html.ActionLink(@layer.Name, "Index", new { @layer.Id })
<a href="@Url.Action("EditLayer", new { @layer.Id })">
<img width="15" height="15" src="@Url.Content("~/modules/orchard.widgets/Content/Admin/images/edit.gif")" />
</a>
</li>
}
}
<ul>
</div>
</fieldset>
</div>
</div>
} }