netzke-basepack 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/CHANGELOG.rdoc +22 -1
  2. data/Rakefile +1 -1
  3. data/lib/netzke/active_record/attributes.rb +1 -1
  4. data/lib/netzke/basepack/action_column.rb +70 -0
  5. data/lib/netzke/basepack/action_column/javascripts/action_column.js +61 -0
  6. data/lib/netzke/basepack/data_accessor.rb +12 -17
  7. data/lib/netzke/basepack/form_panel.rb +5 -4
  8. data/lib/netzke/basepack/form_panel/fields.rb +1 -1
  9. data/lib/netzke/basepack/form_panel/javascripts/form_panel.js +3 -3
  10. data/lib/netzke/basepack/grid_panel.rb +81 -30
  11. data/lib/netzke/basepack/grid_panel/columns.rb +20 -9
  12. data/lib/netzke/basepack/grid_panel/javascripts/event_handling.js +0 -1
  13. data/lib/netzke/basepack/grid_panel/javascripts/grid_panel.js +1 -1
  14. data/lib/netzke/basepack/grid_panel/record_form_window.rb +5 -5
  15. data/lib/netzke/basepack/grid_panel/services.rb +0 -1
  16. data/lib/netzke/basepack/version.rb +1 -1
  17. data/netzke-basepack.gemspec +11 -6
  18. data/test/basepack_test_app/Gemfile.lock +1 -1
  19. data/test/basepack_test_app/app/components/author_grid.rb +1 -5
  20. data/test/basepack_test_app/app/components/book_form.rb +25 -24
  21. data/test/basepack_test_app/app/components/book_grid.rb +6 -9
  22. data/test/basepack_test_app/app/components/book_grid_with_column_actions.rb +15 -0
  23. data/test/basepack_test_app/app/components/book_grid_with_custom_columns.rb +16 -23
  24. data/test/basepack_test_app/app/components/book_grid_with_default_values.rb +5 -7
  25. data/test/basepack_test_app/app/components/book_grid_with_extra_feedback.rb +2 -5
  26. data/test/basepack_test_app/app/components/book_grid_with_overridden_columns.rb +15 -0
  27. data/test/basepack_test_app/app/components/book_grid_with_persistence.rb +0 -1
  28. data/test/basepack_test_app/app/components/book_paging_form_panel.rb +2 -2
  29. data/test/basepack_test_app/app/components/user_form.rb +16 -19
  30. data/test/basepack_test_app/app/components/user_grid.rb +6 -8
  31. data/test/basepack_test_app/db/migrate/20110909071740_add_published_on_to_books.rb +5 -0
  32. data/test/basepack_test_app/db/schema.rb +2 -1
  33. data/test/basepack_test_app/features/form_panel.feature +11 -0
  34. data/test/basepack_test_app/features/grid_panel.feature +34 -33
  35. data/test/basepack_test_app/features/grid_panel_filters.feature +61 -0
  36. data/test/basepack_test_app/features/paging_form_panel.feature +7 -30
  37. data/test/basepack_test_app/features/step_definitions/grid_panel_steps.rb +28 -0
  38. metadata +15 -10
  39. data/lib/netzke/basepack/grid_panel/multi_edit_form.rb +0 -16
@@ -109,6 +109,19 @@ module Netzke
109
109
  @default_columns ||= load_model_level_attrs || data_class.netzke_attributes
110
110
  end
111
111
 
112
+ # Columns that were overridden with :override_columns config option.
113
+ def overridden_default_columns
114
+ if config[:override_columns].present?
115
+ result = []
116
+ default_columns.each do |col|
117
+ result << col.merge(config[:override_columns][col[:name].to_sym] || {})
118
+ end
119
+ result
120
+ else
121
+ default_columns
122
+ end
123
+ end
124
+
112
125
  # Columns that represent a smart merge of default_columns and columns passed during the configuration.
113
126
  def initial_columns(with_excluded = false)
114
127
  # Normalize here, as from the config we can get symbols (names) instead of hashes
