diff --git a/app/views/timesheet/_overhead_form.html.erb b/app/views/timesheet/_overhead_form.html.erb index 922bbd7..2f66201 100644 --- a/app/views/timesheet/_overhead_form.html.erb +++ b/app/views/timesheet/_overhead_form.html.erb @@ -4,7 +4,7 @@
<%= select_tag('timesheet[billable][]', - options_for_select(billable_values), + options_for_select(billable_values, selected_values), {:multiple => true, :size => list_size}) %>

diff --git a/lib/overhead_timesheet_hook.rb b/lib/overhead_timesheet_hook.rb index 3593f79..ecac969 100644 --- a/lib/overhead_timesheet_hook.rb +++ b/lib/overhead_timesheet_hook.rb @@ -24,12 +24,21 @@ class OverheadTimesheetHook < Redmine::Hook::ViewListener # Added a new field for filtering based on "billable?" def plugin_timesheet_views_timesheet_form(context={}) billable_values = select_values_for_field(TimeEntryActivity.billable_custom_field) + if context[:params] && + context[:params][:timesheet] && + context[:params][:timesheet][:billable] + selected_values = context[:params][:timesheet][:billable] + else + selected_values = [] + end + context[:controller].send(:render_to_string, :partial => 'timesheet/overhead_form', :layout => false, :locals => { :list_size => context[:list_size] || 5, - :billable_values => billable_values + :billable_values => billable_values, + :selected_values => selected_values }) end end diff --git a/spec/lib/overhead_timesheet_hook_spec.rb b/spec/lib/overhead_timesheet_hook_spec.rb index 44cc691..5456b38 100644 --- a/spec/lib/overhead_timesheet_hook_spec.rb +++ b/spec/lib/overhead_timesheet_hook_spec.rb @@ -77,5 +77,22 @@ describe OverheadTimesheetHook, "#plugin_timesheet_views_timesheet_form", :type end end - it 'should pre-select the values from the submission' + it 'should pre-select the values from the submission' do + @custom_field = mock_model(TimeEntryActivityCustomField, + :possible_values => ['A','B','Nil'], + :field_format => 'list') + TimeEntryActivity.stub!(:billable_custom_field).and_return(@custom_field) + + context = { + :params => {:timesheet => {:billable => ['A','Nil']}} + } + + response = call_hook(:plugin_timesheet_views_timesheet_form, context) + response.should have_tag('select') do + with_tag('option[value=?][selected=selected]','A','A') + with_tag('option[value=?]','B','B') + with_tag('option[value=?][selected=selected]','Nil','none') + end + + end end