Commit 1b4fb62a4d0ba2fdf23feb24fca27067ecb790ba
1 parent
dde02317
Exists in
master
and in
6 other branches
Relate with issue #230 show only the proposal passed in url. Needs check id's th…
…at not exists in noosfero api.
Showing
1 changed file
with
25 additions
and
3 deletions
Show diff stats
js/main.js
| @@ -36,6 +36,20 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -36,6 +36,20 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 36 | Main = (function(){ | 36 | Main = (function(){ |
| 37 | 37 | ||
| 38 | return { | 38 | return { |
| 39 | + getProposalId: function(){ | ||
| 40 | + var regexProposals = /\d.*\/propostas\/\d.*/; | ||
| 41 | + var proposalId = 0; | ||
| 42 | + | ||
| 43 | + var hasProposal = regexProposals.test(location.hash); | ||
| 44 | + if( hasProposal ){ | ||
| 45 | + var regexExtractProposal = /propostas\/\d.*/; | ||
| 46 | + proposalId = regexExtractProposal.exec(location.hash)[0].split('/')[1]; | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + return proposalId; | ||
| 51 | + }, | ||
| 52 | + | ||
| 39 | loadRandomProposal: function (topic_id, private_token) { | 53 | loadRandomProposal: function (topic_id, private_token) { |
| 40 | var $noProposals = $('.no-proposals'); | 54 | var $noProposals = $('.no-proposals'); |
| 41 | var $loading = $('.loading'); | 55 | var $loading = $('.loading'); |
| @@ -48,10 +62,18 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -48,10 +62,18 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 48 | $loading.show(); | 62 | $loading.show(); |
| 49 | $randomProposal.html(''); | 63 | $randomProposal.html(''); |
| 50 | 64 | ||
| 51 | - var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; | 65 | + var url = host + '/api/v1/articles/' + topic_id + '/children'; |
| 66 | + var childId = this.getProposalId(); | ||
| 67 | + | ||
| 68 | + if(childId != 0){ | ||
| 69 | + url += '/'+childId; | ||
| 70 | + } | ||
| 71 | + url += '?private_token=' + private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; | ||
| 72 | + | ||
| 52 | $.getJSON(url).done(function( data ) { | 73 | $.getJSON(url).done(function( data ) { |
| 53 | $loading.hide(); | 74 | $loading.hide(); |
| 54 | 75 | ||
| 76 | + data.articles = data.articles || [data.article]; | ||
| 55 | if(data.articles.length === 0) { | 77 | if(data.articles.length === 0) { |
| 56 | $noProposals.show(); | 78 | $noProposals.show(); |
| 57 | return; | 79 | return; |
| @@ -387,7 +409,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -387,7 +409,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 387 | // show the 'index' -> category tab | 409 | // show the 'index' -> category tab |
| 388 | this.display_category_tab(); | 410 | this.display_category_tab(); |
| 389 | 411 | ||
| 390 | - | 412 | + |
| 391 | // if(navOffset){ | 413 | // if(navOffset){ |
| 392 | // scrollTop = navOffset.top; | 414 | // scrollTop = navOffset.top; |
| 393 | // } | 415 | // } |
| @@ -610,7 +632,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -610,7 +632,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 610 | 632 | ||
| 611 | 633 | ||
| 612 | $(document).ready(function($) { | 634 | $(document).ready(function($) { |
| 613 | - | 635 | + |
| 614 | FastClick.attach(document.body); | 636 | FastClick.attach(document.body); |
| 615 | 637 | ||
| 616 | if($.cookie('_dialoga_session')) { | 638 | if($.cookie('_dialoga_session')) { |