javascript bugfix, _habit partial bug fixes

This commit is contained in:
Tyler Renelle 2012-02-04 11:29:13 -05:00
parent 06133f9379
commit fdab691cb9
3 changed files with 18 additions and 15 deletions

View file

@ -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

View file

@ -2,9 +2,12 @@
<%= link_to 'New Habit', new_habit_path %>
<table id="layout">
<tr>
<th>Habits</th>
<th>Daily</th>
</tr>
<tr>
<td class="panel">
<h2>Habits</h2>
<ul id="habits">
<% @habits.each do |habit| %>
<%= render :partial => "habit", :locals => { :habit => habit } %>
@ -13,7 +16,6 @@
</td>
<td class="panel">
<h2>Daily</h2>
<ul id="daily">
<% @daily.each do |habit| %>
<%= render :partial => "habit", :locals => { :habit => habit } %>

View file

@ -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 %>");