netzke-basepack 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/CHANGELOG.rdoc +27 -2
  2. data/TODO.rdoc +1 -5
  3. data/app/models/netzke_persistent_array_auto_model.rb +0 -1
  4. data/features/components_in_view.feature +11 -0
  5. data/features/form_panel.feature +49 -0
  6. data/features/grid_panel.feature +32 -1
  7. data/features/i18n.feature +18 -0
  8. data/features/nested_attributes.feature +23 -0
  9. data/features/search_in_grid.feature +9 -9
  10. data/features/simple_app.feature +10 -0
  11. data/features/step_definitions/grid_panel_steps.rb +23 -0
  12. data/features/support/paths.rb +6 -0
  13. data/features/support/pickle.rb +0 -1
  14. data/features/virtual_attributes.feature +20 -0
  15. data/javascripts/basepack.js +166 -243
  16. data/lib/netzke-basepack.rb +3 -3
  17. data/lib/netzke/active_record.rb +6 -7
  18. data/lib/netzke/active_record/attributes.rb +214 -143
  19. data/lib/netzke/active_record/combobox_options.rb +12 -10
  20. data/lib/netzke/basepack.rb +6 -3
  21. data/lib/netzke/basepack/accordion_panel.rb +4 -2
  22. data/lib/netzke/basepack/auth_app.rb +152 -0
  23. data/lib/netzke/basepack/basic_app.rb +2 -262
  24. data/lib/netzke/basepack/form_panel.rb +35 -27
  25. data/lib/netzke/basepack/form_panel/fields.rb +35 -17
  26. data/lib/netzke/basepack/form_panel/javascripts/comma_list_cbg.js +59 -0
  27. data/lib/netzke/basepack/form_panel/javascripts/display_mode.js +62 -0
  28. data/lib/netzke/basepack/form_panel/javascripts/main.js +138 -0
  29. data/lib/netzke/basepack/form_panel/javascripts/n_radio_group.js +25 -0
  30. data/lib/netzke/basepack/form_panel/services.rb +12 -9
  31. data/lib/netzke/basepack/grid_panel.rb +87 -53
  32. data/lib/netzke/basepack/grid_panel/columns.rb +60 -15
  33. data/lib/netzke/basepack/grid_panel/javascripts/advanced_search.js +2 -64
  34. data/lib/netzke/basepack/grid_panel/javascripts/edit_in_form.js +2 -2
  35. data/lib/netzke/basepack/grid_panel/javascripts/{pre.js → main.js} +35 -17
  36. data/lib/netzke/basepack/grid_panel/javascripts/misc.js +4 -0
  37. data/lib/netzke/basepack/grid_panel/services.rb +17 -14
  38. data/lib/netzke/basepack/paging_form_panel.rb +92 -0
  39. data/lib/netzke/basepack/simple_app.rb +71 -0
  40. data/lib/netzke/basepack/simple_app/javascripts/main.js +53 -0
  41. data/lib/netzke/basepack/{basic_app → simple_app/javascripts}/statusbar_ext.js +0 -0
  42. data/lib/netzke/basepack/tab_panel.rb +2 -12
  43. data/lib/netzke/basepack/tab_panel/javascripts/main.js +11 -0
  44. data/lib/netzke/basepack/version.rb +2 -2
  45. data/lib/netzke/basepack/window.rb +6 -7
  46. data/lib/netzke/basepack/wrap_lazy_loaded.rb +3 -1
  47. data/lib/netzke/data_accessor.rb +25 -14
  48. data/lib/netzke/ext.rb +1 -1
  49. data/locales/en.yml +22 -0
  50. data/netzke-basepack.gemspec +66 -12
  51. data/spec/active_record/attributes_spec.rb +31 -2
  52. data/spec/factories.rb +16 -1
  53. data/test/rails_app/Gemfile +2 -2
  54. data/test/rails_app/Gemfile.lock +76 -77
  55. data/test/rails_app/app/components/author_grid.rb +7 -0
  56. data/test/rails_app/app/components/book_form.rb +24 -0
  57. data/test/rails_app/app/components/book_grid.rb +6 -1
  58. data/test/rails_app/app/components/book_grid_with_default_values.rb +11 -0
  59. data/test/rails_app/app/components/book_grid_with_nested_attributes.rb +13 -0
  60. data/test/rails_app/app/components/book_grid_with_virtual_attributes.rb +22 -0
  61. data/test/rails_app/app/components/book_paging_form_panel.rb +20 -0
  62. data/test/rails_app/app/components/book_presentation.rb +18 -0
  63. data/test/rails_app/app/components/books_bound_to_author.rb +10 -0
  64. data/test/rails_app/app/components/form_without_model.rb +19 -0
  65. data/test/rails_app/app/components/lockable_book_form.rb +17 -0
  66. data/test/rails_app/app/components/lockable_user_form.rb +7 -0
  67. data/test/rails_app/app/components/simple_window.rb +10 -0
  68. data/test/rails_app/app/components/some_accordion_panel.rb +22 -0
  69. data/test/rails_app/app/components/{simple_basic_app.rb → some_auth_app.rb} +3 -3
  70. data/test/rails_app/app/components/some_border_layout.rb +10 -7
  71. data/test/rails_app/app/components/some_simple_app.rb +34 -0
  72. data/test/rails_app/app/components/some_tab_panel.rb +16 -11
  73. data/test/rails_app/app/components/user_form.rb +11 -4
  74. data/test/rails_app/app/components/user_grid.rb +7 -1
  75. data/test/rails_app/app/components/window_component_loader.rb +1 -0
  76. data/test/rails_app/app/controllers/application_controller.rb +6 -0
  77. data/test/rails_app/app/controllers/components_controller.rb +3 -3
  78. data/test/rails_app/app/controllers/welcome_controller.rb +2 -2
  79. data/test/rails_app/app/helpers/embedded_components_helper.rb +2 -0
  80. data/test/rails_app/app/models/address.rb +3 -0
  81. data/test/rails_app/app/models/author.rb +2 -0
  82. data/test/rails_app/app/models/book.rb +1 -0
  83. data/test/rails_app/app/models/user.rb +1 -2
  84. data/test/rails_app/app/views/components/simple_panel.html.erb +1 -0
  85. data/test/rails_app/app/views/layouts/nested.html.erb +5 -0
  86. data/test/rails_app/config/application.rb +1 -1
  87. data/test/rails_app/config/initializers/netzke.rb +0 -4
  88. data/test/rails_app/config/locales/es.yml +16 -0
  89. data/test/rails_app/config/routes.rb +4 -1
  90. data/test/rails_app/db/development_structure.sql +33 -4
  91. data/test/rails_app/db/migrate/20101026190021_create_books.rb +2 -0
  92. data/test/rails_app/db/migrate/20110101143818_create_addresses.rb +17 -0
  93. data/test/rails_app/db/schema.rb +33 -1
  94. data/test/rails_app/spec/controllers/embedded_components_controller_spec.rb +12 -0
  95. data/test/rails_app/spec/helpers/embedded_components_helper_spec.rb +15 -0
  96. data/test/rails_app/spec/models/address_spec.rb +5 -0
  97. data/test/rails_app/spec/views/embedded_components/index.html.erb_spec.rb +5 -0
  98. metadata +67 -13
  99. data/features/basic_app.feature +0 -12
  100. data/lib/netzke/active_record/association_attributes.rb +0 -102
  101. data/lib/netzke/basepack/form_panel/javascripts/pre.js +0 -76
  102. data/lib/netzke/basepack/form_panel/javascripts/xcheckbox.js +0 -82
  103. data/lib/netzke/basepack/grid_panel/javascript.rb +0 -69
  104. data/locale/en.yml +0 -16
