active_scaffold 3.7.12 → 4.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +9 -23
  3. data/README.md +3 -2
  4. data/app/assets/config/active_scaffold_manifest.js +3 -0
  5. data/app/assets/javascripts/active_scaffold.js.erb +24 -34
  6. data/app/assets/javascripts/jquery/active_scaffold.js +41 -58
  7. data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +1 -1
  8. data/app/assets/stylesheets/active_scaffold_colors.scss +0 -7
  9. data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -2
  10. data/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +7 -7
  11. data/app/assets/stylesheets/active_scaffold_layout.css +57 -30
  12. data/app/views/active_scaffold_overrides/_add_existing_form.html.erb +10 -10
  13. data/app/views/active_scaffold_overrides/_base_form.html.erb +21 -21
  14. data/app/views/active_scaffold_overrides/_create_form.html.erb +10 -7
  15. data/app/views/active_scaffold_overrides/_create_form_on_list.html.erb +5 -5
  16. data/app/views/active_scaffold_overrides/_field_search.html.erb +6 -6
  17. data/app/views/active_scaffold_overrides/_form.html.erb +11 -14
  18. data/app/views/active_scaffold_overrides/_form_association.html.erb +21 -12
  19. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +19 -10
  20. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +15 -21
  21. data/app/views/active_scaffold_overrides/_form_messages.html.erb +2 -2
  22. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +7 -6
  23. data/app/views/active_scaffold_overrides/_human_conditions.html.erb +2 -2
  24. data/app/views/active_scaffold_overrides/_list.html.erb +15 -8
  25. data/app/views/active_scaffold_overrides/_list_calculations.html.erb +2 -3
  26. data/app/views/active_scaffold_overrides/_list_header.html.erb +2 -2
  27. data/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb +5 -5
  28. data/app/views/active_scaffold_overrides/_list_messages.html.erb +12 -3
  29. data/app/views/active_scaffold_overrides/_list_pagination.html.erb +3 -3
  30. data/app/views/active_scaffold_overrides/_list_pagination_links.html.erb +4 -4
  31. data/app/views/active_scaffold_overrides/_list_record.html.erb +6 -6
  32. data/app/views/active_scaffold_overrides/_list_with_header.html.erb +4 -4
  33. data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
  34. data/app/views/active_scaffold_overrides/_refresh_list.js.erb +2 -2
  35. data/app/views/active_scaffold_overrides/_render_field.js.erb +4 -4
  36. data/app/views/active_scaffold_overrides/_row.html.erb +1 -1
  37. data/app/views/active_scaffold_overrides/_search.html.erb +6 -5
  38. data/app/views/active_scaffold_overrides/_show.html.erb +3 -3
  39. data/app/views/active_scaffold_overrides/_show_actions.html.erb +1 -1
  40. data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
  41. data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +1 -1
  42. data/app/views/active_scaffold_overrides/_show_association_vertical.html.erb +1 -1
  43. data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
  44. data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +1 -1
  45. data/app/views/active_scaffold_overrides/_update_actions.html.erb +1 -1
  46. data/app/views/active_scaffold_overrides/_update_calculations.js.erb +2 -2
  47. data/app/views/active_scaffold_overrides/_update_column.js.erb +8 -7
  48. data/app/views/active_scaffold_overrides/_update_form.html.erb +5 -5
  49. data/app/views/active_scaffold_overrides/_update_messages.js.erb +1 -1
  50. data/app/views/active_scaffold_overrides/_vertical_subform.html.erb +4 -3
  51. data/app/views/active_scaffold_overrides/action_confirmation.html.erb +3 -3
  52. data/app/views/active_scaffold_overrides/add_existing.js.erb +6 -6
  53. data/app/views/active_scaffold_overrides/add_existing_form.html.erb +1 -1
  54. data/app/views/active_scaffold_overrides/add_tab.js.erb +15 -0
  55. data/app/views/active_scaffold_overrides/create.html.erb +1 -1
  56. data/app/views/active_scaffold_overrides/delete.html.erb +4 -4
  57. data/app/views/active_scaffold_overrides/destroy.js.erb +15 -13
  58. data/app/views/active_scaffold_overrides/edit_associated.js.erb +3 -3
  59. data/app/views/active_scaffold_overrides/field_search.html.erb +1 -1
  60. data/app/views/active_scaffold_overrides/form_messages.js.erb +1 -1
  61. data/app/views/active_scaffold_overrides/list.html.erb +1 -1
  62. data/app/views/active_scaffold_overrides/on_action_update.js.erb +13 -8
  63. data/app/views/active_scaffold_overrides/on_create.js.erb +34 -6
  64. data/app/views/active_scaffold_overrides/on_mark.js.erb +3 -3
  65. data/app/views/active_scaffold_overrides/on_update.js.erb +9 -9
  66. data/app/views/active_scaffold_overrides/render_field.js.erb +1 -1
  67. data/app/views/active_scaffold_overrides/render_field_inplace.html.erb +1 -1
  68. data/app/views/active_scaffold_overrides/row.js.erb +2 -2
  69. data/app/views/active_scaffold_overrides/search.html.erb +1 -1
  70. data/app/views/active_scaffold_overrides/show.html.erb +3 -3
  71. data/app/views/active_scaffold_overrides/update.html.erb +2 -2
  72. data/app/views/active_scaffold_overrides/update_column.js.erb +4 -4
  73. data/app/views/active_scaffold_overrides/update_row.js.erb +1 -1
  74. data/lib/active_scaffold/actions/common_search.rb +5 -3
  75. data/lib/active_scaffold/actions/core.rb +57 -32
  76. data/lib/active_scaffold/actions/create.rb +19 -17
  77. data/lib/active_scaffold/actions/delete.rb +10 -12
  78. data/lib/active_scaffold/actions/field_search.rb +28 -13
  79. data/lib/active_scaffold/actions/list.rb +34 -34
  80. data/lib/active_scaffold/actions/mark.rb +5 -5
  81. data/lib/active_scaffold/actions/nested.rb +64 -56
  82. data/lib/active_scaffold/actions/search.rb +2 -2
  83. data/lib/active_scaffold/actions/show.rb +5 -5
  84. data/lib/active_scaffold/actions/subform.rb +15 -4
  85. data/lib/active_scaffold/actions/update.rb +20 -20
  86. data/lib/active_scaffold/active_record_permissions.rb +4 -3
  87. data/lib/active_scaffold/attribute_params.rb +51 -50
  88. data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +4 -4
  89. data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +6 -2
  90. data/lib/active_scaffold/bridges/active_storage.rb +1 -1
  91. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +3 -3
  92. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +4 -1
  93. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  94. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +9 -8
  95. data/lib/active_scaffold/bridges/cancan.rb +8 -8
  96. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +1 -1
  97. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +4 -3
  98. data/lib/active_scaffold/bridges/carrierwave.rb +2 -2
  99. data/lib/active_scaffold/bridges/chosen.rb +1 -5
  100. data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +4 -2
  101. data/lib/active_scaffold/bridges/date_picker/ext.rb +20 -12
  102. data/lib/active_scaffold/bridges/date_picker/helper.rb +37 -33
  103. data/lib/active_scaffold/bridges/date_picker.rb +1 -4
  104. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +1 -1
  105. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +3 -2
  106. data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
  107. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +3 -2
  108. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +2 -1
  109. data/lib/active_scaffold/bridges/file_column/form_ui.rb +4 -9
  110. data/lib/active_scaffold/bridges/file_column/list_ui.rb +6 -3
  111. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +3 -3
  112. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +1 -4
  113. data/lib/active_scaffold/bridges/file_column.rb +1 -0
  114. data/lib/active_scaffold/bridges/paper_trail/actions.rb +4 -2
  115. data/lib/active_scaffold/bridges/paper_trail/config.rb +1 -1
  116. data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -1
  117. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +2 -1
  118. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +3 -2
  119. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
  120. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +10 -9
  121. data/lib/active_scaffold/bridges/paperclip.rb +2 -1
  122. data/lib/active_scaffold/bridges/record_select/helpers.rb +10 -11
  123. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +3 -1
  124. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -7
  125. data/lib/active_scaffold/bridges/tiny_mce.rb +2 -7
  126. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +7 -7
  127. data/lib/active_scaffold/bridges.rb +7 -5
  128. data/lib/active_scaffold/config/base.rb +20 -24
  129. data/lib/active_scaffold/config/core.rb +27 -39
  130. data/lib/active_scaffold/config/create.rb +1 -1
  131. data/lib/active_scaffold/config/delete.rb +9 -9
  132. data/lib/active_scaffold/config/field_search.rb +4 -9
  133. data/lib/active_scaffold/config/form.rb +3 -1
  134. data/lib/active_scaffold/config/list.rb +19 -15
  135. data/lib/active_scaffold/config/nested.rb +2 -2
  136. data/lib/active_scaffold/config/search.rb +5 -5
  137. data/lib/active_scaffold/config/show.rb +1 -1
  138. data/lib/active_scaffold/config/subform.rb +1 -1
  139. data/lib/active_scaffold/config/update.rb +4 -5
  140. data/lib/active_scaffold/configurable.rb +2 -1
  141. data/lib/active_scaffold/constraints.rb +16 -11
  142. data/lib/active_scaffold/core.rb +25 -27
  143. data/lib/active_scaffold/data_structures/action_columns.rb +10 -3
  144. data/lib/active_scaffold/data_structures/action_link.rb +19 -9
  145. data/lib/active_scaffold/data_structures/action_links.rb +20 -26
  146. data/lib/active_scaffold/data_structures/actions.rb +3 -3
  147. data/lib/active_scaffold/data_structures/association/abstract.rb +8 -4
  148. data/lib/active_scaffold/data_structures/association/active_mongoid.rb +1 -0
  149. data/lib/active_scaffold/data_structures/association/active_record.rb +1 -4
  150. data/lib/active_scaffold/data_structures/column.rb +368 -327
  151. data/lib/active_scaffold/data_structures/columns.rb +3 -2
  152. data/lib/active_scaffold/data_structures/nested_info.rb +6 -5
  153. data/lib/active_scaffold/data_structures/proxy_column.rb +68 -0
  154. data/lib/active_scaffold/data_structures/set.rb +7 -4
  155. data/lib/active_scaffold/data_structures/sorting.rb +21 -12
  156. data/lib/active_scaffold/engine.rb +12 -12
  157. data/lib/active_scaffold/extensions/action_controller_rendering.rb +5 -5
  158. data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
  159. data/lib/active_scaffold/extensions/action_view_rendering.rb +29 -31
  160. data/lib/active_scaffold/extensions/ice_nine.rb +2 -1
  161. data/lib/active_scaffold/extensions/localize.rb +2 -2
  162. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
  163. data/lib/active_scaffold/extensions/routing_mapper.rb +5 -4
  164. data/lib/active_scaffold/extensions/unsaved_associated.rb +3 -2
  165. data/lib/active_scaffold/finder.rb +71 -78
  166. data/lib/active_scaffold/helpers/action_link_helpers.rb +37 -49
  167. data/lib/active_scaffold/helpers/association_helpers.rb +3 -2
  168. data/lib/active_scaffold/helpers/controller_helpers.rb +18 -16
  169. data/lib/active_scaffold/helpers/form_column_helpers.rb +69 -53
  170. data/lib/active_scaffold/helpers/human_condition_helpers.rb +17 -15
  171. data/lib/active_scaffold/helpers/id_helpers.rb +5 -5
  172. data/lib/active_scaffold/helpers/list_column_helpers.rb +35 -38
  173. data/lib/active_scaffold/helpers/pagination_helpers.rb +4 -4
  174. data/lib/active_scaffold/helpers/search_column_helpers.rb +25 -34
  175. data/lib/active_scaffold/helpers/show_column_helpers.rb +7 -4
  176. data/lib/active_scaffold/helpers/tabs_helpers.rb +88 -0
  177. data/lib/active_scaffold/helpers/view_helpers.rb +15 -13
  178. data/lib/active_scaffold/marked_model.rb +1 -2
  179. data/lib/active_scaffold/orm_checks.rb +6 -4
  180. data/lib/active_scaffold/paginator.rb +3 -2
  181. data/lib/active_scaffold/registry.rb +5 -0
  182. data/lib/active_scaffold/tableless.rb +24 -14
  183. data/lib/active_scaffold/version.rb +4 -4
  184. data/lib/active_scaffold.rb +8 -34
  185. data/lib/generators/active_scaffold/controller_generator.rb +20 -20
  186. data/lib/generators/active_scaffold/install_generator.rb +4 -8
  187. data/lib/generators/active_scaffold/resource_generator.rb +31 -31
  188. data/lib/tasks/brakeman.rake +1 -1
  189. data/shoulda_macros/macros.rb +14 -14
  190. metadata +11 -232
  191. data/app/assets/javascripts/prototype/active_scaffold.js +0 -1249
  192. data/app/assets/javascripts/prototype/active_scaffold_chosen.js +0 -0
  193. data/app/assets/javascripts/prototype/dhtml_history.js +0 -870
  194. data/app/assets/javascripts/prototype/form_enhancements.js +0 -117
  195. data/app/assets/javascripts/prototype/tiny_mce_bridge.js +0 -17
  196. data/app/views/active_scaffold_overrides/_list_messages_content.html.erb +0 -8
  197. data/app/views/active_scaffold_overrides/_new_record.js.erb +0 -15
  198. data/app/views/active_scaffold_overrides/_popup_adapter.html.erb +0 -20
  199. data/app/views/active_scaffold_overrides/_refresh_create_form.js.erb +0 -12
  200. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +0 -58
  201. data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -17
  202. data/lib/active_scaffold/data_structures/action_link_separator.rb +0 -13
  203. data/lib/active_scaffold/extensions/cow_proxy.rb +0 -102
  204. data/test/active_scaffold_config_mock.rb +0 -33
  205. data/test/bridges/bridge_test.rb +0 -88
  206. data/test/bridges/date_picker_test.rb +0 -31
  207. data/test/bridges/paper_trail_test.rb +0 -16
  208. data/test/bridges/paperclip_test.rb +0 -85
  209. data/test/bridges/tiny_mce_test.rb +0 -61
  210. data/test/class_with_finder.rb +0 -42
  211. data/test/company.rb +0 -97
  212. data/test/config/base_test.rb +0 -17
  213. data/test/config/core_test.rb +0 -66
  214. data/test/config/create_test.rb +0 -72
  215. data/test/config/delete_test.rb +0 -35
  216. data/test/config/field_search_test.rb +0 -49
  217. data/test/config/list_test.rb +0 -134
  218. data/test/config/nested_test.rb +0 -55
  219. data/test/config/search_test.rb +0 -62
  220. data/test/config/show_test.rb +0 -45
  221. data/test/config/subform_test.rb +0 -19
  222. data/test/config/update_test.rb +0 -52
  223. data/test/const_mocker.rb +0 -32
  224. data/test/data_structures/action_columns_test.rb +0 -112
  225. data/test/data_structures/action_link_test.rb +0 -79
  226. data/test/data_structures/action_links_test.rb +0 -78
  227. data/test/data_structures/actions_test.rb +0 -25
  228. data/test/data_structures/association_column_test.rb +0 -41
  229. data/test/data_structures/column_test.rb +0 -186
  230. data/test/data_structures/columns_test.rb +0 -68
  231. data/test/data_structures/set_test.rb +0 -84
  232. data/test/data_structures/sorting_test.rb +0 -148
  233. data/test/data_structures/standard_column_test.rb +0 -23
  234. data/test/data_structures/validation_reflection_test.rb +0 -69
  235. data/test/data_structures/virtual_column_test.rb +0 -23
  236. data/test/extensions/action_view_rendering_test.rb +0 -20
  237. data/test/extensions/active_record_test.rb +0 -44
  238. data/test/extensions/routing_mapper_test.rb +0 -73
  239. data/test/helpers/form_column_helpers_test.rb +0 -34
  240. data/test/helpers/list_column_helpers_test.rb +0 -53
  241. data/test/helpers/pagination_helpers_test.rb +0 -65
  242. data/test/helpers/search_column_helpers_test.rb +0 -15
  243. data/test/misc/active_record_permissions_test.rb +0 -193
  244. data/test/misc/attribute_params_test.rb +0 -460
  245. data/test/misc/calculation_test.rb +0 -39
  246. data/test/misc/configurable_test.rb +0 -97
  247. data/test/misc/constraints_test.rb +0 -209
  248. data/test/misc/convert_numbers_format_test.rb +0 -171
  249. data/test/misc/finder_test.rb +0 -124
  250. data/test/misc/lang_test.rb +0 -10
  251. data/test/misc/parse_datetime_test.rb +0 -159
  252. data/test/misc/render_test.rb +0 -9
  253. data/test/misc/tableless_test.rb +0 -56
  254. data/test/mock_app/.gitignore +0 -2
  255. data/test/mock_app/Rakefile +0 -7
  256. data/test/mock_app/app/assets/config/manifest.js +0 -0
  257. data/test/mock_app/app/controllers/addresses_controller.rb +0 -4
  258. data/test/mock_app/app/controllers/application_controller.rb +0 -10
  259. data/test/mock_app/app/controllers/buildings_controller.rb +0 -4
  260. data/test/mock_app/app/controllers/cars_controller.rb +0 -5
  261. data/test/mock_app/app/controllers/contacts_controller.rb +0 -4
  262. data/test/mock_app/app/controllers/floors_controller.rb +0 -6
  263. data/test/mock_app/app/controllers/people_controller.rb +0 -8
  264. data/test/mock_app/app/controllers/roles_controller.rb +0 -4
  265. data/test/mock_app/app/helpers/application_helper.rb +0 -3
  266. data/test/mock_app/app/models/address.rb +0 -3
  267. data/test/mock_app/app/models/building.rb +0 -9
  268. data/test/mock_app/app/models/car.rb +0 -3
  269. data/test/mock_app/app/models/contact.rb +0 -3
  270. data/test/mock_app/app/models/file_model.rb +0 -31
  271. data/test/mock_app/app/models/floor.rb +0 -8
  272. data/test/mock_app/app/models/person.rb +0 -12
  273. data/test/mock_app/app/models/role.rb +0 -3
  274. data/test/mock_app/app/views/active_scaffold_overrides/_form.html.erb +0 -2
  275. data/test/mock_app/app/views/active_scaffold_overrides/list.html.erb +0 -2
  276. data/test/mock_app/app/views/people/_first_name_form_column.html.erb +0 -2
  277. data/test/mock_app/app/views/people/_form.html.erb +0 -2
  278. data/test/mock_app/app/views/people/list.html.erb +0 -2
  279. data/test/mock_app/config/application.rb +0 -14
  280. data/test/mock_app/config/boot.rb +0 -7
  281. data/test/mock_app/config/database.yml +0 -16
  282. data/test/mock_app/config/environment.rb +0 -6
  283. data/test/mock_app/config/environments/development.rb +0 -24
  284. data/test/mock_app/config/environments/production.rb +0 -49
  285. data/test/mock_app/config/environments/test.rb +0 -34
  286. data/test/mock_app/config/initializers/backtrace_silencers.rb +0 -7
  287. data/test/mock_app/config/initializers/inflections.rb +0 -10
  288. data/test/mock_app/config/initializers/mime_types.rb +0 -5
  289. data/test/mock_app/config/initializers/secret_token.rb +0 -11
  290. data/test/mock_app/config/initializers/session_store.rb +0 -8
  291. data/test/mock_app/config/initializers/wrap_parameters.rb +0 -14
  292. data/test/mock_app/config/locales/en.yml +0 -5
  293. data/test/mock_app/config/routes.rb +0 -17
  294. data/test/mock_app/config.ru +0 -4
  295. data/test/mock_app/db/schema.rb +0 -68
  296. data/test/mock_app/db/test.sqlite3 +0 -1
  297. data/test/model_stub.rb +0 -64
  298. data/test/performance/list_cars_performance_test.rb +0 -34
  299. data/test/performance/list_people_performance_test.rb +0 -31
  300. data/test/performance_test_help.rb +0 -3
  301. data/test/run_all.rb +0 -6
  302. data/test/test_helper.rb +0 -71
  303. data/vendor/assets/javascripts/getprototypeof.js +0 -12
