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
-
#fields ⇒ Object
Hash of fully configured fields, that are referenced in the items.
-
#fields_array_from_model ⇒ Object
The array of fields as specified on the model level (using
netzke_attribute
and alike). -
#fields_from_config ⇒ Object
Hash of normalized field configs extracted from :items, e.g.:.
-
#fields_from_model ⇒ Object
Hash of fields as specified on the model level.
-
#items ⇒ Object
Items with normalized fields (i.e. containing all the necessary attributes needed by Ext.form.FormPanel to render a field).
Instance Method Details
#fields ⇒ Object
Hash of fully configured fields, that are referenced in the items. E.g.:
{
:role__name => {:xtype => 'netzkeremotecombo', :disabled => true, :value => "admin"},
:created_at => {:xtype => 'datetime', :disabled => true, :value => "2010-10-10 10:10"}
}
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/netzke/basepack/form_panel/fields.rb', line 27 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 |
#fields_array_from_model ⇒ Object
The array of fields as specified on the model level (using netzke_attribute
and alike)
43 44 45 |
# File 'lib/netzke/basepack/form_panel/fields.rb', line 43 def fields_array_from_model data_class && data_class.netzke_attributes end |
#fields_from_config ⇒ Object
Hash of normalized field configs extracted from :items, e.g.:
{:role__name => {:xtype => "netzkeremotecombo"}, :password => {:xtype => "passwordfield"}}
55 56 57 58 |
# File 'lib/netzke/basepack/form_panel/fields.rb', line 55 def fields_from_config items if @fields_from_config.nil? # by calling +items+ we initiate building of @fields_from_config @fields_from_config ||= {} end |
#fields_from_model ⇒ Object
Hash of fields as specified on the model level
48 49 50 |
# File 'lib/netzke/basepack/form_panel/fields.rb', line 48 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 |
#items ⇒ Object
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 |
# 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.to_s} 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 |