@@ -14,9 +14,9 @@ module Netzke
14
14
  autoload :Ext, 'ext'
15
15
 
16
16
  module Basepack
17
- class Engine < Rails::Engine
18
- config.after_initialize do
19
- I18n.load_path << File.dirname(__FILE__) + '/../locale/en.yml'
17
+ class Engine < ::Rails::Engine
18
+ config.before_initialize do
19
+ I18n.load_path << File.dirname(__FILE__) + '/../locales/en.yml'
20
20
  end
21
21
  end
22
22
  end
@@ -1,15 +1,14 @@
1
- # require 'netzke/active_record/association_attributes'
2
- # require 'netzke/active_record/attributes'
3
- # require 'netzke/active_record/combobox_options'
4
- # require 'netzke/active_record/data_accessor'
5
-
6
- module Netzke::ActiveRecord
1
+ require 'netzke/active_record/attributes'
2
+ require 'netzke/active_record/combobox_options'
3
+ require 'netzke/active_record/relation_extensions'
7
4
 
5
+ module Netzke
6
+ module ActiveRecord
7
+ end
8
8
  end
9
9
 
10
10
  # Extend ActiveRecord
11
11
  ActiveRecord::Base.class_eval do
12
- include ::Netzke::ActiveRecord::AssociationAttributes
13
12
  include ::Netzke::ActiveRecord::Attributes