@@ -1,341 +1,436 @@
1
1
  module ActiveScaffold::DataStructures
2
2
  class Column
3
- include ActiveScaffold::Configurable
4
- include ActiveScaffold::OrmChecks
5
- NO_PARAMS = Set.new.freeze
6
- NO_OPTIONS = {}.freeze
3
+ module ProxyableMethods
4
+ extend ActiveSupport::Concern
7
5
 
8
- attr_reader :active_record_class
9
- alias model active_record_class
6
+ included do # rubocop:disable Metrics/BlockLength
7
+ # Whether to enable inplace editing for this column. Currently works for text columns, in the List.
8
+ attr_reader :inplace_edit
10
9
 
11
- # this is the name of the getter on the ActiveRecord model. it is the only absolutely required attribute ... all others will be inferred from this name.
12
- attr_reader :name
10
+ # :table to refresh list
11
+ # true or :row to refresh row
12
+ attr_accessor :inplace_edit_update
13
13
 
14
- # Whether to enable inplace editing for this column. Currently works for text columns, in the List.
15
- attr_reader :inplace_edit
16
- def inplace_edit=(value)
17
- clear_link if value
18
- @inplace_edit = value
19
- end
14
+ # Whether this column set is collapsed by default in contexts where collapsing is supported
15
+ attr_accessor :collapsed
20
16
 
