diff --git a/app/controllers/admin/poll/shifts_controller.rb b/app/controllers/admin/poll/shifts_controller.rb index c996724c9..42093439d 100644 --- a/app/controllers/admin/poll/shifts_controller.rb +++ b/app/controllers/admin/poll/shifts_controller.rb @@ -54,7 +54,7 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController end def shift_params - params.require(:shift).permit(:booth_id, :officer_id, :date, :task) + shift_params = params.require(:shift).permit(:booth_id, :officer_id, :task, date:[:vote_collection_date, :recount_scrutiny_date]) + shift_params.merge(date: shift_params[:date]["#{shift_params[:task]}_date".to_sym]) end - end diff --git a/app/helpers/shifts_helper.rb b/app/helpers/shifts_helper.rb index 37f22a3e2..af291779a 100644 --- a/app/helpers/shifts_helper.rb +++ b/app/helpers/shifts_helper.rb @@ -1,11 +1,15 @@ module ShiftsHelper - def shift_dates_select_options(polls) - options = [] - (start_date(polls)..end_date(polls)).each do |date| - options << [l(date, format: :long), l(date)] - end - options_for_select(options, params[:date]) + def shift_vote_collection_dates(polls) + date_options((start_date(polls)..end_date(polls))) + end + + def shift_recount_scrutiny_dates(polls) + date_options(polls.map(&:ends_at).map(&:to_date).inject([]) { |total, date| total << (date..date + 1.week).to_a }.flatten.uniq) + end + + def date_options(dates) + dates.map { |date| [l(date, format: :long), l(date)] } end def start_date(polls) diff --git a/app/views/admin/poll/shifts/_form.html.erb b/app/views/admin/poll/shifts/_form.html.erb index 221294940..9192e1d0a 100644 --- a/app/views/admin/poll/shifts/_form.html.erb +++ b/app/views/admin/poll/shifts/_form.html.erb @@ -22,10 +22,14 @@
- <%= f.select :date, - shift_dates_select_options(@polls), - prompt: t("admin.poll_shifts.new.select_date"), - label: false %> + <%= select 'shift[date]', 'vote_collection_date', + options_for_select(shift_vote_collection_dates(@polls)), + prompt: t("admin.poll_shifts.new.select_date"), + label: false %> + <%= select 'shift[date]', 'recount_scrutiny_date', + options_for_select(shift_recount_scrutiny_dates(@polls)), + prompt: t("admin.poll_shifts.new.select_date"), + label: false %>
<%= f.hidden_field :booth_id, value: @booth.id %>