mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Merge pull request #6 from rickbarrette/filter_vehicles_by_customer
Filter vehicles by customer
This commit is contained in:
@@ -34,10 +34,8 @@ class CustomersController < ApplicationController
|
|||||||
|
|
||||||
autocomplete :customer, :name, :full => false, :extra_data => [:id]
|
autocomplete :customer, :name, :full => false, :extra_data => [:id]
|
||||||
|
|
||||||
def autocomplete_customer_vehicles
|
def filter_vehicles_by_customer
|
||||||
customer = Customer.find_by_id(params[:term])
|
@filtered_vehicles = Vehicle.all.where(customer_id: params[:selected_customer])
|
||||||
items = customer.vehicles if customer
|
|
||||||
render :json => items.to_json if items
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# display a list of all customers
|
# display a list of all customers
|
||||||
|
|||||||
1
app/views/customers/filter_vehicles_by_customer.js.erb
Normal file
1
app/views/customers/filter_vehicles_by_customer.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$('select#issue_vehicles_id').html('<%= j options_from_collection_for_select(@filtered_vehicles, :id, :to_s) %>');
|
||||||
9
assets/javascripts/application.js
Normal file
9
assets/javascripts/application.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
$(function() {
|
||||||
|
$("input#issue_customer_id").on("change", function() {
|
||||||
|
$.ajax({
|
||||||
|
url: "/filter_vehicles_by_customer",
|
||||||
|
type: "GET",
|
||||||
|
data: { selected_customer: $("input#issue_customer_id").val() }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -35,7 +35,7 @@ resources :payments
|
|||||||
post 'qbo/webhook', :to => 'qbo#qbo_webhook'
|
post 'qbo/webhook', :to => 'qbo#qbo_webhook'
|
||||||
|
|
||||||
#ajax
|
#ajax
|
||||||
get "update_vehicles" => 'vehicles#update_vehicles', as: 'update_vehicles'
|
get 'filter_vehicles_by_customer' => 'customers#filter_vehicles_by_customer'
|
||||||
|
|
||||||
# Nest Vehicles under customers
|
# Nest Vehicles under customers
|
||||||
resources :customers do
|
resources :customers do
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
|||||||
|
|
||||||
# Load the javascript
|
# Load the javascript
|
||||||
def view_layouts_base_html_head(context = {})
|
def view_layouts_base_html_head(context = {})
|
||||||
#js = javascript_include_tag 'application', :plugin => 'redmine_qbo'
|
js = javascript_include_tag 'application', :plugin => 'redmine_qbo'
|
||||||
#js += javascript_include_tag 'jquery/jquery-3.1.1.min', :plugin => 'redmine_qbo'
|
js += javascript_include_tag 'autocomplete-rails', :plugin => 'redmine_qbo'
|
||||||
#js += javascript_include_tag 'jquery-ui-1.12.1/jquery-ui', :plugin => 'redmine_qbo'
|
|
||||||
js = javascript_include_tag 'autocomplete-rails', :plugin => 'redmine_qbo'
|
|
||||||
return js
|
return js
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -38,9 +36,9 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
|||||||
select_estimate = f.select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => selected_estimate, include_blank: true
|
select_estimate = f.select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => selected_estimate, include_blank: true
|
||||||
|
|
||||||
if context[:issue].customer
|
if context[:issue].customer
|
||||||
vehicles = customer.vehicles.pluck(:name, :id).sort!
|
vehicles = customer.vehicles.pluck(:name, :id).sort!
|
||||||
else
|
else
|
||||||
vehicles = Vehicle.all.order(:name).pluck(:name, :id)
|
vehicles = [nil].compact
|
||||||
end
|
end
|
||||||
|
|
||||||
vehicle = f.select :vehicles_id, vehicles, :selected => selected_vehicle, include_blank: true
|
vehicle = f.select :vehicles_id, vehicles, :selected => selected_vehicle, include_blank: true
|
||||||
|
|||||||
Reference in New Issue
Block a user