4

I am working on a project, that is a mobile web app. I am using JQuery mobile.

I have a page with a jquery listview, when a user clicks on each item on the list view all data associated with that item is passed to a dialog page. I used local storage to pass the values between pages. However what I am trying to do is record a user's action and display them as an activity feed. Storing what item they clicked on, how long they spent on the opened dialog page and to be able to display all this info on a new page. example

You clicked on item a

You spent 15seconds on item b

etc.

So would local storage be good for this or or WEB SQL?

I also noticed that the WeB SQL is not actively maintained anymore? http://www.w3.org/TR/webdatabase/ does this mean it's going to be deprecated?

Local Storage example:

each item is a json object, I need to pass entire object to view it in a new page so I have:

function addPostToLocalStorage(YTfeeditems){
    $(".item").on('click', function () {
        
        var i = $('.item').index(this);
        console.log(i);
        
        var Viditem = YTfeeditems[i];
        console.log(Viditem);

        localStorage['youtubeclickedPost'] = JSON.stringify(Viditem);
        storedItem = localStorage['youtubeclickedPost'];
        retrievPostFromLocalStorage();
    }
});

function retrievPostFromLocalStorage(){
    var retrievedStringItem = localStorage.getItem(['youtubeclickedPost']);
    var convertedPost = JSON.parse(retrievedStringItem);
    showDetailedPost(convertedPost);
}

when item is clicked I would want to store the the id of the video, record the time it was clicked, record how long the ytfullviewpage was open for and also within that page record if the "thumbs up" image was clicked or if "thumbs down" was clicked, add these details to local ftorage and retrieve them in a new page to show them. I can seem to understand the approach to take with local storage in doing this. I have Pasted my javascript for this here

which might give you a better idea.

Community
  • 1
  • 1
Dot
  • 279
  • 1
  • 9
  • 21
  • Local storage, if available, is ideal for this. It's easy to use, and you're not looking for any type of query language, so SQL (of any type) would just be overkill. – Reinstate Monica Cellio Jul 16 '13 at 15:32
  • @Archer currently I use local storage to store the item when the user clicks on it, I want to be able to retrieve all the items the user has clicked on, but everytime the user clicks on new item it overwrites the key, So I can only retrieve the last stored item. Should i give a different key for every item the user clicks on? If so how could this be achieved because I am looping through a list? :s – Dot Jul 16 '13 at 15:44
  • You could store an object that holds all the item information. Just retrieve the object, write the new information and save it again. If you give an example of what kind of info you want to store per click then I'll do an example for you and post an answer. – Reinstate Monica Cellio Jul 16 '13 at 15:48
  • @Archer thanks so much! I have added my javascript on pastebin and have edited my question with the link. pls do have a look and let me know. – Dot Jul 16 '13 at 16:29
  • I've tidied the code you added, but I don't understand it. You're adding an event handler inside a function??? So you won't handle the click event until that function has been executed. – Reinstate Monica Cellio Jul 16 '13 at 16:40
  • @Archer I have removed the handler off the function now and that, works. – Dot Jul 16 '13 at 22:03

1 Answers1

7

WEB SQL is deprecated however still available on some platforms http://caniuse.com/#feat=sql-storage localstorage we probable be fine for you solution. If you feel you need more storage use http://pouchdb.com/ as it has cross adapters for different browser storages and some nice features like syncing.

timmak
  • 86
  • 5
  • 3
    +1 for PouchDB. It's an elegant solution that replaces Web SQL very well. – Seiyria Jul 16 '13 at 15:47
  • @timmak thanks, I shall have a look at poucheDB however if local storage is a fine solution I want to be able to use it, but I am not to sure, how to implement it, if I am to store a number of items and retrieve them all in a new page – Dot Jul 16 '13 at 21:23