14
13
  include ::Netzke::ActiveRecord::ComboboxOptions
15
14
  end
@@ -1,170 +1,241 @@
1
- module Netzke::ActiveRecord::Attributes
2
- extend ActiveSupport::Concern
3
-
4
- module ClassMethods
5
- # Define or configure an attribute.
6
- # Example:
7
- # netzke_attribute :recent, :type => :boolean, :read_only => true
8
- def netzke_attribute(name, options = {})
9
- name = name.to_s
10
- options[:attr_type] = options.delete(:type) || :string
11
- declared_attrs = read_inheritable_attribute(:netzke_declared_attributes) || []
12
- # if the attr was declared already, simply merge it with the new options
13
- existing = declared_attrs.detect{ |va| va[:name] == name }
14
- if existing
15
- existing.merge!(options)
16
- else
17
- attr_config = {:name => name}.merge(options)
18
- # if primary_key, insert in front, otherwise append
19
- if name == self.primary_key
20
- declared_attrs.insert(0, attr_config)
21
- else
22
- declared_attrs << {:name => name}.merge(options)
1
+ module Netzke
2
+ module ActiveRecord
3
+ module Attributes
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ # Define or configure an attribute.
8
+ # Example:
9
+ # netzke_attribute :recent, :type => :boolean, :read_only => true
10
+ def netzke_attribute(name, options = {})
11
+ name = name.to_s
12
+ options[:attr_type] = options.delete(:type) || options.delete(:attr_type) || :string
13
+ declared_attrs = read_inheritable_attribute(:netzke_declared_attributes) || []
14
+ # if the attr was declared already, simply merge it with the new options
15
+ existing = declared_attrs.detect{ |va| va[:name] == name }
16
+ if existing
17
+ existing.merge!(options)
18
+ else
19
+ attr_config = {:name => name}.merge(options)
20
+ # if primary_key, insert in front, otherwise append
21
+ if name == self.primary_key
22
+ declared_attrs.insert(0, attr_config)
23
+ else
24
+ declared_attrs << {:name => name}.merge(options)
25
+ end
26
+ end
27
+ write_inheritable_attribute(:netzke_declared_attributes, declared_attrs)
23
28
  end
24
- end
25
- write_inheritable_attribute(:netzke_declared_attributes, declared_attrs)
26
- end
27
29
 
28
- # Exclude attributes from being picked up by grids and forms.
29
- # Accepts an array of attribute names (as symbols).
30
- # Example:
31
- # netzke_expose_attributes :created_at, :updated_at, :crypted_password
32
- def netzke_exclude_attributes(*args)
33
- write_inheritable_attribute(:netzke_excluded_attributes, args.map(&:to_s))
34
- end
30
+ # Exclude attributes from being picked up by grids and forms.
31
+ # Accepts an array of attribute names (as symbols).
32
+ # Example:
33
+ # netzke_expose_attributes :created_at, :updated_at, :crypted_password
34
+ def netzke_exclude_attributes(*args)
35
+ write_inheritable_attribute(:netzke_excluded_attributes, args.map(&:to_s))
36
+ end
35
37
 
