Merge pull request #6 from rickbarrette/filter_vehicles_by_customer

Filter vehicles by customer
This commit is contained in:
2017-03-22 22:07:22 -04:00
committed by GitHub
5 changed files with 17 additions and 11 deletions

View File

@@ -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

View File

@@ -0,0 +1 @@
$('select#issue_vehicles_id').html('<%= j options_from_collection_for_select(@filtered_vehicles, :id, :to_s) %>');

View 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() }
});
});
});

View File

@@ -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

View File

@@ -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
@@ -40,7 +38,7 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
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