mirror of
https://github.com/fspc/BikeShed-1.git
synced 2025-02-28 16:53:23 -05:00
Created a custom class for the adding an item in the user log grid
This commit is contained in:
parent
cfeb6fd1d2
commit
62310e7a25
@ -3,6 +3,7 @@
|
||||
// calling superclass's initComponent
|
||||
this.callParent();
|
||||
|
||||
// something...
|
||||
//due to Netzke bug, :min_chars attribute doesn't work
|
||||
var min_char_columns = [
|
||||
"bike_brand__brand",
|
||||
|
@ -1,5 +1,4 @@
|
||||
class UserLogs < Netzke::Basepack::Grid
|
||||
|
||||
def configure(c)
|
||||
super
|
||||
|
||||
@ -52,23 +51,10 @@ class UserLogs < Netzke::Basepack::Grid
|
||||
]
|
||||
end
|
||||
|
||||
def default_fields_for_forms
|
||||
#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
|
||||
[
|
||||
{ :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}
|
||||
]
|
||||
}
|
||||
]
|
||||
# Overriding the defautl add in form
|
||||
def preconfigure_record_window(c)
|
||||
super
|
||||
c.form_config.klass = UserLogsAddItem
|
||||
end
|
||||
|
||||
#override with nil to remove actions
|
||||
@ -76,4 +62,8 @@ class UserLogs < Netzke::Basepack::Grid
|
||||
[ :apply, :add_in_form, :search ]
|
||||
end
|
||||
|
||||
end
|
||||
js_configure do |c|
|
||||
c.mixin :init_component
|
||||
end
|
||||
|
||||
end
|
@ -2,12 +2,48 @@
|
||||
initComponent: function(){
|
||||
// calling superclass's initComponent
|
||||
this.callParent();
|
||||
|
||||
// TESTTING
|
||||
//due to Netzke bug, :min_chars attribute doesn't work
|
||||
var min_char_columns = [
|
||||
"user_action__purpose"]
|
||||
Ext.each(min_char_columns, function(column, index) {
|
||||
Ext.ComponentManager.get(column).editor.minChars = 1;
|
||||
});
|
||||
"user_action__purpose"
|
||||
];
|
||||
|
||||
// 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
Normal file
29
app/components/user_logs_add_item.rb
Normal file
@ -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
|
@ -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…
x
Reference in New Issue
Block a user