netzke-basepack 0.6.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/CHANGELOG.rdoc +7 -4
  2. data/README.md +63 -0
  3. data/Rakefile +4 -4
  4. data/javascripts/basepack.js +113 -133
  5. data/lib/netzke-basepack.rb +9 -2
  6. data/lib/netzke/basepack.rb +9 -6
  7. data/lib/netzke/basepack/accordion_panel.rb +1 -1
  8. data/lib/netzke/basepack/auth_app.rb +28 -21
  9. data/lib/netzke/basepack/border_layout_panel.rb +9 -57
  10. data/lib/netzke/basepack/border_layout_panel/javascripts/border_layout_panel.js +40 -0
  11. data/lib/netzke/basepack/data_accessor.rb +3 -5
  12. data/lib/netzke/basepack/form_panel.rb +55 -52
  13. data/lib/netzke/basepack/form_panel/fields.rb +4 -2
  14. data/lib/netzke/basepack/form_panel/javascripts/comma_list_cbg.js +13 -28
  15. data/lib/netzke/basepack/form_panel/javascripts/form_panel.js +61 -34
  16. data/lib/netzke/basepack/form_panel/javascripts/n_radio_group.js +4 -3
  17. data/lib/netzke/basepack/form_panel/javascripts/readonly_mode.js +10 -10
  18. data/lib/netzke/basepack/form_panel/services.rb +1 -1
  19. data/lib/netzke/basepack/grid_panel.rb +23 -17
  20. data/lib/netzke/basepack/grid_panel/columns.rb +116 -71
  21. data/lib/netzke/basepack/grid_panel/javascripts/advanced_search.js +5 -7
  22. data/lib/netzke/basepack/grid_panel/javascripts/check_column_fix.js +6 -0
  23. data/lib/netzke/basepack/grid_panel/javascripts/edit_in_form.js +18 -15
  24. data/lib/netzke/basepack/grid_panel/javascripts/event_handling.js +178 -0
  25. data/lib/netzke/basepack/grid_panel/javascripts/grid_panel.js +230 -454
  26. data/lib/netzke/basepack/grid_panel/javascripts/rows-dd.js +1 -0
  27. data/lib/netzke/basepack/grid_panel/record_form_window.rb +8 -8
  28. data/lib/netzke/basepack/grid_panel/services.rb +12 -15
  29. data/lib/netzke/basepack/paging_form_panel.rb +1 -82
  30. data/lib/netzke/basepack/paging_form_panel/javascripts/paging_form_panel.js +76 -0
  31. data/lib/netzke/basepack/query_builder.rb +4 -4
  32. data/lib/netzke/basepack/query_builder/javascripts/query_builder.js +7 -4
  33. data/lib/netzke/basepack/search_panel.rb +1 -1
  34. data/lib/netzke/basepack/search_panel/javascripts/condition_field.js +27 -20
  35. data/lib/netzke/basepack/search_panel/javascripts/search_panel.js +4 -4
  36. data/lib/netzke/basepack/search_window.rb +4 -4
  37. data/lib/netzke/basepack/simple_app.rb +36 -8
  38. data/lib/netzke/basepack/simple_app/javascripts/simple_app.js +27 -16
  39. data/lib/netzke/basepack/tab_panel/javascripts/tab_panel.js +1 -1
  40. data/lib/netzke/basepack/version.rb +2 -2
  41. data/lib/netzke/basepack/window.rb +2 -45
  42. data/lib/netzke/basepack/window/javascripts/window.js +18 -0
  43. data/lib/netzke/basepack/wrap_lazy_loaded.rb +1 -1
  44. data/locales/de.yml +79 -0
  45. data/locales/en.yml +0 -10
  46. data/netzke-basepack.gemspec +32 -19
  47. data/stylesheets/basepack.css +16 -16
  48. data/test/rails_app/.gitignore +1 -0
  49. data/test/rails_app/Gemfile +9 -5
  50. data/test/rails_app/Gemfile.lock +51 -49
  51. data/test/rails_app/app/components/author_form.rb +32 -0
  52. data/test/rails_app/app/components/book_form.rb +6 -4
  53. data/test/rails_app/app/components/book_grid.rb +4 -3
  54. data/test/rails_app/app/components/book_grid_loader.rb +2 -2
  55. data/test/rails_app/app/components/book_grid_with_custom_columns.rb +11 -5
  56. data/test/rails_app/app/components/book_grid_with_default_values.rb +1 -1
  57. data/test/rails_app/app/components/book_grid_with_extra_feedback.rb +11 -0
  58. data/test/rails_app/app/components/book_grid_with_extra_filters.rb +14 -0
  59. data/test/rails_app/app/components/book_grid_with_paging.rb +10 -0
  60. data/test/rails_app/app/components/book_grid_with_persistence.rb +6 -0
  61. data/test/rails_app/app/components/book_paging_form_panel.rb +3 -3
  62. data/test/rails_app/app/components/book_with_custom_primary_key_grid.rb +10 -0
  63. data/test/rails_app/app/components/form_without_model.rb +5 -4
  64. data/test/rails_app/app/components/paging_form_with_search.rb +3 -2
  65. data/test/rails_app/app/components/some_auth_app.rb +3 -3
  66. data/test/rails_app/app/components/some_border_layout.rb +2 -2
  67. data/test/rails_app/app/components/some_simple_app.rb +6 -5
  68. data/test/rails_app/app/components/window_component_loader.rb +11 -2
  69. data/test/rails_app/app/controllers/components_controller.rb +1 -1
  70. data/test/rails_app/app/models/book_with_custom_primary_key.rb +4 -0
  71. data/test/rails_app/config/initializers/netzke.rb +6 -0
  72. data/test/rails_app/config/locales/es.yml +0 -10
  73. data/test/rails_app/db/migrate/20110701070052_create_book_with_custom_primary_keys.rb +15 -0
  74. data/test/rails_app/db/schema.rb +12 -2
  75. data/test/rails_app/db/seeds.rb +21 -1
  76. data/test/rails_app/features/form_panel.feature +17 -17
  77. data/test/rails_app/features/grid_panel.feature +20 -4
  78. data/test/rails_app/features/grid_panel_with_custom_primary_key.feature +15 -0
  79. data/test/rails_app/features/paging_form_panel.feature +14 -0
  80. data/test/rails_app/features/search_in_grid.feature +2 -1
  81. data/test/rails_app/features/simple_app.feature +5 -0
  82. data/test/rails_app/features/step_definitions/accordion_steps.rb +1 -5
  83. data/test/rails_app/features/step_definitions/ext_steps.rb +16 -0
  84. data/test/rails_app/features/step_definitions/form_panel_steps.rb +10 -12
  85. data/test/rails_app/features/step_definitions/generic_steps.rb +12 -4
  86. data/test/rails_app/features/step_definitions/grid_panel_steps.rb +47 -32
  87. data/test/rails_app/features/tab_panel.feature +2 -2
  88. data/test/rails_app/spec/factories.rb +4 -0
  89. metadata +26 -13
  90. data/README.rdoc +0 -67
  91. data/from_05_to_06.rdoc +0 -2
  92. data/javascripts/feedback_ghost.js +0 -34
  93. data/test/rails_app/public/netzke/basepack/ts-checkbox.gif +0 -0
