Sitecore 工作流程和管道
我正在尝试在工作流程命令上实现基本的 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();
}
}
I'm trying to implement a basic Javascript confirmation box on a workflow command (e.g. "are you sure you want to edit this?"). Depending on whether a users clicks yes or no, I want to move to a different state in the workflow. Here is the code I currently have (some logic is taken out):
[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();
}
}
}
I'm new to the Pipeline model, especially in relation to Sitecore, so I'm somewhat grasping at straws. The problem that I'm having, I believe, is that I don't have a way of getting the result back to the Workflow Pipeline, from the ClientResponse pipeline, to tell it what to do.
Thank you.
EDIT:
Using Yan's information, I eventually came up with the following solution:
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,我认为这就是您可以利用 ClientPipelineArgs 的地方。假设您将当前项目 ID 添加到要传递的参数中:
稍后当您获得肯定结果时,您将其取回并移至目标工作流程状态(在注释中进行了解释):
这可能需要一些细微的更改(我没有在发布之前我自己运行一下),但希望你能明白。
Well, I think this is where you can take advantage from
ClientPipelineArgs
. Let's say you add the current item ID to the parameters to pass:and later on when you get positive result you get it back and move to the target workflow state (explained in comments):
This might require some minor changes (I didn't run it myself before posting), but hope you get the idea.