@@ -121,13 +134,13 @@ module Netzke
121
134
  # reverse-merge each column hash from config with each column hash from exposed_attributes
122
135
  # (columns from config have higher priority)
123
136
  for c in columns_from_config
124
- corresponding_default_column = default_columns.find{ |k| k[:name] == c[:name] }
137
+ corresponding_default_column = overridden_default_columns.find{ |k| k[:name] == c[:name] }
125
138
  c.reverse_merge!(corresponding_default_column) if corresponding_default_column
126
139
  end
127
140
  columns_for_create = columns_from_config
128
141
  else
129
142
  # we didn't have columns configured in component's config, so, use the columns from the data class
130
- columns_for_create = default_columns
143
+ columns_for_create = overridden_default_columns
131
144
  end
132
145
 
133
146
  filter_out_excluded_columns(columns_for_create) unless with_excluded
@@ -155,10 +168,10 @@ module Netzke
155
168
  set_default_xtype(c)
156
169
  set_default_virtual(c)
157
170
  set_default_text(c)
171
+ set_default_editable(c)
158
172
  set_default_editor(c)
159
173
  set_default_width(c)
160
174
  set_default_hidden(c)
161
- set_default_editable(c)
162
175
  set_default_sortable(c)
163
176
  set_default_filterable(c)
164
177
  c[:assoc] = association_attr?(c)
@@ -182,6 +195,7 @@ module Netzke
182
195
  else
183
196
  c[:editor] ||= editor_for_attr_type(c[:attr_type])
184
197
  end
198
+
185
199
  end
186
200
 
187
201
  def set_default_width(c)
@@ -195,7 +209,7 @@ module Netzke
195
209
 
196
210
  def set_default_editable(c)
197
211
  if c[:editable].nil?
198
- c[:editable] = is_editable_column?(c) || nil
212
+ c[:editable] = is_editable_column?(c)
199
213
  end
200
214
  end
201
215
 
@@ -314,12 +328,9 @@ module Netzke
314
328
  # Default fields that will be displayed in the Add/Edit/Search forms
315
329
  # When overriding this method, keep in mind that the fields inside the layout must be expanded (each field represented by a hash, not just a symbol)
316
330
  def default_fields_for_forms
317
- form_klass = constantize_class_name("Netzke::ModelExtensions::#{config[:model]}ForFormPanel") || original_data_class
318
-
319
- # Select only those fields that are known to the form_klass
320
331
  selected_columns = columns.select do |c|
321
- form_klass.column_names.include?(c[:name]) ||
322
- form_klass.instance_methods.include?("#{c[:name]}=") ||
332
+ data_class.column_names.include?(c[:name]) ||
333
+ data_class.instance_methods.include?("#{c[:name]}=") ||
323
334
  association_attr?(c[:name])
324
335
  end
325
336
 