36
- # Explicitly expose attributes that should be picked up by grids and forms.
37
- # Accepts an array of attribute names (as symbols).
38
- # Takes precedence over <tt>netzke_exclude_attributes</tt>.
39
- # Example:
40
- # netzke_expose_attributes :name, :role__name
41
- def netzke_expose_attributes(*args)
42
- write_inheritable_attribute(:netzke_exposed_attributes, args.map(&:to_s))
43
- end
38
+ # Explicitly expose attributes that should be picked up by grids and forms.
39
+ # Accepts an array of attribute names (as symbols).
40
+ # Takes precedence over <tt>netzke_exclude_attributes</tt>.
41
+ # Example:
42
+ # netzke_expose_attributes :name, :role__name
43
+ def netzke_expose_attributes(*args)
44
+ write_inheritable_attribute(:netzke_exposed_attributes, args.map(&:to_s))
45
+ end
44
46
 
45
- # Returns the attributes that will be picked up by grids and forms.
46
- def netzke_attributes
47
- exposed = netzke_exposed_attributes
48
- exposed ? netzke_attrs_in_forced_order(exposed) : netzke_attrs_in_natural_order
49
- end
47
+ # Returns the attributes that will be picked up by grids and forms.
48
+ def netzke_attributes
49
+ exposed = netzke_exposed_attributes
50
+ exposed ? netzke_attrs_in_forced_order(exposed) : netzke_attrs_in_natural_order
51
+ end
50
52
 
51
- def netzke_exposed_attributes
52
- exposed = read_inheritable_attribute(:netzke_exposed_attributes)
53
- if exposed && !exposed.include?(self.primary_key)
54
- # automatically declare primary key as a netzke attribute
55
- netzke_attribute(self.primary_key)
56
- exposed.insert(0, self.primary_key)
57
- end
58
- exposed
59
- end
53
+ def netzke_attribute_hash
54
+ netzke_attributes.inject({}){ |r,a| r.merge(a[:name].to_sym => a) }
55
+ end
60
56
 
61
- private
62
- def netzke_declared_attributes
63
- read_inheritable_attribute(:netzke_declared_attributes) || []
64
- end
57
+ def netzke_exposed_attributes
58
+ exposed = read_inheritable_attribute(:netzke_exposed_attributes)
59
+ if exposed && !exposed.include?(self.primary_key)
60
+ # automatically declare primary key as a netzke attribute
61
+ netzke_attribute(self.primary_key)
62
+ exposed.insert(0, self.primary_key)
63
+ end
64
+ exposed
65
+ end
65
66
 
66
- def netzke_excluded_attributes
67
- read_inheritable_attribute(:netzke_excluded_attributes) || []
68
- end
67
+ private
68
+ def netzke_declared_attributes
69
+ read_inheritable_attribute(:netzke_declared_attributes) || []
70
+ end
69
71
 
70
- def netzke_attrs_in_forced_order(attrs)
71
- attrs.collect do |attr_name|
72
- declared = netzke_declared_attributes.detect { |va| va[:name] == attr_name } || {}
73
- in_columns_hash = columns_hash[attr_name] && {:name => attr_name, :attr_type => columns_hash[attr_name].type, :default_value => columns_hash[attr_name].default} || {} # {:virtual => true} # if nothing found in columns, mark it as "virtual" or not?
74
- if in_columns_hash.empty?
75
- # If not among the model columns, it's either virtual, or an association
76
- merged = association_attr?(attr_name) ? declared.merge!(:name => attr_name) : declared.merge(:virtual => true)
77
- else
78
- # .. otherwise merge with what's declared
79
- merged = in_columns_hash.merge(declared)
72
+ def netzke_excluded_attributes
73
+ read_inheritable_attribute(:netzke_excluded_attributes) || []
80
74
  end
81
75
 
