Search code examples
sitecoresitecore-speak-ui

Sitecore set SPEAK UI dialog size when opening from WebEdit command


I have a custom experience button for the page editor in Sitecore which references a custom command. What is the correct way to open a SPEAK dialog from this context and how should the width/height of the dialog be set?

I have the following command code:

public class MySpecialCommand : Sitecore.Shell.Applications.WebEdit.Commands.WebEditCommand
{
    public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
    {
        var parameters = new NameValueCollection();
        //add various parameters etc 
        Context.ClientPage.Start((object) this, "Run", parameters);
    }

    protected void Run(ClientPipelineArgs args)
    {
        if (!args.IsPostBack)
        {           
            string url = "/sitecore/client/your%20apps/somespeakdialog?sc_lang=en&someParam" + args.Parameters["someParam"];
            SheerResponse.ShowModalDialog(url, "100", "200", string.Empty, true);
            args.WaitForPostBack();
        }
        else if (args.HasResult)
        {
            //not got this far yet...
        }
    }
}

and I am finding that the size of the dialog bears no resemblance to the width and height parameters passed to SheerResponse.ShowModalDialog. I have also tried passing in values suffixed with "px" but this does not help.


Solution

  • There is no out of the box ability to set the width and height for SPEAK-based dialogs in Sitecore 7.5 (it's available in 8.0)

    However, you could customize the \sitecore\shell\Controls\jQueryModalDialogs.html file. Just find and update the following if statement:

    if (isSpeakDialog) {
      createdDialog.dialog('option', 'width', size.width);
      createdDialog.dialog('option', 'height', size.height);
    }
    

    In Sitecore 8.0 a new method has been added:

    public static ClientCommand ShowModalDialog(ModalDialogOptions options)
    

    Your SheerResponse.ShowModalDialog(url, "100", "200", string.Empty, true); will be

    SheerResponse.ShowModalDialog(new ModalDialogOptions(url)
    {
      Width = "100",
      Height = "200",
      Response = true,
      ForceDialogSize = true
    });
    

    Description of ForceDialogSize property:

    Gets or sets a value indicating whether SPEAK dialogs will take into acount <see cref="Width"/> and <see cref="Height"/>.