@@ -6,9 +6,11 @@ Config options:
6
6
  1) all radio buttons, by boxLabel, e.g.: ["Cool", "To read", "Important"]
7
7
  2) array of arrays in format [value, label], e.g.: [[1, "Good"], [2, "Average"], [3, "Poor"]]
8
8
  */
9
- Ext.netzke.form.NRadioGroup = Ext.extend(Ext.form.RadioGroup, {
9
+ Ext.define('Ext.netzke.form.NRadioGroup', {
10
+ extend: 'Ext.form.RadioGroup',
11
+ alias: 'widget.nradiogroup',
10
12
  initComponent: function(){
11
- Ext.netzke.form.NRadioGroup.superclass.initComponent.call(this);
13
+ this.callParent();
12
14
 
13
15
  this.items = [];
14
16
 
@@ -39,4 +41,3 @@ Ext.netzke.form.NRadioGroup = Ext.extend(Ext.form.RadioGroup, {
39
41
  }
40
42
  });
41
43
 
42
- Ext.reg('nradiogroup', Ext.netzke.form.NRadioGroup);
@@ -1,6 +1,7 @@
1
- Ext.override(Ext.form.Field, {
1
+ // Overrides that implement setReadonlyMode for form fields.
2
+ //
2
3
 
3
- // By calling this, the field is instructed to replace itself with another instance, configured with displayModeConfig
4
+ Ext.form.field.Base.override({
4
5
  setReadonlyMode: function(onOff){
5
6
  if (this.hidden) return;
6
7
 
@@ -9,18 +10,17 @@ Ext.override(Ext.form.Field, {
9
10
  }
10
11
 
11
12
  if (onOff) {
12
- this.addClass("readonly");
13
- if (this.label) this.label.addClass("readonly");
13
+ this.addCls("readonly");
14
+ if (this.label) this.label.addCls("readonly");
14
15
  } else {
15
- this.removeClass("readonly");
16
- if (this.label) this.label.removeClass("readonly");
16
+ this.removeCls("readonly");
17
+ if (this.label) this.label.removeCls("readonly");
17
18
  }
18
19
  }
19
-
20
20
  });
21
21
 
22
- // Composite field has to take care of its children, by setting them into the "display mode"
23
- Ext.override(Ext.form.CompositeField, {
22
+ // Also the FieldContainer
23
+ Ext.form.FieldContainer.override({
24
24
  setReadonlyMode: function(onOff){
25
25
  this.items.each(function(i){
26
26
  i.setReadonlyMode(onOff);
@@ -28,7 +28,7 @@ Ext.override(Ext.form.CompositeField, {
28
28
  }
29
29
  });
30
30
 
31
- Ext.override(Ext.form.Checkbox, {
31
+ Ext.form.field.Checkbox.override({
32
32
  setReadonlyMode: function(onOff){
33
33
  this.setDisabled(onOff);
34
34
  }
@@ -65,7 +65,7 @@ module Netzke
65
65
  @record.errors.to_a.each do |msg|
66
66
  flash :error => msg
67
67
  end
68
- {:feedback => @flash, :apply_form_errors => build_form_errors(record)}
68
+ {:netzke_feedback => @flash, :apply_form_errors => build_form_errors(record)}
69
69
  end
70
70
  end
71
71
 
@@ -51,7 +51,7 @@ module Netzke
51
51
  # == Columns
52
52
  # Columns are configured by passing an array to the +columns+ option. Each element in the array is either the name of model's (virtual) attribute (in which case the configuration will be fully automatic), or a hash that may contain the following configuration options as keys:
53
53
  #
54
- # * +name+ - name of the column, that may correspond to the model's (virtual) attribute
54
+ # * +name+ - (required) name of the column, that may correspond to the model's (virtual) attribute
55
55
  # * +read_only+ - a boolean that defines if the cells in the column should be editable
56
56
  # * +editable+ - same as +read_only+, but in reverse (takes precedence over +read_only+)
57
57
  # * +filterable+ - set to false to disable filtering on this column
@@ -74,7 +74,7 @@ module Netzke
74
74
  # }
75
75
  # end
76
76
  #
77
- # Besides these options, a column can receive any meaningful config option understood by Ext.grid.Column (http://dev.sencha.com/deploy/dev/docs/?class=Ext.grid.Column)
77
+ # Besides these options, a column can receive any meaningful config option understood by Ext.grid.column.Column.
78
78
  #
79
79
  # == One-to-many association support
80
80
  # If the model bound to a grid +belongs_to+ another model, GridPanel can display an "assocition column" - where the user can select the associated record from a drop-down box. You can specify which method of the association should be used as the display value for the drop-down box options by using the double-underscore notation on the column name, where the association name is separated from the association method by "__" (double underscore). For example, let's say we have a Book that +belongs_to+ model Author, and Author responds to +first_name+. This way, the book grid can have a column defined as follows:
@@ -87,6 +87,10 @@ module Netzke
87
87
  #
88
88
  # {:name => "author__first_name", :scope => lambda{|relation| relation.where(:popular => true)}}
89
89
  #
90
+ # == Add/edit/search forms
91
+ # The forms will by default display the fields that correspond to the configured columns, taking over meaningful configuration options (e.g. +text+ will be converted into +fieldLabel+).
92
+ # You may override the default fields displayed in the forms by overriding the +default_fields_for_forms+ method, which should return an array understood by the +items+ config property of the +FormPanel+. If you need to use a custom class instead of +FormPanel+, you may need to go an extra mile overriding the corresponding GridPanel's child component (e.g. "add_form" or "edit_form").
93
+ #
90
94
  # == Actions
91
95
  # You can override GridPanel's actions to change their text, icons, and tooltips (see http://api.netzke.org/core/Netzke/Actions.html).
92
96
  #
@@ -117,7 +121,7 @@ module Netzke
117
121
  # * +edit_in_form_available+ - (defaults to true) include code for (multi-record) editing and adding records through a form
118
122
  # * +extended_search_available+ - (defaults to true) include code for extended configurable search
119
123
  class GridPanel < Netzke::Base
120
- js_base_class "Ext.grid.EditorGridPanel"
124
+ js_base_class "Ext.grid.Panel"
121
125
 
122
126
  # Class-level configuration. These options directly influence the amount of generated
123
127
  # javascript code for this component's class. For example, if you don't want filters for the grid,
@@ -128,9 +132,9 @@ module Netzke
128
132
 
129
133
  class_config_option :edit_in_form_available, true
130
134
 
131
- class_config_option :rows_reordering_available, true
135
+ class_config_option :rows_reordering_available, false
132
136
 
133
- class_config_option :config_tool_available, true
137
+ class_config_option :config_tool_available, false
134
138
 
135
139
  class_config_option :default_instance_config, {
136
140
  :enable_edit_in_form => edit_in_form_available,
@@ -140,7 +144,7 @@ module Netzke
140
144
  :enable_rows_reordering => false, # column drag n drop
141
145
  :enable_pagination => true,
142
146
  :rows_per_page => 30,
143
- :tools => %w{ refresh },
147
+ :tools => %w{ refresh }
144
148
  }
145
149
 
146
150
  extend ActiveSupport::Memoizable
@@ -149,27 +153,28 @@ module Netzke
149
153
  include self::Columns
150
154
  include Netzke::Basepack::DataAccessor
151
155
 
152
- js_mixin :grid_panel
156
+ js_mixin :grid_panel, :event_handling
153
157
  js_mixin :advanced_search if extended_search_available
154
158
  js_mixin :edit_in_form if edit_in_form_available
155
159
 
156
- js_translate *%w[are_you_sure confirmation first_text prev_text next_text last_text before_page_text after_page_text empty_msg refresh_text display_msg]
160
+ js_translate *%w[are_you_sure confirmation]
157
161
 
158
162
  # JavaScript includes
159
- ex = Netzke::Core.ext_location.join("examples")
163
+ ex = Netzke::Core.ext_path.join("examples")
160
164
 
161
165
  js_include(ex.join("ux/CheckColumn.js"))
166
+ js_include :check_column_fix
162
167
 
163
168
  # Includes for column filters
164
169
  if column_filters_available
165
170
  [
166
- "ux/gridfilters/menu/ListMenu.js",
167
- "ux/gridfilters/menu/RangeMenu.js",
168
- "ux/gridfilters/GridFilters.js"
171
+ "ux/grid/menu/ListMenu.js",
172
+ "ux/grid/menu/RangeMenu.js",
173
+ "ux/grid/FiltersFeature.js"
169
174
  ].each{ |path| js_include(ex.join(path)) }
170
175
 
171
176
  %w{Boolean Date List Numeric String}.unshift("").each do |f|
172
- js_include(ex.join"ux/gridfilters/filter/#{f}Filter.js")
177
+ js_include(ex.join"ux/grid/filter/#{f}Filter.js")
173
178
  end
174
179
  end
175
180
 
@@ -198,7 +203,7 @@ module Netzke
198
203
 
199
204
  def get_default_association_values #:nodoc:
200
205
  columns.select{ |c| c[:name].index("__") && c[:default_value] }.each.inject({}) do |r,c|
201
- assoc, assoc_method = assoc_and_assoc_method_for_column(c)
206
+ assoc, assoc_method = assoc_and_assoc_method_for_attr(c)
202
207
  assoc_instance = assoc.klass.find(c[:default_value])
203
208
  r.merge(c[:name] => assoc_instance.send(assoc_method))
204
209
  end
@@ -243,6 +248,7 @@ module Netzke
243
248
  :text => I18n.t('netzke.basepack.grid_panel.actions.add'),
244
249
  :tooltip => I18n.t('netzke.basepack.grid_panel.actions.add'),
245
250
  :disabled => config[:prohibit_create],
251
+ :handler => "onAddInline", # not following naming conventions here as Ext 4 grid has its own onAdd method
246
252
  :icon => :add
247
253
  }
248
254
  end
@@ -314,7 +320,7 @@ module Netzke
314
320
  :strong_default_attrs => config[:strong_default_attrs],
315
321
  :border => true,
316
322
  :bbar => false,
317
- :header => false,
323
+ :prevent_header => true,
318
324
  :mode => config[:mode],
319
325
  :record => data_class.new(columns_default_values)
320
326
  }.deep_merge(config[:add_form_config] || {})]
@@ -333,7 +339,7 @@ module Netzke
333
339
  :items => default_fields_for_forms,
334
340
  :persistent_config => config[:persistent_config],
335
341
  :bbar => false,
336
- :header => false,
342
+ :prevent_header => true,
337
343
  :mode => config[:mode]
338
344
  # :record_id gets assigned by deliver_component dynamically, at the moment of loading
339
345
  }.deep_merge(config[:edit_form_config] || {})]
@@ -352,7 +358,7 @@ module Netzke
352
358
  :items => default_fields_for_forms,
353
359
  :persistent_config => config[:persistent_config],
354
360
  :bbar => false,
355
- :header => false,
361
+ :prevent_header => true,
356
362
  :mode => config[:mode]
357
363
  }.deep_merge(config[:multi_edit_form_config] || {})]
358
364
  }.deep_merge(config[:multi_edit_form_window_config] || {})
@@ -114,7 +114,6 @@ module Netzke
114
114
  # Normalize here, as from the config we can get symbols (names) instead of hashes
115
115
  columns_from_config = config[:columns] && normalize_attrs(config[:columns])
116
116
 
117
-
118
117
  if columns_from_config
119
118
  # automatically add a column that reflects the primary key (unless specified in the config)
120
119
  columns_from_config.insert(0, {:name => data_class.primary_key}) unless columns_from_config.any?{ |c| c[:name] == data_class.primary_key }
@@ -133,23 +132,110 @@ module Netzke
133
132
 
134
133
  filter_out_excluded_columns(columns_for_create) unless with_excluded
135
134
 
136
- # Make the column config complete with the defaults
137
- columns_for_create.each do |c|
138
- detect_association(c)
135
+ # Make the column config complete with the defaults.
136
+ # Note: dup is needed to avoid modifying original hashes.
137
+ columns_for_create.map { |c| c.dup.tap { |c| augment_column_config c } }
138
+ end
139
+
140
+ memoize :initial_columns
141
+
142
+ private
143
+
144
+ # Based on initial column config, e.g.:
145
+ #
146
+ # {:name=>"author__name", :attr_type=>:string}
147
+ #
148
+ # augment it with additional configuration params, e.g.:
149
+ #
150
+ # {:name=>"author__name", :attr_type=>:string, :editor=>{:xtype=>:netzkeremotecombo}, :assoc=>true, :virtual=>true, :header=>"Author name", :editable=>true, :sortable=>false, :filterable=>false}
151
+ #
152
+ # It may be handy to override it.
153
+ def augment_column_config(c)
154
+ # note: the order of these calls is important, as consequent calls may depend on the result of previous ones
155
+ set_default_xtype(c)
139
156
  set_default_virtual(c)
140
- set_default_header(c)
157
+ set_default_text(c)
141
158
  set_default_editor(c)
142
159
  set_default_width(c)
143
160
  set_default_hidden(c)
144
161
  set_default_editable(c)
145
162
  set_default_sortable(c)
146
163
  set_default_filterable(c)
164
+ c[:assoc] = association_attr?(c)
147
165
  end
148
166
 
149
- columns_for_create
150
- end
167
+ def set_default_xtype(c)
168
+ return if c[:renderer] || c[:editor] # if user set those manually, we don't mess with column xtype
169
+ c[:xtype] ||= attr_type_to_xtype_map[c[:attr_type]]
170
+ end
151
171
 
152
- private
172
+ def set_default_text(c)
173
+ c[:text] ||= c[:label] || data_class.human_attribute_name(c[:name])
174
+ end
175
+
176
+ def set_default_editor(c)
177
+ # if shouldn't be editable, don't set any default editor; also, specifying xtype takes care of the editor
178
+ return if c[:read_only] || c[:editable] == false
179
+
180
+ if association_attr?(c)
181
+ set_default_association_editor(c)
182
+ else
183
+ c[:editor] ||= editor_for_attr_type(c[:attr_type])
184
+ end
185
+ end
186
+
187
+ def set_default_width(c)
188
+ c[:width] ||= 50 if c[:attr_type] == :boolean
189
+ c[:width] ||= 150 if c[:attr_type] == :datetime
190
+ end
191
+
192
+ def set_default_hidden(c)
193
+ c[:hidden] = true if primary_key_attr?(c) && c[:hidden].nil?
194
+ end
195
+
196
+ def set_default_editable(c)
197
+ if c[:editable].nil?
198
+ c[:editable] = is_editable_column?(c) || nil
199
+ end
200
+ end
201
+
202
+ def set_default_sortable(c)
203
+ c[:sortable] = !c[:virtual] if c[:sortable].nil? # TODO: optimize - don't set it to false
204
+ end
205
+
206
+ def set_default_filterable(c)
207
+ c[:filterable] = !c[:virtual] if c[:filterable].nil?
208
+ end
209
+
210
+
211
+ # Detects an association column and sets up the proper editor.
212
+ def set_default_association_editor(c)
213
+ assoc, assoc_method = assoc_and_assoc_method_for_attr(c)
214
+ return unless assoc
215
+
216
+ assoc_column = assoc.klass.columns_hash[assoc_method]
217
+ assoc_method_type = assoc_column.try(:type)
218
+
219
+ # if association column is boolean, display a checkbox (or alike), otherwise - a combobox (or alike)
220
+ if c[:nested_attribute]
221
+ c[:editor] ||= editor_for_attr_type(assoc_method_type)
222
+ else
223
+ c[:editor] ||= assoc_method_type == :boolean ? editor_for_attr_type(:boolean) : editor_for_association
224
+ end
225
+ end
226
+
227
+ # If the column should be editable
228
+ def is_editable_column?(c)
229
+ not_editable_if = primary_key_attr?(c)
230
+ not_editable_if ||= c[:virtual] && !association_attr?(c[:name])
231
+ not_editable_if ||= c[:read_only]
232
+
233
+ editable_if = data_class.column_names.include?(c[:name])
234
+ editable_if ||= data_class.instance_methods.map(&:to_s).include?("#{c[:name]}=")
235
+ editable_if ||= association_attr?(c[:name])
236
+
237
+ editable_if && !not_editable_if
238
+ end
153
239
 
154
240
  def initial_columns_order
155
241
  columns.map do |c|
@@ -193,82 +279,36 @@ module Netzke
193
279
  # NetzkeModelAttrList.read_list(data_class.name) if persistent_config_enabled?
194
280
  end
195
281
 
196
- def set_default_header(c)
197
- c[:label] ||= data_class.human_attribute_name(c[:name])
198
- end
199
-
200
- def set_default_editor(c)
201
- # c[:editor] ||= editor_for_attr_type(c[:attr_type]) # This is done in JS!
202
- c[:editor] = {:xtype => c[:editor]} if c[:editor].is_a?(Symbol)
203
- end
204
-
205
- def set_default_width(c)
206
- c[:width] ||= 50 if c[:attr_type] == :boolean
207
- c[:width] ||= 150 if c[:attr_type] == :datetime
208
- end
209
-
210
- def set_default_hidden(c)
211
- c[:hidden] = true if primary_key_attr?(c) && c[:hidden].nil?
212
- end
213
-
214
- def set_default_editable(c)
215
- if c[:editable].nil?
216
- not_editable_if = primary_key_attr?(c)
217
- not_editable_if ||= c[:virtual] && !association_attr?(c[:name])
218
- not_editable_if ||= c.delete(:read_only)
219
-
220
- editable_if = data_class.column_names.include?(c[:name])
221
- editable_if ||= data_class.instance_methods.map(&:to_s).include?("#{c[:name]}=")
222
- editable_if ||= association_attr?(c[:name])
223
-
224
- c[:editable] = editable_if && !not_editable_if
225
- end
226
- end
227
-
228
- def set_default_sortable(c)
229
- c[:sortable] = !c[:virtual] if c[:sortable].nil? # TODO: optimize - don't set it to false
230
- end
231
-
232
- def set_default_filterable(c)
233
- c[:filterable] = !c[:virtual] if c[:filterable].nil?
234
- end
235
-
236
- # Returns editor's xtype for a column type
282
+ # Column editor config for attribute type.
237
283
  def editor_for_attr_type(type)
238
- attr_type_to_editor_map[type] || :textfield
284
+ {:xtype => attr_type_to_editor_xtype_map[type] || :textfield}
239
285
  end
240
286
 
287
+ # Column editor config for one-to-many association
241
288
  def editor_for_association
242
- :netzkeremotecombo
289
+ {:xtype => :netzkeremotecombo}
243
290
  end
244
291
 
245
- # Returns a hash that maps a column type to the editor xtype. Override if you want different editors.
246
- def attr_type_to_editor_map
292
+ # Hash that maps a column type to the editor xtype. Override if you want different editors.
293
+ def attr_type_to_editor_xtype_map
247
294
  {
248
295
  :integer => :numberfield,
249
296
  :boolean => :checkbox,
250
297
  :date => :datefield,
251
- :datetime => :datetimefield,
298
+ # :datetime => :datetimefield, WIP: waiting for Ext 4 fix
299
+ :datetime => :datefield,
252
300
  :text => :textarea,
253
301
  :string => :textfield
254
302
  }
255
303
  end
256
304
 
257
- # Detects an association column and sets up the proper editor.
258
- def detect_association(c)
259
- assoc, assoc_method = assoc_and_assoc_method_for_column(c)
260
- if assoc
261
- assoc_column = assoc.klass.columns_hash[assoc_method]
262
- assoc_method_type = assoc_column.try(:type)
263
-
264
- # if association column is boolean, display a checkbox (or alike), otherwise - a combobox (or alike)
265
- if c[:nested_attribute]
266
- c[:editor] ||= editor_for_attr_type(assoc_method_type)
267
- else
268
- c[:editor] ||= assoc_method_type == :boolean ? editor_for_attr_type(:boolean) : editor_for_association
269
- c[:assoc] = true
270
- end
271
- end
305
+ def attr_type_to_xtype_map
306
+ {
307
+ # :integer => :numbercolumn, # don't like the default formatter
308
+ :boolean => :checkcolumn,
309
+ :date => :datecolumn,
310
+ :datetime => :datecolumn # TODO: replace with datetimepicker
311
+ }
272
312
  end
273
313
 
274
314
  # Default fields that will be displayed in the Add/Edit/Search forms
@@ -284,11 +324,16 @@ module Netzke
284
324
  end
285
325
 
286
326
  selected_columns.map do |c|
287
- field_config = {:name => c[:name]}
327
+ field_config = {
328
+ :name => c[:name],
329
+ :field_label => c[:text] || c[:header]
330
+ }
288
331
 
289
332
  # scopes for combobox options
290
333
  field_config[:scopes] = c[:editor][:scopes] if c[:editor].is_a?(Hash)
291
334
 
335
+ field_config.merge!(c[:editor] || {})
336
+
292
337
  field_config
293
338
  end
294
339
  end
@@ -305,7 +350,7 @@ module Netzke
305
350
 
306
351
  def columns_default_values
307
352
  columns.inject({}) do |r,c|
308
- assoc, assoc_method = assoc_and_assoc_method_for_column(c)
353
+ assoc, assoc_method = assoc_and_assoc_method_for_attr(c)
309
354
  if c[:default_value].nil?
310
355
  r
311
356
  else