• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 846
  • Last Modified:

Spry datasets before loading and when reloading

Hi,

I have multiple spry datasets on a page. Is there any way I could get the spry framework to wait until all the data sets were ready and then do something (in this case it would be remove the display:none attribute from a div).

Also, is it possible to have the spry framework check if a certain element exists in the xml data set and do something if it doesn't everytime the data is reloaded (I have it set to reload every 10 seconds).

I have looked through the documentation but can't find anything covering these two areas so if anyone can point me in the right direction or pop me some sample code I'd be greatful.

Thanks a lot,

Matt
0
intechfs
Asked:
intechfs
  • 4
  • 3
1 Solution
 
Jason C. LevineNo oneCommented:
Hi intechfs,

What you can do is add a loading state region to the spry regions:

<div spry:state="loading" align="center">Please wait...data is loading now</div>

Place the above code inside of the Spry region container.  The state:"loading" parameter tells Spry to display the contents of this div while the data is being generated.
0
 
intechfsAuthor Commented:
Yes but that only works on a per data set basis. I want a global option that would be on the entire page and would be displayed whilst all the data sets loaded and when they had all loaded then the page content is shown.
0
 
Jason C. LevineNo oneCommented:
I don't think that's possible.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
intechfsAuthor Commented:
I worked out a way of doing it.

For anyone else interested you need to add observers to the data sets like this:
var dsf = new Spry.Data.XMLDataSet( "../../test_data/favs.xml", "favs/fav", { useCache: false } );
dsf.setColumnType("@id", "number");
dsf.addObserver ( testDSF );

Then I wrote some custom functions for each observer which set a flag to 1 when the set is loaded and then runs another function which tests to see if all the flags for all sets are at 1 and if they are it shows the page.

Like this:
function testDSF (notificationType, dataSet, data) {

      //check to see if the data has just been loaded
      if ( notificationType == "onPostLoad" ) {

            //if this is the first time this data set has been loaded
            if ( dsfLoad == 0 ) {
                  dsfLoad = 1;
                  allLoad();
            }

      //if spry is reporting a data load error
      } else if (notificationType == "onLoadError") {
            window.location = "../../error?r=df";
      }
}

//little function to test if all data sets have been loaded for the first time, and if they have then we can display the page and remove the loading animation
function allLoad () {

      //if all the data sets are loaded then we can do stuff!
      if ( ( dsvLoad == 1 ) && ( dsfLoad == 1 ) ) {
            document.getElementById('doneLoad').style.display = '';
            document.getElementById('preLoad').style.display = 'none';
      }

      return;
      
}
0
 
Jason C. LevineNo oneCommented:
Right, but you needed a custom function to handle it.  Spry alone does not support it...

Great work, though!
0
 
intechfsAuthor Commented:
Yes true.. there are quite a lot of things Spry can do, but there quite poorly documented.

Adding observers for example, which only has very limited explanation.
0
 
Jason C. LevineNo oneCommented:
>> but there quite poorly documented.

One gets the feeling that the whole Spry project was started late and rushed to the table before it was really complete.  1.4 was awful and buggy and there was zero documentation.  1.6.1 is better, but the documentation is largely in the form of the examples at the Adobe labs.  

You should send the above to them...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now