Sitecore 工作流程和管道

发布于 2024-10-09 07:41:58 字数 2255 浏览 5 评论 0原文

我正在尝试在工作流程命令上实现基本的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆兒滾 2024-10-16 07:41:58

嗯,我认为这就是您可以利用 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();
    }
}

这可能需要一些细微的更改(我没有在发布之前我自己运行一下),但希望你能明白。

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:

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);
}

and later on when you get positive result you get it back and move to the target workflow state (explained in comments):

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();
    }
}

This might require some minor changes (I didn't run it myself before posting), but hope you get the idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文