Access to editor from outside

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Access to editor from outside

Post by Konstantin » Wed May 04, 2016 6:30 pm

Hello !!!
I use WebApp 18.0.0

I load content from outside datasource, at some time I need know state of this content.
I created custom servlet which is getting request from my application but I can not get editor or content from it.
How can I do this?
For example I need know that is this content isDirty

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

Re: Access to editor from outside

Post by cristi_talau » Thu May 05, 2016 9:13 am

Hello,

One way to have access to the editor is to implement a JS extension (ideally as a plugin). You can find more details about how to load your JS code in the editor page here [1]. In the JavaScript file that you load you can use our JavaScript API [2] to get the editor content and to check whether it is dirty or not.

We also have Java API that you can use from a plugin. So, it is important for us to understand your final goal with this integration. This way, we can guide you to the best approach.

Best,
Cristian

[1] https://www.oxygenxml.com/doc/versions/ ... ng_js.html
[2] https://www.oxygenxml.com/maven/com/oxy ... 0.0/jsdoc/

Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: Access to editor from outside

Post by Konstantin » Thu May 05, 2016 12:31 pm

We also have Java API that you can use from a plugin. So, it is important for us to understand your final goal with this integration. This way, we can guide you to the best approach.
We have application which uses WebApp thru iframe.
We can open some WebApp in tabs.
When we close some tab we need know that is this WebApp has changes (isDirty) and then show message to user about saving content and then if necessary send to WebApp request about saving content.
For this we created plugin Servlet but we can't understand how we can get state (isDirty) of editor and it content from Servlet.

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

Re: Access to editor from outside

Post by cristi_talau » Thu May 05, 2016 1:52 pm

Hello,

You will need to inject some custom JavaScript code in the Web Author iframe. This can be done using a plugin as I explained in the previous post.

This JS code should first get a reference to the editor once it is opened, e.g.

Code: Select all


goog.events.listen(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
window.editor = e.editor;
});
Then it should listen for the tab closed event and check whether the editor is dirty [1], and display a dialog.

In order to save the editor you can invoke the editor builtin action using a code like the one below:

Code: Select all


editor.getActionsManager().getActionById('Author/Save').actionPerformed(function(){ 
console.log('done saving');
});
Please let me know if this approach does not work for you.

Best,
Cristian

[1] https://www.oxygenxml.com/maven/com/oxy ... ml#isDirty

Post Reply