Cleaned up issue form hook

This commit is contained in:
2026-01-29 23:22:09 -05:00
parent 715c412668
commit e4d2df889d

View File

@@ -13,40 +13,23 @@ module Vehicles
class IssuesFormHookListener < Redmine::Hook::ViewListener class IssuesFormHookListener < Redmine::Hook::ViewListener
include IssuesHelper include IssuesHelper
# Edit Issue Form
# Here we build the required form components before passing them to a partial view formatting.
def view_issues_form_details_bottom(context={}) def view_issues_form_details_bottom(context={})
f = context[:form]
issue = context[:issue]
# Check to see if the issue already belongs to a customer # Load the customer's vehicles for selection in the issue form.
selected_vehicle = issue.vehicle.id unless issue.vehicle.nil?
# Load customer's vehicles
if issue.customer
if issue.customer.vehicles
vehicles = issue.customer.vehicles.pluck(:name, :id)
else
vehicles = [nil].compact
end
else
vehicles = [nil].compact
end
# Generate the drop down list of vehicles
vehicle = f.select :vehicle_id, vehicles, selected: selected_vehicle, include_blank: true
# Pass all prebuilt form components to our partial
context[:controller].send(:render_to_string, { context[:controller].send(:render_to_string, {
partial: 'issues/form_hook_vehicles', partial: 'issues/form_hook_vehicles',
locals: { locals: {
vehicle: vehicle vehicle: context[:form].select( :vehicle_id,
} context[:issue].customer ? context[:issue].customer.vehicles.pluck(:name, :id) : [],
}) selected: context[:issue].vehicle,
include_blank: true )
}
})
end end
end end
end end
end end