active_scaffold_san 3.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. data/.autotest +27 -0
  2. data/.document +5 -0
  3. data/CHANGELOG +179 -0
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +20 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README +69 -0
  8. data/Rakefile +53 -0
  9. data/active_scaffold_vho.gemspec +388 -0
  10. data/frontends/default/images/add.gif +0 -0
  11. data/frontends/default/images/arrow_down.gif +0 -0
  12. data/frontends/default/images/arrow_up.gif +0 -0
  13. data/frontends/default/images/close.gif +0 -0
  14. data/frontends/default/images/config.png +0 -0
  15. data/frontends/default/images/cross.png +0 -0
  16. data/frontends/default/images/gears.png +0 -0
  17. data/frontends/default/images/indicator-small.gif +0 -0
  18. data/frontends/default/images/indicator.gif +0 -0
  19. data/frontends/default/images/magnifier.png +0 -0
  20. data/frontends/default/javascripts/jquery/active_scaffold.js +1004 -0
  21. data/frontends/default/javascripts/jquery/jquery.editinplace.js +743 -0
  22. data/frontends/default/javascripts/prototype/active_scaffold.js +1003 -0
  23. data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
  24. data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
  25. data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
  26. data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
  27. data/frontends/default/stylesheets/stylesheet.css +973 -0
  28. data/frontends/default/views/_action_group.html.erb +20 -0
  29. data/frontends/default/views/_add_existing_form.html.erb +30 -0
  30. data/frontends/default/views/_base_form.html.erb +51 -0
  31. data/frontends/default/views/_create_form.html.erb +8 -0
  32. data/frontends/default/views/_create_form_on_list.html.erb +6 -0
  33. data/frontends/default/views/_field_search.html.erb +32 -0
  34. data/frontends/default/views/_form.html.erb +24 -0
  35. data/frontends/default/views/_form_association.html.erb +19 -0
  36. data/frontends/default/views/_form_association_footer.html.erb +40 -0
  37. data/frontends/default/views/_form_attribute.html.erb +15 -0
  38. data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
  39. data/frontends/default/views/_form_messages.html.erb +5 -0
  40. data/frontends/default/views/_horizontal_subform.html.erb +29 -0
  41. data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
  42. data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
  43. data/frontends/default/views/_human_conditions.html.erb +1 -0
  44. data/frontends/default/views/_list.html.erb +18 -0
  45. data/frontends/default/views/_list_actions.html.erb +15 -0
  46. data/frontends/default/views/_list_calculations.html.erb +16 -0
  47. data/frontends/default/views/_list_column_headings.html.erb +12 -0
  48. data/frontends/default/views/_list_header.html.erb +10 -0
  49. data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
  50. data/frontends/default/views/_list_messages.html.erb +32 -0
  51. data/frontends/default/views/_list_pagination.html.erb +11 -0
  52. data/frontends/default/views/_list_pagination_links.html.erb +9 -0
  53. data/frontends/default/views/_list_record.html.erb +14 -0
  54. data/frontends/default/views/_list_record_columns.html.erb +8 -0
  55. data/frontends/default/views/_list_with_header.html.erb +32 -0
  56. data/frontends/default/views/_messages.html.erb +10 -0
  57. data/frontends/default/views/_render_field.js.rjs +10 -0
  58. data/frontends/default/views/_row.html.erb +12 -0
  59. data/frontends/default/views/_search.html.erb +34 -0
  60. data/frontends/default/views/_search_attribute.html.erb +10 -0
  61. data/frontends/default/views/_show.html.erb +8 -0
  62. data/frontends/default/views/_show_columns.html.erb +15 -0
  63. data/frontends/default/views/_update_actions.html.erb +9 -0
  64. data/frontends/default/views/_update_form.html.erb +6 -0
  65. data/frontends/default/views/_vertical_subform.html.erb +12 -0
  66. data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
  67. data/frontends/default/views/action_confirmation.html.erb +13 -0
  68. data/frontends/default/views/add_existing.js.rjs +17 -0
  69. data/frontends/default/views/add_existing_form.html.erb +5 -0
  70. data/frontends/default/views/create.html.erb +5 -0
  71. data/frontends/default/views/delete.html.erb +13 -0
  72. data/frontends/default/views/destroy.js.rjs +23 -0
  73. data/frontends/default/views/edit_associated.js.rjs +11 -0
  74. data/frontends/default/views/field_search.html.erb +5 -0
  75. data/frontends/default/views/form_messages.js.rjs +1 -0
  76. data/frontends/default/views/list.html.erb +1 -0
  77. data/frontends/default/views/list.js.rjs +1 -0
  78. data/frontends/default/views/on_action_update.js.rjs +8 -0
  79. data/frontends/default/views/on_create.js.rjs +41 -0
  80. data/frontends/default/views/on_mark_all.js.rjs +4 -0
  81. data/frontends/default/views/on_update.js.rjs +28 -0
  82. data/frontends/default/views/search.html.erb +5 -0
  83. data/frontends/default/views/show.html.erb +5 -0
  84. data/frontends/default/views/update.html.erb +8 -0
  85. data/frontends/default/views/update_column.js.rjs +13 -0
  86. data/frontends/default/views/update_row.js.rjs +1 -0
  87. data/init.rb +8 -0
  88. data/lib/active_scaffold.rb +360 -0
  89. data/lib/active_scaffold/actions/common_search.rb +22 -0
  90. data/lib/active_scaffold/actions/core.rb +180 -0
  91. data/lib/active_scaffold/actions/create.rb +149 -0
  92. data/lib/active_scaffold/actions/delete.rb +75 -0
  93. data/lib/active_scaffold/actions/field_search.rb +82 -0
  94. data/lib/active_scaffold/actions/list.rb +184 -0
  95. data/lib/active_scaffold/actions/mark.rb +63 -0
  96. data/lib/active_scaffold/actions/nested.rb +250 -0
  97. data/lib/active_scaffold/actions/search.rb +47 -0
  98. data/lib/active_scaffold/actions/show.rb +61 -0
  99. data/lib/active_scaffold/actions/subform.rb +27 -0
  100. data/lib/active_scaffold/actions/update.rb +151 -0
  101. data/lib/active_scaffold/active_record_permissions.rb +134 -0
  102. data/lib/active_scaffold/attribute_params.rb +211 -0
  103. data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
  104. data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +39 -0
  105. data/lib/active_scaffold/bridges/bridge.rb +59 -0
  106. data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
  107. data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +83 -0
  108. data/lib/active_scaffold/bridges/cancan/bridge.rb +12 -0
  109. data/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb +107 -0
  110. data/lib/active_scaffold/bridges/carrierwave/bridge.rb +9 -0
  111. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +33 -0
  112. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +12 -0
  113. data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +45 -0
  114. data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
  115. data/lib/active_scaffold/bridges/date_picker/bridge.rb +24 -0
  116. data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
  117. data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
  118. data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
  119. data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
  120. data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
  121. data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
  122. data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
  123. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
  124. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
  125. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
  126. data/lib/active_scaffold/bridges/paperclip/bridge.rb +12 -0
  127. data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
  128. data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
  129. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
  130. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
  131. data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
  132. data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
  133. data/lib/active_scaffold/bridges/shared/date_bridge.rb +209 -0
  134. data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
  135. data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +61 -0
  136. data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
  137. data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
  138. data/lib/active_scaffold/config/base.rb +62 -0
  139. data/lib/active_scaffold/config/core.rb +220 -0
  140. data/lib/active_scaffold/config/create.rb +51 -0
  141. data/lib/active_scaffold/config/delete.rb +34 -0
  142. data/lib/active_scaffold/config/field_search.rb +75 -0
  143. data/lib/active_scaffold/config/form.rb +47 -0
  144. data/lib/active_scaffold/config/list.rb +174 -0
  145. data/lib/active_scaffold/config/mark.rb +22 -0
  146. data/lib/active_scaffold/config/nested.rb +44 -0
  147. data/lib/active_scaffold/config/search.rb +69 -0
  148. data/lib/active_scaffold/config/show.rb +35 -0
  149. data/lib/active_scaffold/config/subform.rb +35 -0
  150. data/lib/active_scaffold/config/update.rb +46 -0
  151. data/lib/active_scaffold/configurable.rb +29 -0
  152. data/lib/active_scaffold/constraints.rb +184 -0
  153. data/lib/active_scaffold/data_structures/action_columns.rb +137 -0
  154. data/lib/active_scaffold/data_structures/action_link.rb +175 -0
  155. data/lib/active_scaffold/data_structures/action_links.rb +185 -0
  156. data/lib/active_scaffold/data_structures/actions.rb +45 -0
  157. data/lib/active_scaffold/data_structures/column.rb +355 -0
  158. data/lib/active_scaffold/data_structures/columns.rb +75 -0
  159. data/lib/active_scaffold/data_structures/error_message.rb +24 -0
  160. data/lib/active_scaffold/data_structures/nested_info.rb +123 -0
  161. data/lib/active_scaffold/data_structures/set.rb +62 -0
  162. data/lib/active_scaffold/data_structures/sorting.rb +168 -0
  163. data/lib/active_scaffold/extensions/action_controller_rendering.rb +20 -0
  164. data/lib/active_scaffold/extensions/action_view_rendering.rb +123 -0
  165. data/lib/active_scaffold/extensions/action_view_resolver.rb +7 -0
  166. data/lib/active_scaffold/extensions/active_association_reflection.rb +13 -0
  167. data/lib/active_scaffold/extensions/active_record_offset.rb +12 -0
  168. data/lib/active_scaffold/extensions/array.rb +7 -0
  169. data/lib/active_scaffold/extensions/localize.rb +10 -0
  170. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +12 -0
  171. data/lib/active_scaffold/extensions/nil_id_in_url_params.rb +7 -0
  172. data/lib/active_scaffold/extensions/paginator_extensions.rb +26 -0
  173. data/lib/active_scaffold/extensions/reverse_associations.rb +62 -0
  174. data/lib/active_scaffold/extensions/routing_mapper.rb +34 -0
  175. data/lib/active_scaffold/extensions/to_label.rb +8 -0
  176. data/lib/active_scaffold/extensions/unsaved_associated.rb +61 -0
  177. data/lib/active_scaffold/extensions/unsaved_record.rb +20 -0
  178. data/lib/active_scaffold/extensions/usa_state.rb +46 -0
  179. data/lib/active_scaffold/finder.rb +343 -0
  180. data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
  181. data/lib/active_scaffold/helpers/controller_helpers.rb +87 -0
  182. data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
  183. data/lib/active_scaffold/helpers/form_column_helpers.rb +350 -0
  184. data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
  185. data/lib/active_scaffold/helpers/id_helpers.rb +127 -0
  186. data/lib/active_scaffold/helpers/list_column_helpers.rb +361 -0
  187. data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
  188. data/lib/active_scaffold/helpers/search_column_helpers.rb +249 -0
  189. data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
  190. data/lib/active_scaffold/helpers/view_helpers.rb +360 -0
  191. data/lib/active_scaffold/locale/de.rb +120 -0
  192. data/lib/active_scaffold/locale/en.rb +119 -0
  193. data/lib/active_scaffold/locale/es.yml +115 -0
  194. data/lib/active_scaffold/locale/fr.rb +122 -0
  195. data/lib/active_scaffold/locale/hu.yml +63 -0
  196. data/lib/active_scaffold/locale/ja.yml +64 -0
  197. data/lib/active_scaffold/locale/ru.yml +119 -0
  198. data/lib/active_scaffold/marked_model.rb +38 -0
  199. data/lib/active_scaffold/paginator.rb +136 -0
  200. data/lib/active_scaffold/responds_to_parent.rb +70 -0
  201. data/lib/active_scaffold/version.rb +9 -0
  202. data/lib/active_scaffold_assets.rb +45 -0
  203. data/lib/active_scaffold_env.rb +14 -0
  204. data/lib/active_scaffold_vho.rb +2 -0
  205. data/lib/generators/active_scaffold/USAGE +29 -0
  206. data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
  207. data/lib/generators/active_scaffold_controller/USAGE +19 -0
  208. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +29 -0
  209. data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
  210. data/lib/generators/active_scaffold_controller/templates/helper.rb +2 -0
  211. data/lib/generators/active_scaffold_setup/USAGE +10 -0
  212. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +61 -0
  213. data/public/blank.html +33 -0
  214. data/shoulda_macros/macros.rb +136 -0
  215. data/test/bridges/bridge_test.rb +47 -0
  216. data/test/config/base_test.rb +15 -0
  217. data/test/config/create_test.rb +55 -0
  218. data/test/config/list_test.rb +74 -0
  219. data/test/config/show_test.rb +43 -0
  220. data/test/config/update_test.rb +17 -0
  221. data/test/const_mocker.rb +36 -0
  222. data/test/data_structures/action_columns_test.rb +113 -0
  223. data/test/data_structures/action_link_test.rb +78 -0
  224. data/test/data_structures/action_links_test.rb +78 -0
  225. data/test/data_structures/actions_test.rb +25 -0
  226. data/test/data_structures/association_column_test.rb +42 -0
  227. data/test/data_structures/column_test.rb +185 -0
  228. data/test/data_structures/columns_test.rb +69 -0
  229. data/test/data_structures/error_message_test.rb +28 -0
  230. data/test/data_structures/set_test.rb +86 -0
  231. data/test/data_structures/sorting_test.rb +126 -0
  232. data/test/data_structures/standard_column_test.rb +24 -0
  233. data/test/data_structures/virtual_column_test.rb +23 -0
  234. data/test/extensions/active_record_test.rb +45 -0
  235. data/test/extensions/array_test.rb +12 -0
  236. data/test/helpers/form_column_helpers_test.rb +31 -0
  237. data/test/helpers/list_column_helpers_test.rb +31 -0
  238. data/test/helpers/pagination_helpers_test.rb +55 -0
  239. data/test/misc/active_record_permissions_test.rb +154 -0
  240. data/test/misc/attribute_params_test.rb +110 -0
  241. data/test/misc/configurable_test.rb +96 -0
  242. data/test/misc/constraints_test.rb +193 -0
  243. data/test/misc/finder_test.rb +93 -0
  244. data/test/misc/lang_test.rb +12 -0
  245. data/test/mock_app/.gitignore +2 -0
  246. data/test/mock_app/app/controllers/application_controller.rb +10 -0
  247. data/test/mock_app/app/helpers/application_helper.rb +3 -0
  248. data/test/mock_app/config/boot.rb +110 -0
  249. data/test/mock_app/config/database.yml +16 -0
  250. data/test/mock_app/config/environment.rb +43 -0
  251. data/test/mock_app/config/environments/development.rb +17 -0
  252. data/test/mock_app/config/environments/production.rb +28 -0
  253. data/test/mock_app/config/environments/test.rb +28 -0
  254. data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
  255. data/test/mock_app/config/initializers/inflections.rb +10 -0
  256. data/test/mock_app/config/initializers/mime_types.rb +5 -0
  257. data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
  258. data/test/mock_app/config/initializers/session_store.rb +15 -0
  259. data/test/mock_app/config/locales/en.yml +5 -0
  260. data/test/mock_app/config/routes.rb +43 -0
  261. data/test/mock_app/db/test.sqlite3 +1 -0
  262. data/test/mock_app/public/blank.html +33 -0
  263. data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
  264. data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
  265. data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
  266. data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
  267. data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
  268. data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
  269. data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
  270. data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
  271. data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
  272. data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
  273. data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
  274. data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
  275. data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
  276. data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
  277. data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
  278. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
  279. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +842 -0
  280. data/test/model_stub.rb +55 -0
  281. data/test/run_all.rb +8 -0
  282. data/test/test_helper.rb +39 -0
  283. data/uninstall.rb +13 -0
  284. metadata +497 -0