21
- # :table to refresh list
22
- # true or :row to refresh row
23
- attr_accessor :inplace_edit_update
17
+ # Whether to enable add_existing for this column
18
+ attr_accessor :allow_add_existing
24
19
 
25
- # Whether this column set is collapsed by default in contexts where collapsing is supported
26
- attr_accessor :collapsed
20
+ # What columns load from main table
21
+ attr_accessor :select_columns
27
22
 
28
- # Whether to enable add_existing for this column
29
- attr_accessor :allow_add_existing
23
+ # define a calculation for the column. anything that ActiveRecord::Calculations::ClassMethods#calculate accepts will do.
24
+ attr_accessor :calculate
30
25
 
31
- # What columns load from main table
32
- attr_accessor :select_columns
26
+ # A placeholder text, to be used inside blank text fields to describe, what should be typed in
27
+ attr_accessor :placeholder
33
28
 
34
- # Any extra parameters this particular column uses. This is for create/update purposes.
35
- def params
36
- return @params || NO_PARAMS if frozen?
37
- @params ||= NO_PARAMS.dup
38
- end
29
+ # this will be /joined/ to the :name for the td's class attribute. useful if you want to style columns on different ActiveScaffolds the same way, but the columns have different names.
30
+ attr_accessor :css_class
39
31
 
