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
@@ -0,0 +1,356 @@
1
+ require 'active_record'
2
+ require 'meta_where'
3
+ require 'will_paginate'
4
+
5
+ module Netzke
6
+ module Basepack
7
+ class GridPanel < Netzke::Base
8
+ module Services
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+
13
+ endpoint :get_data do |*args|
14
+ params = args.first || {} # params are optional
15
+ if !config[:prohibit_read]
16
+ records = get_records(params)
17
+ {:data => records.map{|r| r.to_array(columns)}, :total => config[:enable_pagination] && records.total_entries}
18
+ else
19
+ flash :error => "You don't have permissions to read data"
20
+ {:feedback => @flash}
21
+ end
22
+ end
23
+
24
+ endpoint :post_data do |params|
25
+ mod_records = {}
26
+ [:create, :update].each do |operation|
27
+ data = ActiveSupport::JSON.decode(params["#{operation}d_records"]) if params["#{operation}d_records"]
28
+ if !data.nil? && !data.empty? # data may be nil for one of the operations
29
+ mod_records[operation] = process_data(data, operation)
30
+ mod_records[operation] = nil if mod_records[operation].empty?
31
+ end
32
+ end
33
+
34
+ on_data_changed
35
+
36
+ {
37
+ :update_new_records => mod_records[:create],
38
+ :update_mod_records => mod_records[:update] || {},
39
+ :feedback => @flash
40
+ }
41
+ end
42
+
43
+ endpoint :delete_data do |params|
44
+ if !config[:prohibit_delete]
45
+ record_ids = ActiveSupport::JSON.decode(params[:records])
46
+ data_class.destroy(record_ids)
47
+ on_data_changed
48
+ {:feedback => "Deleted #{record_ids.size} record(s)", :load_store_data => get_data}
49
+ else
50
+ {:feedback => "You don't have permissions to delete data"}
51
+ end
52
+ end
53
+
54
+ endpoint :resize_column do |params|
55
+ raise "Called api_resize_column while not configured to do so" if config[:enable_column_resize] == false
56
+ columns[normalize_index(params[:index].to_i)][:width] = params[:size].to_i
57
+ save_columns!
58
+ {}
59
+ end
60
+
61
+ endpoint :move_column do |params|
62
+ raise "Called api_move_column while not configured to do so" if config[:enable_column_move] == false
63
+ remove_from = normalize_index(params[:old_index].to_i)
64
+ insert_to = normalize_index(params[:new_index].to_i)
65
+ column_to_move = columns.delete_at(remove_from)
66
+ columns.insert(insert_to, column_to_move)
67
+ save_columns!
68
+
69
+ # reorder the columns on the client side (still not sure if it's not an overkill)
70
+ # {:reorder_columns => columns.map(&:name)} # Well, I think it IS an overkill - commented out
71
+ # until proven to be necessary
72
+ {}
73
+ end
74
+
75
+ endpoint :hide_column do |params|
76
+ raise "Called api_hide_column while not configured to do so" if config[:enable_column_hide] == false
77
+ columns[normalize_index(params[:index].to_i)][:hidden] = params[:hidden].to_b
78
+ save_columns!
79
+ {}
80
+ end
81
+
82
+ # Returns choices for a column
83
+ endpoint :get_combobox_options do |params|
84
+ query = params[:query]
85
+
86
+ column = columns.detect{ |c| c[:name] == params[:column] }
87
+ scope = column.to_options[:scope]
88
+ query = params[:query]
89
+
90
+ {:data => combobox_options_for_column(column, :query => query, :scope => scope, :record_id => params[:id])}
91
+ end
92
+
93
+ endpoint :move_rows do |params|
94
+ if defined?(ActsAsList) && data_class.ancestors.include?(ActsAsList::InstanceMethods)
95
+ ids = JSON.parse(params[:ids]).reverse
96
+ ids.each_with_index do |id, i|
97
+ r = data_class.find(id)
98
+ r.insert_at(params[:new_index].to_i + i + 1)
99
+ end
100
+ on_data_changed
101
+ else
102
+ raise RuntimeError, "Data class should 'acts_as_list' to support moving rows"
103
+ end
104
+ {}
105
+ end
106
+
107
+ end
108
+ #
109
+ # Some components' overridden API
110
+ #
111
+
112
+ ## Edit in form specific API
113
+ def add_form__form_panel0__netzke_submit(params)
114
+ res = component_instance(:add_form__form_panel0).netzke_submit(params)
115
+
116
+ if res[:set_form_values]
117
+ # successful creation
118
+ on_data_changed
119
+ res[:set_form_values] = nil
120
+ end
121
+ res.to_nifty_json
122
+ end
123
+
124
+ def edit_form__form_panel0__netzke_submit(params)
125
+ res = component_instance(:edit_form__form_panel0).netzke_submit(params)
126
+
127
+ if res[:set_form_values]
128
+ on_data_changed
129
+ res[:set_form_values] = nil
130
+ end
131
+
132
+ res.to_nifty_json
133
+ end
134
+
135
+ def multi_edit_form__multi_edit_form0__netzke_submit(params)
136
+ ids = ActiveSupport::JSON.decode(params.delete(:ids))
137
+ data = ids.collect{ |id| ActiveSupport::JSON.decode(params[:data]).merge("id" => id) }
138
+
139
+ data.map!{|el| el.delete_if{ |k,v| v.blank? }} # only interested in set values
140
+
141
+ mod_records_count = process_data(data, :update).count
142
+
143
+ # remove duplicated flash messages
144
+ @flash = @flash.inject([]){ |r,hsh| r.include?(hsh) ? r : r.push(hsh) }
145
+
146
+ if mod_records_count > 0
147
+ on_data_changed
148
+ flash :notice => "Updated #{mod_records_count} records."
149
+ {:set_result => "ok", :feedback => @flash}.to_nifty_json
150
+ else
151
+ {:feedback => @flash}.to_nifty_json
152
+ end
153
+ end
154
+
155
+ # When providing the edit_form component, fill in the form with the requested record
156
+ def deliver_component(params)
157
+ components[:edit_form][:items].first.merge!(:record_id => params[:record_id].to_i) if params[:name] == 'edit_form'
158
+ super
159
+ end
160
+
161
+ protected
162
+
163
+ def get_records(params)
164
+
165
+ # Restore params from component_session if requested
166
+ if params[:with_last_params]
167
+ params = component_session[:last_params]
168
+ else
169
+ # remember the last params
170
+ component_session[:last_params] = params
171
+ end
172
+
173
+ # build initial relation based on passed params
174
+ relation = get_relation(params)
175
+
176
+ # addressing the n+1 query problem
177
+ columns.each do |c|
178
+ assoc, method = c[:name].split('__')
179
+ relation = relation.includes(assoc.to_sym) if method
180
+ end
181
+
182
+ # apply sorting if needed
183
+ if params[:sort]
184
+ assoc, method = params[:sort].split('__')
185
+ dir = params[:dir].downcase
186
+
187
+ # if a sorting scope is set, call the scope with the given direction
188
+ column = columns.detect { |c| c[:name] == params[:sort] }
189
+ if column.has_key?(:sorting_scope)
190
+ relation = relation.send(column[:sorting_scope].to_sym, dir.to_sym)
191
+ else
192
+ relation = if method.nil?
193
+ relation.order(assoc.to_sym.send(dir))
194
+ else
195
+ assoc = data_class.reflect_on_association(assoc.to_sym)
196
+ relation.order(assoc.klass.table_name.to_sym => method.to_sym.send(dir)).joins(assoc.name)
197
+ end
198
+ end
199
+ end
200
+
201
+ # apply pagination if needed
202
+ if config[:enable_pagination]
203
+ per_page = config[:rows_per_page]
204
+ page = params[:limit] ? params[:start].to_i/params[:limit].to_i + 1 : 1
205
+ relation.paginate(:per_page => per_page, :page => page)
206
+ else
207
+ relation.all
208
+ end
209
+ end
210
+
211
+ # An ActiveRecord::Relation instance encapsulating all the necessary conditions
212
+ def get_relation(params)
213
+ # make params coming from Ext grid filters understandable by meta_where
214
+ conditions = params[:filter] && convert_filters(params[:filter]) || {}
215
+
216
+ relation = data_class.where(conditions)
217
+
218
+ if params[:extra_conditions]
219
+ extra_conditions = normalize_extra_conditions(ActiveSupport::JSON.decode(params[:extra_conditions]))
220
+ relation = relation.extend_with_netzke_conditions(extra_conditions) if params[:extra_conditions]
221
+ end
222
+
223
+ relation = relation.extend_with(config[:scope]) if config[:scope]
224
+
225
+ relation
226
+ end
227
+
228
+ # Override this method to react on each operation that caused changing of data
229
+ def on_data_changed; end
230
+
231
+ # Given an index of a column among enabled (non-excluded) columns, provides the index (position) in the table
232
+ def normalize_index(index)
233
+ norm_index = 0
234
+ index.times do
235
+ while true do
236
+ norm_index += 1
237
+ break unless columns[norm_index][:included] == false
238
+ end
239
+ end
240
+ norm_index
241
+ end
242
+
243
+ # Params:
244
+ # <tt>:operation</tt>: :update or :create
245
+ def process_data(data, operation)
246
+ success = true
247
+ # mod_record_ids = []
248
+ mod_records = {}
249
+ if !config[:"prohibit_#{operation}"]
250
+ modified_records = 0
251
+ data.each do |record_hash|
252
+ id = record_hash.delete('id')
253
+ record = operation == :create ? data_class.new : data_class.find(id)
254
+ success = true
255
+
256
+ # merge with strong default attirbutes
257
+ record_hash.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
258
+
259
+ # process all attirubutes for this record
260
+ record_hash.each_pair do |k,v|
261
+ begin
262
+ record.send("#{k}=",v)
263
+ rescue ArgumentError => exc
264
+ flash :error => exc.message
265
+ success = false
266
+ break
267
+ end
268
+ end
269
+
270
+ # try to save
271
+ # modified_records += 1 if success && record.save
272
+ mod_records[id] = record.to_array(columns) if success && record.save
273
+ # mod_record_ids << id if success && record.save
274
+
275
+ # flash eventual errors
276
+ if !record.errors.empty?
277
+ success = false
278
+ record.errors.to_a.each do |msg|
279
+ flash :error => msg
280
+ end
281
+ end
282
+ end
283
+ # flash :notice => "#{operation.to_s.capitalize}d #{modified_records} record(s)"
284
+ else
285
+ success = false
286
+ flash :error => "You don't have permissions to #{operation} data"
287
+ end
288
+ mod_records
289
+ end
290
+
291
+ # Converts Ext.ux.grid.GridFilters filters to searchlogic conditions, e.g.
292
+ # {"0" => {
293
+ # "data" => {
294
+ # "type" => "numeric",
295
+ # "comparison" => "gt",
296
+ # "value" => 10 },
297
+ # "field" => "id"
298
+ # },
299
+ # "1" => {
300
+ # "data" => {
301
+ # "type" => "string",
302
+ # "value" => "pizza"
303
+ # },
304
+ # "field" => "food_name"
305
+ # }}
306
+ #
307
+ # =>
308
+ #
309
+ # metawhere: :id.gt => 100, :food_name.matches => '%pizza%'
310
+ def convert_filters(column_filter)
311
+ res = {}
312
+ column_filter.each_pair do |k,v|
313
+ assoc, method = v["field"].split('__')
314
+ if method
315
+ assoc = data_class.reflect_on_association(assoc.to_sym)
316
+ field = [assoc.klass.table_name, method].join('.').to_sym
317
+ else
318
+ field = assoc.to_sym
319
+ end
320
+
321
+ value = v["data"]["value"]
322
+ case v["data"]["type"]
323
+ when "string"
324
+ field = field.send :matches
325
+ value = "%#{value}%"
326
+ when "numeric", "date"
327
+ field = field.send :"#{v['data']['comparison']}"
328
+ end
329
+ res.merge!({field => value})
330
+ end
331
+ res
332
+ end
333
+
334
+ def normalize_extra_conditions(conditions)
335
+ conditions.each_pair do |k,v|
336
+ conditions[k] = "%#{v}%" if ["like", "matches"].include?(k.to_s.split("__").last)
337
+ end
338
+ end
339
+
340
+ # def check_for_positive_result(res)
341
+ # if res[:set_form_values]
342
+ # # successful creation
343
+ # res[:set_form_values] = nil
344
+ # res.merge!({
345
+ # :parent => {:on_successfull_edit => true}
346
+ # })
347
+ # true
348
+ # else
349
+ # false
350
+ # end
351
+ # end
352
+
353
+ end
354
+ end
355
+ end
356
+ end
@@ -0,0 +1,11 @@
1
+ module Netzke
2
+ module Basepack
3
+ class Panel < Netzke::Base
4
+ js_method :update_body_html, <<-JS
5
+ function(html){
6
+ this.body.update(html);
7
+ }
8
+ JS
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,59 @@
1
+ module Netzke
2
+ module Basepack
3
+ class SearchPanel < FormPanel
4
+
5
+ js_properties :header => false,
6
+ :bbar => false
7
+
8
+ # An override
9
+ def normalize_field(f)
10
+ f = if f.is_a?(Symbol) || f.is_a?(String)
11
+ {:name => f.to_s, :operator => default_operator}
12
+ else
13
+ search_condition = f[:name]
14
+ if search_condition.is_a?(MetaWhere::Column)
15
+ {:name => search_condition.column, :operator => search_condition.method}
16
+ else
17
+ {:name => search_condition.to_s}
18
+ end
19
+ end
20
+
21
+ f = super(f)
22
+
23
+ f[:disabled] = primary_key_attr?(f)
24
+
25
+ # Association field
26
+ if f[:name].to_s.index("__")
27
+ f[:xtype] ||= xtype_for_attr_type(:string)
28
+ f[:attr_type] = :string
29
+ end
30
+
31
+ f[:operator] ||= "gt" if [:datetime, :integer, :date].include?(f[:attr_type])
32
+ f[:operator] ||= "eq" if f[:attr_type] == :boolean
33
+ f[:operator] ||= default_operator
34
+
35
+ f[:field_label] = [f[:field_label], f[:operator]].join(" ")
36
+ f.merge(:name => [f[:name], f[:operator]].join("__"))
37
+ end
38
+
39
+ private
40
+ def default_operator
41
+ "like"
42
+ end
43
+
44
+ # we need to correct the queries to cut off the condition suffixes, otherwise the FormPanel gets confused
45
+ def get_combobox_options(params)
46
+ column_name = params[:column]
47
+ CONDITIONS.each { |c| column_name.sub!(/_#{c}$/, "") }
48
+ super(:column => column_name)
49
+ end
50
+
51
+ def attr_type_to_xtype_map
52
+ super.merge({
53
+ :boolean => :tricheckbox
54
+ })
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,32 @@
1
+ module Netzke
2
+ module Basepack
3
+ # = TabPanel
4
+ #
5
+ # Features:
6
+ # * Dynamically loads components for the tabs that get activated for the first time
7
+ # * Is loaded along with the active component - saves a request to the server
8
+ # * (TODO) Provides the method markTabsOutdated to mark all inactive tabs as 'outdated', and calls "update" method on components in tabs when they get activated
9
+ # * (TODO) Stores the last active tab in persistent_config
10
+ #
11
+ # ToDo:
12
+ # * Introduce a second or two delay before informing the server about a tab switched
13
+ class TabPanel < Netzke::Base
14
+
15
+ include WrapLazyLoaded
16
+
17
+ js_base_class "Ext.TabPanel"
18
+
19
+ js_method :init_component, <<-JS
20
+ function(params){
21
+ #{js_full_class_name}.superclass.initComponent.call(this);
22
+ this.on('tabchange', function(self, i){
23
+ if (i.wrappedComponent && !i.items.first()) {
24
+ this.loadComponent({name: i.wrappedComponent, container: i.id});
25
+ }
26
+ }, this);
27
+ }
28
+ JS
29
+
30
+ end
31
+ end
32
+ end