@@ -15,7 +15,6 @@
15
15
  Ext.Msg.confirm(this.i18n.confirmation, this.i18n.areYouSure, function(btn){
16
16
  if (btn == 'yes') {
17
17
  var records = [];
18
- var selection = this.getView().getSelectedNodes();
19
18
  this.getSelectionModel().selected.each(function(r){
20
19
  if (r.isNew) {
21
20
  // this record is not know to server - simply remove from store
@@ -28,7 +28,7 @@
28
28
 
29
29
  if (c.name !== '_meta') fieldConfig.type = this.fieldTypeForAttrType(c.attrType); // field type (grid editors need this to function well)
30
30
 
31
- if (c.attrType == 'datetime') {
31
+ if (c.attrType == 'datetime' || c.attrType == 'date') {
32
32
  fieldConfig.dateFormat = 'Y-m-d g:i:s'; // in this format we receive dates from the server
33
33
  };
34
34
 
@@ -2,12 +2,12 @@ module Netzke
2
2
  module Basepack
3
3
  class GridPanel < Netzke::Base
4
4
  class RecordFormWindow < Window
5
- js_properties :button_align => :right
6
5
 
7
- config :modal => true,
8
- :width => 400,
9
- :auto_height => true,
10
- :fbar => [:ok.action, :cancel.action]
6
+ js_properties :button_align => :right,
7
+ :width => 400,
8
+ :auto_height => true,
9
+ :modal => true,
10
+ :fbar => [:ok.action, :cancel.action]
11
11
 
12
12
  action :ok do
13
13
  { :text => I18n.t('netzke.basepack.grid_panel.record_form_window.actions.ok')}
@@ -137,7 +137,6 @@ module Netzke
137
137
 
138
138
  if mod_records_count > 0
139
139
  on_data_changed
140
- flash :notice => "Updated #{mod_records_count} records."
141
140
  {:set_result => "ok", :netzke_feedback => @flash}.to_nifty_json
142
141
  else
143
142
  {:netzke_feedback => @flash}.to_nifty_json
@@ -3,7 +3,7 @@ module Netzke
3
3
  module Version
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- PATCH = 1
6
+ PATCH = 2
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
9
9
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{netzke-basepack}
8
- s.version = "0.7.1"
8
+ s.version = "0.7.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Sergei Kozlov}]
12
- s.date = %q{2011-09-04}
12
+ s.date = %q{2011-10-20}
13
13
  s.description = %q{A set of full-featured extendible Netzke components (such as FormPanel, GridPanel, Window, BorderLayoutPanel, etc) which can be used as building block for your RIA}
14
14
  s.email = %q{sergei@playcode.nl}
15
15
  s.extra_rdoc_files = [
@@ -40,6 +40,8 @@ Gem::Specification.new do |s|
40
40
  "lib/netzke/active_record/relation_extensions.rb",
41
41
  "lib/netzke/basepack.rb",
42
42
  "lib/netzke/basepack/accordion_panel.rb",
43
+ "lib/netzke/basepack/action_column.rb",
44
+ "lib/netzke/basepack/action_column/javascripts/action_column.js",
43
45
  "lib/netzke/basepack/auth_app.rb",
44
46
  "lib/netzke/basepack/basic_app.rb",
45
47
  "lib/netzke/basepack/border_layout_panel.rb",
@@ -63,7 +65,6 @@ Gem::Specification.new do |s|
63
65
  "lib/netzke/basepack/grid_panel/javascripts/grid_panel.js",
64
66
  "lib/netzke/basepack/grid_panel/javascripts/misc.js",
65
67
  "lib/netzke/basepack/grid_panel/javascripts/rows-dd.js",
66
- "lib/netzke/basepack/grid_panel/multi_edit_form.rb",
67
68
  "lib/netzke/basepack/grid_panel/record_form_window.rb",
68
69
  "lib/netzke/basepack/grid_panel/services.rb",
69
70
  "lib/netzke/basepack/paging_form_panel.rb",
@@ -105,11 +106,13 @@ Gem::Specification.new do |s|
105
106
  "test/basepack_test_app/app/components/book_form_with_nested_attributes.rb",
106
107
  "test/basepack_test_app/app/components/book_grid.rb",
107
108
  "test/basepack_test_app/app/components/book_grid_loader.rb",
109
+ "test/basepack_test_app/app/components/book_grid_with_column_actions.rb",
108
110
  "test/basepack_test_app/app/components/book_grid_with_custom_columns.rb",
109
111
  "test/basepack_test_app/app/components/book_grid_with_default_values.rb",
110
112
  "test/basepack_test_app/app/components/book_grid_with_extra_feedback.rb",
111
113
  "test/basepack_test_app/app/components/book_grid_with_extra_filters.rb",
112
114
  "test/basepack_test_app/app/components/book_grid_with_nested_attributes.rb",
115
+ "test/basepack_test_app/app/components/book_grid_with_overridden_columns.rb",
113
116
  "test/basepack_test_app/app/components/book_grid_with_paging.rb",
114
117
  "test/basepack_test_app/app/components/book_grid_with_persistence.rb",
115
118
  "test/basepack_test_app/app/components/book_grid_with_scoped_authors.rb",
@@ -187,12 +190,14 @@ Gem::Specification.new do |s|
187
190
  "test/basepack_test_app/db/migrate/20110213213050_create_netzke_component_states.rb",
188
191
  "test/basepack_test_app/db/migrate/20110701070052_create_book_with_custom_primary_keys.rb",
189
192
  "test/basepack_test_app/db/migrate/20110901114016_add_last_read_at_to_books.rb",
193
+ "test/basepack_test_app/db/migrate/20110909071740_add_published_on_to_books.rb",
190
194
  "test/basepack_test_app/db/schema.rb",
191
195
  "test/basepack_test_app/db/seeds.rb",
192
196
  "test/basepack_test_app/features/accordion_panel.feature",
193
197
  "test/basepack_test_app/features/components_in_view.feature",
194
198
  "test/basepack_test_app/features/form_panel.feature",
195
199
  "test/basepack_test_app/features/grid_panel.feature",
200
+ "test/basepack_test_app/features/grid_panel_filters.feature",
196
201
  "test/basepack_test_app/features/grid_panel_with_custom_primary_key.feature",
197
202
  "test/basepack_test_app/features/grid_sorting.feature",
198
203
  "test/basepack_test_app/features/i18n.feature",
@@ -287,16 +292,16 @@ Gem::Specification.new do |s|
287
292
  s.specification_version = 3
288
293
 
289
294
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
290
- s.add_runtime_dependency(%q<netzke-core>, ["~> 0.7.0"])
295
+ s.add_runtime_dependency(%q<netzke-core>, ["~> 0.7.4"])
291
296
  s.add_runtime_dependency(%q<will_paginate>, ["~> 3.0.0"])
292
297
  s.add_runtime_dependency(%q<acts_as_list>, ["~> 0.1.4"])
293
298
  else
294
- s.add_dependency(%q<netzke-core>, ["~> 0.7.0"])
299
+ s.add_dependency(%q<netzke-core>, ["~> 0.7.4"])
295
300
  s.add_dependency(%q<will_paginate>, ["~> 3.0.0"])
296
301
  s.add_dependency(%q<acts_as_list>, ["~> 0.1.4"])
297
302
  end
298
303
  else
299
- s.add_dependency(%q<netzke-core>, ["~> 0.7.0"])
304
+ s.add_dependency(%q<netzke-core>, ["~> 0.7.4"])
300
305
  s.add_dependency(%q<will_paginate>, ["~> 3.0.0"])
301
306
  s.add_dependency(%q<acts_as_list>, ["~> 0.1.4"])
302
307
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: vendor/gems/netzke-core
3
3
  specs:
4
- netzke-core (0.7.2)
4
+ netzke-core (0.7.4)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  PATH
@@ -1,7 +1,3 @@
1
1
  class AuthorGrid < Netzke::Basepack::GridPanel
2
- def default_config
3
- super.merge(
4
- :model => "Author"
5
- )
6
- end
2
+ model "Author"
7
3
  end
@@ -1,30 +1,32 @@
1
1
  # Warning: this component participates in i18n.feature, careful with adding new fields!
2
2
  class BookForm < Netzke::Basepack::FormPanel
3
- js_property :title, Book.model_name.human
3
+ extend Extras::BookPresentation
4
4
 
5
- include Extras::BookPresentation
5
+ title Book.model_name.human
6
6
 
7
- def configuration
8
- super.merge(
9
- :model => "Book",
10
- :record => Book.first,
11
- :items => [
12
- :title,
13
- {:name => :author__first_name, :setter => author_first_name_setter},
14
- {:name => :author__last_name, :xtype => :displayfield},
15
- {:name => :rating, :xtype => :combo, :store => [[1, "Good"], [2, "Average"], [3, "Poor"]]},
16
- {:name => :author__updated_at, :editable => false},
17
- :digitized,
18
- :exemplars,
19
- {:name => :in_abundance, :getter => in_abundance_getter, :xtype => :displayfield},
20
- {:name => :updated_at}
21
- # WIP: commalistcbg is kind of broken, giving an Ext error
22
- # {:name => :tags, :xtype => :commalistcbg, :options => %w(read cool recommend buy)},
23
- # WIP: waithing on nradiogroup
24
- # {:name => :rating, :xtype => :nradiogroup, :options => [[1, "Good"], [2, "Average"], [3, "Poor"]]}
25
- ]
26
- )
27
- end
7
+ model "Book"
8
+
9
+ record_id Book.first.try(:id)
10
+
11
+ items [
12
+ :title,
13
+ {:name => :author__first_name, :setter => author_first_name_setter},
14
+ :author__name,
15
+ {:name => :author__last_name, :xtype => :displayfield},
16
+ {:name => :rating, :xtype => :combo, :store => [[1, "Good"], [2, "Average"], [3, "Poor"]]},
17
+ {:name => :author__updated_at, :editable => false},
18
+ :digitized,
19
+ :exemplars,
20
+ {:name => :in_abundance, :getter => in_abundance_getter, :xtype => :displayfield},
21
+ {:name => :updated_at},
22
+ :last_read_at,
23
+ :published_on
24
+
25
+ # WIP: commalistcbg is kind of broken, giving an Ext error
26
+ # {:name => :tags, :xtype => :commalistcbg, :options => %w(read cool recommend buy)},
27
+ # WIP: waithing on nradiogroup
28
+ # {:name => :rating, :xtype => :nradiogroup, :options => [[1, "Good"], [2, "Average"], [3, "Poor"]]}
29
+ ]
28
30
 
29
31
  js_method :init_component, <<-JS
30
32
  function(){
@@ -33,5 +35,4 @@ class BookForm < Netzke::Basepack::FormPanel
33
35
  }
34
36
  JS
35
37
 
36
-
37
38
  end
@@ -1,12 +1,9 @@
1
1
  class BookGrid < Netzke::Basepack::GridPanel
2
- js_property :title, I18n.t('books', :default => "Books")
2
+ title I18n.t('books', :default => "Books")
3
3
 
4
- def default_config
5
- super.merge(
6
- :model => "Book",
7
- # :prohibit_update => true
8
- # :columns => [{:name => :author__first_name, :read_only => true}, :exemplars, {:name => :digitized, :xtype => :checkcolumn, :editable => false}]
9
- # :columns => [{:name => :title, :editable => false, :editor => {:xtype => :datefield}}, :exemplars, :digitized, :notes]
10
- )
11
- end
4
+ model "Book"
5
+
6
+ add_form_config :class_name => "BookForm"
7
+ edit_form_config :class_name => "BookForm"
8
+ multi_edit_form_config :class_name => "BookForm"
12
9
  end
@@ -0,0 +1,15 @@
1
+ # Implements a column action :delete_row
2
+ class BookGridWithColumnActions < Netzke::Basepack::GridPanel
3
+ include Netzke::Basepack::ActionColumn
4
+
5
+ model "Book"
6
+
7
+ column_action :delete_row, :icon => "#{Netzke::Core.ext_uri}/resources/themes/images/default/tree/drop-no.gif"
8
+
9
+ js_method :on_delete_row, <<-JS
10
+ function(record){
11
+ this.getSelectionModel().select(record);
12
+ this.onDel();
13
+ }
14
+ JS
15
+ end
@@ -1,29 +1,22 @@
1
1
  class BookGridWithCustomColumns < Netzke::Basepack::GridPanel
2
2
  js_property :title, "Books"
3
3
 
4
- def default_config
5
- super.merge(
6
- :model => "Book",
7
- :columns => [
8
- {:name => :author__first_name, :renderer => :my_renderer},
9
- {:name => :author__last_name, :renderer => :uppercase},
10
- {:name => :author__name, :flex => 1, :text => "Author"},
11
- {:name => :title, :flex => 1},
12
- {:name => :digitized},
13
- {
14
- :name => :rating,
15
- :editor => {
16
- :trigger_action => :all,
17
- :xtype => :combo,
18
- :store => [[1, "Good"], [2, "Average"], [3, "Poor"]]
19
- },
20
- :renderer => "function(v){return ['', 'Good', 'Average', 'Poor'][v];}"
21
- },
22
- :exemplars,
23
- {:name => :updated_at}
24
- ]
25
- )
26
- end
4
+ model "Book"
5
+
6
+ column :author__first_name, :renderer => :my_renderer
7
+ column :author__last_name, :renderer => :uppercase
8
+ column :author__name, :flex => 1, :text => "Author"
9
+ column :title, :flex => 1
10
+ column :digitized
11
+ column :rating,
12
+ :editor => {
13
+ :trigger_action => :all,
14
+ :xtype => :combo,
15
+ :store => [[1, "Good"], [2, "Average"], [3, "Poor"]]
16
+ },
17
+ :renderer => "function(v){return ['', 'Good', 'Average', 'Poor'][v];}"
18
+ column :exemplars
19
+ column :updated_at
27
20
 
28
21
  js_method :my_renderer, <<-JS
29
22
  function(value){
@@ -1,11 +1,9 @@
1
1
  class BookGridWithDefaultValues < Netzke::Basepack::GridPanel
2
+ model "Book"
2
3
  js_property :title, "Books"
3
4
 
4
- def default_config
5
- super.merge(
6
- :model => "Book",
7
- :columns => [{:name => 'title', :default_value => "Lolita"}, {:name => 'author__last_name', :default_value => Author.first.id}, {:name => 'exemplars', :default_value => 100}, {:name => 'digitized', :default_value => true}]
8
- )
9
- end
10
-
5
+ column :title, :default_value => "Lolita"
6
+ column :author__last_name, :default_value => Author.first.id
7
+ column :exemplars, :default_value => 100
8
+ column :digitized, :default_value => true
11
9
  end
@@ -1,10 +1,7 @@
1
1
  class BookGridWithExtraFeedback < Netzke::Basepack::GridPanel
2
- def default_config
3
- super.merge(
4
- :model => "Book"
5
- )
6
- end
2
+ model "Book"
7
3
 
4
+ # Override the get_data endpoint
8
5
  def get_data_endpoint(params)
9
6
  super.merge(:netzke_feedback => "Data loaded!")
10
7
  end
@@ -0,0 +1,15 @@
1
+ class BookGridWithOverriddenColumns < Netzke::Basepack::GridPanel
2
+ model "Book"
3
+
4
+ # First way to override a column
5
+ override_column :title, :renderer => "uppercase"
6
+
7
+ # Second way to override a column
8
+ # def default_config
9
+ # super.tap do |c|
10
+ # c[:override_columns] = {
11
+ # :title => {:renderer => "uppercase"}
12
+ # }
13
+ # end
14
+ # end
15
+ end
@@ -1,5 +1,4 @@
1
1
  class BookGridWithPersistence < BookGrid
2
-
3
2
  def default_config
4
3
  super.merge :persistence => true
5
4
  end
@@ -10,12 +10,12 @@ class BookPagingFormPanel < Netzke::Basepack::PagingFormPanel
10
10
  :flex => 2,
11
11
  :layout => :anchor,
12
12
  :defaults => {:anchor => "-8"},
13
- :items => [:title, :notes, :digitized, :created_at, :updated_at]
13
+ :items => [:title, :notes, :digitized, :created_at, :updated_at, :last_read_at]
14
14
  },{
15
15
  :flex => 1,
16
16
  :layout => :anchor,
17
17
  :defaults => {:anchor => "-8"},
18
- :items => [:author__name, {:name => :author__first_name, :read_only => true}, :exemplars]
18
+ :items => [:author__name, {:name => :author__first_name, :read_only => true}, :exemplars, :published_on]
19
19
  }]}]
20
20
  })
21
21
  end