40
- def default_value
41
- @default_value || @db_default_value
42
- end
32
+ # whether the field is required or not. used on the form for visually indicating the fact to the user.
33
+ attr_writer :required
43
34
 
44
- def default_value=(value)
45
- raise ArgumentError, "Can't set default value for non-DB columns (virtual columns or associations)" unless column
46
- @default_value = value
47
- end
35
+ # the display-name of the column. this will be used, for instance, as the column title in the table and as the field name in the form.
36
+ # if left alone it will utilize human_attribute_name which includes localization
37
+ attr_writer :label
48
38
 
49
- def default_value?
50
- defined? @default_value
51
- end
39
+ # a textual description of the column and its contents. this will be displayed with any associated form input widget, so you may want to consider adding a content example.
40
+ attr_writer :description
41
+
42
+ attr_reader :update_columns
43
+
44
+ # send all the form instead of only new value when this column changes
45
+ attr_accessor :send_form_on_update_column
46
+
47
+ # add a custom attr_accessor that can contain a Proc (or boolean or symbol)
48
+ # that will be called when the column renders, such that we can dynamically
49
+ # hide or show the column with an element that can be replaced by
50
+ # update_columns, but won't affect the form submission.
51
+ # The value can be set in the scaffold controller as follows to dynamically
52
+ # hide the column based on a Proc's output:
53
+ # config.columns[:my_column].hide_form_column_if = Proc.new { |record, column, scope| record.vehicle_type == 'tractor' }
54
+ # OR to always hide the column:
55
+ # config.columns[:my_column].hide_form_column_if = true
56
+ # OR to call a method on the record to determine whether to hide the column:
57
+ # config.columns[:my_column].hide_form_column_if = :hide_tractor_fields?
58
+ attr_accessor :hide_form_column_if
52
59
 
53
- # the display-name of the column. this will be used, for instance, as the column title in the table and as the field name in the form.
54
- # if left alone it will utilize human_attribute_name which includes localization
55
- attr_writer :label
56
- def label(record = nil, scope = nil)
57
- if @label.respond_to?(:call)
58
- if record
59
- @label.call(record, self, scope)
60
+ # a collection of columns to load from the association when eager loading is disabled, if it's nil all columns will be loaded
61
+ attr_accessor :select_associated_columns
62
+
63
+ # to modify the default order of columns
64
+ attr_accessor :weight
65
+
66
+ attr_accessor :associated_limit
67
+
68
+ attr_writer :associated_number
69
+
70
+ # what string to use to join records from plural associations
71
+ attr_accessor :association_join_text
72
+
73
+ attr_writer :show_blank_record
74
+
75
+ attr_accessor :actions_for_association_links
76
+
77
+ attr_writer :number
78
+
79
+ # supported options:
80
+ # * for association columns
81
+ # * :select - displays a simple <select> or a collection of checkboxes to (dis)associate records
82
+ attr_reader :form_ui
83
+
84
+ attr_reader :form_ui_options
85
+
86
+ # a collection of associations to pre-load when finding the records on a page
87
+ attr_reader :includes
88
+
89
+ # a place to store dev's column specific options
90
+ attr_writer :options
91
+ end
92
+
93
+ def inplace_edit=(value)
94
+ clear_link if value
95
+ @inplace_edit = value
96
+ end
97
+
98
+ # this should not only delete any existing link but also prevent column links from being automatically added by later routines
99
+ def clear_link
100
+ @link = nil
101
+ @autolink = false
102
+ end
103
+
104
+ # get whether to run a calculation on this column
105
+ def calculation?
106
+ !(calculate == false || calculate.nil?)
107
+ end
108
+
109
+ def required?(action = nil)
110
+ if action && @required
111
+ @required == true || @required.include?(action)
60
112
  else
