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

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
aujunior
Posts: 28
Joined: Thu Feb 16, 2023 11:00 pm

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

Post 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 (15.09 KiB) Viewed 424 times
image.png
image.png (43.61 KiB) Viewed 424 times
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.
cosminef
Site Admin
Posts: 84
Joined: Wed Aug 30, 2023 2:33 pm

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

Post 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
Cosmin Eftenie
www.oxygenxml.com
aujunior
Posts: 28
Joined: Thu Feb 16, 2023 11:00 pm

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

Post 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 (14.3 KiB) Viewed 390 times
image.png
image.png (15.81 KiB) Viewed 390 times

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!
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

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

Post 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
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply