arnaucube
arnaucube/thoughtsPublic Self-hosted repository
thoughts/web/index.js
web/index.jsRaw
 1var listThoughts;
 2
 3
 4var urlapi = "http://localhost:3000/api";
 5
 6function OnLoadIndex(){
 7    listThoughts=getAllThoughts();
 8}
 9function getAllThoughts(){
10    $.ajax({
11        type: "GET",
12        dataType: "json",
13        url: urlapi + "/thoughts",
14        success: function(data){
15            listThoughts=data;
16
17            document.getElementById('listThoughtsHtml').innerHTML=generateHtmlListThoughts();
18        }
19    });
20}
21function generateHtmlListThoughts(){
22    var html="";
23    html+="<div class='list'>";
24    html+="</div>";
25    html+="<ul class='list-group'>";
26    for(var i=0; i<listThoughts.length; i++)
27    {
28        html+=" <li class='list-group-item'>";
29        html+="<img src='"+listThoughts[i].usericon+"' width='30px' />";
30        html+="<a href='/userpage.html?value="+listThoughts[i].authorname+"'>" + listThoughts[i].authorname + ":</a>";
31        html+="<br>";
32        html+= listThoughts[i].content;
33        html+="</li>";
34    }
35
36    html+="</ul>";
37
38
39    return(html);
40}
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59/*
60##############################
61userpage.html
62##############################
63*/
64
65function OnLoadUserPage(){
66    var username=window.location.href.split("?value=")[1];
67    $.ajax({
68        type: "GET",
69        dataType: "json",
70        url: urlapi + "/users/byusername/" + username,
71        success: function(data){
72
73            document.getElementById('userpagehtml').innerHTML=generateHtmlUserPage(data[0]);
74        }
75    });
76}
77function generateHtmlUserPage(user){
78    var html="";
79    html+="<div class='well'>";
80    html+="<h3>" + user.username + "</h3>";
81    html+="description: " + user.description;
82
83    html+="<br>mail: " + user.mail;
84    html+="";
85    html+="";
86    html+="";
87    html+="</div>";
88    return(html);
89}