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
intechfsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineDon't talk to me.Commented:
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.
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.
Jason C. LevineDon't talk to me.Commented:
I don't think that's possible.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook 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;
      
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jason C. LevineDon't talk to me.Commented:
Right, but you needed a custom function to handle it.  Spry alone does not support it...

Great work, though!
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.
Jason C. LevineDon't talk to me.Commented:
>> 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...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.