From 4d008163e1d0020f4ef8f7b9a2657680549cc6d0 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Wed, 28 Aug 2013 23:01:29 -0400 Subject: [PATCH] Changing min_chars for autocomplete to 1 char --- app/components/bikes.rb | 13 ++++++++----- app/components/bikes/javascripts/init_component.js | 11 +++++++++++ app/components/user_logs.rb | 2 +- .../user_logs/javascripts/init_component.js | 13 +++++++++++++ app/components/users.rb | 2 +- app/components/users/javascripts/init_component.js | 7 +++++++ 6 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 app/components/user_logs/javascripts/init_component.js diff --git a/app/components/bikes.rb b/app/components/bikes.rb index 327ec8d..a7c42c3 100644 --- a/app/components/bikes.rb +++ b/app/components/bikes.rb @@ -2,11 +2,14 @@ class Bikes < Netzke::Basepack::Grid def configure(c) super c.model = "Bike" + + # columns with :id set, have :min_chars set in init_component + # See: http://stackoverflow.com/questions/17738962/netzke-grid-filtering c.columns = [ { :name => :shop_id, :text => 'Shop ID'}, :serial_number, - { :name => :bike_brand__brand, :text => 'Brand' }, - { :name => :bike_model__model, :text => 'Model', + { :id => :bike_brand__brand, :name => :bike_brand__brand, :text => 'Brand'}, + { :id => :bike_model__model, :name => :bike_model__model, :text => 'Model', :scope => lambda { |rel| if session[:selected_bike_brand_id] rel.where(:bike_brand_id => session[:selected_bike_brand_id]) @@ -17,13 +20,13 @@ class Bikes < Netzke::Basepack::Grid }, #needs to have type :action or else won't work in grid, because... netzke { :name => "color", :text => "Frame Color", :type => :action, :editor => { :xtype => "xcolorcombo"}, :renderer => :color_block}, - { :name => :bike_style__style, :text => 'Style' }, + { :id => :bike_style__style, :name => :bike_style__style, :text => 'Style' }, { :name => :seat_tube_height, :text => 'Seat Tube (in)'}, { :name => :top_tube_length, :text => 'Top Tube (in)'}, { :name => :wheel_size, :text => 'Wheel Size (in)'}, :value, - { :name => :bike_condition__condition, :text => 'Condition'}, - { :name => :bike_status__status, :text => 'Status'}, + { :id => :bike_condition__condition, :name => :bike_condition__condition, :text => 'Condition'}, + { :id => :bike_status__status, :name => :bike_status__status, :text => 'Status'}, { :name => :owner, :getter => lambda { |rec| user = rec.owner user.nil? ? "" : "#{user.first_name} #{user.last_name}" diff --git a/app/components/bikes/javascripts/init_component.js b/app/components/bikes/javascripts/init_component.js index e152db1..fc44002 100644 --- a/app/components/bikes/javascripts/init_component.js +++ b/app/components/bikes/javascripts/init_component.js @@ -3,6 +3,17 @@ // calling superclass's initComponent this.callParent(); + //due to Netzke bug, :min_chars attribute doesn't work + var min_char_columns = [ + "bike_brand__brand", + "bike_model__model", + "bike_style__style", + "bike_condition__condition", + "bike_status__status"] + Ext.each(min_char_columns, function(column, index) { + Ext.ComponentManager.get(column).editor.minChars = 1; + }); + // setting the 'rowclick' event var view = this.getView(); view.on('itemclick', function(view, record){ diff --git a/app/components/user_logs.rb b/app/components/user_logs.rb index 2152d19..78a882a 100644 --- a/app/components/user_logs.rb +++ b/app/components/user_logs.rb @@ -43,7 +43,7 @@ class UserLogs < Netzke::Basepack::Grid { :name => :end_date, :format => "g:ia - D, M j - Y", :default_value => Time.now.to_formatted_s(:db) }, { :name => :hours, :getter => lambda { |rec| (rec.end_date - rec.start_date)/3600 }, :sorting_scope => :sort_by_duration}, :description, - { :name => :user_action__action, :text => 'Action', :default_value => ::ActsAsLoggable::UserAction.all.first.id }, + { :id => :user_action__action, :name => :user_action__action, :text => 'Action', :default_value => ::ActsAsLoggable::UserAction.all.first.id }, { :name => :logged_by, :getter => lambda{ |rec| user = User.find_by_id(rec.logger_id) user.nil? ? "" : "#{user.first_name} #{user.last_name}" diff --git a/app/components/user_logs/javascripts/init_component.js b/app/components/user_logs/javascripts/init_component.js new file mode 100644 index 0000000..05bde6c --- /dev/null +++ b/app/components/user_logs/javascripts/init_component.js @@ -0,0 +1,13 @@ +{ + initComponent: function(){ + // calling superclass's initComponent + this.callParent(); + + //due to Netzke bug, :min_chars attribute doesn't work + var min_char_columns = [ + "user_action__status"] + Ext.each(min_char_columns, function(column, index) { + Ext.ComponentManager.get(column).editor.minChars = 1; + }); + } +} diff --git a/app/components/users.rb b/app/components/users.rb index fc96ca1..c56ad94 100644 --- a/app/components/users.rb +++ b/app/components/users.rb @@ -18,7 +18,7 @@ class Users < Netzke::Basepack::Grid :first_name, :last_name, :email, - :bike__shop_id + { :id => :bike__shop_id, :name => :bike__shop_id} ] c.columns << :reset if can? :manage, User diff --git a/app/components/users/javascripts/init_component.js b/app/components/users/javascripts/init_component.js index de240a6..f2c7e47 100644 --- a/app/components/users/javascripts/init_component.js +++ b/app/components/users/javascripts/init_component.js @@ -2,6 +2,13 @@ initComponent: function(){ // calling superclass's initComponent this.callParent(); + + //due to Netzke bug, :min_chars attribute doesn't work + var min_char_columns = ["bike__shop_id"] + Ext.each(min_char_columns, function(column, index) { + Ext.ComponentManager.get(column).editor.minChars = 1; + }); + this.getView().on('itemclick', function(view, record){ // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! this.selectCustomer({customer_id: record.get('id'), customer_type: 'User'});