61
- # sometimes label is called without a record in context (ie, from table
62
- # headers). In this case fall back to the humanized attribute name
63
- # instead of the Proc
64
- active_record_class.human_attribute_name(name.to_s)
113
+ @required
65
114
  end
66
- else
67
- as_(@label) || active_record_class.human_attribute_name(name.to_s)
68
115
  end
69
- end
70
116
 
71
- # a textual description of the column and its contents. this will be displayed with any associated form input widget, so you may want to consider adding a content example.
72
- attr_writer :description
73
- def description(record = nil, scope = nil)
74
- if @description&.respond_to?(:call)
75
- @description.call(record, self, scope)
76
- elsif @description
77
- @description
78
- else
79
- I18n.t name, :scope => [:activerecord, :description, active_record_class.to_s.underscore.to_sym], :default => ''
117
+ def placeholder
118
+ @placeholder || I18n.t(name, scope: [:activerecord, :placeholder, active_record_class.to_s.underscore.to_sym], default: '')
80
119
  end
81
- end
82
120
 
83
- # A placeholder text, to be used inside blank text fields to describe, what should be typed in
84
- attr_writer :placeholder
85
- def placeholder
86
- @placeholder || I18n.t(name, :scope => [:activerecord, :placeholder, active_record_class.to_s.underscore.to_sym], :default => '')
87
- end
121
+ def label(record = nil, scope = nil)
122
+ label =
123
+ if @label.respond_to?(:call)
124
+ # sometimes label is called without a record in context (ie, from table
125
+ # headers). In this case fall back to the default instead of the Proc.
126
+ @label.call(record, self, scope) if record
127
+ elsif @label
128
+ as_(@label)
129
+ end
130
+ label || active_record_class.human_attribute_name(name.to_s)
131
+ end
88
132
 
89
- # this will be /joined/ to the :name for the td's class attribute. useful if you want to style columns on different ActiveScaffolds the same way, but the columns have different names.
90
- attr_accessor :css_class
133
+ def description(record = nil, scope = nil)
134
+ if @description.respond_to?(:call)
135
+ @description.call(record, self, scope)
136
+ elsif @description
137
+ @description
138
+ else
139
+ I18n.t name, scope: [:activerecord, :description, active_record_class.to_s.underscore.to_sym], default: ''
140
+ end
141
+ end
91
142
 
92
- # whether the field is required or not. used on the form for visually indicating the fact to the user.
93
- # TODO: move into predicate
94
- attr_writer :required
95
- def required?(action = nil)
96
- if action && @required
97
- @required == true || @required.include?(action)
98
- else
99
- @required
143
+ # update dependent columns after value change in form
144
+ # update_columns = :name
145
+ # update_columns = [:name, :age]
146
+ def update_columns=(column_names)
147
+ @update_columns = Array(column_names)
100
148
  end
101
- end
102
149
 
103
- attr_reader :update_columns
150
+ # sorting on a column can be configured four ways:
151
+ # sort = true default, uses intelligent sorting sql default
152
+ # sort = false sometimes sorting doesn't make sense
153
+ # sort = {sql: ""} define your own sql for sorting. this should be result in a sortable value in SQL. ActiveScaffold will handle the ascending/descending.
154
+ # sort = {method: ""} define ruby-side code for sorting. this is SLOW with large recordsets!
155
+ def sort=(value)
156
+ if value.is_a? Hash
157
+ value.assert_valid_keys(:sql, :method)
158
+ @sort = value
159
+ else
160
+ @sort = value ? true : false # force true or false
161
+ end
162
+ end
104
163
 
105
- # update dependent columns after value change in form
106
- # update_columns = :name
107
- # update_columns = [:name, :age]
108
- def update_columns=(column_names)
109
- @update_columns = Array(column_names)
110
- end
164
+ def sort
165
+ initialize_sort if @sort == true
166
+ @sort
167
+ end
111
168
 
112
- # send all the form instead of only new value when this column change
113
- cattr_accessor :send_form_on_update_column, instance_accessor: false
114
- attr_accessor :send_form_on_update_column
115
-
116
- # add a custom attr_accessor that can contain a Proc (or boolean or symbol)
117
- # that will be called when the column renders, such that we can dynamically
118
- # hide or show the column with an element that can be replaced by
119
- # update_columns, but won't affect the form submission.
120
- # The value can be set in the scaffold controller as follows to dynamically
121
- # hide the column based on a Proc's output:
122
- # config.columns[:my_column].hide_form_column_if = Proc.new { |record, column, scope| record.vehicle_type == 'tractor' }
123
- # OR to always hide the column:
124
- # config.columns[:my_column].hide_form_column_if = true
125
- # OR to call a method on the record to determine whether to hide the column:
126
- # config.columns[:my_column].hide_form_column_if = :hide_tractor_fields?
127
- attr_accessor :hide_form_column_if
128
-
129
- # sorting on a column can be configured four ways:
130
- # sort = true default, uses intelligent sorting sql default
131
- # sort = false sometimes sorting doesn't make sense
132
- # sort = {:sql => ""} define your own sql for sorting. this should be result in a sortable value in SQL. ActiveScaffold will handle the ascending/descending.
133
- # sort = {:method => ""} define ruby-side code for sorting. this is SLOW with large recordsets!
134
- def sort=(value)
135
- if value.is_a? Hash
136
- value.assert_valid_keys(:sql, :method)
137
- @sort = value
138
- else
139
- @sort = value ? true : false # force true or false
169
+ def sortable?
170
+ sort != false && !sort.nil?
140
171
  end
141
- end
142
172
 
143
- def sort
144
- initialize_sort if @sort == true
145
- @sort
146
- end
173
+ # a configuration helper for the self.sort property. simply provides a method syntax instead of setter syntax.
174
+ def sort_by(options)
175
+ self.sort = options
176
+ end
147
177
 
148
- def sortable?
149
- sort != false && !sort.nil?
150
- end
178
+ def associated_number?
179
+ @associated_number
180
+ end
151
181
 
152
- # a configuration helper for the self.sort property. simply provides a method syntax instead of setter syntax.
153
- def sort_by(options)
154
- self.sort = options
155
- end
182
+ def show_blank_record?(associated)
183
+ return false unless @show_blank_record
184
+ return false unless association.klass.authorized_for?(crud_type: :create) && !association.readonly?
156
185
 
