From da176e00ba6bea5bb1117f344c7c2c0d7380cc6d Mon Sep 17 00:00:00 2001 From: Ron Warholic Date: Sat, 19 Oct 2013 12:50:38 -0400 Subject: [PATCH 1/4] Added default values for most add-item forms --- app/components/bike_logs.rb | 2 +- app/components/bikes.rb | 13 +++++++------ app/components/transaction_logs.rb | 2 +- .../user_logs/javascripts/init_component.js | 2 ++ app/components/user_role_joins.rb | 4 ++-- app/components/users.rb | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/components/bike_logs.rb b/app/components/bike_logs.rb index e1aff13..a9bfd22 100644 --- a/app/components/bike_logs.rb +++ b/app/components/bike_logs.rb @@ -20,7 +20,7 @@ class BikeLogs < Netzke::Basepack::Grid { :name => :start_date, :format => "g:ia - D, M j - Y", :width => 165, :default_value => Time.now.to_formatted_s(:db) }, { :name => :end_date, :hidden => true, :default_value => Time.now.to_formatted_s(:db) }, :description, - { :name => :bike_action__action, :text => 'Action'}, + { :name => :bike_action__action, :text => 'Action', :default_value => ::ActsAsLoggable::BikeAction.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/bikes.rb b/app/components/bikes.rb index 4467520..1e39a1f 100644 --- a/app/components/bikes.rb +++ b/app/components/bikes.rb @@ -6,9 +6,9 @@ class Bikes < Netzke::Basepack::Grid # 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'}, + { :name => :shop_id, :text => 'Shop ID', :default_value => Bike.last.id.to_i + 1}, :serial_number, - { :id => :bike_brand__brand, :name => :bike_brand__brand, :text => 'Brand'}, + { :id => :bike_brand__brand, :name => :bike_brand__brand, :text => 'Brand', :default_value => BikeBrand.first.id }, { :name => :model, :text => 'Model', :scope => lambda { |rel| if session[:selected_bike_brand_id] @@ -19,14 +19,15 @@ 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}, - { :id => :bike_style__style, :name => :bike_style__style, :text => 'Style' }, + { :name => "color", :text => "Frame Color", :type => :action, :editor => { :xtype => "xcolorcombo"}, :renderer => :color_block, + :default_value => '000000'}, + { :id => :bike_style__style, :name => :bike_style__style, :text => 'Style', :default_value => BikeStyle.first.id}, { :name => :seat_tube_height, :text => 'Seat Tube (in)'}, { :name => :top_tube_length, :text => 'Top Tube (in)'}, { :name => :wheel_size, :text => 'Wheel Size (in)'}, :value, - { :id => :bike_condition__condition, :name => :bike_condition__condition, :text => 'Condition'}, - { :id => :bike_purpose__purpose, :name => :bike_purpose__purpose, :text => 'Purpose'}, + { :id => :bike_condition__condition, :name => :bike_condition__condition, :text => 'Condition', :default_value => BikeCondition.first.id}, + { :id => :bike_purpose__purpose, :name => :bike_purpose__purpose, :text => 'Purpose', :default_value => BikePurpose.first.id}, { :name => :owner, :getter => lambda { |rec| user = rec.owner user.nil? ? "" : "#{user.first_name} #{user.last_name}" diff --git a/app/components/transaction_logs.rb b/app/components/transaction_logs.rb index b0e07d3..cf05ff1 100644 --- a/app/components/transaction_logs.rb +++ b/app/components/transaction_logs.rb @@ -20,7 +20,7 @@ class TransactionLogs < Netzke::Basepack::Grid c.columns = [ { :name => :start_date, :format => "g:ia - D, M j - Y", :width => 165, :default_value => Time.now.to_formatted_s(:db), :text => 'Date' }, { :name => :description, :text => "Amount"} , - { :name => :transaction_action__action, :text => 'Method'}, + { :name => :transaction_action__action, :text => 'Method', :default_value => ::ActsAsLoggable::TransactionAction.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 index d6b5d22..feb5715 100644 --- a/app/components/user_logs/javascripts/init_component.js +++ b/app/components/user_logs/javascripts/init_component.js @@ -9,5 +9,7 @@ Ext.each(min_char_columns, function(column, index) { Ext.ComponentManager.get(column).editor.minChars = 1; }); + + } } diff --git a/app/components/user_role_joins.rb b/app/components/user_role_joins.rb index 623aed3..fc22b3e 100644 --- a/app/components/user_role_joins.rb +++ b/app/components/user_role_joins.rb @@ -10,9 +10,9 @@ class UserRoleJoins < Netzke::Basepack::Grid { :name => :name, :getter => lambda{ |rec| user = User.find_by_id(rec.user_id) user.nil? ? "" : "#{user.first_name} #{user.last_name}" - } + }, }, - { :name => :role__role, :text => "Role"}, + { :name => :role__role, :text => "Role", :default_value => Role.exists? ? Role.first.id : nil}, :created_at, :updated_at, :ends ] diff --git a/app/components/users.rb b/app/components/users.rb index 0109b4d..30d73a5 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, - { :id => :bike__shop_id, :name => :bike__shop_id} + { :id => :bike__shop_id, :name => :bike__shop_id, :default_value => Bike.exists? ? Bike.first.id : nil } ] c.columns << :reset if can? :manage, User From 83bdaf5973ec80436a1ce1830d70e65a57d3a1a4 Mon Sep 17 00:00:00 2001 From: Ron Warholic Date: Sat, 19 Oct 2013 12:53:28 -0400 Subject: [PATCH 2/4] Removed errant whitespace --- app/components/user_logs/javascripts/init_component.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/components/user_logs/javascripts/init_component.js b/app/components/user_logs/javascripts/init_component.js index feb5715..d6b5d22 100644 --- a/app/components/user_logs/javascripts/init_component.js +++ b/app/components/user_logs/javascripts/init_component.js @@ -9,7 +9,5 @@ Ext.each(min_char_columns, function(column, index) { Ext.ComponentManager.get(column).editor.minChars = 1; }); - - } } From dc60630d2dc06fac4011df7b4ddda2c91608564e Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Sat, 19 Oct 2013 18:08:32 -0400 Subject: [PATCH 3/4] On second thought, don't want to default this one. --- app/components/bikes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/bikes.rb b/app/components/bikes.rb index 02ff40d..30dd873 100644 --- a/app/components/bikes.rb +++ b/app/components/bikes.rb @@ -8,7 +8,7 @@ class Bikes < Netzke::Basepack::Grid c.columns = [ { :name => :shop_id, :text => 'Shop ID', :default_value => Bike.last.id.to_i + 1}, :serial_number, - { :id => :bike_brand__brand, :name => :bike_brand__brand, :text => 'Brand', :default_value => BikeBrand.first.id }, + { :id => :bike_brand__brand, :name => :bike_brand__brand, :text => 'Brand'}, { :name => :model, :text => 'Model', :scope => lambda { |rel| if session[:selected_bike_brand_id] From 4eae374aa910d81d0e883fa051ed5ca04e838a27 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Sat, 19 Oct 2013 18:08:55 -0400 Subject: [PATCH 4/4] Fix column title while we're at it --- app/components/users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/users.rb b/app/components/users.rb index 30d73a5..51c7d38 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, - { :id => :bike__shop_id, :name => :bike__shop_id, :default_value => Bike.exists? ? Bike.first.id : nil } + { :text => "Bike - Shop ID", :id => :bike__shop_id, :name => :bike__shop_id, :default_value => Bike.exists? ? Bike.first.id : nil } ] c.columns << :reset if can? :manage, User