mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-02-13 01:33:58 -05:00
Cleaned up issue form hook
This commit is contained in:
@@ -15,36 +15,19 @@ module Vehicles
|
|||||||
|
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user