如何在保存Sitecore项目时显示弹出窗口? [英] How to display a popup when saving a Sitecore item?

查看:14
本文介绍了如何在保存Sitecore项目时显示弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保存Sitecore项目时,我尝试显示弹出窗口以与用户交互。根据他们更改的数据,我可能会显示一系列1到2个弹出窗口,询问他们是否要继续。我已经想出了如何接入OnItemSaving管道。这很简单。我不明白的是如何显示弹出窗口并对用户的输入做出反应。现在我想我应该以某种方式使用Sitecore.Context.ClientPage.ClientResponse对象。下面是一些代码,它显示了我正在尝试做的事情:

public class MyCustomEventProcessor
{
    public void OnItemSaving(object sender, EventArgs args)
    {
      if([field criteria goes here])
      {
        Sitecore.Context.ClientPage.ClientResponse.YesNoCancel("Are you sure you want to continue?", "500", "200");
        [Based on results from the YesNoCancel then potentially cancel the Item Save or show them another dialog]
      }
    }
}

我是否应该使用其他方法?我看到还有ShowModalDialog、ShowPopUp和ShowQuery等等,我似乎找不到任何关于这些的文档。此外,我甚至不确定这样做是否正确。

推荐答案

该过程大致如下(我应该注意,我从未尝试过在Item:Saving事件中执行此操作,但是,我相信它应该会起作用):

  1. item:saving事件中,调用客户端管道中的对话处理程序,并向其传递一组参数。
  2. 处理器执行以下两项操作之一:显示对话框或使用响应。
  3. 收到响应时,处理器使用它,您可以在那里执行操作。

下面是演示上述步骤的示例:

private void StartDialog()
{
    // Start the dialog and pass in an item ID as an argument
    ClientPipelineArgs cpa = new ClientPipelineArgs();
    cpa.Parameters.Add("id", Item.ID.ToString());

    // Kick off the processor in the client pipeline
    Context.ClientPage.Start(this, "DialogProcessor", cpa);
}

protected void DialogProcessor(ClientPipelineArgs args)
{
    var id = args.Parameters["id"];

    if (!args.IsPostBack)
    {
        // Show the modal dialog if it is not a post back
        SheerResponse.YesNoCancel("Are you sure you want to do this?", "300px", "100px");

        // Suspend the pipeline to wait for a postback and resume from another processor
        args.WaitForPostBack(true);
    }
    else
    {
        // The result of a dialog is handled because a post back has occurred
        switch (args.Result)
        {
            case "yes":

                var item = Context.ContentDatabase.GetItem(new ID(id));
                if (item != null)
                {
                    // TODO: act on the item

                    // Reload content editor with this item selected...
                    var load = String.Format("item:load(id={0})", item.ID);
                    Context.ClientPage.SendMessage(this, load);
                }

                break;

            case "no":

                // TODO: cancel ItemSavingEventArgs

                break;

            case "cancel":
                break;
        }
    }
}

这篇关于如何在保存Sitecore项目时显示弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