title: Closing a Sitecore Speak Dialog that was opened from a Rich Text Editor
body: <p>I'm converting a Sheer UI module to SPEAK, and it's generally been pretty painless except for one problem. It's a dialog that opens from a button click in the rich text editor. I can't work out how to close it and return a value.</p>
  
  <p>I've tried looking at the way Sitecore's existing SPEAK dialogs do it. For example <code>SelectMediaDialog</code>:  </p>
  
  <ul>
  <li>It has a rule component called <code>insertButtonRule</code>. </li>
  <li>The target control is set to <code>SelectMediaButton</code> and the trigger is
  set to <code>click</code>. </li>
  <li>The condition / action for the associated rule is
  "when <code>always</code>, set the dialog return value to component
  <code>MediaResultsListControl</code> <code>selectedItemId</code>".</li>
  </ul>
  
  <p>This seems fairly straight forward, but I couldn't duplicate it for my application - it just does nothing. I realise that none of the current Sitecore SPEAK dialogs are launched from the rich text editor, so this isn't really a like-for-like comparison. Perhaps it's the way I'm opening the dialog?</p>
  
  <p>Here's the js command that I use to open my dialog (it's basically the same as my old Sheer UI app but with a different URL):</p>
  
  <pre class="lang-js prettyprint-override"><code>RadEditorCommandList["OpenMyApp"] = function(commandName, editor, tool) 
  {
      scEditor = editor; 
      var range = scEditor.getSelection().getRange()
  
      range.expand("word");
      scEditor.getSelection().selectRange(range)
      var html = scEditor.getSelection().getText().trim();
  
      scEditor.showExternalDialog(
        "/sitecore/client/MySpeakApp?term=" + escape(html),
        null, //argument
        300, //width
        500, //height
        scMyCallback,
        null,
        "My Speak App",
        true, //modal
        Telerik.Web.UI.WindowBehaviors.Close, // behaviors
        false, //showStatusBar
        false //showTitleBar
      );
  };
  
  
  function scMyCallback(sender, returnValue) 
  {
      if (returnValue) 
         scEditor.pasteHtml(returnValue.text);
  }
  </code></pre>
  
  <p>Has anyone else written a SPEAK app for the Rich text editor?
  Any suggestions welcome.</p>