Skip to content
This repository has been archived by the owner on Dec 31, 2019. It is now read-only.

Commit

Permalink
cleaned up in-place-editing of houses by moving line items into a par…
Browse files Browse the repository at this point in the history
…tial and abstracting options for select boxes into helpers
  • Loading branch information
brianmaissy committed Dec 29, 2011
1 parent d463264 commit 195d8cd
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 63 deletions.
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ def profile_link(attributes = {})
link_to "Profile", {:controller => :users, :action => :profile, :id => @logged_user.to_param}, attributes
end

def reverse_elements(array)
array.collect{|a| a.reverse}
end

end
13 changes: 13 additions & 0 deletions app/helpers/houses_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
module HousesHelper

def permanent_chores_start_week_options
(1..15).collect {|i|[i,i]}
end

def using_online_sign_off_options
[['Yes', 1], ['No', 0]]
end

def sign_off_verification_mode_options
[["None", 0], ["Without password", 1], ["With password", 2]]
end

end
13 changes: 13 additions & 0 deletions app/views/houses/_house.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<tr>
<td><%= best_in_place house, :name %></td>
<td><%= house.semester_start_date %></td>
<td><%= house.semester_end_date %></td>
<td><%= best_in_place house, :permanent_chores_start_week, :type => :select, :collection => reverse_elements(permanent_chores_start_week_options) %></td>
<td><%= best_in_place house, :hours_per_week %></td>
<td><%= best_in_place house, :sign_off_by_hours_after %></td>
<td><%= best_in_place house, :using_online_sign_off, :type => :select, :collection => reverse_elements(using_online_sign_off_options) %></td>
<td><%= best_in_place house, :sign_off_verification_mode, :type => :select, :collection => reverse_elements(sign_off_verification_mode_options) %></td>
<td><%= best_in_place house, :blow_off_penalty_factor %></td>
<td><%= best_in_place house, :wsm_email %></td>
<td><%= link_to 'x', house, :confirm => 'Are you sure you want to delete this house?', :method => :delete, :remote => true, :class => 'delete_button' %></td>
</tr>
35 changes: 35 additions & 0 deletions app/views/houses/_new_house.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<tr id="new_item_line">
<td class="new_item_field">
<%= f.text_field :name %>
</td>
<td class="new_item_field">
<%= f.text_field :semester_start_date %>
</td>
<td class="new_item_field">
<%= f.text_field :semester_end_date %>
</td>
<td class="new_item_field">
<%= f.select(:permanent_chores_start_week, options_for_select(permanent_chores_start_week_options)) %>
</td>
<td class="new_item_field">
<%= f.text_field :hours_per_week %>
</td>
<td class="new_item_field">
<%= f.text_field :sign_off_by_hours_after %>
</td>
<td class="new_item_field">
<%= f.select(:using_online_sign_off, options_for_select(using_online_sign_off_options, 0)) %>
</td>
<td class="new_item_field">
<%= f.select(:sign_off_verification_mode, options_for_select(sign_off_verification_mode_options, 2)) %>
</td>
<td class="new_item_field">
<%= f.text_field :blow_off_penalty_factor %>
</td>
<td class="new_item_field">
<%= f.text_field :wsm_email %>
</td>
<td class="actions">
<%= f.submit "Create" %>
</td>
</tr>
14 changes: 1 addition & 13 deletions app/views/houses/create.js.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<% if @house.errors.none? %>
$('#new_item_line').before('<tr>\
<td><%= escape_javascript best_in_place @house, :name %></td>\
<td><%= @house.semester_start_date %></td>\
<td><%= @house.semester_end_date %></td>\
<td><%= escape_javascript best_in_place @house, :permanent_chores_start_week, :type => :select, :collection => (1..15).collect {|i|[i,i]} %></td>\
<td><%= escape_javascript best_in_place @house, :hours_per_week %></td>\
<td><%= escape_javascript best_in_place @house, :sign_off_by_hours_after %></td>\
<td><%= escape_javascript best_in_place @house, :using_online_sign_off, :type => :select, :collection => [[1, "Yes"], [0, "No"]] %></td>\
<td><%= escape_javascript best_in_place @house, :sign_off_verification_mode, :type => :select, :collection => [[0, "None"], [1, "Without password"], [2, "With password"]] %></td>\
<td><%= escape_javascript best_in_place @house, :blow_off_penalty_factor %></td>\
<td><%= escape_javascript best_in_place @house, :wsm_email %></td>\
<td><%= link_to "x", @house, :confirm => "Are you sure you want to delete this house?", :method => :delete, :remote => true, :class => "delete_button" %></td>\
</tr>')
$('#new_item_line').before('<%= escape_javascript(render(@house)) %>')
$('#new_house')[0].reset()
setup()
flash_green('<%= escape_javascript flash[:notice] %>')
Expand Down
52 changes: 2 additions & 50 deletions app/views/houses/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,9 @@
<th></th>
</tr>

<% @houses.each do |house| %>
<tr>
<td><%= best_in_place house, :name %></td>
<td><%= house.semester_start_date %></td>
<td><%= house.semester_end_date %></td>
<td><%= best_in_place house, :permanent_chores_start_week, :type => :select, :collection => (1..15).collect {|i|[i,i]} %></td>
<td><%= best_in_place house, :hours_per_week %></td>
<td><%= best_in_place house, :sign_off_by_hours_after %></td>
<td><%= best_in_place house, :using_online_sign_off, :type => :select, :collection => [[1, "Yes"], [0, "No"]] %></td>
<td><%= best_in_place house, :sign_off_verification_mode, :type => :select, :collection => [[0, "None"], [1, "Without password"], [2, "With password"]] %></td>
<td><%= best_in_place house, :blow_off_penalty_factor %></td>
<td><%= best_in_place house, :wsm_email %></td>
<td><%= link_to 'x', house, :confirm => 'Are you sure you want to delete this house?', :method => :delete, :remote => true, :class => 'delete_button' %></td>
</tr>
<% end %>
<%= render @houses %>
<tr id="new_item_line">
<td class="new_item_field">
<%= f.text_field :name %>
</td>
<td class="new_item_field">
<%= f.text_field :semester_start_date %>
</td>
<td class="new_item_field">
<%= f.text_field :semester_end_date %>
</td>
<td class="new_item_field">
<%= f.select(:permanent_chores_start_week, options_for_select((1..15).collect {|i|[i,i]})) %>
</td>
<td class="new_item_field">
<%= f.text_field :hours_per_week %>
</td>
<td class="new_item_field">
<%= f.text_field :sign_off_by_hours_after %>
</td>
<td class="new_item_field">
<%= f.select(:using_online_sign_off, options_for_select([['Yes', 1], ['No', 0]], 0)) %>
</td>
<td class="new_item_field">
<%= f.select(:sign_off_verification_mode, options_for_select([['None', 0], ['Without password', 1], ['With password', 2]], 2)) %>
</td>
<td class="new_item_field">
<%= f.text_field :blow_off_penalty_factor %>
</td>
<td class="new_item_field">
<%= f.text_field :wsm_email %>
</td>
<td class="actions">
<%= f.submit "Create" %>
</td>
</tr>
<%= render :partial => 'new_house', :locals => {:f => f} %>

</table>
<% end %>

0 comments on commit 195d8cd

Please sign in to comment.