Class: Netzke::FieldsConfigurator
- Defined in:
- lib/netzke/fields_configurator.rb
Overview
FieldsConfigurator
Provides dynamic configuring columns/fields for GridPanel and FormPanel. Configuration parameters:
-
:widget
- widget to configure columns/fields for
Constant Summary
Constants inherited from GridPanel
Class Method Summary collapse
Instance Method Summary collapse
- #actions ⇒ Object
-
#before_load ⇒ Object
each time that we are loaded into the app, rebuild the table.
- #commit(params) ⇒ Object
- #default_config ⇒ Object
- #independent_config ⇒ Object
-
#initialize(*args) ⇒ FieldsConfigurator
constructor
A new instance of FieldsConfigurator.
- #load_defaults(params) ⇒ Object
- #predefined_columns ⇒ Object
Methods inherited from GridPanel
#column_at, #columns, config, config_columns, #configuration_widgets, #data_class, #default_columns, #default_context_menu, enforce_config_consistency, #get_columns, include_js, #initial_late_aggregatees, #normalized_columns, property_fields, #save_columns!
Methods included from Plugins::ConfigurationTool
#config_tool_needed?, #config_with_config_tool, included, #initial_aggregatees_with_config_tool, #js_config_with_config_tool, #tools_with_config_tool
Methods included from DataAccessor
#apply_helpers, #normalize_array_of_columns, #normalize_column, #normalize_columns
Methods included from GridPanelApi
#configuration_panel__columns__get_combobox_options, #delete_data, #get_combobox_options, #get_data, #get_search, #hide_column, #move_column, #post_data, #resize_column
Methods included from GridPanelJs
Constructor Details
#initialize(*args) ⇒ FieldsConfigurator
Returns a new instance of FieldsConfigurator.
9 10 11 12 |
# File 'lib/netzke/fields_configurator.rb', line 9 def initialize(*args) super NetzkeAutoColumn. = config[:widget] end |
Class Method Details
.js_extend_properties ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/netzke/fields_configurator.rb', line 44 def self.js_extend_properties { # Disable the 'gear' tool for now :gear => <<-END_OF_JAVASCRIPT.l, function(){ this.feedback("You can't configure configurator (yet)"); } END_OF_JAVASCRIPT # we need to provide this function so that the server-side commit would happen :get_commit_data => <<-END_OF_JAVASCRIPT.l, :defaults => <<-END_OF_JAVASCRIPT.l, function(){ Ext.Msg.confirm('Confirm', 'Are you sure?', function(btn){ if (btn == 'yes') { this.loadDefaults(); } }, this); } END_OF_JAVASCRIPT } end |
Instance Method Details
#actions ⇒ Object
28 29 30 31 32 |
# File 'lib/netzke/fields_configurator.rb', line 28 def actions super.merge( :defaults => {:text => 'Restore defaults'} ) end |
#before_load ⇒ Object
each time that we are loaded into the app, rebuild the table
90 91 92 |
# File 'lib/netzke/fields_configurator.rb', line 90 def before_load NetzkeAutoColumn.rebuild_table end |
#commit(params) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/netzke/fields_configurator.rb', line 78 def commit(params) defaults_hash = config[:widget].class.config_columns.inject({}){ |r, c| r.merge!(c[:name] => c[:default]) } config[:widget].persistent_config[:layout__columns] = NetzkeAutoColumn.all_columns.map do |c| # reject all keys that are 1) same as defaults, 2) 'position' c.reject!{ |k,v| defaults_hash[k.to_sym].to_s == v.to_s || k == 'position'} c = c["name"] if c.keys.count == 1 # denormalize the column c end {} end |
#default_config ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/netzke/fields_configurator.rb', line 14 def default_config super.deep_merge({ :name => 'columns', :data_class_name => "NetzkeAutoColumn", :ext_config => { :header => false, :enable_extended_search => false, :enable_edit_in_form => false, :enable_rows_reordering => GridPanel.config[:rows_reordering_available], :enable_pagination => false }, }) end |
#independent_config ⇒ Object
34 35 36 37 38 |
# File 'lib/netzke/fields_configurator.rb', line 34 def independent_config res = super res[:ext_config][:bbar] = %w{ edit apply - defaults } res end |
#load_defaults(params) ⇒ Object
72 73 74 75 76 |
# File 'lib/netzke/fields_configurator.rb', line 72 def load_defaults(params) config[:widget].persistent_config[:layout__columns] = config[:widget].default_columns NetzkeAutoColumn.rebuild_table {:load_store_data => get_data, :reconfigure => js_config} end |
#predefined_columns ⇒ Object
40 41 42 |
# File 'lib/netzke/fields_configurator.rb', line 40 def predefined_columns [{:name => :id}, *config[:widget].class.config_columns] end |