如何使用 Sitecore ShowControlPopup 与用户进行对话交互?

发布于 2024-11-27 09:37:36 字数 1311 浏览 1 评论 0原文

我根据 Data Definition Cookbook 中的内容创建了一些简单的命令,其中用户交互是右键单击某个项目 ->插入-> MyCommand 后跟一个简单的对话框,显示“您真的想这样做吗”。那太棒了。

现在我想要一个命令,允许我在对话框中与用户进行更多交互。我需要添加几个单选按钮列表,以便用户可以选择选项,然后选择一个按钮来运行命令。我想我需要为此使用 ShowControlPopup 。我创建了一个控件 (ascx) 来定义弹出窗口的外观(并发布了一个测试版本以查看它是否可以作为 Sitecore 中的基本控件运行)。但是,我不确定 ShowControlPopup 的参数到底是什么。

第一个参数称为“Id” - 我在此处放置什么 Id?使用弹出控件的项目的 id?

第二个参数称为“where” - 我猜这是弹出窗口将具有的 URL。这里是否需要存在内容项,或者它只是一个虚拟 URL?

第三个参数称为“controlId” - 我在此处放置什么 id?我已经尝试了定义弹出窗口的控件的 id,但收到一条错误消息,指出找不到该控件。

当用户在对话框中选择选项并单击“确定”时,什么处理该事件?命令类的 Run 方法或弹出控件代码隐藏中的事件处理程序?

这是我到目前为止的代码。如果尝试创建控件时失败,并出现无法找到具有提供的 id 的项目的错误。我刚刚猜测了弹出控件想要了解哪些项目。

protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
{
 if (args.IsPostBack)
 {
  if (args.HasResult)
  { // normally code here would run when the dialog box is completed by the user.  Is that so in this case?

  }
 }
 else
 {
  Sitecore.Context.ClientPage.ClientResponse.ShowControlPopup("F3684C4C-D9EF-4796-A471-5B05553119B6",
                 "http://mysite/dummy.aspx",
                 "B8D503D0-AEBE-43AE-B924-C3849F03E90D");

  args.WaitForPostBack();
 }
}

干杯,

詹姆斯。

Sitecore 6.2 rev 091012 / Win7 32bit / IIS7 / SQLExpress 2008(仅限本地开发)

I've created a few simple commands based on what's in the Data Definition Cookbook where the user interaction is right click on an item -> insert -> MyCommand followed by a simple dialog box saying "Do you really want to do this". That's great.

Now I want a command that allows me to interact a bit more with the user at the dialog box. I need to add a couple of radio button lists so the user can select options and then a button to run the command. I think I need to use ShowControlPopup for this. I have created a control (ascx) to define what the popup will look like (and have published a test version to see that it works as a basic control in Sitecore). However, I am not sure exactly what the parameters to ShowControlPopup are.

The first paratered is called "Id" - What Id do I put in here? The id of an item that uses the popup control?

The second parameter is called "where" - I'm guessing this is the URL that the popup will have. Does a content item need to exist here or is it simply a dummy URL?

The third parameter is called "controlId" - What id do I put here? I have tried the id of my control that defines the popup but I get an error saying the control cannot be found.

When the user has chosen their options in the dialog box and clicks "ok" what handles the event? The Run method of the command class or an event handler in the codebehind for the popup control?

This is my code so far. If fails when it tries to create the control with an error about not being able to find the items with the id's supplied. I have just taken guesses at what items the popup control wants to know about.

protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
{
 if (args.IsPostBack)
 {
  if (args.HasResult)
  { // normally code here would run when the dialog box is completed by the user.  Is that so in this case?

  }
 }
 else
 {
  Sitecore.Context.ClientPage.ClientResponse.ShowControlPopup("F3684C4C-D9EF-4796-A471-5B05553119B6",
                 "http://mysite/dummy.aspx",
                 "B8D503D0-AEBE-43AE-B924-C3849F03E90D");

  args.WaitForPostBack();
 }
}

Cheers,

James.

Sitecore 6.2 rev 091012 / Win7 32bit / IIS7 / SQLExpress 2008 (local dev only)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

白首有我共你 2024-12-04 09:37:36

仅作为记录,Sitecore 支持返回了一些答案

1)“Id”是触发弹出窗口的项目的 ID

2)“Where”是相对于“Id”的位置。例如,上方、下方、右下方

3) “controlId”是弹出项目的 ID

Sitecore 中使用 ShowPopupControl 的示例是主菜单和上下文菜单。

此外,SheerUI 仍然没有文档记录,我被告知只需在 Sitecore 代码库中查找示例即可。很高兴我们可以查看 Sitecore 代码,但如果有一点指导就更好了。即使 doco 只是说“对于 ShowPopupControl 的使用,UI 示例 x 可以在 dll z 的类 y 中找到”。

命令和命令的生命周期弹出窗口可以使用弹出窗口中的代码隐藏或命令本身来完成。这取决于最终的args.WaitForPostBack(),它也可以是“args.WaitForPostBack(true)”或“args.WaitForPostBack(false)”。

最后我选择了 ShowModalDialog(),因为这实际上是我想要的,而不是用户可以点击离开的弹出窗口。

所以我的代码最终看起来像这样

protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
{
    if (args.IsPostBack)
    {
        ;// we never come here becuase we have set waitforpostback to false.  all processing is handled by the popup control
    }
    else
    {
        Sitecore.Text.UrlString popUpUrl = new Sitecore.Text.UrlString("/sitecore/content/MYSITE/MyControlPageItem.aspx");
        popUpUrl.Append("id", args.Parameters["id"]);
        popUpUrl.Append("database", args.Parameters["database"]);
        popUpUrl.Append("language", args.Parameters["language"]);
        Sitecore.Context.ClientPage.ClientResponse.ShowModalDialog(popUpUrl.ToString(),"400", "600", "", true);

        args.WaitForPostBack(false);    // if this is true this command will wait for the modal dialog created above to close
                                        // at which time the Run method will check for postback & args
    }
}

Just for the record, Sitecore Support came back with some answers

1) "Id" is the ID of the item that is fires the popup

2) "Where" is a location relative to "Id". eg above, below, right-below

3) "controlId" is the ID of the item that is the popup

Examples from Sitecore that use ShowPopupControl are the main menu and context menu.

Also, the SheerUI is still undocumented and I was told to simply look for examples in the Sitecore code base. It is great that we can look at the Sitecore code, but a little direction would be great. Even if the doco simply said "For use of ShowPopupControl the UI example x can be found in class y in dll z".

The life of the command & popup can finish with the codebehind in the popup or with the command itself. This is dependant on the final args.WaitForPostBack() which can also be 'args.WaitForPostBack(true)or 'args.WaitForPostBack(false).

In the end I went with ShowModalDialog() because this was actually what I wanted rather than a popup that a user could click away from.

So my code ended up looking like this

protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
{
    if (args.IsPostBack)
    {
        ;// we never come here becuase we have set waitforpostback to false.  all processing is handled by the popup control
    }
    else
    {
        Sitecore.Text.UrlString popUpUrl = new Sitecore.Text.UrlString("/sitecore/content/MYSITE/MyControlPageItem.aspx");
        popUpUrl.Append("id", args.Parameters["id"]);
        popUpUrl.Append("database", args.Parameters["database"]);
        popUpUrl.Append("language", args.Parameters["language"]);
        Sitecore.Context.ClientPage.ClientResponse.ShowModalDialog(popUpUrl.ToString(),"400", "600", "", true);

        args.WaitForPostBack(false);    // if this is true this command will wait for the modal dialog created above to close
                                        // at which time the Run method will check for postback & args
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文