netzke-basepack 0.5.14 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. data/.gitignore +3 -2
  2. data/CHANGELOG.rdoc +15 -0
  3. data/README.rdoc +45 -50
  4. data/Rakefile +8 -8
  5. data/TODO.rdoc +1 -6
  6. data/app/components/netzke/basepack/accordion_panel.rb +37 -0
  7. data/app/components/netzke/basepack/basic_app.rb +267 -0
  8. data/{lib/netzke → app/components/netzke/basepack}/basic_app/statusbar_ext.js +0 -0
  9. data/app/components/netzke/basepack/border_layout_panel.rb +39 -0
  10. data/app/components/netzke/basepack/form_panel.rb +102 -0
  11. data/app/components/netzke/basepack/form_panel/fields.rb +206 -0
  12. data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/netzkefileupload.js +0 -0
  13. data/app/components/netzke/basepack/form_panel/javascripts/pre.js +76 -0
  14. data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/xcheckbox.js +0 -0
  15. data/app/components/netzke/basepack/form_panel/services.rb +99 -0
  16. data/app/components/netzke/basepack/grid_panel.rb +374 -0
  17. data/app/components/netzke/basepack/grid_panel/columns.rb +233 -0
  18. data/app/components/netzke/basepack/grid_panel/javascript.rb +69 -0
  19. data/app/components/netzke/basepack/grid_panel/javascripts/advanced_search.js +96 -0
  20. data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/edit_in_form.js +5 -4
  21. data/{lib/netzke/grid_panel/javascripts/grid_panel_pre.js → app/components/netzke/basepack/grid_panel/javascripts/pre.js} +17 -37
  22. data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/rows-dd.js +0 -0
  23. data/app/components/netzke/basepack/grid_panel/multi_edit_form.rb +16 -0
  24. data/app/components/netzke/basepack/grid_panel/record_form_window.rb +36 -0
  25. data/app/components/netzke/basepack/grid_panel/search_window.rb +56 -0
  26. data/app/components/netzke/basepack/grid_panel/services.rb +356 -0
  27. data/app/components/netzke/basepack/panel.rb +11 -0
  28. data/app/components/netzke/basepack/search_panel.rb +59 -0
  29. data/app/components/netzke/basepack/tab_panel.rb +32 -0
  30. data/app/components/netzke/basepack/window.rb +73 -0
  31. data/app/components/netzke/basepack/wrapper.rb +28 -0
  32. data/{lib/app → app}/models/netzke_field_list.rb +1 -1
  33. data/{lib/app → app}/models/netzke_model_attr_list.rb +0 -0
  34. data/{lib/app → app}/models/netzke_persistent_array_auto_model.rb +0 -0
  35. data/config/database.yml +35 -0
  36. data/features/accordion_panel.feature +15 -0
  37. data/features/basic_app.feature +12 -0
  38. data/features/form_panel.feature +40 -0
  39. data/features/grid_panel.feature +62 -0
  40. data/features/search_in_grid.feature +35 -0
  41. data/features/simple_panel.feature +15 -0
  42. data/features/step_definitions/accordion_steps.rb +9 -0
  43. data/features/step_definitions/generic_steps.rb +15 -0
  44. data/features/step_definitions/grid_panel_steps.rb +26 -0
  45. data/features/step_definitions/pickle_steps.rb +100 -0
  46. data/features/step_definitions/web_steps.rb +219 -0
  47. data/features/support/env.rb +66 -0
  48. data/features/support/paths.rb +59 -0
  49. data/features/support/pickle.rb +25 -0
  50. data/features/tab_panel.feature +15 -0
  51. data/features/window.feature +11 -0
  52. data/from_05_to_06.rdoc +2 -0
  53. data/javascripts/basepack.js +54 -2
  54. data/lib/netzke-basepack.rb +38 -25
  55. data/lib/netzke/active_record.rb +12 -4
  56. data/lib/netzke/active_record/attributes.rb +60 -5
  57. data/lib/netzke/active_record/combobox_options.rb +3 -2
  58. data/lib/netzke/active_record/relation_extensions.rb +35 -0
  59. data/lib/netzke/basepack.rb +27 -0
  60. data/lib/netzke/basepack/version.rb +11 -0
  61. data/lib/netzke/basepack/wrap_lazy_loaded.rb +26 -0
  62. data/lib/netzke/data_accessor.rb +60 -32
  63. data/lib/netzke/fields_configurator.rb +5 -9
  64. data/lib/netzke/masquerade_selector.rb +1 -1
  65. data/locale/en.yml +16 -0
  66. data/netzke-basepack.gemspec +298 -0
  67. data/spec/active_record/attributes_spec.rb +14 -0
  68. data/spec/active_record/relation_extensions_spec.rb +44 -0
  69. data/spec/components/form_panel_spec.rb +70 -0
  70. data/spec/components/grid_panel_spec.rb +10 -0
  71. data/spec/factories.rb +9 -0
  72. data/spec/spec_helper.rb +35 -0
  73. data/test/rails_app/.gitignore +4 -0
  74. data/test/rails_app/Gemfile +32 -0
  75. data/test/rails_app/Gemfile.lock +171 -0
  76. data/test/rails_app/README +256 -0
  77. data/test/rails_app/Rakefile +7 -0
  78. data/test/rails_app/app/components/generic_user_form.rb +12 -0
  79. data/test/rails_app/app/components/simple_accordion.rb +11 -0
  80. data/test/rails_app/app/components/simple_basic_app.rb +32 -0
  81. data/test/rails_app/app/components/simple_panel.rb +17 -0
  82. data/test/rails_app/app/components/simple_tab_panel.rb +11 -0
  83. data/test/rails_app/app/components/simple_wrapper.rb +7 -0
  84. data/test/rails_app/app/components/some_border_layout.rb +24 -0
  85. data/test/rails_app/app/components/some_search_panel.rb +34 -0
  86. data/test/rails_app/app/components/some_tab_panel.rb +15 -0
  87. data/test/rails_app/app/components/user_form.rb +21 -0
  88. data/test/rails_app/app/components/user_form_with_default_fields.rb +8 -0
  89. data/test/rails_app/app/components/user_grid.rb +4 -0
  90. data/test/rails_app/app/components/window_component_loader.rb +17 -0
  91. data/test/{app_root/app/controllers/application.rb → rails_app/app/controllers/application_controller.rb} +1 -0
  92. data/test/rails_app/app/controllers/components_controller.rb +6 -0
  93. data/test/rails_app/app/controllers/welcome_controller.rb +5 -0
  94. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  95. data/test/{app_root → rails_app}/app/models/role.rb +0 -0
  96. data/test/rails_app/app/models/user.rb +6 -0
  97. data/test/rails_app/app/presenters/forms/generic_user.rb +6 -0
  98. data/test/rails_app/app/views/layouts/application.html.erb +13 -0
  99. data/test/rails_app/config.ru +4 -0
  100. data/test/rails_app/config/application.rb +45 -0
  101. data/test/rails_app/config/boot.rb +13 -0
  102. data/test/rails_app/config/database.yml +35 -0
  103. data/test/rails_app/config/environment.rb +6 -0
  104. data/test/rails_app/config/environments/development.rb +22 -0
  105. data/test/rails_app/config/environments/production.rb +49 -0
  106. data/test/rails_app/config/environments/test.rb +35 -0
  107. data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
  108. data/test/rails_app/config/initializers/inflections.rb +10 -0
  109. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  110. data/test/rails_app/config/initializers/netzke.rb +7 -0
  111. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  112. data/test/rails_app/config/initializers/session_store.rb +8 -0
  113. data/test/rails_app/config/locales/es.yml +12 -0
  114. data/test/rails_app/config/routes.rb +65 -0
  115. data/test/rails_app/db/development_structure.sql +39 -0
  116. data/test/{app_root/db/migrate/20081222035855_create_netzke_preferences.rb → rails_app/db/migrate/20100905214933_create_netzke_preferences.rb} +2 -4
  117. data/test/{app_root/db/migrate/20090423222114_create_users.rb → rails_app/db/migrate/20100914104207_create_users.rb} +4 -1
  118. data/test/{app_root/db/migrate/20090423214303_create_roles.rb → rails_app/db/migrate/20100914104236_create_roles.rb} +2 -0
  119. data/test/rails_app/db/schema.rb +38 -0
  120. data/test/rails_app/db/seeds.rb +20 -0
  121. data/test/rails_app/features/support/paths.rb +47 -0
  122. data/test/{app_root/config/environments/in_memory.rb → rails_app/lib/tasks/.gitkeep} +0 -0
  123. data/test/rails_app/public/404.html +26 -0
  124. data/test/rails_app/public/422.html +26 -0
  125. data/test/rails_app/public/500.html +26 -0
  126. data/test/{app_root/config/environments/mysql.rb → rails_app/public/favicon.ico} +0 -0
  127. data/test/rails_app/public/images/header-deco.gif +0 -0
  128. data/test/rails_app/public/images/rails.png +0 -0
  129. data/test/rails_app/public/javascripts/application.js +2 -0
  130. data/test/rails_app/public/javascripts/controls.js +965 -0
  131. data/test/rails_app/public/javascripts/dragdrop.js +974 -0
  132. data/test/rails_app/public/javascripts/effects.js +1123 -0
  133. data/test/rails_app/public/javascripts/prototype.js +6001 -0
  134. data/test/rails_app/public/javascripts/rails.js +175 -0
  135. data/test/rails_app/public/robots.txt +5 -0
  136. data/test/{app_root/config/environments/postgresql.rb → rails_app/public/stylesheets/.gitkeep} +0 -0
  137. data/test/rails_app/script/rails +6 -0
  138. data/test/rails_app/spec/models/role_spec.rb +5 -0
  139. data/test/rails_app/spec/models/user_spec.rb +5 -0
  140. data/test/rails_app/test/performance/browsing_test.rb +9 -0
  141. data/test/rails_app/test/test_helper.rb +13 -0
  142. data/test/{app_root/config/environments/sqlite.rb → rails_app/vendor/plugins/.gitkeep} +0 -0
  143. data/test/unit/accordion_panel_test.rb +3 -3
  144. data/test/unit/active_record_basepack_test.rb +4 -4
  145. data/test/unit/tab_panel_test.rb +4 -4
  146. metadata +199 -119
  147. data/lib/netzke/accordion_panel.rb +0 -115
  148. data/lib/netzke/active_record/data_accessor.rb +0 -25
  149. data/lib/netzke/attributes_configurator.rb +0 -195
  150. data/lib/netzke/basic_app.rb +0 -368
  151. data/lib/netzke/border_layout_panel.rb +0 -130
  152. data/lib/netzke/configuration_panel.rb +0 -24
  153. data/lib/netzke/form_panel.rb +0 -138
  154. data/lib/netzke/form_panel/form_panel_api.rb +0 -81
  155. data/lib/netzke/form_panel/form_panel_fields.rb +0 -149
  156. data/lib/netzke/form_panel/form_panel_js.rb +0 -163
  157. data/lib/netzke/grid_panel.rb +0 -367
  158. data/lib/netzke/grid_panel/grid_panel_api.rb +0 -364
  159. data/lib/netzke/grid_panel/grid_panel_columns.rb +0 -232
  160. data/lib/netzke/grid_panel/grid_panel_js.rb +0 -73
  161. data/lib/netzke/grid_panel/javascripts/advanced_search.js +0 -65
  162. data/lib/netzke/grid_panel/multi_edit_form.rb +0 -14
  163. data/lib/netzke/grid_panel/record_form_window.rb +0 -50
  164. data/lib/netzke/panel.rb +0 -11
  165. data/lib/netzke/plugins/configuration_tool.rb +0 -121
  166. data/lib/netzke/property_editor.rb +0 -111
  167. data/lib/netzke/property_editor/helper_model.rb +0 -122
  168. data/lib/netzke/search_panel.rb +0 -199
  169. data/lib/netzke/tab_panel.rb +0 -174
  170. data/lib/netzke/table_editor.rb +0 -118
  171. data/lib/netzke/tree_panel.rb +0 -25
  172. data/lib/netzke/window.rb +0 -82
  173. data/lib/netzke/wrapper.rb +0 -42
  174. data/test/app_root/app/models/book.rb +0 -9
  175. data/test/app_root/app/models/category.rb +0 -2
  176. data/test/app_root/app/models/city.rb +0 -3
  177. data/test/app_root/app/models/continent.rb +0 -2
  178. data/test/app_root/app/models/country.rb +0 -3
  179. data/test/app_root/app/models/genre.rb +0 -3
  180. data/test/app_root/app/models/user.rb +0 -3
  181. data/test/app_root/config/boot.rb +0 -114
  182. data/test/app_root/config/database.yml +0 -21
  183. data/test/app_root/config/environment.rb +0 -14
  184. data/test/app_root/config/environments/sqlite3.rb +0 -0
  185. data/test/app_root/config/routes.rb +0 -4
  186. data/test/app_root/db/migrate/20081222033343_create_books.rb +0 -15
  187. data/test/app_root/db/migrate/20081222033440_create_genres.rb +0 -15
  188. data/test/app_root/db/migrate/20081223024935_create_categories.rb +0 -13
  189. data/test/app_root/db/migrate/20081223025635_create_countries.rb +0 -14
  190. data/test/app_root/db/migrate/20081223025653_create_continents.rb +0 -13
  191. data/test/app_root/db/migrate/20081223025732_create_cities.rb +0 -15
  192. data/test/app_root/db/migrate/20090102223630_create_netzke_field_lists.rb +0 -18
  193. data/test/app_root/script/console +0 -7
  194. data/test/app_root/vendor/plugins/acts_as_list/README +0 -23
  195. data/test/app_root/vendor/plugins/acts_as_list/init.rb +0 -3
  196. data/test/app_root/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +0 -256
