Page 1 of 1

Create a single javascript action and collect the element that called it programmatically

Posted: Mon Nov 13, 2023 5:56 pm
by aujunior
Good morning guys!

We are creating some Actions via Javascript that collect information from a WebService and insert a fragment into the XML that is being edited.

We created the Action in framework and linked it to the Content Completion Item configuration.

We realized that we are creating several Actions that are almost identical because we are linking each element to a specific action.

Is there a way to retrieve which element called the Action via Javascript?
With this we can create an action factory and create specific classes per element.
image.png
image.png
Our idea is to create an "Insert CIR REF" action and connect each element to this single action and the action collects the element that called it and calls its respective action.


Another question... Is there any way to send a parameter via URL and collect this parameter via Javascript or Java?

Example:

//localhost:8008/oxygenxml-web-author/app/oxygen.html?url=webdav-http%3A%2F%2Fwebdav-dev-host.pub.com.br%2FName%2520Procedure%2520Data%2520Module.xml&project=OUR_PROJECT

We want to collect this project information.

Re: Create a single javascript action and collect the element that called it programmatically

Posted: Tue Nov 14, 2023 12:12 pm
by cosminef
Hello,

Regarding the first question, you can use the getNodeAtCaret method [1]. In the future, if needed, you can refer to the Oxygen XML Web Author API Documentation [2].
Regarding the second question, you can obtain the URL using the documentation provided here [3] and then use URLSearchParams [4]

[1] https://www.oxygenxml.com/maven/com/oxy ... et__anchor
[2] https://www.oxygenxml.com/maven/com/oxy ... c0__anchor
[3] https://developer.mozilla.org/en-US/doc ... w/location
[4] https://developer.mozilla.org/en-US/doc ... archParams

Best Regards,
Cosmin

Re: Create a single javascript action and collect the element that called it programmatically

Posted: Tue Nov 14, 2023 6:14 pm
by aujunior
Good afternoon cosminef!

The getNodeAtCaret() function is returning exactly the element where the cursor is, which is expected.

I would like to know if it is possible to identify which element was clicked on in Content Completion via a javascript action.
image.png
image.png

In this case I would like to identify the "accessPointRef" element within the javascript action that is registered and not the element that the cursor is on.



Thanks for the response about the URL, we are already testing what you indicated!

Re: Create a single javascript action and collect the element that called it programmatically

Posted: Wed Nov 15, 2023 7:04 pm
by mihaela
Hello,

From what I saw you created an action that replaces the element from content completion. This means that you execute some JAVA operation when the accessPointRef element is chosen from the content completion menu. Why do you want to know the element on the javascript side? It is not sufficient to know the element in the JAVA code (from the operation)?

Best Regards,
Mihaela