Perform action from side view in Oxygen Web Author

Post here questions and problems related to oXygen frameworks/document types.
NicoAMP
Posts: 61
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Perform action from side view in Oxygen Web Author

Post by NicoAMP » Mon Oct 11, 2021 11:13 am

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

cristi_talau
Posts: 358
Joined: Thu Sep 04, 2014 4:22 pm

Re: Perform action from side view in Oxygen Web Author

Post by cristi_talau » Mon Oct 11, 2021 12:30 pm

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

NicoAMP
Posts: 61
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Re: Perform action from side view in Oxygen Web Author

Post by NicoAMP » Mon Oct 11, 2021 4:14 pm

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.

cristi_talau
Posts: 358
Joined: Thu Sep 04, 2014 4:22 pm

Re: Perform action from side view in Oxygen Web Author

Post by cristi_talau » Mon Oct 11, 2021 6:12 pm

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

Post Reply