@@ -1,364 +0,0 @@
1
- require 'active_record'
2
- require 'searchlogic'
3
- require 'will_paginate'
4
-
5
- module Netzke
6
- class GridPanel < Base
7
- module GridPanelApi
8
-
9
- #
10
- # Grid's native API
11
- #
12
-
13
- def get_data(params = {})
14
- if !ext_config[:prohibit_read]
15
- records = get_records(params)
16
- {:data => records.map{|r| r.to_array(columns, self)}, :total => ext_config[:enable_pagination] && records.total_entries}
17
- else
18
- flash :error => "You don't have permissions to read data"
19
- {:feedback => @flash}
20
- end
21
- end
22
-
23
- def post_data(params)
24
- mod_records = {}
25
- [:create, :update].each do |operation|
26
- data = ActiveSupport::JSON.decode(params["#{operation}d_records"]) if params["#{operation}d_records"]
27
- if !data.nil? && !data.empty? # data may be nil for one of the operations
28
- mod_records[operation] = process_data(data, operation)
29
- mod_records[operation] = nil if mod_records[operation].empty?
30
- end
31
- end
32
-
33
- on_data_changed
34
-
35
- {
36
- :update_new_records => mod_records[:create],
37
- :update_mod_records => mod_records[:update] || {},
38
- :feedback => @flash
39
- }
40
- end
41
-
42
- def delete_data(params)
43
- if !ext_config[:prohibit_delete]
44
- record_ids = ActiveSupport::JSON.decode(params[:records])
45
- data_class.destroy(record_ids)
46
- on_data_changed
47
- {:feedback => "Deleted #{record_ids.size} record(s)", :load_store_data => get_data}
48
- else
49
- {:feedback => "You don't have permissions to delete data"}
50
- end
51
- end
52
-
53
- def resize_column(params)
54
- raise "Called api_resize_column while not configured to do so" if ext_config[:enable_column_resize] == false
55
- columns[normalize_index(params[:index].to_i)][:width] = params[:size].to_i
56
- save_columns!
57
- {}
58
- end
59
-
60
- def move_column(params)
61
- raise "Called api_move_column while not configured to do so" if ext_config[:enable_column_move] == false
62
- remove_from = normalize_index(params[:old_index].to_i)
63
- insert_to = normalize_index(params[:new_index].to_i)
64
- column_to_move = columns.delete_at(remove_from)
65
- columns.insert(insert_to, column_to_move)
66
- save_columns!
67
-
68
- # reorder the columns on the client side (still not sure if it's not an overkill)
69
- # {:reorder_columns => columns.map(&:name)} # Well, I think it IS an overkill - commented out
70
- # until proven to be necessary
71
- {}
72
- end
73
-
74
- def hide_column(params)
75
- raise "Called api_hide_column while not configured to do so" if ext_config[:enable_column_hide] == false
76
- columns[normalize_index(params[:index].to_i)][:hidden] = params[:hidden].to_b
77
- save_columns!
78
- {}
79
- end
80
-
81
- # Returns choices for a column
82
- def get_combobox_options_DELETME(params)
83
- column = params[:column]
84
- query = params[:query]
85
- {:data => data_class.options_for(column, query).map{|s| [s]}}
86
- # {:data => data_class.options_for(column, query).map{|s| [s]}}
87
- end
88
-
89
- # Returns choices for a column
90
- def get_combobox_options(params)
91
- column = columns.detect{ |c| c[:name] == params[:column] }.try(:to_options!)
92
- scopes = (column[:editor].is_a?(Hash) && column[:editor] || {}).to_options[:scopes]
93
- query = params[:query]
94
-
95
- {:data => combobox_options_for_column(column, :query => query, :scopes => scopes)}
96
- end
97
-
98
- def move_rows(params)
99
- if defined?(ActsAsList) && data_class.ancestors.include?(ActsAsList::InstanceMethods)
100
- ids = JSON.parse(params[:ids]).reverse
101
- ids.each_with_index do |id, i|
102
- r = data_class.find(id)
103
- r.insert_at(params[:new_index].to_i + i + 1)
104
- end
105
- on_data_changed
106
- else
107
- raise RuntimeError, "Data class should 'acts_as_list' to support moving rows"
108
- end
109
- {}
110
- end
111
-
112
- #
113
- # Some aggregatees' overridden API
114
- #
115
-
116
- ## Edit in form specific API
117
- def add_form__item__netzke_submit(params)
118
- res = aggregatee_instance(:add_form__item).netzke_submit(params)
119
-
120
- if res[:set_form_values]
121
- # successful creation
122
- on_data_changed
123
- res[:set_form_values] = nil
124
- end
125
- res.to_nifty_json
126
- end
127
-
128
- def edit_form__item__netzke_submit(params)
129
- res = aggregatee_instance(:edit_form__item).netzke_submit(params)
130
-
131
- if res[:set_form_values]
132
- on_data_changed
133
- res[:set_form_values] = nil
134
- end
135
-
136
- res.to_nifty_json
137
- end
138
-
139
- def multi_edit_form__item__netzke_submit(params)
140
- ids = ActiveSupport::JSON.decode(params.delete(:ids))
141
- data = ids.collect{ |id| ActiveSupport::JSON.decode(params[:data]).merge("id" => id) }
142
-
143
- mod_records_count = process_data(data, :update).count
144
-
145
- # remove duplicated flash messages
146
- @flash = @flash.inject([]){ |r,hsh| r.include?(hsh) ? r : r.push(hsh) }
147
-
148
- if mod_records_count > 0
149
- on_data_changed
150
- flash :notice => "Updated #{mod_records_count} records."
151
- {:set_result => "ok", :feedback => @flash}.to_nifty_json
152
- else
153
- {:feedback => @flash}.to_nifty_json
154
- end
155
- end
156
-
157
- protected
158
- # Override this method to react on each operation that caused changing of data
159
- def on_data_changed; end
160
-
161
- # Given an index of a column among enabled (non-excluded) columns, provides the index (position) in the table
162
- def normalize_index(index)
163
- norm_index = 0
164
- index.times do
165
- while true do
166
- norm_index += 1
167
- break unless columns[norm_index][:included] == false
168
- end
169
- end
170
- norm_index
171
- end
172
-
173
- # Returns searchlogic's search with all the conditions
174
- def get_search(params)
175
- @search ||= begin
176
- # make params coming from Ext grid filters understandable by searchlogic
177
- search_params = normalize_params(params)
178
-
179
- # merge with conditions coming from the config
180
- search_params[:conditions].deep_merge!(config[:conditions] || {})
181
-
182
- # merge with extra conditions (in searchlogic format, come from the extended search form)
183
- search_params[:conditions].deep_merge!(
184
- normalize_extra_conditions(ActiveSupport::JSON.decode(params[:extra_conditions]))
185
- ) if params[:extra_conditions]
186
-
187
- search = data_class.searchlogic(search_params)
188
-
189
- # applying scopes
190
- scopes.each do |s|
191
- if s.is_a?(Array)
192
- scope_name, *args = s
193
- search.send(scope_name, *args)
194
- else
195
- search.send(s, true)
196
- end
197
- end
198
-
199
- search
200
- end
201
- end
202
-
203
- # Params:
204
- # <tt>:operation</tt>: :update or :create
205
- def process_data(data, operation)
206
- success = true
207
- # mod_record_ids = []
208
- mod_records = {}
209
- if !ext_config[:"prohibit_#{operation}"]
210
- modified_records = 0
211
- data.each do |record_hash|
212
- id = record_hash.delete('id')
213
- record = operation == :create ? data_class.new : data_class.find(id)
214
- success = true
215
-
216
- # merge with strong default attirbutes
217
- record_hash.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
218
-
219
- # process all attirubutes for this record
220
- record_hash.each_pair do |k,v|
221
- begin
222
- record.send("#{k}=",v)
223
- rescue ArgumentError => exc
224
- flash :error => exc.message
225
- success = false
226
- break
227
- end
228
- end
229
-
230
- # try to save
231
- # modified_records += 1 if success && record.save
232
- mod_records[id] = record.to_array(columns, self) if success && record.save
233
- # mod_record_ids << id if success && record.save
234
-
235
- # flash eventual errors
236
- if !record.errors.empty?
237
- success = false
238
- record.errors.each_full do |msg|
239
- flash :error => msg
240
- end
241
- end
242
- end
243
- # flash :notice => "#{operation.to_s.capitalize}d #{modified_records} record(s)"
244
- else
245
- success = false
246
- flash :error => "You don't have permissions to #{operation} data"
247
- end
248
- mod_records
249
- end
250
-
251
- # get records
252
- def get_records(params)
253
- # Restore params from widget_session if requested
254
- if params[:with_last_params]
255
- params = widget_session[:last_params]
256
- else
257
- # remember the last params
258
- widget_session[:last_params] = params
259
- end
260
-
261
- search = get_search(params)
262
-
263
- # sorting
264
- if params[:sort]
265
- assoc, method = params[:sort].split('__')
266
- sort_string = method.nil? ? assoc : "#{assoc}_#{method}"
267
- sort_string = (params[:dir] == "ASC" ? "ascend_by_" : "descend_by_") + sort_string
268
- search.order(sort_string)
269
- end
270
-
271
- # pagination
272
- if ext_config[:enable_pagination]
273
- per_page = ext_config[:rows_per_page]
274
- page = params[:limit] ? params[:start].to_i/params[:limit].to_i + 1 : 1
275
- search.paginate(:per_page => per_page, :page => page)
276
- else
277
- search.all
278
- end
279
- end
280
-
281
- # When providing the edit_form aggregatee, fill in the form with the requested record
282
- def load_aggregatee_with_cache(params)
283
- if params[:id] == 'editForm'
284
- aggregatees[:edit_form][:item].merge!(:record_id => params[:record_id])
285
- end
286
-
287
- super
288
- end
289
-
290
- # Search scopes, in searchlogic format
291
- def scopes
292
- @scopes ||= config[:scopes] || []
293
- end
294
-
295
- # Converts Ext.ux.grid.GridFilters filters to searchlogic conditions, e.g.
296
- # {"0" => {
297
- # "data" => {
298
- # "type" => "numeric",
299
- # "comparison" => "gt",
300
- # "value" => 10 },
301
- # "field" => "id"
302
- # },
303
- # "1" => {
304
- # "data" => {
305
- # "type" => "string",
306
- # "value" => "pizza"
307
- # },
308
- # "field" => "food_name"
309
- # }}
310
- #
311
- # =>
312
- #
313
- # {"id_gt" => 100, "food_name_contains" => "pizza"}
314
- def convert_filters(column_filter)
315
- res = {}
316
- column_filter.each_pair do |k,v|
317
- field = v["field"].dup
318
-
319
- case v["data"]["type"]
320
- when "string"
321
- field << "_contains"
322
- when "numeric", "date"
323
- field << "_#{v["data"]["comparison"]}"
324
- end
325
-
326
- value = v["data"]["value"]
327
- res.merge!({field => value})
328
- end
329
- res
330
- end
331
-
332
- def normalize_extra_conditions(conditions)
333
- conditions.deep_convert_keys{|k| k.to_s.gsub("__", "_").to_sym}
334
- end
335
-
336
- # make params understandable to searchlogic
337
- def normalize_params(params)
338
- # filters
339
- conditions = params[:filter] && convert_filters(params[:filter])
340
-
341
- normalized_conditions = {}
342
- conditions && conditions.each_pair do |k, v|
343
- normalized_conditions.merge!(k.gsub("__", "_") => v)
344
- end
345
-
346
- {:conditions => normalized_conditions}
347
- end
348
-
349
- # def check_for_positive_result(res)
350
- # if res[:set_form_values]
351
- # # successful creation
352
- # res[:set_form_values] = nil
353
- # res.merge!({
354
- # :parent => {:on_successfull_edit => true}
355
- # })
356
- # true
357
- # else
358
- # false
359
- # end
360
- # end
361
-
362
- end
363
- end
364
- end
@@ -1,232 +0,0 @@
1
- module Netzke
2
- class GridPanel < Base
3
- module GridPanelColumns
4
- module ClassMethods
5
- # Columns to be displayed by the FieldConfigurator, "meta-columns". Each corresponds to a configuration
6
- # option for each column in the grid.
7
- def meta_columns
8
- [
9
- # Whether the column will be present in the grid, also in :hidden or :meta state. The value for this column will
10
- # always be sent to/from the JS grid to the server
11
- {:name => "included", :attr_type => :boolean, :width => 40, :header => "Incl", :default_value => true},
12
-
13
- # The name of the column. May be any accessible method or attribute of the data_class.
14
- {:name => "name", :attr_type => :string, :width => 200},
15
-
16
- # The header for the column.
17
- {:name => "label", :attr_type => :string, :width => 200, :header => "Header"},
18
-
19
- # The default value of this column. Is used when a new row in the grid gets created.
20
- {:name => "default_value", :attr_type => :string, :width => 200},
21
-
22
- # Options for drop-downs
23
- {:name => "combobox_options", :attr_type => :string, :editor => :textarea, :width => 200},
24
-
25
- # Whether the column is editable in the grid.
26
- {:name => "read_only", :attr_type => :boolean, :header => "R/O", :tooltip => "Read-only"},
27
-
28
- # Whether the column will be in the hidden state (hide/show columns from the column menu, if it's enabled).
29
- {:name => "hidden", :attr_type => :boolean},
30
-
31
- # Whether the column should have "grid filters" enabled
32
- # (see here: http://www.extjs.com/deploy/dev/examples/grid-filtering/grid-filter-local.html)
33
- {:name => "with_filters", :attr_type => :boolean, :default_value => true, :header => "Filters"},
34
-
35
- #
36
- # Below some rarely used parameters, hidden by default (you can always un-hide them from the column menu).
37
- #
38
-
39
- # The column's width
40
- {:name => "width", :attr_type => :integer, :hidden => true},
41
-
42
- # Whether the column should be hideable
43
- {:name => "hideable", :attr_type => :boolean, :default_value => true, :hidden => true},
44
-
45
- # Whether the column should be sortable (why change it? normally it's hardcoded)
46
- {:name => "sortable", :attr_type => :boolean, :default_value => true, :hidden => true},
47
- ]
48
- end
49
-
50
- end
51
-
52
- # Normalized columns for the grid, e.g.:
53
- # [{:name => :id, :hidden => true, ...}, {:name => :name, :editable => false, ...}, ...]
54
- def columns(only_included = true)
55
- @columns ||= begin
56
- if cols = load_columns
57
- filter_out_excluded_columns(cols) if only_included
58
- reverse_merge_equally_named_columns(cols, initial_columns)
59
- cols
60
- else
61
- initial_columns(only_included)
62
- end
63
- end
64
- end
65
-
66
- # Columns that we fall back to when neither persistent columns, nor configured columns are present.
67
- # If there's a model-level field configuration, it's being used.
68
- # Otherwise the defaults straight from the ActiveRecord model ("netzke_attributes").
69
- # Override this method if you want to provide a fix set of columns in your subclass.
70
- def default_columns
71
- @default_columns ||= load_model_level_attrs || data_class.netzke_attributes
72
- end
73
-
74
- # Columns that represent a smart merge of default_columns and columns passed during the configuration.
75
- def initial_columns(only_included = true)
76
- # Normalize here, as from the config we can get symbols (names) instead of hashes
77
- columns_from_config = config[:columns] && normalize_attr_config(config[:columns])
78
-
79
- if columns_from_config
80
- # reverse-merge each column hash from config with each column hash from exposed_attributes (columns from config have higher priority)
81
- for c in columns_from_config
82
- corresponding_default_column = default_columns.find{ |k| k[:name] == c[:name] }
83
- c.reverse_merge!(corresponding_default_column) if corresponding_default_column
84
- end
85
- columns_for_create = columns_from_config
86
- else
87
- # we didn't have columns configured in widget's config, so, use the columns from the data class
88
- columns_for_create = default_columns
89
- end
90
-
91
- filter_out_excluded_columns(columns_for_create) if only_included
92
-
93
- # Make the column config complete with the defaults
94
- columns_for_create.each do |c|
95
- detect_association(c)
96
- set_default_header(c)
97
- set_default_editor(c)
98
- set_default_width(c)
99
- set_default_hidden(c)
100
- set_default_editable(c)
101
- set_default_sortable(c)
102
- set_default_filterable(c)
103
- end
104
-
105
- columns_for_create
106
- end
107
-
108
- private
109
- def filter_out_excluded_columns(cols)
110
- cols.reject!{ |c| c[:included] == false }
111
- end
112
-
113
- # Stores modified columns in persistent storage
114
- def save_columns!
115
- NetzkeFieldList.update_list_for_current_authority(global_id, columns(false), original_data_class.name) if persistent_config_enabled?
116
- end
117
-
118
- def load_columns
119
- NetzkeFieldList.read_list(global_id) if persistent_config_enabled?
120
- end
121
-
122
- def load_model_level_attrs
123
- NetzkeModelAttrList.read_list(data_class.name) if persistent_config_enabled?
124
- end
125
-
126
- # whether a column is bound to the primary_key
127
- def reflects_primary_key?(c)
128
- c[:name] == data_class.primary_key
129
- end
130
-
131
- def set_default_header(c)
132
- c[:label] ||= c[:name].humanize
133
- end
134
-
135
- def set_default_editor(c)
136
- c[:editor] ||= editor_for_attr_type(c[:attr_type])
137
- c[:editor] = {:xtype => c[:editor]} if c[:editor].is_a?(Symbol)
138
- end
139
-
140
- def set_default_width(c)
141
- c[:width] ||= 50 if c[:attr_type] == :boolean
142
- c[:width] ||= 150 if c[:attr_type] == :datetime
143
- end
144
-
145
- def set_default_hidden(c)
146
- c[:hidden] = true if reflects_primary_key?(c) && c[:hidden].nil?
147
- end
148
-
149
- def set_default_editable(c)
150
- c[:editable] = c[:read_only].nil? ? !(reflects_primary_key?(c) || c[:virtual]) : !c[:read_only]
151
- c.delete(:read_only)
152
- end
153
-
154
- def set_default_sortable(c)
155
- c[:sortable] = !c[:virtual] if c[:sortable].nil?
156
- end
157
-
158
- def set_default_filterable(c)
159
- c[:filterable] = !c[:virtual] if c[:filterable].nil?
160
- end
161
-
162
- # Returns editor's xtype for a column type
163
- def editor_for_attr_type(type)
164
- attr_type_to_editor_map[type]
165
- end
166
-
167
- def editor_for_association
168
- :combobox
169
- end
170
-
171
- # Returns a hash that maps a column type to the editor xtype. Override if you want different editors.
172
- def attr_type_to_editor_map
173
- {
174
- :integer => :numberfield,
175
- :boolean => :checkbox,
176
- :date => :datefield,
177
- :datetime => :xdatetime,
178
- :text => :textarea,
179
- :string => :textfield
180
- }
181
- end
182
-
183
- # Detects an association column and sets up the proper editor.
184
- def detect_association(c)
185
- # double-underscore notation? surely an association column
186
- if c[:name].index('__')
187
- assoc_name, assoc_method = c[:name].split('__')
188
- assoc = data_class.reflect_on_association(assoc_name.to_sym)
189
-
190
- if assoc && assoc_method
191
- assoc_column = assoc.klass.columns_hash[assoc_method]
192
- assoc_method_type = assoc_column.try(:type)
193
-
194
- # if association column is boolean, display a checkbox (or alike), otherwise - a combobox (or alike)
195
- c[:editor] ||= assoc_method_type == :boolean ? editor_for_attr_type(:boolean) : editor_for_association
196
- end
197
- end
198
- end
199
-
200
- # Default fields that will be displayed in the Add/Edit/Search forms
201
- def default_fields_for_forms
202
- form_klass = "Netzke::ModelExtensions::#{config[:model]}ForFormPanel".constantize rescue nil
203
- form_klass ||= original_data_class
204
-
205
- # Select only those fields that are known to the form_klass
206
- selected_columns = columns.select do |c|
207
- form_klass.column_names.include?(c[:name]) ||
208
- form_klass.instance_methods.include?("#{c[:name]}=") ||
209
- association_attr?(c[:name])
210
- end
211
-
212
- selected_columns.map do |c|
213
- field_config = {:name => c[:name]}
214
-
215
- # scopes for combobox options
216
- field_config[:scopes] = c[:editor].is_a?(Hash) && c[:editor][:scopes]
217
-
218
- field_config
219
- end
220
- end
221
-
222
- # Receives 2 arrays of columns. Merges the missing config from the +source+ into +dest+, matching columns by name
223
- def reverse_merge_equally_named_columns(dest, source)
224
- dest.each{ |dc| dc.reverse_merge!(source.detect{ |sc| sc[:name] == dc[:name] } || {}) }
225
- end
226
-
227
- def self.included(receiver)
228
- receiver.extend ClassMethods
229
- end
230
- end
231
- end
232
- end