Class: Netzke::FormPanel
- Inherits:
-
Base
- Object
- Base
- Netzke::FormPanel
- Includes:
- DataAccessor, FormPanelApi, FormPanelJs, Plugins::ConfigurationTool
- Defined in:
- lib/netzke/form_panel.rb
Overview
FormPanel
Represents Ext.form.FormPanel
Configuration
-
:data_class_name
- name of the ActiveRecord model that provides data to this GridPanel. -
:record
- record to be displayd in the form. Takes precedence over:record_id
-
:record_id
- id of the record to be displayd in the form. Also see:record
In the :ext_config
hash (see Netzke::Base) the following FormPanel specific options are available:
-
:mode
- when set to:config
, FormPanel loads in configuration mode
Direct Known Subclasses
Constant Summary collapse
- XTYPE_MAP =
{ :integer => :numberfield, :boolean => :xcheckbox, :date => :datefield, :datetime => :xdatetime, :text => :textarea, :json => :jsonfield # :string => :textfield }
Instance Attribute Summary collapse
-
#record ⇒ Object
Returns the value of attribute record.
Class Method Summary collapse
-
.config ⇒ Object
Class-level configuration with defaults.
-
.config_columns ⇒ Object
columns to be displayed by the FieldConfigurator (which is GridPanel-based).
-
.include_js ⇒ Object
Extra javascripts.
- .property_fields ⇒ Object
Instance Method Summary collapse
- #actions ⇒ Object
- #columns ⇒ Object
- #configuration_widgets ⇒ Object
- #data_class ⇒ Object
- #default_columns ⇒ Object
- #get_columns ⇒ Object
-
#initialize(*args) ⇒ FormPanel
constructor
A new instance of FormPanel.
-
#js_config ⇒ Object
parameters used to instantiate the JS object.
-
#normalized_columns ⇒ Object
Normalized 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, #predefined_columns
Methods included from FormPanelApi
#array_of_values, #configuration_panel__fields__get_combobox_options, #create_or_update_record, #get_combobox_options, #load, #submit
Methods included from FormPanelJs
Constructor Details
#initialize(*args) ⇒ FormPanel
Returns a new instance of FormPanel.
45 46 47 48 49 |
# File 'lib/netzke/form_panel.rb', line 45 def initialize(*args) super apply_helpers @record = config[:record] || data_class && data_class.find_by_id(config[:record_id]) end |
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record.
43 44 45 |
# File 'lib/netzke/form_panel.rb', line 43 def record @record end |
Class Method Details
.config ⇒ Object
Class-level configuration with defaults
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/netzke/form_panel.rb', line 20 def self.config set_default_config({ :config_tool_available => true, :default_config => { :ext_config => { :bbar => %w{ apply }, :tools => %w{ } }, :persistent_config => false } }) end |
.config_columns ⇒ Object
columns to be displayed by the FieldConfigurator (which is GridPanel-based)
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/netzke/form_panel.rb', line 95 def self.config_columns [ {:name => :name, :type => :string, :editor => :combobox, :width => 200}, {:name => :hidden, :type => :boolean, :editor => :checkbox, :width => 40, :header => "Excl"}, {:name => :disabled, :type => :boolean, :editor => :checkbox, :width => 40, :header => "Dis"}, {:name => :xtype, :type => :string}, {:name => :value, :type => :string}, {:name => :field_label, :type => :string}, {:name => :input_type, :type => :string} ] end |
.include_js ⇒ Object
Extra javascripts
35 36 37 38 39 |
# File 'lib/netzke/form_panel.rb', line 35 def self.include_js [ "#{File.dirname(__FILE__)}/form_panel_extras/javascripts/xcheckbox.js" ] end |
.property_fields ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/netzke/form_panel.rb', line 107 def self.property_fields res = [ {:name => :ext_config__title, :type => :string}, {:name => :ext_config__header, :type => :boolean, :default => true} # {:name => :ext_config__bbar, :type => :json}, # {:name => :ext_config__prohibit_create, :type => :boolean}, # {:name => :ext_config__prohibit_update, :type => :boolean}, # {:name => :ext_config__prohibit_delete, :type => :boolean}, # {:name => :ext_config__prohibit_read, :type => :boolean} ] res end |
Instance Method Details
#actions ⇒ Object
76 77 78 79 80 |
# File 'lib/netzke/form_panel.rb', line 76 def actions { :apply => {:text => 'Apply'} } end |
#columns ⇒ Object
82 83 84 |
# File 'lib/netzke/form_panel.rb', line 82 def columns @columns ||= get_columns.convert_keys{|k| k.to_sym} end |
#configuration_widgets ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/netzke/form_panel.rb', line 55 def res = [] res << { :name => 'fields', :widget_class_name => "FieldsConfigurator", :active => true, :widget => self, :persistent_config => true } res << { :name => 'general', :widget_class_name => "PropertyEditor", :widget => self, :ext_config => {:title => false} } res end |
#data_class ⇒ Object
51 52 53 |
# File 'lib/netzke/form_panel.rb', line 51 def data_class @data_class ||= config[:data_class_name] && config[:data_class_name].constantize end |
#default_columns ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/netzke/form_panel.rb', line 155 def default_columns # columns specified in widget's config columns_from_config = config[:columns] && normalize_columns(config[:columns]) if columns_from_config # reverse-merge each column hash from config with each column hash from exposed_attributes (columns from config have higher priority) for c in columns_from_config corresponding_exposed_column = predefined_columns.find{ |k| k[:name] == c[:name] } c.reverse_merge!(corresponding_exposed_column) if corresponding_exposed_column end columns_for_create = columns_from_config elsif predefined_columns # we didn't have columns configured in widget's config, so, use the columns from the data class columns_for_create = predefined_columns else raise ArgumentError, "No columns specified for widget '#{id_name}'" end columns_for_create.map! do |c| if data_class # Try to figure out the configuration from data class # detect :assoc__method if c[:name].to_s.index('__') assoc_name, method = c[:name].to_s.split('__').map(&:to_sym) if assoc = data_class.reflect_on_association(assoc_name) assoc_column = assoc.klass.columns_hash[method.to_s] assoc_method_type = assoc_column.try(:type) if assoc_method_type c[:xtype] ||= XTYPE_MAP[assoc_method_type] == :xcheckbox ? :xcheckbox : :combobox end end end # detect association column (e.g. :category_id) if assoc = data_class.reflect_on_all_associations.detect{|a| a.primary_key_name.to_sym == c[:name]} c[:xtype] ||= :combobox assoc_method = %w{name title label id}.detect{|m| (assoc.klass.instance_methods + assoc.klass.column_names).include?(m) } || assoc.klass.primary_key c[:name] = "#{assoc.name}__#{assoc_method}".to_sym end c[:hidden] = true if c[:name] == data_class.primary_key.to_sym && c[:hidden].nil? # hide ID column by default end # detect column type type = c[:type] || data_class && data_class.columns_hash[c[:name].to_s].try(:type) || :string c[:type] ||= type c[:xtype] ||= XTYPE_MAP[type] unless XTYPE_MAP[type].nil? # if the column is finally simply {:name => "something"}, cut it down to "something" c.reject{ |k,v| k == :name }.empty? ? c[:name] : c end columns_for_create end |
#get_columns ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/netzke/form_panel.rb', line 128 def get_columns if config[:persistent_config] persistent_config['layout__columns'] ||= default_columns res = normalize_array_of_columns(persistent_config['layout__columns']) else res = default_columns end # merge values for each field if the record is specified @record && res.map! do |c| value = @record.send(normalize_column(c)[:name]) value.nil? ? c : normalize_column(c).merge(:value => value) end res end |
#js_config ⇒ Object
parameters used to instantiate the JS object
87 88 89 90 91 92 |
# File 'lib/netzke/form_panel.rb', line 87 def js_config res = super res.merge!(:clmns => columns) res.merge!(:data_class_name => config[:data_class_name]) res end |
#normalized_columns ⇒ Object
Normalized columns
123 124 125 |
# File 'lib/netzke/form_panel.rb', line 123 def normalized_columns @normalized_columns ||= normalize_columns(columns) end |