82
- # We didn't find it among declared, nor among the model columns, nor does it seem association attribute
83
- merged[:name].nil? && raise(ArgumentError, "Unknown attribute '#{attr_name}' for model #{self.name}", caller)
76
+ def netzke_attrs_in_forced_order(attrs)
77
+ attrs.collect do |attr_name|
78
+ declared = netzke_declared_attributes.detect { |va| va[:name] == attr_name } || {}
79
+ in_columns_hash = columns_hash[attr_name] && {:name => attr_name, :attr_type => columns_hash[attr_name].type, :default_value => columns_hash[attr_name].default} || {} # {:virtual => true} # if nothing found in columns, mark it as "virtual" or not?
80
+ if in_columns_hash.empty?
81
+ # If not among the model columns, it's either virtual, or an association
82
+ merged = association_attr?(attr_name) ? declared.merge!(:name => attr_name) : declared.merge(:virtual => true)
83
+ else
84
+ # .. otherwise merge with what's declared
85
+ merged = in_columns_hash.merge(declared)
86
+ end
87
+
88
+ # We didn't find it among declared, nor among the model columns, nor does it seem association attribute
89
+ merged[:name].nil? && raise(ArgumentError, "Unknown attribute '#{attr_name}' for model #{self.name}", caller)
90
+
91
+ merged
92
+ end
93
+ end
84
94
 
85
- merged
86
- end
87
- end
95
+ # Returns netzke attributes in the order of columns in the table, followed by extra declared attributes
96
+ # Detects one-to-many association columns and replaces the name of the column with association column name (Netzke style), e.g.:
97
+ #
98
+ # role_id => role__name
99
+ def netzke_attrs_in_natural_order
100
+ (
101
+ declared_attrs = netzke_declared_attributes
102
+
103
+ column_names.map do |name|
104
+ c = {:name => name, :attr_type => columns_hash[name].type}
105
+
106
+ # If it's named as foreign key of some association, then it's an association column
107
+ assoc = reflect_on_all_associations.detect{|a| a.primary_key_name == c[:name]}
108
+
109
+ if assoc && !assoc.options[:polymorphic]
110
+ candidates = %w{name title label} << assoc.primary_key_name
111
+ assoc_method = candidates.detect{|m| (assoc.klass.instance_methods.map(&:to_s) + assoc.klass.column_names).include?(m) }
112
+ c[:name] = "#{assoc.name}__#{assoc_method}"
113
+ c[:attr_type] = assoc.klass.columns_hash[assoc_method].try(:type) || :string # when it's an instance method rather than a column, fall back to :string
114
+ end
115
+
116
+ # auto set up the default value from the column settings
117
+ c.merge!(:default_value => columns_hash[name].default) if columns_hash[name].default
118
+
119
+ # if there's a declared attr with the same name, simply merge it with what's taken from the model's columns
120
+ if declared = declared_attrs.detect{ |va| va[:name] == c[:name] }
121
+ c.merge!(declared)
122
+ declared_attrs.delete(declared)
123
+ end
124
+ c
125
+ end +
126
+ declared_attrs
127
+ ).reject { |attr| netzke_excluded_attributes.include?(attr[:name]) }
128
+ end
88
129
 
89
- # Returns netzke attributes in the order of columns in the table, followed by extra declared attributes
90
- # Detects one-to-many association columns and replaces the name of the column with association column name (Netzke style), e.g.:
91
- #
92
- # role_id => role__name
93
- def netzke_attrs_in_natural_order
94
- (
95
- declared_attrs = netzke_declared_attributes
96
-
97
- column_names.map do |name|
98
- c = {:name => name, :attr_type => columns_hash[name].type}
99
-
100
- # If it's named as foreign key of some association, then it's an association column
101
- assoc = reflect_on_all_associations.detect{|a| a.primary_key_name == c[:name]}
102
-
103
- if assoc && !assoc.options[:polymorphic]
104
- candidates = %w{name title label} << assoc.primary_key_name
105
- assoc_method = candidates.detect{|m| (assoc.klass.instance_methods.map(&:to_s) + assoc.klass.column_names).include?(m) }
106
- c[:name] = "#{assoc.name}__#{assoc_method}"
107
- c[:attr_type] = assoc.klass.columns_hash[assoc_method].try(:type) || :string # when it's an instance method rather than a column, fall back to :string
108
- end
130
+ def association_attr?(attr_name)
131
+ !!attr_name.index("__") # probably we can't do much better than this, as we don't know at this moment if the associated model has a specific attribute, and we don't really want to find it out
132
+ end
109
133
 
110
- # auto set up the default value from the column settings
111
- c.merge!(:default_value => columns_hash[name].default) if columns_hash[name].default
134
+ end
112
135
 
113
- # if there's a declared attr with the same name, simply merge it with what's taken from the model's columns
114
- if declared = declared_attrs.detect{ |va| va[:name] == c[:name] }
115
- c.merge!(declared)
116
- declared_attrs.delete(declared)
117
- end
118
- c
119
- end +
120
- declared_attrs
121
- ).reject { |attr| netzke_excluded_attributes.include?(attr[:name]) }
136
+ # Transforms a record to array of values according to the passed attributes
137
+ def to_array(attributes)
138
+ res = []
139
+ for a in attributes
140
+ next if a[:included] == false
141
+ res << value_for_attribute(a)
142
+ end
143
+ res
122
144
  end
