Permalink
Browse files

Filter shared/missing achievements.

  • Loading branch information...
1 parent b41f5d7 commit 0df528c6f38d5f6c84a0cae68d648968ab8647db @jschuur committed Sep 22, 2011
Showing with 28 additions and 5 deletions.
  1. +21 −0 app/assets/javascripts/achievements.js.coffee
  2. +7 −5 app/views/achievements/_results.html.erb
View
21 app/assets/javascripts/achievements.js.coffee
@@ -42,6 +42,27 @@ $ ->
e.preventDefault()
)
+ $("#filters a").live('click', (e) ->
+ range = $(this).attr("data-range")
+ if range == 'all'
+ $("#achievements .achievement").show()
+ $("#tallyfilter").empty()
+ else if range == 'shared'
+ $("#achievements .achievement.missing").hide()
+ $("#achievements .achievement.shared").show()
+ $("#tallyfilter").html('(showing ' + $("#achievements .achievement:visible:").size() + ')')
+ else
+ $("#achievements .achievement.shared").hide()
+ $("#achievements .achievement.missing").show()
+ $("#tallyfilter").html('(showing ' + $("#achievements .achievement:visible:").size() + ')')
+
+ $("#achievements .achievement:visible:even").removeClass('achievement2').addClass('achievement1')
+ $("#achievements .achievement:visible:odd").removeClass('achievement1').addClass('achievement2')
+ $("#achievements .achievement:visible").last().css('border-bottom', '1px solid gray')
+
+ e.preventDefault()
+ )
+
$(window).bind "popstate", ->
initialPop = not popped and location.href == initialURL
popped = true
View
12 app/views/achievements/_results.html.erb
@@ -1,15 +1,17 @@
<% if @achievements.unlocked %>
- <div id="tally"><%= @achievements.unlocked.length %> of <%= @achievements.all.length %> unlocked
+ <div id="tally"><%= @achievements.unlocked.length %> of <%= @achievements.all.length %> unlocked <span id="tallyfilter"></span>
<% if @achievements.sparkline_history.sum.nonzero? %>
(<%= sparkline_tag @achievements.sparkline_history, :type => 'bar', :title => '4 week history', :step => 4, :height => 12, :background_color => '#fff', :below_color => 'black' %>)
<% end %>
</div>
+ <% if @compare_achievements %>
+ <div id="filters"><a data-range="all" href="#">All</a> | <a data-range="shared" href="#">Shared</a> | <a data-range="missing" href="#">Missing</a></div>
+ <% end %>
<div id="achievements">
<% @achievements.unlocked.each do |achievement| %>
- <div class="achievement <%= cycle('achievement1', 'achievement2')%>">
- <% if @compare_achievements && @current_user_achievements.detect() {|a| a.api_name == achievement.api_name } %>
- <%= image_tag("star.png", :class => 'shared', :title => 'Shared achievement') %>
- <% end %>
+ <% shared = (@compare_achievements && @current_user_achievements.detect() {|a| a.api_name == achievement.api_name }) %>
+ <div class="achievement <%= cycle('achievement1', 'achievement2')%> <%= shared ? 'shared' : 'missing' %>">
+ <%= image_tag("star.png", :class => 'shared', :title => 'Shared achievement') if shared %>
<%= content_tag(:div, achievement.name, :class => 'name') %>
<%= content_tag(:div, achievement.description, :class => 'description') %>
<%= content_tag(:div, achievement.timestamp.strftime("%D"), :class => 'time') if achievement.timestamp %>

0 comments on commit 0df528c

Please sign in to comment.