2013-03-13 88 views
1

我有一個純粹的UI嚮導,它收集用戶的信息,然後在sitecore中創建一個內容項目。嚮導使用命令模板啓動。如何在Sitecore內容編輯器中選擇項目

我想讓嚮導在內容編輯器中將新創建的內容項目製作爲當前選定的項目,但我無法弄清楚如何執行此操作。有誰知道這是如何完成的?

更新

Trayek的建議已經得到了我遠一點。現在我已經得到了在命令下面的代碼,我用它來啓動向導:

[Serializable] 
public class MyNewContentCommand : Command 
{ 

    public override void Execute(CommandContext context) 
    { 
     ClientPipelineArgs args = new ClientPipelineArgs(); 
     args.Parameters["id"] = context.Parameters["id"]; 
     Context.ClientPage.Start(this, "Run", args); 
    } 

    protected void Run(ClientPipelineArgs args) 
    { 
     if (!args.IsPostBack) 
     { 
      // This runs when the users clicks to add the item 
      // in the content editor. 

      // Launches a modal wizard to collect user data 

      string id = args.Parameters["id"]; 

      string controlUrl = Sitecore.UIUtil.GetUri("control:MyNewItemWizard"); 
      UrlString urlStr = new UrlString(controlUrl); 
      urlStr.Append("id", id); 

      SheerResponse.ShowModalDialog(urlStr.ToString(), true); 
      args.WaitForPostBack(); 

     } 
     else if (args.HasResult) 
     { 
      // This runs once the wizard has finished 

      // Wizard passes ID of created item in its result 
      // This is used to find the newly created item. 
      Item created = Client.GetItemNotNull(ID.Parse(args.Result)); 

      // Sending these messages result in refreshing the child items 
      // of the parent. And they work. 
      Context.ClientPage.SendMessage(this, string.Format("item:updated(id={0})", created.Parent.ID)); 
      Context.ClientPage.SendMessage(this, string.Format("item:refreshchildren(id={0})", created.Parent.ID)); 

      // This message should select the new item in content editor, but 
      // it doesn't have the desired effect. 
      Context.ClientPage.SendMessage(this, string.Format("item:load(id={0})", (object)created.ID)); 
     } 
    } 
} 

回答

1

對不起,回答我的問題。問題是由於「刷新內容樹中的項目」命令和「選擇內容樹中的項目」命令之間似乎存在爭用條件而導致的。我必須延遲選擇命令幾毫秒才能使其工作。

Context.ClientPage.SendMessage(this, 
    string.Format("item:updated(id={0})", created.Parent.ID)); 
Context.ClientPage.SendMessage(this, 
    string.Format("item:refreshchildren(id={0})", created.Parent.ID)); 
Context.ClientPage.ClientResponse.Timer(
    string.Format("item:load(id={0})", created.ID), 100); 
+0

如果這是一個有效的答案,那麼爲了上帝的緣故吧! – cwallenpoole 2013-06-14 13:42:22

2

有一個讀通過this鏈接。它爲您提供了3種選擇:

  • 生成URL,並鏈接到它
  • 打開它從XAML應用程序
  • 打開它從JavaScript
+0

感謝您的提示讓我更進一步:內容樹現在已更新以顯示新項目,但仍無法獲取內容編輯器來選擇我的新項目。有任何想法嗎? – 2013-03-13 16:04:07

+0

Sitecore使用Context.ClientPage.SendMessage(this,「item:loadid =」+ args.Result +「)」); 你試過了嗎? 我在想你爲什麼要將created.ID轉換成對象?不會created.ID或created.ID.ToString()工作? – Trayek 2013-03-13 16:14:48

+0

發送消息代碼基於反編譯一些現有的sitecore命令;這是演員出身的地方。查看我的答案,找出問題的原因。 – 2013-03-14 10:20:52

相關問題