ldriver
I'm new here

Is it possible to have FS_BUTTON open an iFrame or modal?

Jump to solution

I want to create an FS_BUTTON which pops open an iFrame or modal with custom HTML.  Is this possible?  Would it be better to use script or class for the onClick?  This will be used in ContentCreator and not Site Architect.

1 Solution

Accepted Solutions
mbergmann
Crownpeak employee

Hi Leland,

I understand that you ask for FS_BUTTON because you want to use it in a ContentCreator form and not on the page itself - right?

So your basically need to perform two steps:

1. Execute JavaScript from an FS_BUTTON from within in a form

2. Use that JS to display a dialog / iFrame

1. Execute JavaScript using an FS_BUTTON

You can implement an FS_BUTTON that calls a script (onClick="script:...") or - which is the recommended approach - an Executable (onClick = "class:PUBLIC_COMPONENT_NAME_OF_EXECUTABLE").

Here you can use the ClientScriptOperation to execute JavaScript code (on the client side in CC), something like this:

public class OpenDialogExecutable implements Executable {

    private static final String PARAM_CONTEXT = "context";

    private BaseContext context = null;

    @Override

    public Object execute(Map<String, Object> params) {

        return execute(params, new PrintWriter(System.out), new PrintWriter(System.err));

    }

    @Override

    public Object execute(Map<String, Object> params, Writer writer, Writer writer1) {

        context = (BaseContext) params.get(PARAM_CONTEXT);

        ClientScriptOperation scriptOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(ClientScriptOperation.TYPE);

        String myJavaScript = "alert('Hello World');";

        scriptOperation.perform(myJavaScript, false);

        return null;

    }

}

The JS will then be responsible for opening a window or just do anything you want.

2. Use the JS to open a window / dialog

Now you can use this mechanism to not just show an alert(...) but to open the dialog.

Of course you can implement your own dialog mechanism here, but a good idea might be to use the Dialog (also see Common.createDialog()) of the CC-JavaScript API. It allows you to open a dialog window in the FirstSpirit UI design and use HMTL elements or just an iframe.

You have to create the JS in the executable and call the clientScriptOperation.perform(myJavaScript, false).

For example it could look like this:

String myJavaScript = "var dialog = top.WE_API.Common.createDialog();"

  + "dialog.setTitle('This is a demo dialog');"

  + "dialog.addButton('Close', function(){dialog.hide();});"

  + "dialog.setSize(1200, 600);"

  + "elem = document.createElement('iframe');"

  + "elem.setAttribute('src', 'http://www.e-spirit.com');"

  + "elem.setAttribute('width', '100%');"

  + "elem.setAttribute('height', '100%');"

  + "elem.setAttribute('frameborder', 0);"

  + "dialog.setContent(elem);"

  + "dialog.show();";

This will open a CC style modal dialog showing the e-Spirit website inside...

Just for clarification: Everything beneath de.espirit.firstspirit.webedit.client.api refers to JavaScript and not Java.

And of course you can also use "part 2" directly from the page if you don't need the FS_BUTTON and/or the form first.

Hope this helps.

Michael

View solution in original post

2 Replies
mbergmann
Crownpeak employee

Hi Leland,

I understand that you ask for FS_BUTTON because you want to use it in a ContentCreator form and not on the page itself - right?

So your basically need to perform two steps:

1. Execute JavaScript from an FS_BUTTON from within in a form

2. Use that JS to display a dialog / iFrame

1. Execute JavaScript using an FS_BUTTON

You can implement an FS_BUTTON that calls a script (onClick="script:...") or - which is the recommended approach - an Executable (onClick = "class:PUBLIC_COMPONENT_NAME_OF_EXECUTABLE").

Here you can use the ClientScriptOperation to execute JavaScript code (on the client side in CC), something like this:

public class OpenDialogExecutable implements Executable {

    private static final String PARAM_CONTEXT = "context";

    private BaseContext context = null;

    @Override

    public Object execute(Map<String, Object> params) {

        return execute(params, new PrintWriter(System.out), new PrintWriter(System.err));

    }

    @Override

    public Object execute(Map<String, Object> params, Writer writer, Writer writer1) {

        context = (BaseContext) params.get(PARAM_CONTEXT);

        ClientScriptOperation scriptOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(ClientScriptOperation.TYPE);

        String myJavaScript = "alert('Hello World');";

        scriptOperation.perform(myJavaScript, false);

        return null;

    }

}

The JS will then be responsible for opening a window or just do anything you want.

2. Use the JS to open a window / dialog

Now you can use this mechanism to not just show an alert(...) but to open the dialog.

Of course you can implement your own dialog mechanism here, but a good idea might be to use the Dialog (also see Common.createDialog()) of the CC-JavaScript API. It allows you to open a dialog window in the FirstSpirit UI design and use HMTL elements or just an iframe.

You have to create the JS in the executable and call the clientScriptOperation.perform(myJavaScript, false).

For example it could look like this:

String myJavaScript = "var dialog = top.WE_API.Common.createDialog();"

  + "dialog.setTitle('This is a demo dialog');"

  + "dialog.addButton('Close', function(){dialog.hide();});"

  + "dialog.setSize(1200, 600);"

  + "elem = document.createElement('iframe');"

  + "elem.setAttribute('src', 'http://www.e-spirit.com');"

  + "elem.setAttribute('width', '100%');"

  + "elem.setAttribute('height', '100%');"

  + "elem.setAttribute('frameborder', 0);"

  + "dialog.setContent(elem);"

  + "dialog.show();";

This will open a CC style modal dialog showing the e-Spirit website inside...

Just for clarification: Everything beneath de.espirit.firstspirit.webedit.client.api refers to JavaScript and not Java.

And of course you can also use "part 2" directly from the page if you don't need the FS_BUTTON and/or the form first.

Hope this helps.

Michael

Well this is a great day, because that does what I want and it worked first try.  Thank you!