Netzke::FieldsConfigurator

FieldsConfigurator

Provides dynamic configuring columns/fields for GridPanel and FormPanel. Configuration parameters:

Public Class Methods

js_properties() click to toggle source
    # File lib/netzke/fields_configurator.rb, line 39
39:     def self.js_properties
40:       {
41:         :init_component =>           function(){            #{js_full_class_name}.superclass.initComponent.call(this);            // Automatically set the correct editor for the default_value column            this.on('beforeedit', function(e){              var column = this.getColumnModel().getColumnById(this.getColumnModel().getColumnId(e.column));              var record = this.getStore().getAt(e.row);              if (column.dataIndex === "default_value") {                if (record.get("name") === this.pri) {                  // Don't allow setting default value for the primary key                  column.setEditor(null);                } else {                  // Auto set the editor, dependent on the field type                  var attrType = record.get("attr_type");                  column.setEditor(Ext.create({xtype: this.attrTypeEditorMap[attrType] || "textfield"}));                }              }            }, this);          }.l,
42: 
43:         :attr_type_editor_map => {
44:           :integer  => "numberfield",
45:           :boolean  => "checkbox",
46:           :decimal  => "numberfield",
47:           :datetime => "xdatetime",
48:           :date     => "datefield",
49:           :string   => "textfield"
50:         },
51: 
52:         # Disable the 'gear' tool for now
53:         :on_gear =>           function(){            this.feedback("You can't configure configurator (yet)");          }.l,
54: 
55:         # we need to provide this function so that the server-side commit would happen
56:         :get_commit_data =>           function(){            return null; // because our commit data is already at the server          }.l,
57: 
58:         :on_defaults =>           function(){            Ext.Msg.confirm('Confirm', 'Are you sure?', function(btn){              if (btn == 'yes') {                this.loadDefaults();              }            }, this);          }.l,
59:       }
60:     end

Public Instance Methods

config_tool_needed?() click to toggle source

Never show the config tool

     # File lib/netzke/fields_configurator.rb, line 113
113:     def config_tool_needed?
114:       false
115:     end
default_bbar() click to toggle source
    # File lib/netzke/fields_configurator.rb, line 25
25:     def default_bbar
26:       %{ add edit apply del }.map(&:action) + "-" + [:defaults.action]
27:     end
default_columns() click to toggle source

Default columns for the configurator

    # File lib/netzke/fields_configurator.rb, line 30
30:     def default_columns
31:       [
32:         {:name => "id", :attr_type => :integer, :meta => true},
33:         {:name => "position", :attr_type => :integer, :meta => true},
34:         {:name => "attr_type", :attr_type => :string, :meta => true},
35:         *config[:owner].class.meta_columns.map { |c| c[:name] == "name" ? inject_combo_for_name_column(c) : c }
36:       ]
37:     end
default_config() click to toggle source
    # File lib/netzke/fields_configurator.rb, line 9
 9:     def default_config
10:       super.deep_merge({
11:         :name              => 'columns',
12:         :ext_config        => {
13:           :config_tool => false,
14:           :header => false,
15:           :enable_extended_search => false,
16:           :enable_edit_in_form => false,
17:           :enable_rows_reordering => GridPanel.rows_reordering_available,
18:           :enable_pagination => false
19:         }
20:       })
21:     end
load_defaults(params) click to toggle source
     # File lib/netzke/fields_configurator.rb, line 101
101:     def load_defaults(params)
102:       # Reload the temp table with default values
103:       data_class.replace_data(default_owner_fields)
104: 
105:       # ... and reflect it in the persistent storage
106:       on_data_changed
107: 
108:       # Update the grid
109:       {:load_store_data => get_data}
110:     end

Private Instance Methods

default_owner_fields() click to toggle source
     # File lib/netzke/fields_configurator.rb, line 154
154:       def default_owner_fields
155:         config[:owner].initial_columns(false).map(&:deebeefy_values)
156:       end
initial_data() click to toggle source

An override

     # File lib/netzke/fields_configurator.rb, line 144
144:       def initial_data
145:         NetzkeFieldList.read_list(config[:owner].global_id) || default_owner_fields
146:       end
inject_combo_for_name_column(c) click to toggle source

Set strict combo for the “name” column, with options of the attributes provided by the data_class

     # File lib/netzke/fields_configurator.rb, line 149
149:       def inject_combo_for_name_column(c)
150:         netzke_attrs = config[:owner].data_class.netzke_attributes.map{ |a| a[:name] }
151:         c.merge(:editor => {:xtype => :combo, :store => netzke_attrs, :force_selection => true})
152:       end
on_data_changed() click to toggle source

This is an override of GridPanel#on_data_changed

     # File lib/netzke/fields_configurator.rb, line 159
159:       def on_data_changed
160:         # Default column settings taken from
161:         defaults_hash = config[:owner].class.meta_columns.inject({}){ |r, c| r.merge!(c[:name] => c[:default_value]) }
162:         stripped_columns = data_class.all_columns.map do |c|
163:           # reject all keys that are 1) same as defaults
164:           c.reject{ |k,v| defaults_hash[k.to_sym].to_s == v.to_s }
165:         end
166:         store_data(stripped_columns)
167:       end
process_data(data, operation) click to toggle source

An override

     # File lib/netzke/fields_configurator.rb, line 120
120:       def process_data(data, operation)
121:         if operation == :update
122:           meta_attrs_to_update = data.inject({}) do |r,el|
123:             r.merge({
124:               data_class.find(el["id"]).name => el.reject{ |k,v| k == "id" }
125:             })
126:           end
127: 
128:           res = super
129: 
130:           NetzkeFieldList.update_fields(config[:owner].global_id, meta_attrs_to_update)
131: 
132:           res
133:         else
134:           super
135:         end
136:       end
store_data(data) click to toggle source

An override

     # File lib/netzke/fields_configurator.rb, line 139
139:       def store_data(data)
140:         NetzkeFieldList.update_list_for_current_authority(config[:owner].global_id, data, config[:owner].data_class.name)
141:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.