diff options
| -rw-r--r-- | public/javascripts/app.js | 28 | ||||
| -rw-r--r-- | routes/character-images.js | 19 |
2 files changed, 33 insertions, 14 deletions
diff --git a/public/javascripts/app.js b/public/javascripts/app.js index c54651a..f78b204 100644 --- a/public/javascripts/app.js +++ b/public/javascripts/app.js @@ -2,26 +2,32 @@ var App = App || null; (function() { var cApp = function() { - this.characters = null; + this.characters = []; this.answer = null; + this.playlist = [] // CoverFlow var initialise_js_cover_flow = function(playlist) { + var that = this; coverflow('character-select-container').setup({ width: '100%', playlist: playlist, coverheight: 130, textoffset: 68 }).on('ready', function() { - this.on('click', function() { - alert('chosen'); + var the_other = that; + this.on('click', function(e) { +// if (the_other.answer == + console.log(e); + var selection = this.playlist[e]; +// alert('chosen'); }); }); }; this.initialize_video = function(url) { - + console.log(url); }; this.get_characters = function(series_id) { @@ -34,17 +40,19 @@ var App = App || null; var r = JSON.parse(response); $character_container.empty() - - var playlist = [] + for (var i = 0; i < r.characters.length; i++) { - playlist.push({ + that.playlist.push({ image: r.characters[i].image, title: r.characters[i].name }); + + that.characters.push({ + personId: r.characters[i].tms_personId, + name: r.characters[i].name + }); } - initialise_js_cover_flow(playlist); - - that.characters = _.pluck(r.characters, 'tms_personId'); + initialise_js_cover_flow(that.playlist); } ); }; diff --git a/routes/character-images.js b/routes/character-images.js index a30ee9c..581f5b6 100644 --- a/routes/character-images.js +++ b/routes/character-images.js @@ -17,14 +17,18 @@ module.exports = function(req, res) { var r = JSON.parse(body); var request_count = 0; + var actor_count = r.cast.length; var the_other = that; for (var i = 0; i < r.cast.length; i++) { if (r.cast[i].role === 'Actor') { - that.person_request(r.cast[i].personId, function() { + that.person_request(r.cast[i].personId, {character_name: r.cast[i].characterName}, function(success) { if (request_count == (r.cast.length - 1)) { the_other.render(); } + if (!success) { + actor_count--; + } request_count++; }); } @@ -33,8 +37,11 @@ module.exports = function(req, res) { }); }; - this.person_request = function(person_id, callback) { + this.person_request = function(person_id, params, callback) { var that = this; + var params = params || { + character_name: '' + }; var url = config.tms.host + '/v1/celebs/' + person_id + '?api_key=' + config.tms.key; request(url, function(error, response, body) { if (!error && response.statusCode == 200) { @@ -42,11 +49,15 @@ module.exports = function(req, res) { that.data.character_images.characters.push({ image: 'http://developer.tmsimg.com/' + r.preferredImage.uri + '?api_key=' + config.tms.key + '&h=100', - name: r.preferredImage.caption.content, + name: params.character_name, tms_personId: r.personId }); + console.log(r); - callback(); + callback(true); + } + else { + callback(false); } }); }; |
