From 195d8cd43cf2e4a98e70e265ff7d50f7758239dd Mon Sep 17 00:00:00 2001 From: Brian Maissy Date: Wed, 28 Dec 2011 18:10:18 -0800 Subject: [PATCH] cleaned up in-place-editing of houses by moving line items into a partial and abstracting options for select boxes into helpers --- app/helpers/application_helper.rb | 4 +++ app/helpers/houses_helper.rb | 13 +++++++ app/views/houses/_house.html.erb | 13 +++++++ app/views/houses/_new_house.html.erb | 35 +++++++++++++++++++ app/views/houses/create.js.erb | 14 +------- app/views/houses/index.html.erb | 52 ++-------------------------- 6 files changed, 68 insertions(+), 63 deletions(-) create mode 100644 app/views/houses/_house.html.erb create mode 100644 app/views/houses/_new_house.html.erb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2f86b72..4d857f4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/helpers/houses_helper.rb b/app/helpers/houses_helper.rb index b462fca..bf412d4 100644 --- a/app/helpers/houses_helper.rb +++ b/app/helpers/houses_helper.rb @@ -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 diff --git a/app/views/houses/_house.html.erb b/app/views/houses/_house.html.erb new file mode 100644 index 0000000..c40e19f --- /dev/null +++ b/app/views/houses/_house.html.erb @@ -0,0 +1,13 @@ + + <%= best_in_place house, :name %> + <%= house.semester_start_date %> + <%= house.semester_end_date %> + <%= best_in_place house, :permanent_chores_start_week, :type => :select, :collection => reverse_elements(permanent_chores_start_week_options) %> + <%= best_in_place house, :hours_per_week %> + <%= best_in_place house, :sign_off_by_hours_after %> + <%= best_in_place house, :using_online_sign_off, :type => :select, :collection => reverse_elements(using_online_sign_off_options) %> + <%= best_in_place house, :sign_off_verification_mode, :type => :select, :collection => reverse_elements(sign_off_verification_mode_options) %> + <%= best_in_place house, :blow_off_penalty_factor %> + <%= best_in_place house, :wsm_email %> + <%= link_to 'x', house, :confirm => 'Are you sure you want to delete this house?', :method => :delete, :remote => true, :class => 'delete_button' %> + \ No newline at end of file diff --git a/app/views/houses/_new_house.html.erb b/app/views/houses/_new_house.html.erb new file mode 100644 index 0000000..94fc53a --- /dev/null +++ b/app/views/houses/_new_house.html.erb @@ -0,0 +1,35 @@ + + + <%= f.text_field :name %> + + + <%= f.text_field :semester_start_date %> + + + <%= f.text_field :semester_end_date %> + + + <%= f.select(:permanent_chores_start_week, options_for_select(permanent_chores_start_week_options)) %> + + + <%= f.text_field :hours_per_week %> + + + <%= f.text_field :sign_off_by_hours_after %> + + + <%= f.select(:using_online_sign_off, options_for_select(using_online_sign_off_options, 0)) %> + + + <%= f.select(:sign_off_verification_mode, options_for_select(sign_off_verification_mode_options, 2)) %> + + + <%= f.text_field :blow_off_penalty_factor %> + + + <%= f.text_field :wsm_email %> + + + <%= f.submit "Create" %> + + \ No newline at end of file diff --git a/app/views/houses/create.js.erb b/app/views/houses/create.js.erb index dd51499..52577d0 100644 --- a/app/views/houses/create.js.erb +++ b/app/views/houses/create.js.erb @@ -1,17 +1,5 @@ <% if @house.errors.none? %> - $('#new_item_line').before('\ - <%= escape_javascript best_in_place @house, :name %>\ - <%= @house.semester_start_date %>\ - <%= @house.semester_end_date %>\ - <%= escape_javascript best_in_place @house, :permanent_chores_start_week, :type => :select, :collection => (1..15).collect {|i|[i,i]} %>\ - <%= escape_javascript best_in_place @house, :hours_per_week %>\ - <%= escape_javascript best_in_place @house, :sign_off_by_hours_after %>\ - <%= escape_javascript best_in_place @house, :using_online_sign_off, :type => :select, :collection => [[1, "Yes"], [0, "No"]] %>\ - <%= escape_javascript best_in_place @house, :sign_off_verification_mode, :type => :select, :collection => [[0, "None"], [1, "Without password"], [2, "With password"]] %>\ - <%= escape_javascript best_in_place @house, :blow_off_penalty_factor %>\ - <%= escape_javascript best_in_place @house, :wsm_email %>\ - <%= link_to "x", @house, :confirm => "Are you sure you want to delete this house?", :method => :delete, :remote => true, :class => "delete_button" %>\ - ') + $('#new_item_line').before('<%= escape_javascript(render(@house)) %>') $('#new_house')[0].reset() setup() flash_green('<%= escape_javascript flash[:notice] %>') diff --git a/app/views/houses/index.html.erb b/app/views/houses/index.html.erb index 5f8d117..89a3d59 100644 --- a/app/views/houses/index.html.erb +++ b/app/views/houses/index.html.erb @@ -16,57 +16,9 @@ - <% @houses.each do |house| %> - - <%= best_in_place house, :name %> - <%= house.semester_start_date %> - <%= house.semester_end_date %> - <%= best_in_place house, :permanent_chores_start_week, :type => :select, :collection => (1..15).collect {|i|[i,i]} %> - <%= best_in_place house, :hours_per_week %> - <%= best_in_place house, :sign_off_by_hours_after %> - <%= best_in_place house, :using_online_sign_off, :type => :select, :collection => [[1, "Yes"], [0, "No"]] %> - <%= best_in_place house, :sign_off_verification_mode, :type => :select, :collection => [[0, "None"], [1, "Without password"], [2, "With password"]] %> - <%= best_in_place house, :blow_off_penalty_factor %> - <%= best_in_place house, :wsm_email %> - <%= link_to 'x', house, :confirm => 'Are you sure you want to delete this house?', :method => :delete, :remote => true, :class => 'delete_button' %> - - <% end %> + <%= render @houses %> - - - <%= f.text_field :name %> - - - <%= f.text_field :semester_start_date %> - - - <%= f.text_field :semester_end_date %> - - - <%= f.select(:permanent_chores_start_week, options_for_select((1..15).collect {|i|[i,i]})) %> - - - <%= f.text_field :hours_per_week %> - - - <%= f.text_field :sign_off_by_hours_after %> - - - <%= f.select(:using_online_sign_off, options_for_select([['Yes', 1], ['No', 0]], 0)) %> - - - <%= f.select(:sign_off_verification_mode, options_for_select([['None', 0], ['Without password', 1], ['With password', 2]], 2)) %> - - - <%= f.text_field :blow_off_penalty_factor %> - - - <%= f.text_field :wsm_email %> - - - <%= f.submit "Create" %> - - + <%= render :partial => 'new_house', :locals => {:f => f} %> <% end %> \ No newline at end of file