我正在尝试在工作流程命令上实现一个基本的 Javascript确认框(例如“你确定要编辑它吗?”).根据用户是单击是还是否,我想转到工作流程中的其他状态.这是我目前的代码(取出一些逻辑
[Serializable] public class ConfirmAction { public void Process(WorkflowPipelineArgs args) { Item currentItem = args.DataItem; ClientPipelineArgs clientArgs = new ClientPipelineArgs(); Sitecore.Context.ClientPage.Start(this, "DialogProcessor", clientArgs); } protected void DialogProcessor(ClientPipelineArgs args) { if (args.IsPostBack) { if (args.Result != "yes") { args.AbortPipeline(); return; } } else { Sitecore.Context.ClientPage.ClientResponse.Confirm("Are you sure you want to edit this?"); args.WaitForPostBack(); } } }
我是Pipeline模型的新手,特别是与Sitecore有关,所以我有点掌握稻草.我相信,我遇到的问题是,我没有办法将结果从ClientResponse管道返回到工作流管道,告诉它该做什么.
谢谢.
编辑:
使用Yan的信息,我最终想出了以下解决方案:
public void Process(WorkflowPipelineArgs args) { Item currentItem = args.DataItem; ClientPipelineArgs clientArgs = new ClientPipelineArgs(); clientArgs.Parameters.Add("itemID", currentItem.ID.ToString()); clientArgs.Parameters.Add("stateID", currentItem.Fields["__Workflow state"].Value); Sitecore.Context.ClientPage.Start(this, "DialogProcessor", clientArgs); } protected void DialogProcessor(ClientPipelineArgs args) { if (args.IsPostBack) { if (args.Result != "yes") { Item currentItem = Sitecore.Configuration.Factory.GetDatabase("master").GetItem(args.Parameters["itemID"]); currentItem.Editing.BeginEdit(); currentItem.Fields["__Workflow state"].Value = args.Parameters["stateID"]; currentItem.Editing.EndEdit(); return; } SheerResponse.Eval("window.location.reload();"); } else { Sitecore.Context.ClientPage.ClientResponse.YesNoCancel("Are you sure you want to edit this?", "200", "200"); args.WaitForPostBack(); } }好吧,我认为这是您可以利用ClientPipelineArgs的地方.假设您将当前项ID添加到要传递的参数中:
public void Process(WorkflowPipelineArgs args) { Item currentItem = args.DataItem; ClientPipelineArgs clientArgs = new ClientPipelineArgs(); clientArgs.Parameters.Add("id", currentItem.ID.ToString()); Sitecore.Context.ClientPage.Start(this, "DialogProcessor", clientArgs); }
然后当你得到肯定的结果时,你会把它拿回来并转移到目标工作流状态(在评论中解释):
protected void DialogProcessor(ClientPipelineArgs args) { if (args.IsPostBack) { if (args.Result == "yes") { // 1. take item ID from args.Parameters["id"]; // 2. get item by this ID // 3. move item to target workflow state } } else { Sitecore.Context.ClientPage.ClientResponse.Confirm("Are you sure you want to edit this?"); args.WaitForPostBack(); } }
这可能需要一些小的改动(我在发布之前没有自己运行),但希望你明白这个想法.