157
- # supported options:
158
- # * for association columns
159
- # * :select - displays a simple <select> or a collection of checkboxes to (dis)associate records
160
- attr_reader :form_ui
186
+ association.collection? || (association.singular? && associated.blank?)
187
+ end
161
188
 
162
- attr_reader :form_ui_options
189
+ def number?
190
+ @number
191
+ end
163
192
 
164
- # value must be a Symbol, or an Array of form_ui and options hash which will be used with form_ui only
165
- def form_ui=(value)
166
- check_valid_action_ui_params(value)
167
- @form_ui, @form_ui_options = *value
168
- end
193
+ def <=>(other)
194
+ order_weight = weight <=> other.weight
195
+ order_weight.nonzero? ? order_weight : name.to_s <=> other.name.to_s
196
+ end
169
197
 
170
- # value must be a Symbol, or an Array of list_ui and options hash which will be used with list_ui only
171
- def list_ui=(value)
172
- check_valid_action_ui_params(value)
173
- @list_ui, @list_ui_options = *value
174
- end
198
+ def convert_to_native?
199
+ number? && options[:format] && form_ui != :number
200
+ end
175
201
 
176
- def list_ui
177
- @list_ui || form_ui
178
- end
202
+ def number_to_native(value)
203
+ return value if value.blank? || !value.is_a?(String)
204
+
205
+ native = '.' # native ruby separator
206
+ format = {separator: '', delimiter: ''}.merge! I18n.t('number.format', default: {})
207
+ specific =
208
+ case options[:format]
209
+ when :currency
210
+ I18n.t('number.currency.format', default: nil)
211
+ when :size
212
+ I18n.t('number.human.format', default: nil)
213
+ when :percentage
214
+ I18n.t('number.percentage.format', default: nil)
215
+ end
216
+ format.merge! specific unless specific.nil?
217
+ if format[:separator].blank? || (value.exclude?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/))
218
+ value
219
+ else
220
+ value.gsub(/[^0-9\-#{format[:separator]}]/, '').gsub(format[:separator], native)
221
+ end
222
+ end
179
223
 
180
- def list_ui_options
181
- @list_ui ? @list_ui_options : form_ui_options
182
- end
224
+ # value must be a Symbol, or an Array of form_ui and options hash which will be used with form_ui only
225
+ def form_ui=(value)
226
+ check_valid_action_ui_params(value)
227
+ @form_ui, @form_ui_options = *value
228
+ end
183
229
 
184
- # value must be a Symbol, or an Array of show_ui and options hash which will be used with show_ui only
185
- def show_ui=(value)
186
- check_valid_action_ui_params(value)
187
- @show_ui, @show_ui_options = *value
188
- end
230
+ # value must be a Symbol, or an Array of list_ui and options hash which will be used with list_ui only
231
+ def list_ui=(value)
232
+ check_valid_action_ui_params(value)
233
+ @list_ui, @list_ui_options = *value
234
+ end
189
235
 
190
- def show_ui
191
- @show_ui || list_ui
192
- end
236
+ def list_ui
237
+ @list_ui || form_ui
238
+ end
193
239
 
194
- def show_ui_options
195
- @show_ui ? @show_ui_options : list_ui_options
196
- end
240
+ def list_ui_options
241
+ @list_ui ? @list_ui_options : form_ui_options
242
+ end
197
243
 
198
- # value must be a Symbol, or an Array of search_ui and options hash which will be used with search_ui only
199
- def search_ui=(value)
200
- check_valid_action_ui_params(value)
201
- @search_ui, @search_ui_options = *value
202
- end
244
+ # value must be a Symbol, or an Array of show_ui and options hash which will be used with show_ui only
245
+ def show_ui=(value)
246
+ check_valid_action_ui_params(value)
247
+ @show_ui, @show_ui_options = *value
248
+ end
203
249
 
204
- def search_ui
205
- @search_ui || @form_ui || (:select if association && !association.polymorphic?)
206
- end
250
+ def show_ui
251
+ @show_ui || list_ui
252
+ end
207
253
 
208
- def search_ui_options
209
- @search_ui ? @search_ui_options : form_ui_options
210
- end
254
+ def show_ui_options
255
+ @show_ui ? @show_ui_options : list_ui_options
256
+ end
211
257
 
212
- # a place to store dev's column specific options
213
- attr_writer :options
214
- def options
215
- return @options || NO_OPTIONS if frozen?
216
- @options ||= NO_OPTIONS.dup
217
- end
258
+ # value must be a Symbol, or an Array of search_ui and options hash which will be used with search_ui only
259
+ def search_ui=(value)
260
+ check_valid_action_ui_params(value)
261
+ @search_ui, @search_ui_options = *value
262
+ end
218
263
 
219
- def link
220
- return @link.call(self) if frozen? && @link.is_a?(Proc)
221
- @link = @link.call(self) if @link.is_a? Proc
222
- @link
223
- end
264
+ def search_ui
265
+ @search_ui || form_ui || (:select if association && !association.polymorphic?)
266
+ end
224
267
 
225
- # associate an action_link with this column
226
- def set_link(action, options = {})
227
- if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc)
228
- @link = action
229
- else
230
- options[:label] ||= label
231
- options[:position] ||= :after unless options.key?(:position)
232
- options[:type] ||= :member
233
- @link = ActiveScaffold::DataStructures::ActionLink.new(action, options)
268
+ def search_ui_options
269
+ @search_ui ? @search_ui_options : form_ui_options
234
270
  end
235
- end
236
271
 
237
- # set an action_link to nested list or inline form in this column
238
- def autolink?
239
- @autolink
240
- end
272
+ def includes=(value)
273
+ @includes =
274
+ case value
275
+ when Array then value
276
+ else value ? [value] : value # not convert nil to [nil]
277
+ end
278
+ end
241
279
 
242
- # this should not only delete any existing link but also prevent column links from being automatically added by later routines
243
- def clear_link
244
- @link = nil
245
- @autolink = false
246
- end
280
+ # a collection of associations to do left join when this column is included on search
281
+ def search_joins
282
+ @search_joins || includes
283
+ end
247
284
 
248
- # define a calculation for the column. anything that ActiveRecord::Calculations::ClassMethods#calculate accepts will do.
249
- attr_accessor :calculate
285
+ def search_joins=(value)
286
+ @search_joins =
287
+ case value
288
+ when Array then value
289
+ else [value] # automatically convert to an array
290
+ end
291
+ end
250
292
 
251
- # get whether to run a calculation on this column
252
- def calculation?
253
- !(@calculate == false || @calculate.nil?)
254
- end
293
+ # describes how to search on a column
294
+ # search = true default, uses intelligent search sql
295
+ # search = "CONCAT(a, b)" define your own sql for searching. this should be the "left-side" of a WHERE condition. the operator and value will be supplied by ActiveScaffold.
296
+ # search = [:a, :b] searches in both fields
297
+ def search_sql=(value)
298
+ @search_sql =
299
+ if value
300
+ value == true || value.is_a?(Proc) ? value : Array(value)
301
+ else
302
+ value
303
+ end
304
+ end
255
305
 
256
- # a collection of associations to pre-load when finding the records on a page
257
- attr_reader :includes
258
- def includes=(value)
259
- @includes =
260
- case value
261
- when Array then value
262
- else value ? [value] : value # not convert nil to [nil]
306
+ def search_sql
307
+ initialize_search_sql if @search_sql == true
308
+ @search_sql
309
+ end
310
+
311
+ def searchable?
312
+ search_sql.present?
313
+ end
314
+
315
+ def link
316
+ if frozen? && @link.is_a?(Proc)
317
+ ActiveScaffold::Registry.cache(:column_links, cache_key) { @link.call(self).deep_freeze! }
318
+ else
319
+ @link = @link.call(self) if @link.is_a? Proc
320
+ @link
263
321
  end
322
+ end
323
+
324
+ # associate an action_link with this column
325
+ def set_link(action, options = {})
326
+ if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc)
327
+ @link = action
328
+ else
329
+ options[:label] ||= label
330
+ options[:position] ||= :after unless options.key?(:position)
331
+ options[:type] ||= :member
332
+ @link = ActiveScaffold::DataStructures::ActionLink.new(action, options)
333
+ end
334
+ end
335
+
336
+ def cache_count?
337
+ includes.blank? && associated_number? && association&.cache_count?
338
+ end
339
+
340
+ def attributes=(opts)
341
+ opts.each do |setting, value|
342
+ send :"#{setting}=", value
343
+ end
344
+ end
345
+
346
+ protected
347
+
348
+ def initialize_sort
349
+ self.sort =
350
+ if column && !tableless?
351
+ {sql: field}
352
+ else
353
+ false
354
+ end
355
+ end
356
+
357
+ def initialize_search_sql
358
+ self.search_sql =
359
+ unless virtual?
360
+ if association.nil?
361
+ field.to_s unless tableless?
362
+ elsif association.allow_join?
363
+ [association.quoted_table_name, association.quoted_primary_key].join('.') unless association.klass < ActiveScaffold::Tableless
364
+ end
365
+ end
366
+ end
264
367
  end
