mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fix Issue #4352: Added prompt on workflow save to give choice of stopping running workflows.
This commit is contained in:
@@ -23,6 +23,7 @@ using Orchard.UI.Notify;
|
||||
using Orchard.Workflows.Models;
|
||||
using Orchard.Workflows.Services;
|
||||
using Orchard.Workflows.ViewModels;
|
||||
using Orchard.Workflows.Helpers;
|
||||
|
||||
namespace Orchard.Workflows.Controllers {
|
||||
[ValidateInput(false)]
|
||||
@@ -234,7 +235,7 @@ namespace Orchard.Workflows.Controllers {
|
||||
dynamic activity = new JObject();
|
||||
activity.Name = x.Name;
|
||||
activity.Id = x.Id;
|
||||
activity.ClientId = x.Name + "_" + x.Id;
|
||||
activity.ClientId = x.GetClientId();
|
||||
activity.Left = x.X;
|
||||
activity.Top = x.Y;
|
||||
activity.Start = x.Start;
|
||||
@@ -259,7 +260,7 @@ namespace Orchard.Workflows.Controllers {
|
||||
|
||||
[HttpPost, ActionName("Edit")]
|
||||
[FormValueRequired("submit.Save")]
|
||||
public ActionResult EditPost(int id, string localId, string data) {
|
||||
public ActionResult EditPost(int id, string localId, string data, bool clearWorkflows) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
@@ -275,7 +276,6 @@ namespace Orchard.Workflows.Controllers {
|
||||
var activitiesIndex = new Dictionary<string, ActivityRecord>();
|
||||
|
||||
workflowDefinitionRecord.ActivityRecords.Clear();
|
||||
workflowDefinitionRecord.WorkflowRecords.Clear();
|
||||
|
||||
foreach (var activity in state.Activities) {
|
||||
ActivityRecord activityRecord;
|
||||
@@ -303,9 +303,32 @@ namespace Orchard.Workflows.Controllers {
|
||||
});
|
||||
}
|
||||
|
||||
if (clearWorkflows) {
|
||||
workflowDefinitionRecord.WorkflowRecords.Clear();
|
||||
}
|
||||
else {
|
||||
foreach (var workflowRecord in workflowDefinitionRecord.WorkflowRecords) {
|
||||
// Update any awaiting activity records with the new activity record.
|
||||
foreach (var awaitingActivityRecord in workflowRecord.AwaitingActivities) {
|
||||
var clientId = awaitingActivityRecord.ActivityRecord.GetClientId();
|
||||
if (activitiesIndex.ContainsKey(clientId)) {
|
||||
awaitingActivityRecord.ActivityRecord = activitiesIndex[clientId];
|
||||
}
|
||||
else {
|
||||
workflowRecord.AwaitingActivities.Remove(awaitingActivityRecord);
|
||||
}
|
||||
}
|
||||
// Remove any workflows with no awaiting activities.
|
||||
if (!workflowRecord.AwaitingActivities.Any()) {
|
||||
workflowDefinitionRecord.WorkflowRecords.Remove(workflowRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Workflow saved successfully"));
|
||||
|
||||
return RedirectToAction("Edit", new { id, localId });
|
||||
// Don't pass the localId to force the activites to refresh and use the deterministic clientId.
|
||||
return RedirectToAction("Edit", new { id });
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Edit")]
|
||||
|
@@ -38,5 +38,14 @@ namespace Orchard.Workflows.Models {
|
||||
/// containing this activity.
|
||||
/// </summary>
|
||||
public virtual WorkflowDefinitionRecord WorkflowDefinitionRecord { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id which can be used on the client.
|
||||
/// </summary>
|
||||
/// <returns>An unique Id to represent this activity on the client.</returns>
|
||||
public string GetClientId() {
|
||||
return Name + "_" + Id;
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@
|
||||
Style.Require("WorkflowsAdmin");
|
||||
Style.Require("WorkflowsActivities");
|
||||
Style.Require("jQueryUI_Orchard");
|
||||
Script.Require("jQueryUI_Dialog").AtFoot();
|
||||
Script.Require("jsPlumb").AtFoot();
|
||||
Script.Include("orchard-workflows-serialize.js").AtFoot();
|
||||
Script.Include("orchard-workflows.js").AtFoot();
|
||||
@@ -74,23 +75,41 @@
|
||||
@Html.Hidden("data", String.Empty)
|
||||
|
||||
@Html.Hidden("confirm-delete-activity", T("Are you sure you want to remove this activity?"))
|
||||
@Html.Hidden("confirm-delete-instances", T("Are you sure you want to remove running instances of this workflow?"))
|
||||
@Html.Hidden("confirm-delete-instances", T("You have running instances of this workflow, do you want to stop them?"))
|
||||
|
||||
using (Script.Foot()) {
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
$("form").submit(function () {
|
||||
saveLocal(localId);
|
||||
var workflow = loadWorkflow(localId);
|
||||
var data = JSON.stringify(workflow);
|
||||
$("[name='data']").val(data);
|
||||
$("form").submit(function (e, submit, clearWorkflows) {
|
||||
if(submit){
|
||||
saveLocal(localId);
|
||||
var workflow = loadWorkflow(localId);
|
||||
var data = JSON.stringify(workflow);
|
||||
$("[name='data']").val(data);
|
||||
var values = [$("<input>", { type: "hidden", name: "clearWorkflows", value: clearWorkflows }), $("<input>", { type: "hidden", name: "submit.Save", value: "Save" })];
|
||||
$(this).append(values);
|
||||
return true;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
url: stateUrl + "/" + $("#id").val(),
|
||||
async: false,
|
||||
success: function(state) {
|
||||
if(state.isRunning && !confirm($("#confirm-delete-instances").val())) {
|
||||
e.preventDefault();
|
||||
if (state.isRunning) {
|
||||
var dialog = $('<p>' + $("#confirm-delete-instances").val() + '</p>').dialog({
|
||||
buttons: {
|
||||
'@T("Yes")': function() { $('form').trigger('submit', [true, true]); },
|
||||
'@T("No")': function() { $('form').trigger('submit', [true, false]); },
|
||||
'@T("Cancel")': function() {
|
||||
dialog.dialog('close');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('form').trigger('submit', [true, false]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user