diff --git a/app/models/poll.rb b/app/models/poll.rb index 27125d8a1..f08f9bdcd 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -90,4 +90,8 @@ class Poll < ActiveRecord::Base end end + def shifts_in_booth(booth_id) + officer_assignments.where(booth_assignment_id: booth_assignments.where(booth_id: booth_id).pluck(:id)).pluck(:officer_id).uniq + end + end diff --git a/app/models/poll/booth_assignment.rb b/app/models/poll/booth_assignment.rb index 8489c3cf0..a1d0c0d39 100644 --- a/app/models/poll/booth_assignment.rb +++ b/app/models/poll/booth_assignment.rb @@ -8,5 +8,18 @@ class Poll has_many :voters has_many :partial_results has_many :recounts + + before_destroy :destroy_poll_shifts + + def has_shifts? + + end + + private + + def destroy_poll_shifts +# officers = poll.officers_in_booth(booth.id) +# Poll::Shift.where(officer_id: officers, booth_id: booth.id) + end end end diff --git a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb index 8fb944e9c..b1ab3885e 100644 --- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -14,7 +14,8 @@ method: :delete, remote: true, title: t("admin.booth_assignments.manage.actions.unassign"), - class: "button hollow alert #{@poll.expired? ? 'disabled' : ''}" %> + class: "button hollow alert #{@poll.expired? ? 'disabled' : ''}", + data: (booth_assignment.has_shifts? ? {confirm: "Are you sure?"} : nil) %> <% else %>