Browse Source

Created a custom class for the adding an item in the user log grid

eperez-timeinput
Edwin Perez 11 years ago
parent
commit
62310e7a25
  1. 1
      app/components/bikes/javascripts/init_component.js
  2. 28
      app/components/user_logs.rb
  3. 46
      app/components/user_logs/javascripts/init_component.js
  4. 29
      app/components/user_logs_add_item.rb
  5. 21
      app/components/user_logs_add_item/javascripts/init_component.js

1
app/components/bikes/javascripts/init_component.js

@ -3,6 +3,7 @@
// calling superclass's initComponent // calling superclass's initComponent
this.callParent(); this.callParent();
// something...
//due to Netzke bug, :min_chars attribute doesn't work //due to Netzke bug, :min_chars attribute doesn't work
var min_char_columns = [ var min_char_columns = [
"bike_brand__brand", "bike_brand__brand",

28
app/components/user_logs.rb

@ -1,5 +1,4 @@
class UserLogs < Netzke::Basepack::Grid class UserLogs < Netzke::Basepack::Grid
def configure(c) def configure(c)
super super
@ -52,23 +51,10 @@ class UserLogs < Netzke::Basepack::Grid
] ]
end end
def default_fields_for_forms # Overriding the defautl add in form
#figure out a better way to do this def preconfigure_record_window(c)
bike_store = Bike.all.map { |b| [b.id, b.shop_id] } super
current_user ||= User.find_by_id(session[:selected_user_id]) || controller.current_user c.form_config.klass = UserLogsAddItem
bike_id = current_user.bike.nil? ? nil : current_user.bike.id
[
{ :no_binding => true, :xtype => 'displayfield', :fieldLabel => "Log for:", :value => "#{current_user.to_s}"},
{ :name => :start_date},
{ :name => :end_date},
{ :name => :description},
#had to hack acts_as_loggable/log.rb to get this to work
{ :name => :user_action__action, :field_label => 'Action'},
{ :name => :for_bike, :checkboxName => :copy_log, :inputValue => true, :title => "Copy description to a Bike's History?", :xtype => 'fieldset', :checkboxToggle => true, :collapsed => true, :items => [
{:xtype => 'combo', :no_binding => true, :name => :copy_id, :title => 'Bike', :fieldLabel => 'Bike', :store => bike_store, :value => bike_id}
]
}
]
end end
#override with nil to remove actions #override with nil to remove actions
@ -76,4 +62,8 @@ class UserLogs < Netzke::Basepack::Grid
[ :apply, :add_in_form, :search ] [ :apply, :add_in_form, :search ]
end end
end js_configure do |c|
c.mixin :init_component
end
end

46
app/components/user_logs/javascripts/init_component.js

@ -2,12 +2,48 @@
initComponent: function(){ initComponent: function(){
// calling superclass's initComponent // calling superclass's initComponent
this.callParent(); this.callParent();
// TESTTING
//due to Netzke bug, :min_chars attribute doesn't work //due to Netzke bug, :min_chars attribute doesn't work
var min_char_columns = [ var min_char_columns = [
"user_action__purpose"] "user_action__purpose"
Ext.each(min_char_columns, function(column, index) { ];
Ext.ComponentManager.get(column).editor.minChars = 1;
}); // Ext.each(min_char_columns, function(column, index) {
// Ext.ComponentManager.get(column).editor.minChars = 1;
// });
var view = this.getView();
view.on('itemclick', function(view, record){
console.log('clicking ');
// The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server!
// console.log('Old record', record);
}, this);
view.on('itemupdate', function(record, index, node){
console.log('Updating item');
// if('end_date' in record.data.modified){
// console.log('start', record.data.start_date);
// console.log('end', record.data.end_date);
// }else if('start_date' in record.data.modified){
// }
}, this);
// var hoursInput = Ext.getCmp('user_logs_add_form_hours-inputEl');
// console.log(hoursInput);
// hoursInput.on('change', function(field, newValue, oldValue){
// console.log('Hours changing...', newValue);
// });
},
addNewItem: function(e){
e.fireEvent('click', {});
console.log(e);
console.log('Adding new item');
} }
} }

29
app/components/user_logs_add_item.rb

@ -0,0 +1,29 @@
# The User Log Add Item Form
class UserLogsAddItem < Netzke::Basepack::Form
def configure(c)
super
c.model = 'ActsAsLoggable::Log'
#figure out a better way to do this
bike_store = Bike.all.map { |b| [b.id, b.shop_id] }
current_user ||= User.find_by_id(session[:selected_user_id]) || controller.current_user
bike_id = current_user.bike.nil? ? nil : current_user.bike.id
c.items = [
{ :no_binding => true, :xtype => 'displayfield', :fieldLabel => "Log for:", :value => "#{current_user.to_s}"},
{ :name => :start_date},
{ :id => :user_logs_add_form_hours, :no_binding => true, :name => :hours, :xtype => 'field', :fieldLabel => "Hours:" },
{ :id => :user_logs_add_form_end_date, :name => :end_date, :hidden => true },
{ :name => :description},
#had to hack acts_as_loggable/log.rb to get this to work
{ :name => :user_action__action, :field_label => 'Action'},
{ :name => :for_bike, :checkboxName => :copy_log, :inputValue => true, :title => "Copy description to a Bike's History?", :xtype => 'fieldset', :checkboxToggle => true, :collapsed => true, :items => [
{:xtype => 'combo', :no_binding => true, :name => :copy_id, :title => 'Bike', :fieldLabel => 'Bike', :store => bike_store, :value => bike_id}
]
}
]
end
js_configure do |c|
c.mixin :init_component
end
end

21
app/components/user_logs_add_item/javascripts/init_component.js

@ -0,0 +1,21 @@
{
initComponent: function(){
// calling superclass's initComponent
this.callParent();
var panel = this;
var theForm = this.getForm();
console.log(theForm);
var hoursInput = Ext.getCmp('user_logs_add_form_hours');
console.log(hoursInput);
hoursInput.on('change', function(e){
console.log('I am changing');
});
}
}
Loading…
Cancel
Save