Here is the requirement:
In a border layout UI, a user(staff) grid is at the west, while the accordion at the center will show the selected user's several collections(say, awards, etc) in each panel when one staff is selected.
The code:
class StaffsAndAwards < Netzke::Base
# Remember regions collapse state and size
include Netzke::Basepack::ItemPersistence
def configure(c)
super
c.items = [
{ netzke_component: :staffs, region: :west, width: 300, split: true },
{ netzke_component: :accordion, region: :center }
]
end
js_configure do |c|
c.layout = :border
c.border = false
# Overriding initComponent
c.init_component = <<-JS
function(){
// calling superclass's initComponent
this.callParent();
// setting the 'rowclick' event
var view = this.getComponent('staffs').getView();
view.on('itemclick', function(view, record){
this.selectStaff({staff_id: record.get('id')});
this.getComponent('awards').getStore().load();
}, this);
}
JS
end
endpoint :select_staff do |params, this|
component_session[:selected_staff_id] = params[:staff_id]
end
component :staffs do |c|
c.klass = Netzke::Basepack::Grid
c.model = "Staff"
c.region = :west
end
component :awards do |c|
c.kclass = Netzke::Basepack::Grid
c.model = 'Award'
c.data_store = {auto_load: false}
c.scope = {:staff_id => component_session[:selected_staff_id]}
c.strong_default_attrs = {:staff_id => component_session[:selected_staff_id]}
end
component :accordion do |c|
c.klass = Netzke::Basepack::Accordion
c.region = :center
c.prevent_header = true
c.items = [ { :title => "A Panel" }, :awards ] # The error may occur here. :awards cannot be found.
end
end
The error is "NameError (uninitialized constant Awards)". Seems :awards component can not be found, even though it's already defined in the above.
Can one component be embedded in another one? Or how to solve it? Thanks.