Commit 944cecb5a77f08e66f8e49960bf43613a9cc6097
1 parent
23846083
Exists in
master
and in
11 other branches
Display random proposal
Showing
2 changed files
with
66 additions
and
40 deletions
Show diff stats
index.html
@@ -65,16 +65,23 @@ | @@ -65,16 +65,23 @@ | ||
65 | <input type='submit' id='make-proposal-button' name='make-proposal-button' value='Submit'> | 65 | <input type='submit' id='make-proposal-button' name='make-proposal-button' value='Submit'> |
66 | </form> | 66 | </form> |
67 | </div> | 67 | </div> |
68 | - <div class='support-proposal'> | ||
69 | - <div class='title'> Apoie outras propostas</div> | ||
70 | - <div class='author'>{{author.name}}</div> | ||
71 | - <div class='abstract'>{{abstract}}</div> | ||
72 | - </div> | 68 | + <div class='support-proposal-container'></div> |
73 | <div class='experience-proposal'>Conte sua experiência</div> | 69 | <div class='experience-proposal'>Conte sua experiência</div> |
74 | <div class='talk-proposal'>Fale com o ministro</div> | 70 | <div class='talk-proposal'>Fale com o ministro</div> |
75 | </div> | 71 | </div> |
76 | {{/each}} | 72 | {{/each}} |
77 | - | 73 | + </script> |
74 | + | ||
75 | + <script id='support-proposal-template' type='text/x-handlebars-template'> | ||
76 | + <div class='support-proposal'> | ||
77 | + <div class='title'> Apoie outras propostas</div> | ||
78 | + <div class='author'>{{author.name}}</div> | ||
79 | + <div class='abstract'>{{abstract}}</div> | ||
80 | + <div class="vote-actions"> | ||
81 | + <a href="#" class="like" data-vote-value="1">Gostei</a> | ||
82 | + <a href="#" class="like" data-vote-value="-1">Não Gostei</a> | ||
83 | + </div> | ||
84 | + </div> | ||
78 | </script> | 85 | </script> |
79 | 86 | ||
80 | <div id='proposal-result'></div> | 87 | <div id='proposal-result'></div> |
js/main.js
1 | // The template code | 1 | // The template code |
2 | var templateSource = document.getElementById('proposal-template').innerHTML; | 2 | var templateSource = document.getElementById('proposal-template').innerHTML; |
3 | - | 3 | + |
4 | // compile the template | 4 | // compile the template |
5 | var template = Handlebars.compile(templateSource); | 5 | var template = Handlebars.compile(templateSource); |
6 | - | 6 | + |
7 | +var supportProposalTemplate = Handlebars.compile(document.getElementById('support-proposal-template').innerHTML); | ||
8 | + | ||
7 | // The div/container that we are going to display the results in | 9 | // The div/container that we are going to display the results in |
8 | var resultsPlaceholder = document.getElementById('proposal-result'); | 10 | var resultsPlaceholder = document.getElementById('proposal-result'); |
9 | 11 | ||
@@ -15,10 +17,10 @@ if(participa){ | @@ -15,10 +17,10 @@ if(participa){ | ||
15 | var private_token = '9350c1488fcae884ad955091a3d2d960'; //participa | 17 | var private_token = '9350c1488fcae884ad955091a3d2d960'; //participa |
16 | var proposal_discussion = '92856'; //participa | 18 | var proposal_discussion = '92856'; //participa |
17 | }else{ | 19 | }else{ |
18 | - var host = 'http://localhost:3000'; | 20 | + var host = 'http://noosfero.com:3000'; |
19 | //var private_token = 'bd8996155f5ea4354e42fee50b4b6891'; //casa | 21 | //var private_token = 'bd8996155f5ea4354e42fee50b4b6891'; //casa |
20 | - var private_token = '89419a2d331a17e815c3ecc53b303aac'; //local serpro | ||
21 | - var proposal_discussion = '377'; //local serpro | 22 | + var private_token = '04c9b36cf0afba52915fe86f182e741c'; //local serpro |
23 | + var proposal_discussion = '632'; //local serpro | ||
22 | //var proposal_discussion = '401'; //casa | 24 | //var proposal_discussion = '401'; //casa |
23 | } | 25 | } |
24 | 26 | ||
@@ -30,35 +32,53 @@ $.getJSON(noosferoAPI) | @@ -30,35 +32,53 @@ $.getJSON(noosferoAPI) | ||
30 | data['private_token'] = private_token; | 32 | data['private_token'] = private_token; |
31 | resultsPlaceholder.innerHTML = template(data); | 33 | resultsPlaceholder.innerHTML = template(data); |
32 | //Actions for links | 34 | //Actions for links |
33 | - $( 'a' ).click(function(event){ | 35 | + $( '#nav-proposal-categories a' ).click(function(event){ |
36 | + //Display the category tab | ||
37 | + $('#proposal-group').hide(); | ||
38 | + $('#proposal-categories').show(); | ||
39 | + $('#nav-proposal-categories a').addClass('active'); | ||
40 | + $('#nav-proposal-group a').removeClass('active'); | ||
41 | + $('.proposal-category-item').hide(); | ||
42 | + $('.proposal-detail').hide(); | ||
43 | + event.preventDefault(); | ||
44 | + }); | ||
45 | + $( '#nav-proposal-group a' ).click(function(event){ | ||
46 | + //Display the Topics or Discussions tab | ||
47 | + $('#proposal-categories').hide(); | ||
48 | + $('#proposal-group').show(); | ||
49 | + $('#nav-proposal-group a').addClass('active'); | ||
50 | + $('#nav-proposal-categories a').removeClass('active'); | ||
51 | + event.preventDefault(); | ||
52 | + }); | ||
53 | + $( '.proposal-item a' ).click(function(event){ | ||
34 | var item = this.href.split('#').pop(); | 54 | var item = this.href.split('#').pop(); |
35 | - if(item == 'proposal-categories'){ | ||
36 | - //Display the category tab | ||
37 | - $('#proposal-group').hide(); | ||
38 | - $('#proposal-categories').show(); | ||
39 | - $('#nav-proposal-categories a').addClass('active'); | ||
40 | - $('#nav-proposal-group a').removeClass('active'); | 55 | + //Display Proposal |
56 | + $('#proposal-categories').hide(); | ||
57 | + $('#proposal-group').hide(); | ||
58 | + $('.proposal-detail').hide(); | ||
59 | + $('#' + item).show(); | ||
60 | + | ||
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 | + }); | ||
75 | + }); | ||
76 | + $( '.proposal-category a' ).click(function(event){ | ||
77 | + var item = this.href.split('#').pop(); | ||
78 | + if($('#' + item).hasClass('proposal-category-item')){ | ||
79 | + //Display Topics or Discussion by category | ||
41 | $('.proposal-category-item').hide(); | 80 | $('.proposal-category-item').hide(); |
42 | - $('.proposal-detail').hide(); | ||
43 | - }else if(item == 'proposal-group'){ | ||
44 | - //Display the Topics or Discussions tab | ||
45 | - $('#proposal-categories').hide(); | ||
46 | - $('#proposal-group').show(); | ||
47 | - $('#nav-proposal-group a').addClass('active'); | ||
48 | - $('#nav-proposal-categories a').removeClass('active'); | ||
49 | - }else{ | ||
50 | - if($('#' + item).hasClass('proposal-category-item')){ | ||
51 | - //Display Topics or Discussion by category | ||
52 | - $('.proposal-category-item').hide(); | ||
53 | - $('#' + item).show(); | ||
54 | - | ||
55 | - }else{ | ||
56 | - //Display Proposal | ||
57 | - $('#proposal-categories').hide(); | ||
58 | - $('#proposal-group').hide(); | ||
59 | - $('.proposal-detail').hide(); | ||
60 | - $('#' + item).show(); | ||
61 | - } | 81 | + $('#' + item).show(); |
62 | } | 82 | } |
63 | event.preventDefault(); | 83 | event.preventDefault(); |
64 | }); | 84 | }); |
@@ -66,7 +86,7 @@ $.getJSON(noosferoAPI) | @@ -66,7 +86,7 @@ $.getJSON(noosferoAPI) | ||
66 | $('.make-proposal-form').submit(function (e) { | 86 | $('.make-proposal-form').submit(function (e) { |
67 | e.preventDefault(); | 87 | e.preventDefault(); |
68 | var proposal_id = this.id.split('-').pop(); | 88 | var proposal_id = this.id.split('-').pop(); |
69 | - $.ajax({ | 89 | + $.ajax({ |
70 | type: 'post', | 90 | type: 'post', |
71 | url: host + '/api/v1/articles/' + proposal_id + '/children', | 91 | url: host + '/api/v1/articles/' + proposal_id + '/children', |
72 | data: $('#'+this.id).serialize() | 92 | data: $('#'+this.id).serialize() |
@@ -84,4 +104,3 @@ $.getJSON(noosferoAPI) | @@ -84,4 +104,3 @@ $.getJSON(noosferoAPI) | ||
84 | var err = textStatus + ", " + error; | 104 | var err = textStatus + ", " + error; |
85 | console.log( "Request Failed: " + err ); | 105 | console.log( "Request Failed: " + err ); |
86 | }); | 106 | }); |
87 | - |