main.js
2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// The template code
var templateSource = document.getElementById('proposal-template').innerHTML;
// compile the template
var template = Handlebars.compile(templateSource);
// The div/container that we are going to display the results in
var resultsPlaceholder = document.getElementById('proposal-result');
var topics;
var host = 'http://www.participa.br';
//var host = 'http://localhost:3000';
var private_token = '9350c1488fcae884ad955091a3d2d960';
//var private_token = 'bd8996155f5ea4354e42fee50b4b6891';
var proposal_discussion = '92856';
//var proposal_discussion = '401';
//var noosferoAPI = 'http://localhost:3000/api/v1/articles?private_token=89419a2d331a17e815c3ecc53b303aac&content_type=ProposalsDiscussionPlugin::Topic&parent_id=377&callback=?';
var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + private_token + '&callback=?';
//var noosferoAPI = host + '/api/v1/articles?private_token=' + private_token + '&parent_id=401&callback=?';
$.getJSON(noosferoAPI)
.done(function( data ) {
data['host'] = host;
resultsPlaceholder.innerHTML = template(data);
$( 'a' ).click(function(event){
var item = this.href.split('#').pop();
if(item == 'proposal-categories'){
//Display the category tab
$('#proposal-group').hide();
$('#proposal-categories').show();
$('#nav-proposal-categories a').addClass('active');
$('#nav-proposal-group a').removeClass('active');
$('.proposal-category-item').hide();
$('.proposal-detail').hide();
}else if(item == 'proposal-group'){
//Display the Topics or Discussions tab
$('#proposal-categories').hide();
$('#proposal-group').show();
$('#nav-proposal-group a').addClass('active');
$('#nav-proposal-categories a').removeClass('active');
}else{
if($('#' + item).hasClass('proposal-category-item')){
//Display Topics or Discussion by category
$('.proposal-category-item').hide();
$('#' + item).show();
}else{
//Display Proposal
$('#proposal-categories').hide();
$('#proposal-group').hide();
$('.proposal-detail').hide();
$('#' + item).show();
}
}
event.preventDefault();
});
})
.fail(function( jqxhr, textStatus, error ) {
var err = textStatus + ", " + error;
console.log( "Request Failed: " + err );
});