Commit e38debeda5af8be675163d50c7491eeb9db3aede

Authored by Victor Costa
1 parent fb0d6da5

Reload proposal after vote

Showing 1 changed file with 20 additions and 13 deletions   Show diff stats
@@ -59,19 +59,7 @@ $.getJSON(noosferoAPI) @@ -59,19 +59,7 @@ $.getJSON(noosferoAPI)
59 $('#' + item).show(); 59 $('#' + item).show();
60 60
61 var topic_id = this.id.replace('\#',''); 61 var topic_id = this.id.replace('\#','');
62 - var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()';  
63 - $.getJSON(url).done(function( data ) {  
64 - var article = data.articles.length > 0 ? data.articles[0] : null;  
65 - $('.support-proposal-container').html(supportProposalTemplate(article));  
66 - $(document.body).on('click', '.vote-actions .like', function(e) {  
67 - $.ajax({  
68 - type: 'post',  
69 - url: host + '/api/v1/articles/' + article.id + '/vote',  
70 - data: {value: $(this).data('vote-value'), private_token: private_token}  
71 - });  
72 - e.preventDefault();  
73 - });  
74 - }); 62 + loadRandomProposal(topic_id, private_token);
75 }); 63 });
76 $( '.proposal-category a' ).click(function(event){ 64 $( '.proposal-category a' ).click(function(event){
77 var item = this.href.split('#').pop(); 65 var item = this.href.split('#').pop();
@@ -104,3 +92,22 @@ $.getJSON(noosferoAPI) @@ -104,3 +92,22 @@ $.getJSON(noosferoAPI)
104 var err = textStatus + ", " + error; 92 var err = textStatus + ", " + error;
105 console.log( "Request Failed: " + err ); 93 console.log( "Request Failed: " + err );
106 }); 94 });
  95 +
  96 +function loadRandomProposal(topic_id, private_token) {
  97 + var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()';
  98 + $.getJSON(url).done(function( data ) {
  99 + var article = data.articles.length > 0 ? data.articles[0] : null;
  100 + $('.support-proposal-container').html(supportProposalTemplate(article));
  101 + $(document.body).off('click', '.vote-actions .like');
  102 + $(document.body).on('click', '.vote-actions .like', function(e) {
  103 + $.ajax({
  104 + type: 'post',
  105 + url: host + '/api/v1/articles/' + article.id + '/vote',
  106 + data: {value: $(this).data('vote-value'), private_token: private_token}
  107 + }).done(function( data ) {
  108 + loadRandomProposal(topic_id, private_token);
  109 + });
  110 + e.preventDefault();
  111 + });
  112 + });
  113 +}