Call js function from backend
Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
-
- Posts: 168
- Joined: Fri Jan 20, 2017 1:11 pm
Call js function from backend
Hello,
With Oxygen 27, is it possible to call javascript function from backend ?
We have extended WSEditorListener to implement our own editorSaved(int var1) method.
But we need to show a modal to the user and for that we need to send to frontend a json element and call a javascript function.
Is it possible from java to throw event or call javascript method with parameters ?
Thanks.
Regards,
Isabelle
With Oxygen 27, is it possible to call javascript function from backend ?
We have extended WSEditorListener to implement our own editorSaved(int var1) method.
But we need to show a modal to the user and for that we need to send to frontend a json element and call a javascript function.
Is it possible from java to throw event or call javascript method with parameters ?
Thanks.
Regards,
Isabelle
-
- Site Admin
- Posts: 233
- Joined: Wed Aug 30, 2023 2:33 pm
Re: Call js function from backend
Hello,
You should use the JavaScript API [1] to override the method with the ID "Author/Save".
Do you also want to modify the autosave functionality?
[1] https://www.oxygenxml.com/maven/com/oxy ... 0.0/jsdoc/
Best,
Cosmin
You should use the JavaScript API [1] to override the method with the ID "Author/Save".
Do you also want to modify the autosave functionality?
[1] https://www.oxygenxml.com/maven/com/oxy ... 0.0/jsdoc/
Best,
Cosmin
Cosmin Eftenie
www.oxygenxml.com
www.oxygenxml.com
-
- Posts: 168
- Joined: Fri Jan 20, 2017 1:11 pm
Re: Call js function from backend
Hello,
The link you have mentioned does not explain how to override the method with the ID "Author/Save".
But I have found this on your github => web-author-block-save-if-invalid.
I have tried to implement it like this to launch our own validation after save:
But it fails on application start with the error "missing ;"
Any idea why ?
Thanks,
Regards,
Isabelle
No thanks, only save functionality.Do you also want to modify the autosave functionality?
The link you have mentioned does not explain how to override the method with the ID "Author/Save".
But I have found this on your github => web-author-block-save-if-invalid.
I have tried to implement it like this to launch our own validation after save:
Code: Select all
function applicationStarted(pluginWorkspaceAccess) {
pluginWorkspaceAccess.addEditingSessionLifecycleListener(
new JavaAdapter(Packages.ro.sync.ecss.extensions.api.webapp.access.WebappEditingSessionLifecycleListener, {
editingSessionStarted: function (docId, authorDocumentModel) {
authorDocumentModel.getWSEditor().addEditorListener(new JavaAdapter(Packages.ro.sync.exml.workspace.api.listeners.WSEditorListener, {
editorSaved: function(var1) {
this.editor.getActionsManager().invokeOperation('SetReadOnlyStatusOperation', {'read-only': true});
this.editor.getActionsManager().invokeOperation('com.plugin.operations.ValidationOperation', {},
((error, result) => {
this.editor.getActionsManager().invokeOperation('SetReadOnlyStatusOperation', {'read-only': false});
if (error == null) {
if (result) {
currentValidationResults = JSON.parse(result);
createValidationModal(callback);
}
}
}));
return true;
}
}))
}
}));
}
Any idea why ?
Thanks,
Regards,
Isabelle
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: Call js function from backend
Hello,
The plugin that you mentioned is a JavaScript-Based Workspace Access Plugin Extension:
https://www.oxygenxml.com/doc/versions/ ... in-js.html
This type of extension can use the same API as the JAVA Workspace Access plugin extension, but the implementation is JavaScript-based and uses the bundled Rhino library to create and work with Java API from the JavaScript code.
So all the code executes on the server side actually so you cannot mix it with the javascript API that is called on the client:
https://www.oxygenxml.com/maven/com/oxy ... 0.0/jsdoc/
This is why you obtain the error above.
Best Regards,
Mihaela
The plugin that you mentioned is a JavaScript-Based Workspace Access Plugin Extension:
https://www.oxygenxml.com/doc/versions/ ... in-js.html
This type of extension can use the same API as the JAVA Workspace Access plugin extension, but the implementation is JavaScript-based and uses the bundled Rhino library to create and work with Java API from the JavaScript code.
So all the code executes on the server side actually so you cannot mix it with the javascript API that is called on the client:
https://www.oxygenxml.com/maven/com/oxy ... 0.0/jsdoc/
This is why you obtain the error above.
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
http://www.oxygenxml.com
-
- Posts: 168
- Joined: Fri Jan 20, 2017 1:11 pm
Re: Call js function from backend
Hello,
Ok, I understand the problem.
But then can you tell me, how, in javascript, can I add our custom validation method after save action (only save and not auto save) ?
Thanks,
Regards,
Isabelle
Ok, I understand the problem.
But then can you tell me, how, in javascript, can I add our custom validation method after save action (only save and not auto save) ?
Thanks,
Regards,
Isabelle
-
- Posts: 515
- Joined: Wed May 20, 2009 2:40 pm
Re: Call js function from backend
Hello,
Here is a possibility: there is an event called "DIRTY_STATUS_CHANGED" that is triggered on the editor, that you can listen to:
https://www.oxygenxml.com/maven/com/oxy ... es__anchor
When the "isDirty" status is set to false you can trigger your validation.
Check the documentation for a sample code on how to listen on this event:
https://www.oxygenxml.com/maven/com/oxy ... Event.html
Best Regards,
Mihaela
Here is a possibility: there is an event called "DIRTY_STATUS_CHANGED" that is triggered on the editor, that you can listen to:
https://www.oxygenxml.com/maven/com/oxy ... es__anchor
When the "isDirty" status is set to false you can trigger your validation.
Check the documentation for a sample code on how to listen on this event:
https://www.oxygenxml.com/maven/com/oxy ... Event.html
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service