@@ -25,52 +25,91 @@ function populateWall(momentlist) {
2525 /* Temporal computation for speed purposes */
2626 var timelapse = 0 ;
2727
28- // jQuery AJAX call for JSON
29- $ . getJSON ( momentlist , function ( data ) {
30- // For each item in our JSON, add an 'article.moment'
31- $ . each ( data , function ( ) {
32- wallContent += '<article class="moment">' ;
33- wallContent += '<div class="has">' ;
34- // wallContent += '<div class="heart">'
35- // wallContent += '<div class="icon-heart_white"></div>'
36- // wallContent += '<div class="heart-number">10</div></div>'
37- wallContent += '<img src="' + this . user . image + '" alt=""/>' ;
38- wallContent += '<div class="text_has">' ;
39- wallContent += this . user . username ;
40- wallContent += ' <span class="transparent"> tuvo un </span>' ;
41- wallContent += ' momento <span class="transparent"> de </span>' ;
42-
43- timelapse = Math . floor ( this . timelapse / 30 ) ;
44- ipsos += timelapse ;
45- wallContent += timelapse ;
46- wallContent += ' ipsos</div></div>'
47- wallContent += '<div class="right_moment">' ;
48-
49- if ( this . attachement != '' ) {
50- wallContent += '<div class="tipe_moment image">' ;
51- wallContent += '<img src="' + this . attachement [ 0 ] + '".jpg alt=""/>' ;
52- }
53-
54- wallContent += '<div class="tipe_moment text"><span class="icon-Comillas-10"></span>' + this . description + '</div></div></article>' ;
55- } ) ;
28+ /* User id */
29+ var userid ;
5630
57- // Inject the whole content string into our existing HTML section
58- $ ( '#wall' ) . html ( wallContent ) ;
59-
60- // If we are in profile
61- if ( momentlist === '/profile/momentList' ) {
62- if ( Object . keys ( data ) . length === 0 )
63- $ ( '#momentsQuantity' ) . html ( "Es hora de idear. ¡Inicia un nuevo momento!" ) ;
64- else {
65- $ ( '#momentsQuantity' ) . html ( Object . keys ( data ) . length + " momentos logrados" ) ;
66- $ ( '#ipsos' ) . html ( ipsos + ' ipsos' ) ;
67- }
68- }
31+ $ . getJSON ( "api/user_data" , function ( user ) {
32+ // Make sure the data contains the username as expected before using it
33+ userid = user . userid ;
6934
70- //================================== CHANGE COLOR HEART ===============================
71- $ ( ".icon-heart_white" ) . click ( function ( ) {
72- $ ( this ) . removeClass ( "icon-heart_white" ) ;
73- $ ( this ) . addClass ( "icon-heart_red" ) ;
74- } ) ;
35+ // jQuery AJAX call for JSON
36+ $ . getJSON ( momentlist , function ( data ) {
37+ // For each item in our JSON, add an 'article.moment'
38+ $ . each ( data , function ( ) {
39+ /* Replace undefined hearts with zeroes */
40+ if ( this . heart == null )
41+ this . heart = 0 ;
42+
43+ var usersHeart = this . usersHeart ;
44+ var specifiedClass = "icon-heart_white" ;
45+
46+ /* Class depending if it was clickable or not */
47+ for ( var i in usersHeart ) {
48+ var id = usersHeart [ i ] ;
49+ if ( id == userid )
50+ specifiedClass = "icon-heart_red" ;
51+ }
52+
53+ wallContent += '<article class="moment">' ;
54+ wallContent += '<div class="has">' ;
55+ wallContent += '<div class="heart" onClick="addHref(\'' + this . _id + '\')">' ;
56+
57+
58+ wallContent += '<div id=' + this . _id + "c" + ' class=' + specifiedClass + '></div>' ;
59+
60+ wallContent += '<div id=' + this . _id + ' class="heart-number">' + this . heart + '</div></div>' ;
61+ wallContent += '<img src="' + this . user . image + '" alt=""/>' ;
62+ wallContent += '<div class="text_has">' ;
63+ wallContent += this . user . username ;
64+ wallContent += ' <span class="transparent"> tuvo un </span>' ;
65+ wallContent += ' momento <span class="transparent"> de </span>' ;
66+
67+ timelapse = Math . floor ( this . timelapse / 30 ) ;
68+ ipsos += timelapse ;
69+ wallContent += timelapse ;
70+ wallContent += ' ipsos</div></div>'
71+ wallContent += '<div class="right_moment">' ;
72+
73+ if ( this . attachement != '' ) {
74+ wallContent += '<div class="tipe_moment image">' ;
75+ wallContent += '<img src="' + this . attachement [ 0 ] + '".jpg alt=""/>' ;
76+ }
77+
78+ wallContent += '<div class="tipe_moment text"><span class="icon-Comillas-10"></span>' + this . description + '</div></div></article>' ;
79+
80+ // Inject the whole content string into our existing HTML section
81+ $ ( '#wall' ) . html ( wallContent ) ;
82+
83+ //================================== CHANGE COLOR HEART ===============================
84+ $ ( ".icon-heart_white" ) . click ( function ( ) {
85+ /* $(this).removeClass("icon-heart_white");
86+ $(this).addClass("icon-heart_red");*/
87+ } ) ;
88+ } ) ;
89+ } ) ;
7590 } ) ;
91+
92+
93+
94+ // If we are in profile
95+ if ( momentlist === '/profile/momentList' ) {
96+ if ( Object . keys ( data ) . length === 0 )
97+ $ ( '#momentsQuantity' ) . html ( "Es hora de idear. ¡Inicia un nuevo momento!" ) ;
98+ else {
99+ $ ( '#momentsQuantity' ) . html ( Object . keys ( data ) . length + " momentos logrados" ) ;
100+ $ ( '#ipsos' ) . html ( ipsos + ' ipsos' ) ;
101+ }
102+ }
76103} ;
104+
105+ function addHref ( clickedID ) {
106+ if ( $ ( "#" + clickedID + "c" ) . prop ( 'className' ) == "icon-heart_white" ) {
107+ $ . post ( 'home/vote/' + clickedID , function ( ) {
108+
109+ } ) ;
110+ $ ( "#" + clickedID ) . html ( parseInt ( $ ( "#" + clickedID ) . html ( ) ) + 1 ) ;
111+
112+ $ ( "#" + clickedID + "c" ) . removeClass ( "icon-heart_white" ) ;
113+ $ ( "#" + clickedID + "c" ) . addClass ( "icon-heart_red" ) ;
114+ }
115+ }
0 commit comments