123
145
 
124
- def association_attr?(attr_name)
125
- !!attr_name.index("__") # probably we can't do much better than this, as we don't know at this moment if the associated model has a specific attribute, and we don't really want to find it out
146
+ # Accepts both hash and array of attributes
147
+ def to_hash(attributes)
148
+ res = {}
149
+ for a in (attributes.is_a?(Hash) ? attributes.values : attributes)
150
+ next if a[:included] == false
151
+ res[a[:name].to_sym] = self.value_for_attribute(a)
152
+ end
153
+ res
126
154
  end
127
155
 
128
- end
156
+ # Fetches the value specified by an (association) attribute
157
+ def value_for_attribute(a)
158
+ v = if a[:getter]
159
+ a[:getter].call(self)
160
+ elsif respond_to?("#{a[:name]}")
161
+ send("#{a[:name]}")
162
+ elsif is_association_attr?(a)
163
+ split = a[:name].to_s.split(/\.|__/)
164
+ split.inject(self) do |r,m|
165
+ if r.respond_to?(m)
166
+ r.send(m)# unless res.nil?
167
+ else
168
+ logger.debug "!!! Netzke::Basepack: Wrong attribute name: #{a[:name]}" unless r.nil?
169
+ nil
170
+ end
171
+ end
172
+ end
129
173
 
130
- # Transforms a record to array of values according to the passed attributes
131
- def to_array(attributes)
132
- res = []
133
- for a in attributes
134
- begin
135
- next if a[:included] == false
136
- v = send(a[:name])
137
174
  # a work-around for to_json not taking the current timezone into account when serializing ActiveSupport::TimeWithZone
138
175
  v = v.to_datetime.to_s(:db) if v.is_a?(ActiveSupport::TimeWithZone)
139
- res << v
140
- rescue NoMethodError
141
- # So that we don't crash at a badly configured column
142
- res << "UNDEF"
176
+ v
143
177
  end
144
- end
145
- res
146
- end
147
178
 
148
- # Accepts both hash and array of attributes
149
- def to_hash(attributes)
150
- res = {}
151
- for a in (attributes.is_a?(Hash) ? attributes.values : attributes)
152
- next if a[:included] == false
153
- res[a[:name].to_sym] = self.value_for_attribute(a)
154
- end
155
- res
156
- end
179
+ # Assigns new value to an (association) attribute
180
+ def set_value_for_attribute(a, v)
181
+ if a[:setter]
182
+ a[:setter].call(self, v)
183
+ elsif respond_to?("#{a[:name]}=")
184
+ send("#{a[:name]}=", v)
185
+ elsif is_association_attr?(a)
186
+ split = a[:name].to_s.split(/\.|__/)
187
+ if a[:nested_attribute]
188
+ # We want:
189
+ # set_value_for_attribute({:name => :assoc_1__assoc_2__method, :nested_attribute => true}, 100)
190
+ # =>
191
+ # self.assoc_1.assoc_2.method = 100
192
+ split.inject(self) { |r,m| m == split.last ? (r && r.send("#{m}=", v) && r.save) : r.send(m) }
193
+ else
194
+ if split.size == 2
195
+ # search for association and assign it to self
196
+ assoc = self.class.reflect_on_association(split.first.to_sym)
197
+ assoc_method = split.last
198
+ if assoc
199
+ if assoc.macro == :has_one
200
+ assoc_instance = self.send(assoc.name)
201
+ if assoc_instance
202
+ assoc_instance.send("#{assoc_method}=", v)
203
+ assoc_instance.save # what should we do when this fails?..
204
+ else
205
+ # what should we do in this case?
206
+ end
207
+ else
208
+ begin
209
+ assoc_instance = assoc.klass.send("find_by_#{assoc_method}", v)
210
+ rescue NoMethodError
211
+ assoc_instance = nil
212
+ logger.debug "!!! Netzke::Basepack: No find_by_#{assoc_method} method for class #{assoc.klass.name}\n"
213
+ end
214
+ if (assoc_instance)
215
+ # we found association instance to assign
216
+ self.send("#{split.first}=", assoc_instance)
217
+ else
218
+ logger.debug "!!! Netzke::Basepack: Couldn't find association #{split.first} by #{assoc_method} '#{v}'"
219
+ end
220
+ end
221
+ else
222
+ logger.debug "!!! Netzke::Basepack: Association #{assoc} is not known for class #{self.class.name}"
223
+ end
224
+ else
225
+ logger.debug "!!! Netzke::Basepack: Wrong attribute name: #{a[:name]}"
226
+ end
227
+ end
228
+ end
229
+ end
230
+
231
+ protected
232
+
233
+ # Returns true if passed attribute is an "association attribute"
234
+ def is_association_attr?(a)
235
+ # maybe the check is too simplistic, but will do for now
236
+ !!a[:name].to_s.index("__")
237
+ end
157
238
 
