sitecoresitecore-speak-ui

Closing a Sitecore Speak Dialog that was opened from a Rich Text Editor


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.

I've tried looking at the way Sitecore's existing SPEAK dialogs do it. For example SelectMediaDialog:

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?

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):

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);
}

Has anyone else written a SPEAK app for the Rich text editor? Any suggestions welcome.


Solution

  • So I had to go looking on the Telerik site, and this code is adapted from what I found:

    var radWindow;
    
    if (window.radWindow)
        radWindow = window.radWindow;
    else if (window.frameElement && window.frameElement.radWindow)
        radWindow = window.frameElement.radWindow;
    else
        window.close();
    
    radWindow.Close("My return value");
    

    It feels a little messy mixing this in with shiny new SPEAK code, but right now I'm just glad it works.