From e38debeda5af8be675163d50c7491eeb9db3aede Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Wed, 15 Apr 2015 10:32:00 -0300 Subject: [PATCH] Reload proposal after vote --- js/main.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/js/main.js b/js/main.js index 1a5ca8a..c8f4250 100644 --- a/js/main.js +++ b/js/main.js @@ -59,19 +59,7 @@ $.getJSON(noosferoAPI) $('#' + item).show(); var topic_id = this.id.replace('\#',''); - var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()'; - $.getJSON(url).done(function( data ) { - var article = data.articles.length > 0 ? data.articles[0] : null; - $('.support-proposal-container').html(supportProposalTemplate(article)); - $(document.body).on('click', '.vote-actions .like', function(e) { - $.ajax({ - type: 'post', - url: host + '/api/v1/articles/' + article.id + '/vote', - data: {value: $(this).data('vote-value'), private_token: private_token} - }); - e.preventDefault(); - }); - }); + loadRandomProposal(topic_id, private_token); }); $( '.proposal-category a' ).click(function(event){ var item = this.href.split('#').pop(); @@ -104,3 +92,22 @@ $.getJSON(noosferoAPI) var err = textStatus + ", " + error; console.log( "Request Failed: " + err ); }); + +function loadRandomProposal(topic_id, private_token) { + var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()'; + $.getJSON(url).done(function( data ) { + var article = data.articles.length > 0 ? data.articles[0] : null; + $('.support-proposal-container').html(supportProposalTemplate(article)); + $(document.body).off('click', '.vote-actions .like'); + $(document.body).on('click', '.vote-actions .like', function(e) { + $.ajax({ + type: 'post', + url: host + '/api/v1/articles/' + article.id + '/vote', + data: {value: $(this).data('vote-value'), private_token: private_token} + }).done(function( data ) { + loadRandomProposal(topic_id, private_token); + }); + e.preventDefault(); + }); + }); +} -- libgit2 0.21.2