265
368
 
266
- # a collection of associations to do left join when this column is included on search
267
- def search_joins
268
- @search_joins || @includes
369
+ include ActiveScaffold::Configurable
370
+ include ActiveScaffold::OrmChecks
371
+ NO_PARAMS = Set.new.freeze
372
+ NO_OPTIONS = {}.freeze
373
+
374
+ attr_reader :active_record_class
375
+ alias model active_record_class
376
+
377
+ # this is the name of the getter on the ActiveRecord model. it is the only absolutely required attribute ... all others will be inferred from this name.
378
+ attr_reader :name
379
+
380
+ include ProxyableMethods
381
+
382
+ # Any extra parameters this particular column uses. This is for create/update purposes.
383
+ def params
384
+ return @params || NO_PARAMS if frozen?
385
+
386
+ @params ||= NO_PARAMS.dup
269
387
  end
270
388
 
271
- def search_joins=(value)
272
- @search_joins =
273
- case value
274
- when Array then value
275
- else [value] # automatically convert to an array
276
- end
389
+ def default_value
390
+ @default_value || @db_default_value
277
391
  end
278
392
 
279
- # a collection of columns to load when eager loading is disabled, if it's nil all columns will be loaded
280
- attr_accessor :select_associated_columns
281
-
282
- # describes how to search on a column
283
- # search = true default, uses intelligent search sql
284
- # search = "CONCAT(a, b)" define your own sql for searching. this should be the "left-side" of a WHERE condition. the operator and value will be supplied by ActiveScaffold.
285
- # search = [:a, :b] searches in both fields
286
- def search_sql=(value)
287
- @search_sql =
288
- if value
289
- value == true || value.is_a?(Proc) ? value : Array(value)
290
- else
291
- value
292
- end
393
+ def default_value=(value)
394
+ raise ArgumentError, "Can't set default value for non-DB columns (virtual columns or associations)" unless column
395
+
396
+ @default_value = value
293
397
  end
294
398
 
295
- def search_sql
296
- initialize_search_sql if @search_sql == true
297
- @search_sql
399
+ def default_value?
400
+ defined? @default_value
298
401
  end
299
402
 
300
- def searchable?
301
- search_sql.present?
403
+ # default to send all the form instead of only new value when a column changes
404
+ cattr_accessor :send_form_on_update_column, instance_accessor: false
405
+
406
+ def options
407
+ return @options || NO_OPTIONS if frozen?
408
+
409
+ @options ||= NO_OPTIONS.dup
302
410
  end
303
411
 
304
- # to modify the default order of columns
305
- attr_accessor :weight
412
+ # set an action_link to nested list or inline form in this column
413
+ def autolink?
414
+ @autolink
415
+ end
306
416
 
307
417
  # to set how many associated records a column with plural association must show in list
308
418
  cattr_accessor :associated_limit, instance_accessor: false
309
419
  @@associated_limit = 3
310
- attr_accessor :associated_limit
311
420
 
312
421
  # whether the number of associated records must be shown or not
313
422
  cattr_accessor :associated_number, instance_accessor: false
314
423
  @@associated_number = true
315
- attr_writer :associated_number
316
- def associated_number?
317
- @associated_number
318
- end
319
-
320
- # what string to use to join records from plural associations
321
- attr_accessor :association_join_text
322
424
 
323
425
  # whether a blank row must be shown in the subform
324
426
  cattr_accessor :show_blank_record, instance_accessor: false
325
427
  @@show_blank_record = true
326
- attr_writer :show_blank_record
327
- def show_blank_record?(associated)
328
- return false unless @show_blank_record
329
- return false unless association.klass.authorized_for?(:crud_type => :create) && !association.readonly?
330
- association.collection? || (association.singular? && associated.blank?)
331
- end
332
428
 
333
429
  # methods for automatic links in singular association columns
334
430
  cattr_accessor :actions_for_association_links, instance_accessor: false
335
431
  @@actions_for_association_links = %i[new edit show]
336
- attr_accessor :actions_for_association_links
337
432
 
338
- cattr_accessor :association_form_ui
433
+ cattr_accessor :association_form_ui, instance_accessor: false
339
434
  @@association_form_ui = nil
340
435
 
341
436
  # ----------------------------------------------------------------- #
