~nik90/cliffhanger/more-improvements

« back to all changes in this revision

Viewing changes to backend/GenreMovies.js

  • Committer: Nekhelesh Ramananthan
  • Date: 2013-11-14 16:29:44 UTC
  • Revision ID: krnekhelesh@gmail.com-20131114162944-s2xh152z0y245dsa
Added ability to filter movies by genre

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
WorkerScript.onMessage = function(message) {
 
2
 
 
3
    var XHR = new XMLHttpRequest();
 
4
    var thumb_url;
 
5
    message.model.clear()
 
6
 
 
7
    XHR.open("GET", message.url);
 
8
    XHR.setRequestHeader("Accept", "application/json");
 
9
 
 
10
    XHR.onreadystatechange = function() {
 
11
        if(XHR.readyState != XHR.DONE)
 
12
            return;
 
13
        if(XHR.status != 200)
 
14
            return;
 
15
 
 
16
        var obj = JSON.parse(XHR.responseText);
 
17
 
 
18
        for(var i=0; i<obj.results.length; i++) {
 
19
 
 
20
            if (obj.results[i].poster_path == null)
 
21
                thumb_url = "null"
 
22
            else
 
23
                thumb_url = "http://d3gtl9l2a4fn1j.cloudfront.net/t/p/" + "w185/" + obj.results[i].poster_path
 
24
 
 
25
            message.model.append({"name": obj.results[i].title,
 
26
                                     "thumb_url": thumb_url,
 
27
                                     "id": obj.results[i].id});
 
28
            message.model.sync()
 
29
        }
 
30
    };
 
31
 
 
32
    XHR.send();
 
33
}