保存Sitecore项目时如何显示弹出窗口?

Cor*_*ett 4 sitecore sitecore6

保存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]
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

我应该使用不同的方法吗?我看到还有ShowModalDialog和ShowPopUp以及ShowQuestion等.我似乎无法找到关于这些的任何文档.此外,我甚至不确定这是否是这样做的正确方法.

Der*_*ker 7

这个过程是这样的(我应该注意到我从未尝试过这个项目:保存事件,但是,我相信它应该有效):

  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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)