From fdab691cb913f06db6c1ae7af58f166d5ec99b0e Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sat, 4 Feb 2012 11:29:13 -0500 Subject: [PATCH] javascript bugfix, _habit partial bug fixes --- app/helpers/habits_helper.rb | 23 ++++++++++++----------- app/views/habits/index.html.erb | 6 ++++-- app/views/habits/vote.js.erb | 4 ++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/helpers/habits_helper.rb b/app/helpers/habits_helper.rb index 67af8d55c5..373fb18648 100644 --- a/app/helpers/habits_helper.rb +++ b/app/helpers/habits_helper.rb @@ -11,18 +11,19 @@ module HabitsHelper end end - def vote_link(habit, state) - case state - when 'up' - return unless habit.up - text,dir,style = "+","up","up" - when 'down' - return unless habit.down - text,dir,style = "-","down","down" - when 'checked' then text,dir,style = "[ ]","up","check" - when 'unchecked' then text,dir,style = "[X]","down","check" + def vote_link(habit, direction=nil) + if direction=='up' + return unless habit.up + text,dir,style = "+","up","up" + elsif direction=='down' + return unless habit.down + text,dir,style = "-","down","down" + elsif habit.done + text,dir,style = "[X]","down","check" + else + text,dir,style = "[ ]","up","check" end - return link_to(text, { :action => "vote", :id => habit.id, :vote => 'dir' }, :class=>style, :remote=>true) + return link_to(text, { :action => "vote", :id => habit.id, :vote => dir }, :class=>style, :remote=>true) end end diff --git a/app/views/habits/index.html.erb b/app/views/habits/index.html.erb index 4124d800d1..cc5ad121b2 100644 --- a/app/views/habits/index.html.erb +++ b/app/views/habits/index.html.erb @@ -2,9 +2,12 @@ <%= link_to 'New Habit', new_habit_path %> + + + +
HabitsDaily
-

Habits

    <% @habits.each do |habit| %> <%= render :partial => "habit", :locals => { :habit => habit } %> @@ -13,7 +16,6 @@
-

Daily

    <% @daily.each do |habit| %> <%= render :partial => "habit", :locals => { :habit => habit } %> diff --git a/app/views/habits/vote.js.erb b/app/views/habits/vote.js.erb index 4a1cb10254..919decaac6 100644 --- a/app/views/habits/vote.js.erb +++ b/app/views/habits/vote.js.erb @@ -1,2 +1,2 @@ -$('#habit_<%= @habit.id %>').html("<%= escape_javascript(render :partial => "habit", :locals => { :habit => @habit }) %>"); -$('#score').html("<%= @score %>"); +$('#habit_<%= @habit.id %>').replaceWith("<%= escape_javascript(render :partial => "habit", :locals => { :habit => @habit }) %>"); +$('#score').replaceWith("<%= @score %>");