footer.html.erb 1.5 KB
<script>
  $('.members-block .block-footer-content').prepend('<span class="members-counter"><%= profile.nil? ? '' : profile.members.count %> participantes</span>');
</script>

<% if params[:controller] == 'profile' and params[:action] == 'index' %>
<% blocks = profile.blocks
   blocks.keep_if{|b| b.type == 'CommunityTrackPlugin::TrackListBlock'}
   tracks = blocks.empty? ? [] : Block.find(blocks[0].id).tracks
   stats = {'tracks' => {'comments' => Array.new,'hits' => Array.new}}
   tracks.each do |t|
     stats['tracks']['comments'].unshift t.comments_count
     stats['tracks']['hits'].unshift t.hits
   end
%>
<script>
  var tracks = $('div.track_content .lead');
  var comments = <%= stats["tracks"]["comments"]%>;
  var hits = <%= stats["tracks"]["hits"]%>;
  var i = 0;
  tracks.each(function(i){
    var link = $(this).find('h3 a').attr('href');
    var readMore = $('<div class="read_more"><a><span>Leia mais</span></a></div>');
    var track = $('<div class="track_enum"><span class="counter">'+(i+1)+'</span><span class="track_label">Trilha '+(i+1)+'</span></div>');
    var status = $('<div class="stats"><div class="comments_count"><span></span></div><div class="hits_count"><span></span></div></div>');
    $(status).find('div.comments_count span').text(comments.pop());
    $(status).find('div.hits_count span').text(hits.pop()+' acesso(s)');
    $(readMore).children().attr('href', link);
    $(this).prepend(track);
    $(this).append(readMore);  
    $(this).append(status);
    i++;
  }); 
</script>
<% end %>