Module: Netzke::Basepack::Fields

Extended by:
ActiveSupport::Concern
Included in:
Form::Base
Defined in:
lib/netzke/basepack/fields.rb

Overview

Because Form 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.

Instance Method Summary collapse

Instance Method Details

#fieldsObject

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"}
}


17
18
19
20
21
22
23
# File 'lib/netzke/basepack/fields.rb', line 17

def fields
  @_fields ||= fields_from_items.tap do |flds|
    # add primary key field if not present
    primary_key = model_adapter.primary_key
    flds[primary_key.to_sym] ||= {name: primary_key}
  end
end

#fields_from_itemsObject

Hash of normalized field configs extracted from :items, e.g.:

{
  role__name: {xtype: "netzkeremotecombo"},
  password: {xtype: "passwordfield"}
}


31
32
33
# File 'lib/netzke/basepack/fields.rb', line 31

def fields_from_items
  @fields_from_items || (normalize_config || true) && @fields_from_items
end

#itemsObject

Items with normalized fields (i.e. containing all the necessary attributes needed by Ext.form.Form to render a field)



8
9
10
# File 'lib/netzke/basepack/fields.rb', line 8

def items
  prepend_primary_key(config.items || attributes)
end