Adding the ability to rename workflows, fixes #3570

This commit is contained in:
Lombiq
2015-05-14 18:04:45 +02:00
committed by Zoltán Lehóczky
parent 1cfbfbce92
commit 3760e12029
3 changed files with 50 additions and 20 deletions

View File

@@ -175,19 +175,29 @@ namespace Orchard.Workflows.Controllers {
return View(viewModel);
}
public ActionResult Create() {
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to create workflows")))
public ActionResult EditProperties(int id = 0)
{
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows.")))
return new HttpUnauthorizedResult();
return View();
if (id == 0) {
return View();
}
else {
var workflowDefinition = _workflowDefinitionRecords.Get(id);
return View(new AdminEditViewModel { WorkflowDefinition = new WorkflowDefinitionViewModel { Name = workflowDefinition.Name, Id = workflowDefinition.Id } });
}
}
[HttpPost, ActionName("Create")]
public ActionResult CreatePost(string name) {
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to create workflows")))
[HttpPost, ActionName("EditProperties")]
public ActionResult EditPropertiesPost(AdminEditViewModel adminEditViewModel, int id = 0) {
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows.")))
return new HttpUnauthorizedResult();
if (String.IsNullOrWhiteSpace(name)) {
if (String.IsNullOrWhiteSpace(adminEditViewModel.WorkflowDefinition.Name)) {
ModelState.AddModelError("Name", T("The Name can't be empty.").Text);
}
@@ -195,21 +205,22 @@ namespace Orchard.Workflows.Controllers {
return View();
}
var workflowDefinitionRecord = new WorkflowDefinitionRecord {
Name = name
};
if (id == 0) {
var workflowDefinitionRecord = new WorkflowDefinitionRecord {
Name = adminEditViewModel.WorkflowDefinition.Name
};
if (ModelState.IsValid) {
_workflowDefinitionRecords.Create(workflowDefinitionRecord);
}
if (!ModelState.IsValid) {
Services.TransactionManager.Cancel();
return RedirectToAction("Edit", new { workflowDefinitionRecord.Id });
}
else {
var workflowDefinition = _workflowDefinitionRecords.Get(id);
workflowDefinition.Name = adminEditViewModel.WorkflowDefinition.Name;
return RedirectToAction("Index");
}
return RedirectToAction("Edit", new { workflowDefinitionRecord.Id });
}
public ActionResult Edit(int id, string localId, int? workflowId) {

View File

@@ -0,0 +1,19 @@
@model Orchard.Workflows.ViewModels.AdminEditViewModel
@using Orchard.Workflows.Models;
@using Orchard.Workflows.ViewModels;
@using (Html.BeginFormAntiForgeryPost()) {
@Html.ValidationSummary()
<fieldset>
<div>
<label for="name">@T("Name")</label>
@Html.TextBoxFor(m => m.WorkflowDefinition.Name, new { @class = "text medium" })
<span class="hint">@T("The name of the Workflow.")</span>
</div>
</fieldset>
<fieldset>
<button class="primaryAction" type="submit">@T("Save")</button>
</fieldset>
}

View File

@@ -14,7 +14,7 @@
<h1>@Html.TitleForPage(T("Manage Workflow Definitions").ToString()) </h1>
@using (Html.BeginFormAntiForgeryPost()) {
@Html.ValidationSummary()
<div class="manage">@Html.ActionLink(T("Create new Workflow Definition").ToString(), "Create", new { Area = "Orchard.Workflows", returnurl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })</div>
<div class="manage">@Html.ActionLink(T("Create new Workflow Definition").Text, "EditProperties", new { Area = "Orchard.Workflows", returnurl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })</div>
<fieldset class="bulk-actions">
<label for="publishActions">@T("Actions:")</label>
@@ -65,9 +65,9 @@
&nbsp;
</td>
<td>
@* TODO: As WD is not a Content Item, an EditProperties action is necessary @Html.ActionLink(T("Properties").ToString(), "Edit", new { Area = "Contents", id = entry.WokflowDefinitionId, returnurl = HttpContext.Current.Request.RawUrl }) |*@
@Html.ActionLink(T("Edit").ToString(), "Edit", new { id = entry.WokflowDefinitionId }) |
@Html.ActionLink(T("Delete").ToString(), "Delete", new { id = entry.WokflowDefinitionId }, new { itemprop = "RemoveUrl UnsafeUrl" })
@Html.ActionLink(T("Properties").Text, "EditProperties", new { Id = entry.WokflowDefinitionId, ReturnUrl = HttpContext.Current.Request.RawUrl }) |
@Html.ActionLink(T("Edit").Text, "Edit", new { Id = entry.WokflowDefinitionId }) |
@Html.ActionLink(T("Delete").Text, "Delete", new { Id = entry.WokflowDefinitionId }, new { ItemProp = "RemoveUrl UnsafeUrl" })
</td>
</tr>
index++;