How to use toggleSpinner in javascript for a client Action?

I have a medium-long running client action and are trying to use aras.browserHelper.toggleSpinner() while the client is busy and waiting for the server method to complete. It works fine in Firefox browser but I cant get it to work in Chrome or IE. These browsers just freeze until the action have completed and the "red spinner" is never shown. If someone have an idea about this please share.

The Action (Type: Item, Location: Client) is calling a javascript method (Method: test_client_method, Target: None)

The JS Method (test_client_method)

try
{
aras.browserHelper.toggleSpinner(document, true);

this.apply("long_running_server_method");
}
finally
{
aras.browserHelper.toggleSpinner(document, false);
}

  • Maybe your toggleSpinner needs some additional code to be displayed correct? The Method 'VCN_OnShowItem' also uses this element, but it uses additional code to display the spinner on top position (as far as I understand the code...).

  • Thanks for the suggestion. I tried already that but still the same behaviour.

    var topWnd = window.TopWindowHelper.getMostTopWindowWithAras();

    aras.browserHelper.toggleSpinner(topWnd.document, true);

  • Just to chime in.

    I have the same scenario, only that I can't display a spinner in any of the three browsers.

    I tried the "topWnd" from VCN_OnShowItem and experienced no difference. I also found a use in the aras codetree with an extra parameter, which does also not produce a spinner

    aras.browserHelper.toggleSpinner(topWnd.document, true, 'dimmer_spinner_whole_window');

  • Hi,

    I wonder if the try/finally concept is the best approach. I made a quick test and it looked to me like the toggle spinner is disabled before the Method is finished.

    Maybe a promise is a better approach? Very simple sample:

    // enable toggle spinner
    aras.browserHelper.toggleSpinner(document, true);

    var promise = new Promise(function(resolve, reject) {
    // after 2 seconds disable toggle spinner
    setTimeout(
    function(){
    alert("Done");
    aras.browserHelper.toggleSpinner(document, false);
    }, 2000);
    });

  • Super! With just minor tweaking of your code it works fine and the red spinner is shown in all browsers while the server code is working. Many thanks Angela!

    var this_item = this;
    aras.browserHelper.toggleSpinner(document, true);
    var promise = new Promise(function(resolve, reject) {
    setTimeout(function() {
    var result = this_item.apply("long_running_server_method");
    aras.browserHelper.toggleSpinner(document, false);
    }, 100);
    });