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

1k views Asked by At

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:

  • It has a rule component called insertButtonRule.
  • The target control is set to SelectMediaButton and the trigger is set to click.
  • The condition / action for the associated rule is "when always, set the dialog return value to component MediaResultsListControl selectedItemId".

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.

3

There are 3 answers

3
Martin Davies On BEST ANSWER

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.

1
dervlap On

The select Media dialog is using this line to return the value

 window.top.dialogClose(returnValue); //return value is the value you want to return

If you try to call this method in your SPEAK page, does it close the dialog?

PS: I have never tried it.

0
gorhal On

I know its a bit late and you have already solved it :-) In SPEAK you can trigger ConfirmationDialog like this:

myConfirmationDialog.CloseClick = "ok";
myConfirmationDialog.hide();

(If you where using ConfirmationDialog)