signalpoint / DrupalGap

An application development kit for Drupal websites.
https://www.drupalgap.org
GNU General Public License v2.0
232 stars 185 forks source link

How to show "loading" while downloading views data #1003

Closed jsbriantes closed 6 years ago

jsbriantes commented 6 years ago

Hello. I have a home page that shows 5 views. It tooks some seconds to load, and I would like to show the "loading" dialog (drupalgap_loading_show) while the page is loading. I tried with pages events (show, create, change) but without success. How could I do it?

signalpoint commented 6 years ago

@jsbriantes Perhaps this function will help:

drupalgap_loading_message_show()

jsbriantes commented 6 years ago

Thanks for your help. That's the function I used (there is a writing error in my question, as I can see). The problem is pageshow event is triggered before the views request were triggered. If I add an alert message to pageshow event, I can see the alert and after this, the page is showed and then I have to wait some seconds until the AJAX request was finished, to see the views result. After more test, the unique way I can show a load dialog was using pagechange event and setTimeout function:

function my_module_my_home_page_pagechange() {
    setTimeout(function(){
        $.mobile.loading('show');
    },200);
}

Is there another way to do it? Is It the right place to do it? Due to AJAX is asynchronous, I would like to show a loading message before the view was fired, and hide it after the view was rendered. Thanks.

signalpoint commented 6 years ago

@jsbriantes That seems like an OK way to do it in my opinion. It gets tricky with those multiple calls, because I think once one of them finishes it probably hides the loader by default, so if your technique works, I'd call it good! :)

jsbriantes commented 6 years ago

Ok. Thanks for your help.