Shifts are destroyed when a booths is unassigned. An alert appears if there are shifts, but it doesn't if there aren't.
This commit is contained in:
@@ -90,8 +90,4 @@ class Poll < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
@@ -3,23 +3,26 @@ class Poll
|
|||||||
belongs_to :booth
|
belongs_to :booth
|
||||||
belongs_to :poll
|
belongs_to :poll
|
||||||
|
|
||||||
|
before_destroy :destroy_poll_shifts, only: :destroy
|
||||||
|
|
||||||
has_many :officer_assignments, class_name: "Poll::OfficerAssignment", dependent: :destroy
|
has_many :officer_assignments, class_name: "Poll::OfficerAssignment", dependent: :destroy
|
||||||
has_many :officers, through: :officer_assignments
|
has_many :officers, through: :officer_assignments
|
||||||
has_many :voters
|
has_many :voters
|
||||||
has_many :partial_results
|
has_many :partial_results
|
||||||
has_many :recounts
|
has_many :recounts
|
||||||
|
|
||||||
before_destroy :destroy_poll_shifts
|
def shifts?
|
||||||
|
shifts.empty? ? false : true
|
||||||
def has_shifts?
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def shifts
|
||||||
|
Poll::Shift.where(booth_id: booth_id, officer_id: officer_assignments.pluck(:officer_id), date: officer_assignments.pluck(:date))
|
||||||
|
end
|
||||||
|
|
||||||
def destroy_poll_shifts
|
def destroy_poll_shifts
|
||||||
# officers = poll.officers_in_booth(booth.id)
|
shifts.destroy_all
|
||||||
# Poll::Shift.where(officer_id: officers, booth_id: booth.id)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
remote: true,
|
remote: true,
|
||||||
title: t("admin.booth_assignments.manage.actions.unassign"),
|
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) %>
|
data: (booth_assignment.shifts? ? {confirm: "#{t("admin.poll_booth_assignments.alert.shifts")}"} : nil) %>
|
||||||
</td>
|
</td>
|
||||||
<% else %>
|
<% else %>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -544,6 +544,8 @@ en:
|
|||||||
assign: Assign booth
|
assign: Assign booth
|
||||||
unassign: Unassign booth
|
unassign: Unassign booth
|
||||||
poll_booth_assignments:
|
poll_booth_assignments:
|
||||||
|
alert:
|
||||||
|
shifts: "There are shifts associated to this booth. If you remove the booth assignment, the shifts will be also deleted. Continue?"
|
||||||
flash:
|
flash:
|
||||||
destroy: "Booth not assigned anymore"
|
destroy: "Booth not assigned anymore"
|
||||||
create: "Booth assigned"
|
create: "Booth assigned"
|
||||||
|
|||||||
@@ -544,6 +544,8 @@ es:
|
|||||||
assign: Assign booth
|
assign: Assign booth
|
||||||
unassign: Unassign booth
|
unassign: Unassign booth
|
||||||
poll_booth_assignments:
|
poll_booth_assignments:
|
||||||
|
alert:
|
||||||
|
shifts: "Hay turnos asignados para esta urna. Si la desasignas, esos turnos se eliminarán. ¿Deseas continuar?"
|
||||||
flash:
|
flash:
|
||||||
destroy: "Urna desasignada"
|
destroy: "Urna desasignada"
|
||||||
create: "Urna asignada"
|
create: "Urna asignada"
|
||||||
|
|||||||
Reference in New Issue
Block a user