Page 1 of 1

Perform action from side view in Oxygen Web Author

Posted: Mon Oct 11, 2021 11:13 am
by NicoAMP
Hello,

I created a custom side view in OWA with following javascript.
In this side view, I try to perform an action (insert fragment) when I click on a button. But nothing append when I click on it.
"test-insert-fragment" action exist in my framework.

Thanks for your help.

Code: Select all

workspace.getViewManager().addView('cms-custom-view');

/**
 * CMS View Renderer
 */
MyViewRenderer = function() {
  sync.view.ViewRenderer.call(this);
};
MyViewRenderer.prototype = Object.create(sync.view.ViewRenderer.prototype);
MyViewRenderer.prototype.constructor = MyViewRenderer;

MyViewRenderer.prototype.getTitle = function() {
  return 'Custom View';
};

MyViewRenderer.prototype.install = function(element) {
    element.innerHTML = ' <button onclick="performAction(test-insert-fragment)">Click me</button>';
};

workspace.getViewManager().installView('cms-custom-view', new MyViewRenderer(), 'right');


function performAction(actionID) {
    // Create an action
    myAction = authorAccess.getEditorAccess().getActionsProvider().getAuthorExtensionActions().get(actionID);
    authorAccess.getEditorAccess().getActionsProvider().invokeAction(myAction);
}

Re: Perform action from side view in Oxygen Web Author

Posted: Mon Oct 11, 2021 12:30 pm
by cristi_talau
Hello,

The script that you pasted is executed inside the browser. However, the function "performAction" at the end of your script tries to use the Java API which has to be executed on the Web Author server.

What you should do is to use the JavaScript API to execute an operation. The code should look like the one below [1]:

Code: Select all

if (editor.getEditingSupport().getType() === sync.api.Editor.EditorTypes.AUTHOR) {
    editor.getActionsManager().invokeOperation(
      'ro.sync.ecss.extensions.commons.operations.InsertFragmentOperation', 
      {fragment: 'Oxygen XML Web Author'}, 
      function() {
        console.log('Done!');
    }); 
  }
To obtain a reference to the editor object you should implement the "editorChanged" callback of the ViewRenderer [2].

Also, we have a sample plugin that displays the list of elements that can be inserted at the caret position in a side-view. Clicking on them will insert the element. Maybe you can start from this plugin: https://github.com/oxygenxml/web-author ... ments-view .

Best,
Cristian

[1] https://www.oxygenxml.com/maven/com/oxy ... fydoc.html
[2] https://www.oxygenxml.com/maven/com/oxy ... ed__anchor

Re: Perform action from side view in Oxygen Web Author

Posted: Mon Oct 11, 2021 4:14 pm
by NicoAMP
Hello Cristian,

Thanks for you help, I start from the plugin and it works!

I have another question. My goal is to manage a library of XML fragments that I could add from a side view (e.g. prefilled list, floating image with text, predefined legal text, etc.) as it is made for Templates (https://www.oxygenxml.com/xml_web_autho ... -templates).

Do you think that is possible?

Thanks.

Re: Perform action from side view in Oxygen Web Author

Posted: Mon Oct 11, 2021 6:12 pm
by cristi_talau
Hello,

Yes. It should be possible to implement this in a plugin. You can either hard-code fragments in the plugin configuration, retrieve them from a web service or even save them in a file in the CMS.

If you have questions on how to implement a specific behaviour, let us know.

Best,
Cristian