Commit 4e4333f4e2d04db06888c1613f8600da9b669de4
1 parent
bff477be
Exists in
master
and in
12 other branches
accessing noosfero API
Showing
2 changed files
with
31 additions
and
18 deletions
Show diff stats
index.html
1 | 1 | <html> |
2 | 2 | <head> |
3 | + <script src='js/jquery-1.11.2.min.js'></script> | |
3 | 4 | <script src='js/handlebars-v3.0.1.js'></script> |
5 | + <script src='js/handlebars-helpers.js'></script> | |
4 | 6 | </head> |
5 | 7 | <body> |
6 | 8 | |
7 | 9 | <script id='proposal-template' type='text/x-handlebars-template'> |
8 | 10 | <ul class="proposal-group"> |
9 | - <li class="proposal-item"> | |
10 | - <h1>{{proposal.title}}</h1> | |
11 | - {{proposal.description}} | |
12 | - </li> | |
11 | + {{#each articles}} | |
12 | + <li class="proposal-item"> | |
13 | + {{#link title id}}{{/link}} | |
14 | + <h2>{{title}}</h2> | |
15 | + <spam>{{body}} </spam> | |
16 | + </li> | |
17 | + {{/each}} | |
13 | 18 | </ul> |
19 | + {{#each articles}} | |
20 | + <div id="proposal-{{id}}"> | |
21 | + <div class='title'>{{title}}</div> | |
22 | + <spam>{{body}} </spam> | |
23 | + </div> | |
24 | + {{/each}} | |
25 | + | |
14 | 26 | </script> |
15 | 27 | |
16 | 28 | <div id='proposal-result'></div> | ... | ... |
js/main.js
... | ... | @@ -7,20 +7,21 @@ var template = Handlebars.compile(templateSource); |
7 | 7 | // The div/container that we are going to display the results in |
8 | 8 | var resultsPlaceholder = document.getElementById('proposal-result'); |
9 | 9 | |
10 | +var topics; | |
10 | 11 | |
11 | -$.ajax({ | |
12 | - dataType: "json", | |
13 | - url: 'http://localhost:3000/api/v1/articles?private_token=89419a2d331a17e815c3ecc53b303aac&content_type=ProposalsDiscussionPlugin::Topic&parent_id=377', | |
14 | - data: data, | |
15 | - success: success | |
16 | -}); | |
12 | +var noosferoAPI = 'http://localhost:3000/api/v1/articles?private_token=89419a2d331a17e815c3ecc53b303aac&content_type=ProposalsDiscussionPlugin::Topic&parent_id=377&callback=?'; | |
17 | 13 | |
18 | -var data = { | |
19 | - "proposal": | |
20 | - { | |
21 | - "title": "Handlebars", | |
22 | - "description": "Demo" | |
23 | - } | |
24 | -}; | |
14 | +$.getJSON(noosferoAPI) | |
15 | + .done(function( data ) { | |
16 | + //console.log(data); | |
17 | + resultsPlaceholder.innerHTML = template(data); | |
18 | + $( 'a' ).click(function(){ | |
19 | + resultsPlaceholder.innerHTML = $('#proposal-' + this.id.replace('#','')).html(); | |
20 | + }); | |
21 | + //console.log(resultsPlaceholder); | |
22 | + }) | |
23 | + .fail(function( jqxhr, textStatus, error ) { | |
24 | + var err = textStatus + ", " + error; | |
25 | + console.log( "Request Failed: " + err ); | |
26 | + }); | |
25 | 27 | |
26 | -resultsPlaceholder.innerHTML = template(data); | ... | ... |