diff --git a/app/controllers/admin/poll/shifts_controller.rb b/app/controllers/admin/poll/shifts_controller.rb index 89bb68999..1261f2951 100644 --- a/app/controllers/admin/poll/shifts_controller.rb +++ b/app/controllers/admin/poll/shifts_controller.rb @@ -6,6 +6,8 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController def new load_shifts @shift = ::Poll::Shift.new + @voting_polls = @booth.polls.current_or_incoming + @recount_polls = @booth.polls.current_or_recounting_or_incoming end def create diff --git a/app/helpers/shifts_helper.rb b/app/helpers/shifts_helper.rb index 3a55feb4f..7ea17baf2 100644 --- a/app/helpers/shifts_helper.rb +++ b/app/helpers/shifts_helper.rb @@ -1,10 +1,12 @@ module ShiftsHelper def shift_vote_collection_dates(booth, polls) + return [] if polls.blank? date_options((start_date(polls)..end_date(polls)), Poll::Shift.tasks[:vote_collection], booth) end def shift_recount_scrutiny_dates(booth, polls) + return [] if polls.blank? dates = polls.map(&:ends_at).map(&:to_date).sort.inject([]) do |total, date| initial_date = date < Date.current ? Date.current : date total << (initial_date..date + Poll::RECOUNT_DURATION).to_a diff --git a/app/views/admin/poll/shifts/_form.html.erb b/app/views/admin/poll/shifts/_form.html.erb index 07e07381f..230864218 100644 --- a/app/views/admin/poll/shifts/_form.html.erb +++ b/app/views/admin/poll/shifts/_form.html.erb @@ -3,7 +3,7 @@
- <%= t("admin.poll_shifts.new.new_shift") %> + <%= t("admin.poll_shifts.new.new_shift") %>
@@ -24,12 +24,12 @@
<%= select 'shift[date]', 'vote_collection_date', - options_for_select(shift_vote_collection_dates(@booth, @booth.polls.current_or_incoming)), - { prompt: t("admin.poll_shifts.new.select_date"), + options_for_select(shift_vote_collection_dates(@booth, @vote_collection_polls)), + { prompt: @voting_polls.present? ? t("admin.poll_shifts.new.select_date") : t("admin.poll_shifts.new.no_voting_days"), label: false }, class: 'js-shift-vote-collection-dates' %> <%= select 'shift[date]', 'recount_scrutiny_date', - options_for_select(shift_recount_scrutiny_dates(@booth, @booth.polls.current_or_recounting_or_incoming)), + options_for_select(shift_recount_scrutiny_dates(@booth, @recount_polls)), { prompt: t("admin.poll_shifts.new.select_date"), label: false }, class: 'js-shift-recount-scrutiny-dates', diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 2e5e38dc2..50e0b84ff 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -515,6 +515,7 @@ en: search_officer_placeholder: Search officer search_officer_text: Search for an officer to assign a new shift select_date: "Select day" + no_voting_days: "Los dias de votación terminaron" select_task: "Select task" table_shift: "Shift" table_email: "Email" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 06ffa6c52..76747ecf2 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -515,6 +515,7 @@ es: search_officer_placeholder: Buscar presidentes de mesa search_officer_text: Busca al presidente de mesa para asignar un turno select_date: "Seleccionar día" + no_voting_days: "Voting days ended" select_task: "Seleccionar tarea" table_shift: "Turno" table_email: "Email"