Module: Netzke::Basepack::FormPanel::Fields
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/netzke/basepack/form_panel/fields.rb
Overview
Because FormPanel allows for arbitrary layout of fields, we need to have all fields configured in one place (the fields method), and then have references to those fields from items.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary (collapse)
-
- (Object) fields
Hash of fully configured fields, that are referenced in the items.
-
- (Object) fields_array_from_model
The array of fields as specified on the model level (using netzke_attribute and alike).
-
- (Object) fields_from_config
Hash of normalized field configs extracted from :items, e.g.:.
-
- (Object) fields_from_model
Hash of fields as specified on the model level.
-
- (Object) items
Items with normalized fields (i.e. containing all the necessary attributes needed by Ext.form.FormPanel to render a field).
Instance Method Details
- (Object) fields
Hash of fully configured fields, that are referenced in the items. E.g.:
{
:role__name => {:xtype => 'combobox', :disabled => true, :value => "admin"},
:created_at => {:xtype => 'datetime', :disabled => true, :value => "2010-10-10 10:10"}
}
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/netzke/basepack/form_panel/fields.rb', line 28 def fields @fields ||= begin if static_layout? # extract incomplete field configs from +config+ flds = fields_from_config # and merged them with fields from the model deep_merge_existing_fields(flds, fields_from_model) if data_class else # extract flds configs from the model flds = fields_from_model end flds end end |
- (Object) fields_array_from_model
The array of fields as specified on the model level (using netzke_attribute and alike)
44 45 46 |
# File 'lib/netzke/basepack/form_panel/fields.rb', line 44 def fields_array_from_model data_class && data_class.netzke_attributes end |
- (Object) fields_from_config
Hash of normalized field configs extracted from :items, e.g.:
{:role__name => {:xtype => "combobox"}, :password => {:xtype => "passwordfield"}}
56 57 58 59 |
# File 'lib/netzke/basepack/form_panel/fields.rb', line 56 def fields_from_config items if @fields_from_config.nil? # by calling +items+ we initiate building of @fields_from_config @fields_from_config ||= {} end |
- (Object) fields_from_model
Hash of fields as specified on the model level
49 50 51 |
# File 'lib/netzke/basepack/form_panel/fields.rb', line 49 def fields_from_model @fields_from_model ||= fields_array_from_model && fields_array_from_model.inject({}){ |hsh, f| hsh.merge(f[:name].to_sym => f) } end |
- (Object) items
Items with normalized fields (i.e. containing all the necessary attributes needed by Ext.form.FormPanel to render a field)
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/netzke/basepack/form_panel/fields.rb', line 9 def items @form_panel_items ||= begin res = normalize_fields(super || data_class && data_class.netzke_attributes || []) # netzke_attributes as default items # if primary key isn't there, insert it as first if data_class && !res.detect{ |f| f[:name] == data_class.primary_key} primary_key_item = normalize_field(data_class.primary_key.to_sym) @fields_from_config[data_class.primary_key.to_sym] = primary_key_item res.insert(0, primary_key_item) end res end end |