@@ -0,0 +1,55 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ module PaginationHelpers
4
+ def pagination_ajax_link(page_number, url_options, options)
5
+ link_to page_number, url_options.merge(:page => page_number), options.merge(:class => "as_paginate")
6
+ end
7
+
8
+ def pagination_ajax_links(current_page, url_options, options, window_size)
9
+ start_number = current_page.number - window_size
10
+ end_number = current_page.number + window_size
11
+ start_number = 1 if start_number <= 0
12
+ if current_page.pager.infinite?
13
+ offsets = [20, 100]
14
+ else
15
+ end_number = current_page.pager.last.number if end_number > current_page.pager.last.number
16
+ end
17
+
18
+ html = []
19
+ unless start_number == 1
20
+ last_page = 1
21
+ html << pagination_ajax_link(last_page, url_options, options)
22
+ if current_page.pager.infinite?
23
+ offsets.reverse.each do |offset|
24
+ page = current_page.number - offset
25
+ if page < start_number && page > 1
26
+ html << '..' if page > last_page + 1
27
+ html << pagination_ajax_link(page, params)
28
+ last_page = page
29
+ end
30
+ end
31
+ end
32
+ html << ".." if start_number > last_page + 1
33
+ end
34
+
35
+ start_number.upto(end_number) do |num|
36
+ if current_page.number == num
37
+ html << content_tag(:span, num.to_s, {:class => "as_paginate current"})
38
+ else
39
+ html << pagination_ajax_link(num, url_options, options)
40
+ end
41
+ end
42
+
43
+ if current_page.pager.infinite?
44
+ offsets.each do |offset|
45
+ html << '..' << pagination_ajax_link(current_page.number + offset, url_options, options)
46
+ end
47
+ else
48
+ html << ".." unless end_number >= current_page.pager.last.number - 1
49
+ html << pagination_ajax_link(current_page.pager.last.number, url_options, options) unless end_number == current_page.pager.last.number
50
+ end
51
+ html.join(' ').html_safe
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,249 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ # Helpers that assist with the rendering of a Form Column
4
+ module SearchColumnHelpers
5
+ # This method decides which input to use for the given column.
6
+ # It does not do any rendering. It only decides which method is responsible for rendering.
7
+ def active_scaffold_search_for(column)
8
+ options = active_scaffold_search_options(column)
9
+
10
+ # first, check if the dev has created an override for this specific field for search
11
+ if override_search_field?(column)
12
+ send(override_search_field(column), @record, options)
13
+
14
+ # second, check if the dev has specified a valid search_ui for this column, using specific ui for searches
15
+ elsif column.search_ui and override_search?(column.search_ui)
16
+ send(override_search(column.search_ui), column, options)
17
+
18
+ # third, check if the dev has specified a valid search_ui for this column, using generic ui for forms
19
+ elsif column.search_ui and override_input?(column.search_ui)
20
+ send(override_input(column.search_ui), column, options)
21
+
22
+ # fourth, check if the dev has created an override for this specific field
23
+ elsif override_form_field?(column)
24
+ send(override_form_field(column), @record, options)
25
+
26
+ # fallback: we get to make the decision
27
+ else
28
+ if column.association or column.virtual?
29
+ active_scaffold_search_text(column, options)
30
+
31
+ else # regular model attribute column
32
+ # if we (or someone else) have created a custom render option for the column type, use that
33
+ if override_search?(column.column.type)
34
+ send(override_search(column.column.type), column, options)
35
+ # if we (or someone else) have created a custom render option for the column type, use that
36
+ elsif override_input?(column.column.type)
37
+ send(override_input(column.column.type), column, options)
38
+ # final ultimate fallback: use rails' generic input method
39
+ else
40
+ # for textual fields we pass different options
41
+ text_types = [:text, :string, :integer, :float, :decimal]
42
+ options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type)
43
+ text_field(:record, column.name, options.merge(column.options))
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ # the standard active scaffold options used for class, name and scope
50
+ def active_scaffold_search_options(column)
51
+ { :name => "search[#{column.name}]", :class => "#{column.name}-input", :id => "search_#{column.name}", :value => field_search_params[column.name] }
52
+ end
53
+
54
+ ##
55
+ ## Search input methods
56
+ ##
57
+
58
+ def active_scaffold_search_multi_select(column, options)
59
+ associated = options.delete :value
60
+ associated = [associated].compact unless associated.is_a? Array
61
+ associated.collect!(&:to_i)
62
+
63
+ if column.association
64
+ select_options = options_for_association(column.association, false)
65
+ else
66
+ select_options = Array(column.options[:options])
67
+ end
68
+ return as_(:no_options) if select_options.empty?
69
+
70
+ active_scaffold_checkbox_list(column, select_options, associated, options)
71
+ end
72
+
73
+ def active_scaffold_search_select(column, html_options)
74
+ associated = html_options.delete :value
75
+ if column.association
76
+ associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil?
77
+ method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name
78
+ select_options = options_for_association(column.association, true)
79
+ else
80
+ method = column.name
81
+ select_options = Array(column.options[:options])
82
+ end
83
+
84
+ options = { :selected => associated }.merge! column.options
85
+ html_options.merge! column.options[:html_options] || {}
86
+ if html_options[:multiple]
87
+ html_options[:name] += '[]'
88
+ else
89
+ options[:include_blank] ||= as_(:_select_)
90
+ end
91
+ select(:record, method, select_options, options, html_options)
92
+ end
93
+
94
+ def active_scaffold_search_text(column, options)
95
+ text_field :record, column.name, active_scaffold_input_text_options(options)
96
+ end
97
+
98
+ # we can't use active_scaffold_input_boolean because we need to have a nil value even when column can't be null
99
+ # to decide whether search for this field or not
100
+ def active_scaffold_search_boolean(column, options)
101
+ select_options = []
102
+ select_options << [as_(:_select_), nil]
103
+ select_options << [as_(:true), true]
104
+ select_options << [as_(:false), false]
105
+
106
+ select_tag(options[:name], options_for_select(select_options, column.column.type_cast(field_search_params[column.name])))
107
+ end
108
+ # we can't use checkbox ui because it's not possible to decide whether search for this field or not
109
+ alias_method :active_scaffold_search_checkbox, :active_scaffold_search_boolean
110
+
111
+ def active_scaffold_search_null(column, options)
112
+ select_options = []
113
+ select_options << [as_(:_select_), nil]
114
+ select_options.concat ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp), comp]}
115
+ select_tag(options[:name], options_for_select(select_options, field_search_params[column.name]))
116
+ end
117
+
118
+ def field_search_params_range_values(column)
119
+ values = field_search_params[column.name]
120
+ return nil if values.nil?
121
+ return values[:opt], (values[:from].blank? ? nil : values[:from]), (values[:to].blank? ? nil : values[:to])
122
+
123
+ end
124
+
125
+ def active_scaffold_search_range_comparator_options(column)
126
+ select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
127
+ if column.column && column.column.text?
128
+ select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]}
129
+ end
130
+ select_options
131
+ end
132
+
133
+ def active_scaffold_search_range(column, options)
134
+ opt_value, from_value, to_value = field_search_params_range_values(column)
135
+
136
+ select_options = active_scaffold_search_range_comparator_options(column)
137
+ text_field_size = ((column.column && column.column.text?) ? 15 : 10)
138
+
139
+ from_value = controller.class.condition_value_for_numeric(column, from_value)
140
+ to_value = controller.class.condition_value_for_numeric(column, to_value)
141
+ from_value = format_number_value(from_value, column.options) if from_value.is_a?(Numeric)
142
+ to_value = format_number_value(to_value, column.options) if to_value.is_a?(Numeric)
143
+ html = select_tag("#{options[:name]}[opt]",
144
+ options_for_select(select_options, opt_value),
145
+ :id => "#{options[:id]}_opt",
146
+ :class => "as_search_range_option")
147
+ html << ' ' << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => text_field_size))
148
+ html << ' ' << content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value,
149
+ active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => text_field_size))).html_safe,
150
+ :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:#{(opt_value == 'BETWEEN') ? '' : 'none'}")
151
+ html
152
+ end
153
+ alias_method :active_scaffold_search_integer, :active_scaffold_search_range
154
+ alias_method :active_scaffold_search_decimal, :active_scaffold_search_range
155
+ alias_method :active_scaffold_search_float, :active_scaffold_search_range
156
+ alias_method :active_scaffold_search_string, :active_scaffold_search_range
157
+
158
+ def active_scaffold_search_record_select(column, options)
159
+ value = field_search_record_select_value(column)
160
+ active_scaffold_record_select(column, options, value, column.options[:multiple])
161
+ end
162
+
163
+ def field_search_record_select_value(column)
164
+ begin
165
+ value = field_search_params[column.name]
166
+ unless value.blank?
167
+ if column.options[:multiple]
168
+ column.association.klass.find value.collect!(&:to_i)
169
+ else
170
+ column.association.klass.find(value.to_i)
171
+ end
172
+ end
173
+ rescue Exception => e
174
+ logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}"
175
+ raise e
176
+ end
177
+ end
178
+
179
+ def field_search_datetime_value(value)
180
+ DateTime.new(value[:year].to_i, value[:month].to_i, value[:day].to_i, value[:hour].to_i, value[:minute].to_i, value[:second].to_i) unless value.nil? || value[:year].blank?
181
+ end
182
+
183
+ def active_scaffold_search_datetime(column, options)
184
+ opt_value, from_value, to_value = field_search_params_range_values(column)
185
+ options = column.options.merge(options)
186
+ helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}"
187
+
188
+ send(helper, field_search_datetime_value(from_value), {:include_blank => true, :prefix => "#{options[:name]}[from]"}.merge(options)) <<
189
+ ' - '.html_safe << send(helper, field_search_datetime_value(to_value), {:include_blank => true, :prefix => "#{options[:name]}[to]"}.merge(options))
190
+ end
191
+
192
+ def active_scaffold_search_date(column, options)
193
+ active_scaffold_search_datetime(column, options.merge!(:discard_time => true))
194
+ end
195
+ def active_scaffold_search_time(column, options)
196
+ active_scaffold_search_datetime(column, options.merge!(:discard_date => true))
197
+ end
198
+ alias_method :active_scaffold_search_timestamp, :active_scaffold_search_datetime
199
+
200
+ ##
201
+ ## Search column override signatures
202
+ ##
203
+
204
+ def override_search_field?(column)
205
+ respond_to?(override_search_field(column))
206
+ end
207
+
208
+ # the naming convention for overriding form fields with helpers
209
+ def override_search_field(column)
210
+ "#{column.name}_search_column"
211
+ end
212
+
213
+ def override_search?(search_ui)
214
+ respond_to?(override_search(search_ui))
215
+ end
216
+
217
+ # the naming convention for overriding search input types with helpers
218
+ def override_search(form_ui)
219
+ "active_scaffold_search_#{form_ui}"
220
+ end
221
+
222
+ def visibles_and_hiddens(search_config)
223
+ visibles = []
224
+ hiddens = []
225
+ search_config.columns.each do |column|
226
+ next unless column.search_sql
227
+ if search_config.optional_columns.include?(column.name) && !searched_by?(column)
228
+ hiddens << column
229
+ else
230
+ visibles << column
231
+ end
232
+ end
233
+ return visibles, hiddens
234
+ end
235
+
236
+ def searched_by?(column)
237
+ value = field_search_params[column.name]
238
+ case value
239
+ when Hash
240
+ !value['from'].blank?
241
+ when String
242
+ !value.blank?
243
+ else
244
+ false
245
+ end
246
+ end
247
+ end
248
+ end
249
+ end
@@ -0,0 +1,46 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ # Helpers that assist with the rendering of a List Column
4
+ module ShowColumnHelpers
5
+ def show_column_value(record, column)
6
+ # check for an override helper
7
+ if show_column_override? column
8
+ # we only pass the record as the argument. we previously also passed the formatted_value,
9
+ # but mike perham pointed out that prohibited the usage of overrides to improve on the
10
+ # performance of our default formatting. see issue #138.
11
+ send(show_column_override(column), record)
12
+ # second, check if the dev has specified a valid list_ui for this column
13
+ elsif column.list_ui and override_show_column_ui?(column.list_ui)
14
+ send(override_show_column_ui(column.list_ui), column, record)
15
+ else
16
+ if column.column and override_show_column_ui?(column.column.type)
17
+ send(override_show_column_ui(column.column.type), column, record)
18
+ else
19
+ get_column_value(record, column)
20
+ end
21
+ end
22
+ end
23
+
24
+ def active_scaffold_show_text(column, record)
25
+ simple_format(clean_column_value(record.send(column.name)))
26
+ end
27
+
28
+ def show_column_override(column)
29
+ "#{column.name.to_s.gsub('?', '')}_show_column" # parse out any question marks (see issue 227)
30
+ end
31
+
32
+ def show_column_override?(column)
33
+ respond_to?(show_column_override(column))
34
+ end
35
+
36
+ def override_show_column_ui?(list_ui)
37
+ respond_to?(override_show_column_ui(list_ui))
38
+ end
39
+
40
+ # the naming convention for overriding show types with helpers
41
+ def override_show_column_ui(list_ui)
42
+ "active_scaffold_show_#{list_ui}"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,360 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ # All extra helpers that should be included in the View.
4
+ # Also a dumping ground for uncategorized helpers.
5
+ module ViewHelpers
6
+ include ActiveScaffold::Helpers::IdHelpers
7
+ include ActiveScaffold::Helpers::AssociationHelpers
8
+ include ActiveScaffold::Helpers::PaginationHelpers
9
+ include ActiveScaffold::Helpers::ListColumnHelpers
10
+ include ActiveScaffold::Helpers::ShowColumnHelpers
11
+ include ActiveScaffold::Helpers::FormColumnHelpers
12
+ include ActiveScaffold::Helpers::SearchColumnHelpers
13
+ include ActiveScaffold::Helpers::CountryHelpers
14
+ include ActiveScaffold::Helpers::HumanConditionHelpers
15
+
16
+ ##
17
+ ## Delegates
18
+ ##
19
+
20
+ # access to the configuration variable
21
+ def active_scaffold_config
22
+ controller.class.active_scaffold_config
23
+ end
24
+
25
+ def active_scaffold_config_for(*args)
26
+ controller.class.active_scaffold_config_for(*args)
27
+ end
28
+
29
+ def active_scaffold_controller_for(*args)
30
+ controller.class.active_scaffold_controller_for(*args)
31
+ end
32
+
33
+ ##
34
+ ## Uncategorized
35
+ ##
36
+
37
+ def controller_path_for_activerecord(klass)
38
+ begin
39
+ controller = active_scaffold_controller_for(klass)
40
+ controller.controller_path
41
+ rescue ActiveScaffold::ControllerNotFound
42
+ controller = nil
43
+ end
44
+ end
45
+
46
+ def generate_temporary_id
47
+ (Time.now.to_f*1000).to_i.to_s
48
+ end
49
+
50
+ # Turns [[label, value]] into <option> tags
51
+ # Takes optional parameter of :include_blank
52
+ def option_tags_for(select_options, options = {})
53
+ select_options.insert(0,[as_(:_select_),nil]) if options[:include_blank]
54
+ select_options.collect do |option|
55
+ label, value = option[0], option[1]
56
+ value.nil? ? "<option value="">#{label}</option>" : "<option value=\"#{value}\">#{label}</option>"
57
+ end
58
+ end
59
+
60
+ # Should this column be displayed in the subform?
61
+ def in_subform?(column, parent_record)
62
+ return true unless column.association
63
+
64
+ # Polymorphic associations can't appear because they *might* be the reverse association, and because you generally don't assign an association from the polymorphic side ... I think.
65
+ return false if column.polymorphic_association?
66
+
67
+ # A column shouldn't be in the subform if it's the reverse association to the parent
68
+ return false if column.association.reverse_for?(parent_record.class)
69
+
70
+ return true
71
+ end
72
+
73
+ def form_remote_upload_tag(url_for_options = {}, options = {})
74
+ options[:target] = action_iframe_id(url_for_options)
75
+ options[:multipart] ||= true
76
+ options[:class] = "#{options[:class]} as_remote_upload".strip
77
+ output=""
78
+ output << form_tag(url_for_options, options)
79
+ (output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>").html_safe
80
+ end
81
+
82
+ # Provides list of javascripts to include with +javascript_include_tag+
83
+ # You can use this with your javascripts like
84
+ # <%= javascript_include_tag :defaults, 'your_own_cool_script', active_scaffold_javascripts, :cache => true %>
85
+ def active_scaffold_javascripts(frontend = :default)
86
+ ActiveScaffold::Config::Core.javascripts(frontend).collect do |name|
87
+ ActiveScaffold::Config::Core.asset_path(name, frontend)
88
+ end
89
+ end
90
+
91
+ # Provides stylesheets to include with +stylesheet_link_tag+
92
+ def active_scaffold_stylesheets(frontend = :default)
93
+ [ActiveScaffold::Config::Core.asset_path("stylesheet.css", frontend)]
94
+ end
95
+
96
+ # Provides stylesheets for IE to include with +stylesheet_link_tag+
97
+ def active_scaffold_ie_stylesheets(frontend = :default)
98
+ [ActiveScaffold::Config::Core.asset_path("stylesheet-ie.css", frontend)]
99
+ end
100
+
101
+ # easy way to include ActiveScaffold assets
102
+ def active_scaffold_includes(*args)
103
+ frontend = args.first.is_a?(Symbol) ? args.shift : :default
104
+ options = args.first.is_a?(Hash) ? args.shift : {}
105
+ js = javascript_include_tag(*active_scaffold_javascripts(frontend).push(options))
106
+
107
+ css = stylesheet_link_tag(*active_scaffold_stylesheets(frontend).push(options))
108
+ options[:cache] += '_ie' if options[:cache].is_a? String
109
+ options[:concat] += '_ie' if options[:concat].is_a? String
110
+ ie_css = stylesheet_link_tag(*active_scaffold_ie_stylesheets(frontend).push(options))
111
+
112
+ js + "\n" + css + "\n<!--[if IE]>".html_safe + ie_css + "<![endif]-->\n".html_safe
113
+ end
114
+
115
+ # a general-use loading indicator (the "stuff is happening, please wait" feedback)
116
+ def loading_indicator_tag(options)
117
+ image_tag "/images/active_scaffold/default/indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator"
118
+ end
119
+
120
+ # Creates a javascript-based link that toggles the visibility of some element on the page.
121
+ # By default, it toggles the visibility of the sibling after the one it's nested in. You may pass custom javascript logic in options[:of] to change that, though. For example, you could say :of => '$("my_div_id")'.
122
+ # You may also flag whether the other element is visible by default or not, and the initial text will adjust accordingly.
123
+ def link_to_visibility_toggle(id, options = {})
124
+ options[:default_visible] = true if options[:default_visible].nil?
125
+ options[:hide_label] = as_(:hide)
126
+ options[:show_label] = as_(:show)
127
+ javascript_tag("ActiveScaffold.create_visibility_toggle('#{id}', #{options.to_json});")
128
+ end
129
+
130
+ def skip_action_link(link, *args)
131
+ (!link.ignore_method.nil? and controller.try(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args))
132
+ end
133
+
134
+ def render_action_link(link, url_options, record = nil, html_options = {})
135
+ url_options = action_link_url_options(link, url_options, record)
136
+ html_options = action_link_html_options(link, url_options, record, html_options)
137
+ action_link_html(link, url_options, html_options, record)
138
+ end
139
+
140
+ def render_group_action_link(link, url_options, options, record = nil)
141
+ if link.type == :member && !options[:authorized]
142
+ action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}, record)
143
+ else
144
+ render_action_link(link, url_options, record)
145
+ end
146
+ end
147
+
148
+ def action_link_url_options(link, url_options, record, options = {})
149
+ url_options = url_options.clone
150
+ url_options[:action] = link.action
151
+ url_options[:controller] = link.controller if link.controller
152
+ url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller]
153
+ url_options.merge! link.parameters if link.parameters
154
+ @link_record = record
155
+ url_options.merge! self.instance_eval(&(link.dynamic_parameters)) if link.dynamic_parameters.is_a?(Proc)
156
+ @link_record = nil
157
+ url_options_for_nested_link(link.column, record, link, url_options, options) if link.nested_link?
158
+ url_options_for_sti_link(link.column, record, link, url_options, options) unless record.nil? || active_scaffold_config.sti_children.nil?
159
+ url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get
160
+ url_options
161
+ end
162
+
163
+ def action_link_html_options(link, url_options, record, html_options)
164
+ link_id = get_action_link_id(url_options, record, link.column)
165
+ html_options.reverse_merge! link.html_options.merge(:class => link.action)
166
+
167
+ # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails
168
+ html_options[:method] = link.method if link.method != :get
169
+
170
+ html_options['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm?
171
+ html_options['data-position'] = link.position if link.position and link.inline?
172
+ html_options[:class] += ' as_action' if link.inline?
173
+ if link.popup?
174
+ html_options['data-popup'] = true
175
+ html_options[:target] = '_blank'
176
+ end
177
+ html_options[:id] = link_id
178
+ html_options[:remote] = true unless link.page? || link.popup?
179
+ if link.dhtml_confirm?
180
+ html_options[:class] += ' as_action' if !link.inline?
181
+ html_options[:page_link] = 'true' if !link.inline?
182
+ html_options[:dhtml_confirm] = link.dhtml_confirm.value
183
+ html_options[:onclick] = link.dhtml_confirm.onclick_function(controller, link_id)
184
+ end
185
+ html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank?
186
+ html_options
187
+ end
188
+
189
+ def get_action_link_id(url_options, record = nil, column = nil)
190
+ id = url_options[:id] || url_options[:parent_id]
191
+ id = "#{column.association.name}-#{record.id}" if column && column.plural_association?
192
+ if record.try(column.association.name.to_sym).present?
193
+ id = "#{column.association.name}-#{record.send(column.association.name).id}-#{record.id}"
194
+ else
195
+ id = "#{column.association.name}-#{record.id}" unless record.nil?
196
+ end if column && column.singular_association?
197
+ id = "#{id}-#{url_options[:batch_scope].downcase}" if url_options[:batch_scope]
198
+ action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}"
199
+ action_link_id(action_id, id)
200
+ end
201
+
202
+ def action_link_html(link, url, html_options, record)
203
+ # issue 260, use url_options[:link] if it exists. This prevents DB data from being localized.
204
+ label = url.delete(:link) if url.is_a?(Hash)
205
+ label ||= link.label
206
+ if link.image.nil?
207
+ html = link_to(label, url, html_options)
208
+ else
209
+ html = link_to(image_tag(link.image[:name] , :size => link.image[:size], :alt => label), url, html_options)
210
+ end
211
+ # if url is nil we would like to generate an anchor without href attribute
212
+ url.nil? ? html.sub(/href=".*?"/, '') : html
213
+ end
214
+
215
+ def url_options_for_nested_link(column, record, link, url_options, options = {})
216
+ if column && column.association
217
+ url_options[:assoc_id] = url_options.delete(:id)
218
+ url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present?
219
+ link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless options.has_key?(:reuse_eid)
220
+ url_options[:eid] = link.eid
221
+ elsif link.parameters && link.parameters[:named_scope]
222
+ url_options[:assoc_id] = url_options.delete(:id)
223
+ link.eid = "#{controller_id.from(3)}_#{record.id}_#{link.parameters[:named_scope]}" unless options.has_key?(:reuse_eid)
224
+ url_options[:eid] = link.eid
225
+ end
226
+ end
227
+
228
+ def url_options_for_sti_link(column, record, link, url_options, options = {})
229
+ #need to find out controller of current record type
230
+ #and set parameters
231
+ sti_controller_path = controller_path_for_activerecord(record.class)
232
+ if sti_controller_path
233
+ url_options[:controller] = sti_controller_path
234
+ url_options[:parent_sti] = controller_path
235
+ end
236
+ end
237
+
238
+ def column_class(column, column_value, record)
239
+ classes = []
240
+ classes << "#{column.name}-column"
241
+ if column.css_class.is_a?(Proc)
242
+ css_class = column.css_class.call(column_value, record)
243
+ classes << css_class unless css_class.nil?
244
+ else
245
+ classes << column.css_class
246
+ end unless column.css_class.nil?
247
+
248
+ classes << 'empty' if column_empty? column_value
249
+ classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column)
250
+ classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type)
251
+ classes.join(' ').rstrip
252
+ end
253
+
254
+ def column_heading_class(column, sorting)
255
+ classes = []
256
+ classes << "#{column.name}-column_heading"
257
+ classes << "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column
258
+ classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc)
259
+ classes.join(' ')
260
+ end
261
+
262
+ def column_empty?(column_value)
263
+ empty = column_value.nil?
264
+ empty ||= column_value.empty? if column_value.respond_to? :empty?
265
+ empty ||= ['&nbsp;', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value
266
+ return empty
267
+ end
268
+
269
+ def column_calculation(column)
270
+ unless column.calculate.instance_of? Proc
271
+ conditions = controller.send(:all_conditions)
272
+ includes = active_scaffold_config.list.count_includes
273
+ includes ||= controller.send(:active_scaffold_includes) unless conditions.nil?
274
+ calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions,
275
+ :joins => controller.send(:joins_for_collection), :include => includes)
276
+ else
277
+ column.calculate.call(@records)
278
+ end
279
+ end
280
+
281
+ def render_column_calculation(column)
282
+ calculation = column_calculation(column)
283
+ override_formatter = "render_#{column.name}_#{column.calculate}"
284
+ calculation = send(override_formatter, calculation) if respond_to? override_formatter
285
+
286
+ "#{"#{as_(column.calculate)}: " unless column.calculate.is_a? Proc}#{format_column_value nil, column, calculation}"
287
+ end
288
+
289
+ def column_show_add_existing(column)
290
+ (column.allow_add_existing and options_for_association_count(column.association) > 0)
291
+ end
292
+
293
+ def column_show_add_new(column, associated, record)
294
+ value = column.plural_association? || (column.singular_association? and not associated.empty?)
295
+ value = false unless record.class.authorized_for?(:crud_type => :create)
296
+ value
297
+ end
298
+
299
+ def active_scaffold_error_messages_for(*params)
300
+ options = params.extract_options!.symbolize_keys
301
+ options.reverse_merge!(:container_tag => :div, :list_type => :ul)
302
+
303
+ objects = Array.wrap(options.delete(:object) || params).map do |object|
304
+ object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model)
305
+ object = convert_to_model(object)
306
+
307
+ if object.class.respond_to?(:model_name)
308
+ options[:object_name] ||= object.class.model_name.human.downcase
309
+ end
310
+
311
+ object
312
+ end
313
+
314
+ objects.compact!
315
+ count = objects.inject(0) {|sum, object| sum + object.errors.count }
316
+
317
+ unless count.zero?
318
+ html = {}
319
+ [:id, :class].each do |key|
320
+ if options.include?(key)
321
+ value = options[key]
322
+ html[key] = value unless value.blank?
323
+ else
324
+ html[key] = 'errorExplanation'
325
+ end
326
+ end
327
+ options[:object_name] ||= params.first
328
+
329
+ header_message = if options.include?(:header_message)
330
+ options[:header_message]
331
+ else
332
+ as_('errors.template.header', :count => count, :model => options[:object_name].to_s.gsub('_', ' '))
333
+ end
334
+
335
+ message = options.include?(:message) ? options[:message] : as_('errors.template.body')
336
+
337
+ error_messages = objects.sum do |object|
338
+ object.errors.full_messages.map do |msg|
339
+ options[:list_type] != :br ? content_tag(:li, msg) : msg
340
+ end
341
+ end
342
+ error_messages = if options[:list_type] == :br
343
+ error_messages.join('<br/>').html_safe
344
+ else
345
+ content_tag(options[:list_type], error_messages.join.html_safe)
346
+ end
347
+
348
+ contents = []
349
+ contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
350
+ contents << content_tag(:p, message) unless message.blank?
351
+ contents << error_messages
352
+ contents = contents.join.html_safe
353
+ options[:container_tag] ? content_tag(options[:container_tag], contents, html) : contents
354
+ else
355
+ ''
356
+ end
357
+ end
358
+ end
359
+ end
360
+ end