Trigger update/refresh in oxygen web author

Oxygen general issues.
Srinarayan
Posts: 42
Joined: Tue Jun 08, 2021 3:27 pm

Trigger update/refresh in oxygen web author

Post by Srinarayan »

Hi Team,

We are currently calling an API call which is asynchronous so that it wont delay the loading of documents. Based on the content received from the API call we are enabling/disabling a button in the toolbar. As it is an async call to the API the button is enabled by default as it doesn't have to wait for the API.
But when we click/focus in the editor manually the button is updating itself based on the content from the API. I think an update/refresh function is happening after focusing/clicking on an element in the editor. So in order for us enable/disable the button without having to click/focus and element manually, is there anyway we can call this update/refresh on the editor so that our button is synced? Please help.

Regards,
Srinarayan
mihai_coanda
Posts: 78
Joined: Wed Jul 20, 2016 8:22 am

Re: Trigger update/refresh in oxygen web author

Post by mihai_coanda »

Hello,
The toolbar item reflects the action it represents enable/disabled status[1] so if the isEnabled method of the action returns true the item will be reactivated.
In your case, the action should return whether it is enabled or disabled based on the data received from the request.
We do not provide any API to disable a toolbar's item as it is tied to the action. What is the JS code you are executing to disable the toolbar item?
A more detailed description of your scenario would help us come up with a more suitable solution for your use case.

Best Regards,
Michael

1. https://www.oxygenxml.com/maven/com/oxy ... ction.html
Michael

https://www.oxygenxml.com
Srinarayan
Posts: 42
Joined: Tue Jun 08, 2021 3:27 pm

Re: Trigger update/refresh in oxygen web author

Post by Srinarayan »

Hi Michael,

This is my code snippet which I am using for enabling/disabling the button:

Code: Select all

function getContent(param1, param2) {
    try {
        var xhttp = new XMLHttpRequest();
        xhttp.onload = function() {
            arr1 = JSON.parse(this.responseText);
            URN.prototype.isEnabled = function() {
                if (arr1 != undefined) {
                    return true;
                } else {
                    return false;
                }
            }
            //Have to trigger the button enabling/disabling here.
        };
        xhttp.open("GET", "API-URL", false);
        xhttp.setRequestHeader("authorization", authID);
        xhttp.setRequestHeader("accept", "application/json");
        xhttp.send();
    } catch {
        console.log("Error");
    }
}
The call is an asynchronous call. Please let me know if you need additional info.

Regards,
Srinarayan.
mihai_coanda
Posts: 78
Joined: Wed Jul 20, 2016 8:22 am

Re: Trigger update/refresh in oxygen web author

Post by mihai_coanda »

Hello,
To update the toolbar button's enabled/disabled status without moving to the document you can use the ActionsManager.refreshActionsStatus JS API.

Best Regards
Michael


1. https://www.oxygenxml.com/maven/com/oxy ... us__anchor
Michael

https://www.oxygenxml.com
Srinarayan
Posts: 42
Joined: Tue Jun 08, 2021 3:27 pm

Re: Trigger update/refresh in oxygen web author

Post by Srinarayan »

Hi Michael,

Thanks for the help. It worked.

Just a thought-> can we create another thread apart from the main one that loads the documents and toolbar actions so that we could call our API synchronously but on another thread.
For Example : the main thread would load all the toolbar actions and document content and another thread would simultaneously call the API and then additionally do some updates

Please let me know if we can do that.

Regards,
Srinarayan
mihai_coanda
Posts: 78
Joined: Wed Jul 20, 2016 8:22 am

Re: Trigger update/refresh in oxygen web author

Post by mihai_coanda »

Hello,
Javascript has a single-threaded nature.
You could use javascript as a Web Worker to execute scripts from an HTML page that runs on a background thread away from the main execution thread.
I suspect that running your API synchronously using a Web Worker would not help you too much compared with the asynchronous invocation as your code does nothing during the request.
Our application does not have heavy code that throttles the js thread and the loading time is mainly caused by waiting for responses from the server time in which JS the thread is free.
Best Regards,
Michael
Michael

https://www.oxygenxml.com
Post Reply