Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Twitter Sign In with OpenID Sign In with Google

Sign In Sign Up

In this Discussion

Welcome to the Jo support forums! Please Sign Up and join in the discussion. You can also Sign In instantly with Twitter, OpenID or your Google ID.
Easy way to clear a a joRecord?
  • jpsheridanjpsheridan June 2012
    Posts: 35

    Hellooooo,


    I'm loving joRecord and databinding.  But I now need an easy to clear each object upon logging out of my application.

    What is the easiest way to this?

    Thanks,
    JP
  • davedave June 2012
    Posts: 415

    Hmmm... joRecord extends joDataSource, which has a setData() method. You could call that and pass in an initial state object. Careful you don't pass in the same "cleared" object more than once though, because it'll have data after it gets used. Really, it needs a clear() method. Problem there is, you might want different default values for a "clear" state than, say, all nulls.

    Dave Balmer, Jo Code Wrangler
  • davedave June 2012
    Posts: 415

    Also, setData() will fire the changeEvent, which might be undesirable. This sounds like a solid feature request. :)

    Dave Balmer, Jo Code Wrangler
  • jpsheridanjpsheridan June 2012
    Posts: 35

    Well thanks for the reply Dave. I'm at home for the weekend now until Tuesday so I'll look at my code when back in work.

    I did manage to come up with an untested solution. Untested because I wrote it right before I left work ;) I think in cases where I wanted particular parts of a records data to be changed but not others I called myRecord.getDelegate('myproperty').setData(newData); but can't quite recall. In other cases I think I just created a new object e.g. UserData = new joRecord({blah : "days"}). Not sure it's working though because when I log back in some data is still displayed. I created a reset() function in each view and each model I needed to clear. Then upon logout() I call a reset function In my main controller that in turn calls all the individual reset() functions.

    Anyway I'll test more on Tuesday. I'm nearing completion of our app and I'm glad I found Jo, it made life much easier. Well done Dave. I only wish my JavaScript and software skills were sufficient to contribute. Perhaps in time? I think if a community got behind it and there were more frequent releases it would fly!

    Ciao, JP

  • jpsheridanjpsheridan June 2012
    Posts: 35

    Hi Dave (et al),

    Sony havent got back to me app yet but I noticed running my phone the UI isn't being cleared. I really must investigate later. Quick question:

    I think for some records I was just assigning a new record. Unfortunately the data was still there in the Ui. Perhaps set data is the better option?

    Essentially upon log out I want the ui to be cleared of all data. It's a financial app and I want the data to be securely retrieved every time the user logs in.

    So setData is what I'll try later. But any other suggestions would be appreciated! :)

    Cheers, JP

  • jpsheridanjpsheridan June 2012
    Posts: 35

    Hello,


    So I pretty much got this working.  I use setData where I need to retain some of the record (username for the login form for example).  In other places I simply use new joRecord().setAutoSave(false);

    I think I'm having an issue with joTable but I'll look into it more to see if I can resolve the issue.  It could simply be my own crappy code ;~)

    JP
  • davedave June 2012
    Posts: 415

    Glad you found a solution that works for you. Also, joTable is pretty sparse, feature-wise. Definitely interested in your feedback as you explore it.

    Dave Balmer, Jo Code Wrangler