@@ -356,17 +451,12 @@ module ActiveScaffold::DataStructures
356
451
  column.nil? && association.nil?
357
452
  end
358
453
 
359
- attr_writer :number
360
- def number?
361
- @number
362
- end
363
-
364
454
  def text?
365
455
  @text
366
456
  end
367
457
 
368
458
  # this is so that array.delete and array.include?, etc., will work by column name
369
- def ==(other) #:nodoc:
459
+ def ==(other) # :nodoc:
370
460
  # another column
371
461
  if other.respond_to?(:name) && other.class == self.class
372
462
  name == other.name.to_sym
@@ -383,7 +473,7 @@ module ActiveScaffold::DataStructures
383
473
  attr_reader :cache_key
384
474
 
385
475
  # instantiation is handled internally through the DataStructures::Columns object
386
- def initialize(name, active_record_class, delegated_association = nil) #:nodoc:
476
+ def initialize(name, active_record_class, delegated_association = nil) # :nodoc:
387
477
  @name = name.to_sym
388
478
  @active_record_class = active_record_class
389
479
  @column = _columns_hash[name.to_s]
@@ -419,9 +509,9 @@ module ActiveScaffold::DataStructures
419
509
  # default all the configurable variables
420
510
  self.css_class = ''
421
511
  validators_force_require_on = active_record_class.validators_on(name)
422
- .map { |val| validator_force_required?(val) }
423
- .select(&:present?)
424
- self.required = validators_force_require_on.any? { |opt| opt == true } ||
512
+ .map { |val| validator_force_required?(val) }
513
+ .compact_blank
514
+ self.required = validators_force_require_on.any?(true) ||
425
515
  validators_force_require_on.reject { |opt| opt == true }.flatten.presence
426
516
  self.sort = true
427
517
  self.search_sql = true
@@ -432,41 +522,13 @@ module ActiveScaffold::DataStructures
432
522
  # just the field (not table.field)
433
523
  def field_name
434
524
  return nil if virtual?
435
- @field_name ||= column ? quoted_field_name(column.name) : quoted_field_name(association.foreign_key)
436
- end
437
-
438
- def <=>(other)
439
- order_weight = weight <=> other.weight
440
- order_weight.nonzero? ? order_weight : name.to_s <=> other.name.to_s
441
- end
442
525
 
443
- def convert_to_native?
444
- number? && options[:format] && form_ui != :number
445
- end
446
-
447
- def number_to_native(value)
448
- return value if value.blank? || !value.is_a?(String)
449
- native = '.' # native ruby separator
450
- format = {:separator => '', :delimiter => ''}.merge! I18n.t('number.format', :default => {})
451
- specific =
452
- case options[:format]
453
- when :currency
454
- I18n.t('number.currency.format', :default => nil)
455
- when :size
456
- I18n.t('number.human.format', :default => nil)
457
- when :percentage
458
- I18n.t('number.percentage.format', :default => nil)
459
- end
460
- format.merge! specific unless specific.nil?
461
- if format[:separator].blank? || !value.include?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/)
462
- value
463
- else
464
- value.gsub(/[^0-9\-#{format[:separator]}]/, '').gsub(format[:separator], native)
465
- end
526
+ @field_name ||= column ? quoted_field_name(column.name) : quoted_field_name(association.foreign_key)
466
527
  end
467
528
 
468
529
  def default_for_empty_value
469
530
  return nil unless column
531
+
470
532
  if column.is_a?(ActiveModel::Attribute)
471
533
  column.value
472
534
  elsif active_record? && null?
@@ -501,12 +563,6 @@ module ActiveScaffold::DataStructures
501
563
  ActiveScaffold::OrmChecks.column_type active_record_class, name
502
564
  end
503
565
 
504
- def attributes=(opts)
505
- opts.each do |setting, value|
506
- send "#{setting}=", value
507
- end
508
- end
509
-
510
566
  def cast(value)
511
567
  ActiveScaffold::OrmChecks.cast active_record_class, name, value
512
568
  end
@@ -516,11 +572,11 @@ module ActiveScaffold::DataStructures
516
572
  def setup_defaults_for_column
517
573
  if active_record_class.respond_to?(:defined_enums) && active_record_class.defined_enums[name.to_s]
518
574
  @form_ui = :select
519
- @options = {:options => active_record_class.send(name.to_s.pluralize).keys.map(&:to_sym)}
575
+ @options = {options: active_record_class.send(name.to_s.pluralize).keys.map(&:to_sym)}
520
576
  elsif column_number?
521
577
  @number = true
522
578
  @form_ui = :number
523
- @options = {:format => :i18n_number}
579
+ @options = {format: :i18n_number}
524
580
  else
525
581
  @form_ui =
526
582
  case column_type
@@ -547,6 +603,7 @@ module ActiveScaffold::DataStructures
547
603
 
548
604
  def validator_force_required?(val)
549
605
  return false if val.options[:if] || val.options[:unless]
606
+
550
607
  case val
551
608
  when ActiveModel::Validations::PresenceValidator
552
609
  validator_required_on(val)
@@ -588,8 +645,11 @@ module ActiveScaffold::DataStructures
588
645
  end
589
646
 
590
647
  def column_number?
591
- return %i[float decimal integer].include? column_type if active_record?
592
- return @column.type < Numeric if mongoid?
648
+ if active_record?
649
+ %i[float decimal integer].include? column_type
650
+ elsif mongoid?
651
+ @column.type < Numeric
652
+ end
593
653
  end
594
654
 
595
655
  def quoted_field_name(column_name)
@@ -604,26 +664,6 @@ module ActiveScaffold::DataStructures
604
664
  active_record? ? [_quoted_table_name, name].compact.join('.') : name
605
665
  end
606
666
 
607
- def initialize_sort
608
- self.sort =
609
- if column && !tableless?
610
- {:sql => field}
611
- else
612
- false
613
- end
614
- end
615
-
616
- def initialize_search_sql
617
- self.search_sql =
618
- unless virtual?
619
- if association.nil?
620
- field.to_s unless tableless?
621
- elsif association.allow_join?
622
- [association.quoted_table_name, association.quoted_primary_key].join('.') unless association.klass < ActiveScaffold::Tableless
623
- end
624
- end
625
- end
626
-
627
667
  # the table name from the ActiveRecord class
628
668
  attr_reader :table
629
669
 
@@ -645,6 +685,7 @@ module ActiveScaffold::DataStructures
645
685
 
646
686
  def check_valid_action_ui_params(value)
647
687
  return true if valid_action_ui_params?(value)
688
+
648
689
  raise ArgumentError, 'value must be a Symbol, or an array of Symbol and Hash'
649
690
  end
650
691