When creating content items from lists, redirect back to the list when finished. Create action now supports ReturnUrl querystring param.

--HG--
branch : dev
This commit is contained in:
Dave Reed
2011-03-14 16:37:24 -07:00
parent cf241ae898
commit f9d0cf5297
3 changed files with 10 additions and 7 deletions

View File

@@ -202,8 +202,8 @@ namespace Orchard.Core.Contents.Controllers {
[HttpPost, ActionName("Create")]
[FormValueRequired("submit.Save")]
public ActionResult CreatePOST(string id) {
return CreatePOST(id, contentItem => {
public ActionResult CreatePOST(string id, string returnUrl) {
return CreatePOST(id, returnUrl, contentItem => {
if (!contentItem.Has<IPublishingControlAspect>() && !contentItem.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable)
_contentManager.Publish(contentItem);
});
@@ -211,14 +211,14 @@ namespace Orchard.Core.Contents.Controllers {
[HttpPost, ActionName("Create")]
[FormValueRequired("submit.Publish")]
public ActionResult CreateAndPublishPOST(string id) {
public ActionResult CreateAndPublishPOST(string id, string returnUrl) {
if (!Services.Authorizer.Authorize(Permissions.PublishContent, T("Couldn't create content")))
return new HttpUnauthorizedResult();
return CreatePOST(id, contentItem => _contentManager.Publish(contentItem));
return CreatePOST(id, returnUrl, contentItem => _contentManager.Publish(contentItem));
}
private ActionResult CreatePOST(string id, Action<ContentItem> conditionallyPublish) {
private ActionResult CreatePOST(string id, string returnUrl, Action<ContentItem> conditionallyPublish) {
var contentItem = _contentManager.New(id);
if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Couldn't create content")))
@@ -238,6 +238,9 @@ namespace Orchard.Core.Contents.Controllers {
Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName)
? T("Your content has been created.")
: T("Your {0} has been created.", contentItem.TypeDefinition.DisplayName));
if (!string.IsNullOrEmpty(returnUrl)) {
return this.RedirectLocal(returnUrl);
}
var adminRouteValues = _contentManager.GetItemMetadata(contentItem).AdminRouteValues;
return RedirectToRoute(adminRouteValues);
}

View File

@@ -1,5 +1,5 @@
@{ Layout.Title = T("Create New Content").ToString(); }
@foreach (var type in Model.ContentTypes) {
<p>@Html.ActionLink((string)type.DisplayName, "Create", new { Area = "Contents", Id = (string)type.Name, ContainerId = Model.ContainerId })</p>
<p>@Html.ActionLink((string)type.DisplayName, "Create", new { Area = "Contents", Id = (string)type.Name, ContainerId = Model.ContainerId, ReturnUrl = Request.QueryString["ReturnUrl"] })</p>
}

View File

@@ -5,7 +5,7 @@
Layout.Title = (string)pageTitle.Text;
}
@using (Html.BeginFormAntiForgeryPost()) {
@using (Html.BeginFormAntiForgeryPost(Url.Action("Create", new { ReturnUrl = Request.QueryString["ReturnUrl"] }))) {
@Html.ValidationSummary()
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
@Display(Model)