158
- def value_for_attribute(a)
159
- begin
160
- v = send(a[:name])
161
- # a work-around for to_json not taking the current timezone into account when serializing ActiveSupport::TimeWithZone
162
- v = v.to_datetime.to_s(:db) if v.is_a?(ActiveSupport::TimeWithZone)
163
- v
164
- rescue NoMethodError
165
- # So that we don't crash at a badly configured column
166
- "UNDEF"
167
239
  end
168
240
  end
169
-
170
241
  end
@@ -1,14 +1,16 @@
1
- module Netzke::ActiveRecord::ComboboxOptions
2
- module ClassMethods
1
+ module Netzke
2
+ module ActiveRecord
3
+ module ComboboxOptions
4
+ module ClassMethods
5
+ def netzke_combo_options_for(column, query = "")
6
+ records = query.empty? ? find_by_sql("select distinct #{column} from #{table_name}") : find_by_sql("select distinct #{column} from #{table_name} where #{column} like '#{query}%'")
7
+ records.map{|r| r.send(column)}
8
+ end
9
+ end
3
10
 
4
- def netzke_combo_options_for(column, query = "")
5
- records = query.empty? ? find_by_sql("select distinct #{column} from #{table_name}") : find_by_sql("select distinct #{column} from #{table_name} where #{column} like '#{query}%'")
6
- records.map{|r| r.send(column)}
11
+ def self.included(receiver)
12
+ receiver.extend ClassMethods
13
+ end
7
14
  end
8
-
9
- end
10
-
11
- def self.included(receiver)
12
- receiver.extend ClassMethods
13
15
  end
14
16
  end
@@ -10,14 +10,17 @@ module Netzke
10
10
  class << self
11
11
  # Called from netzke-basepack.rb
12
12
  def init
13
- Netzke::Core.javascripts << "#{File.dirname(__FILE__)}/../../javascripts/basepack.js"
14
- Netzke::Core.stylesheets << "#{File.dirname(__FILE__)}/../../stylesheets/basepack.css"
13
+ Netzke::Core.ext_javascripts << "#{File.dirname(__FILE__)}/../../javascripts/basepack.js"
14
+ Netzke::Core.ext_stylesheets << "#{File.dirname(__FILE__)}/../../stylesheets/basepack.css"
15
+
16
+ Netzke::Core.external_ext_css << "/extjs/examples/ux/gridfilters/css/RangeMenu"
17
+ Netzke::Core.external_ext_css << "/extjs/examples/ux/gridfilters/css/GridFilters"
15
18
  end
16
19
 
17
20
  # Use it to confirure Basepack in the initializers, e.g.:
18
21
  #
19
22
  # Netzke::Basepack.setup do |config|
20
- # config.icons_uri = "/images/famfamfam/icons"
23
+ # config.icons_uri = "/images/famfamfam/icons"
21
24
  # end
22
25
  def setup
23
26
  yield self