active_scaffold 3.2.18 → 3.2.19

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 (246) hide show
  1. data/CHANGELOG +3 -0
  2. data/app/assets/images/active_scaffold/add.png +0 -0
  3. data/app/assets/images/active_scaffold/arrow_down.png +0 -0
  4. data/app/assets/images/active_scaffold/arrow_up.png +0 -0
  5. data/app/assets/images/active_scaffold/close.png +0 -0
  6. data/app/assets/images/active_scaffold/close_touch.png +0 -0
  7. data/app/assets/images/active_scaffold/config.png +0 -0
  8. data/app/assets/images/active_scaffold/cross.png +0 -0
  9. data/app/assets/images/active_scaffold/gears.png +0 -0
  10. data/app/assets/images/active_scaffold/indicator-small.gif +0 -0
  11. data/app/assets/images/active_scaffold/indicator.gif +0 -0
  12. data/app/assets/images/active_scaffold/magnifier.png +0 -0
  13. data/app/assets/javascripts/active_scaffold.js.erb +19 -0
  14. data/app/assets/javascripts/jquery/active_scaffold.js +1113 -0
  15. data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +24 -0
  16. data/app/assets/javascripts/jquery/draggable_lists.js +27 -0
  17. data/app/assets/javascripts/jquery/jquery.editinplace.js +743 -0
  18. data/app/assets/javascripts/jquery/tiny_mce_bridge.js +7 -0
  19. data/app/assets/javascripts/prototype/active_scaffold.js +1107 -0
  20. data/app/assets/javascripts/prototype/dhtml_history.js +870 -0
  21. data/app/assets/javascripts/prototype/form_enhancements.js +117 -0
  22. data/app/assets/javascripts/prototype/rico_corner.js +370 -0
  23. data/app/assets/javascripts/prototype/tiny_mce_bridge.js +7 -0
  24. data/app/assets/stylesheets/active_scaffold-ie.css.scss +54 -0
  25. data/app/assets/stylesheets/active_scaffold.css.scss +14 -0
  26. data/app/assets/stylesheets/active_scaffold_colors.css.scss +395 -0
  27. data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -0
  28. data/app/assets/stylesheets/active_scaffold_images.css.scss +40 -0
  29. data/app/assets/stylesheets/active_scaffold_layout.css +936 -0
  30. data/app/assets/stylesheets/blue-theme.css +74 -0
  31. data/config/locales/de.yml +125 -0
  32. data/config/locales/en.yml +127 -0
  33. data/config/locales/es.yml +128 -0
  34. data/config/locales/fr.yml +131 -0
  35. data/config/locales/hu.yml +126 -0
  36. data/config/locales/ja.yml +126 -0
  37. data/config/locales/ru.yml +135 -0
  38. data/frontends/default/views/_action_group.html.erb +24 -0
  39. data/frontends/default/views/_add_existing_form.html.erb +30 -0
  40. data/frontends/default/views/_base_form.html.erb +53 -0
  41. data/frontends/default/views/_create_form.html.erb +8 -0
  42. data/frontends/default/views/_create_form_on_list.html.erb +6 -0
  43. data/frontends/default/views/_field_search.html.erb +32 -0
  44. data/frontends/default/views/_form.html.erb +28 -0
  45. data/frontends/default/views/_form_association.html.erb +17 -0
  46. data/frontends/default/views/_form_association_footer.html.erb +47 -0
  47. data/frontends/default/views/_form_attribute.html.erb +23 -0
  48. data/frontends/default/views/_form_hidden_attribute.html.erb +7 -0
  49. data/frontends/default/views/_form_messages.html.erb +5 -0
  50. data/frontends/default/views/_horizontal_subform.html.erb +22 -0
  51. data/frontends/default/views/_horizontal_subform_footer.html.erb +0 -0
  52. data/frontends/default/views/_horizontal_subform_header.html.erb +11 -0
  53. data/frontends/default/views/_horizontal_subform_record.html.erb +43 -0
  54. data/frontends/default/views/_human_conditions.html.erb +1 -0
  55. data/frontends/default/views/_list.html.erb +18 -0
  56. data/frontends/default/views/_list_actions.html.erb +15 -0
  57. data/frontends/default/views/_list_calculations.html.erb +16 -0
  58. data/frontends/default/views/_list_column_headings.html.erb +12 -0
  59. data/frontends/default/views/_list_header.html.erb +10 -0
  60. data/frontends/default/views/_list_inline_adapter.html.erb +21 -0
  61. data/frontends/default/views/_list_messages.html.erb +28 -0
  62. data/frontends/default/views/_list_pagination.html.erb +11 -0
  63. data/frontends/default/views/_list_pagination_links.html.erb +9 -0
  64. data/frontends/default/views/_list_record.html.erb +13 -0
  65. data/frontends/default/views/_list_record_columns.html.erb +8 -0
  66. data/frontends/default/views/_list_with_header.html.erb +36 -0
  67. data/frontends/default/views/_messages.html.erb +10 -0
  68. data/frontends/default/views/_refresh_list.js.erb +1 -0
  69. data/frontends/default/views/_render_field.js.erb +20 -0
  70. data/frontends/default/views/_row.html.erb +1 -0
  71. data/frontends/default/views/_search.html.erb +34 -0
  72. data/frontends/default/views/_search_attribute.html.erb +10 -0
  73. data/frontends/default/views/_show.html.erb +8 -0
  74. data/frontends/default/views/_show_columns.html.erb +15 -0
  75. data/frontends/default/views/_update_actions.html.erb +9 -0
  76. data/frontends/default/views/_update_calculations.js.erb +4 -0
  77. data/frontends/default/views/_update_form.html.erb +6 -0
  78. data/frontends/default/views/_update_messages.js.erb +2 -0
  79. data/frontends/default/views/_vertical_subform.html.erb +12 -0
  80. data/frontends/default/views/_vertical_subform_record.html.erb +43 -0
  81. data/frontends/default/views/action_confirmation.html.erb +13 -0
  82. data/frontends/default/views/add_existing.js.erb +14 -0
  83. data/frontends/default/views/add_existing_form.html.erb +5 -0
  84. data/frontends/default/views/create.html.erb +5 -0
  85. data/frontends/default/views/delete.html.erb +13 -0
  86. data/frontends/default/views/destroy.js.erb +26 -0
  87. data/frontends/default/views/edit_associated.js.erb +12 -0
  88. data/frontends/default/views/field_search.html.erb +5 -0
  89. data/frontends/default/views/form_messages.js.erb +1 -0
  90. data/frontends/default/views/list.html.erb +1 -0
  91. data/frontends/default/views/on_action_update.js.erb +22 -0
  92. data/frontends/default/views/on_create.js.erb +38 -0
  93. data/frontends/default/views/on_mark.js.erb +6 -0
  94. data/frontends/default/views/on_update.js.erb +29 -0
  95. data/frontends/default/views/refresh_list.js.erb +2 -0
  96. data/frontends/default/views/render_field.js.erb +1 -0
  97. data/frontends/default/views/row.js.erb +2 -0
  98. data/frontends/default/views/search.html.erb +5 -0
  99. data/frontends/default/views/show.html.erb +5 -0
  100. data/frontends/default/views/update.html.erb +8 -0
  101. data/frontends/default/views/update_column.js.erb +15 -0
  102. data/frontends/default/views/update_row.js.erb +1 -0
  103. data/lib/active_scaffold/actions/common_search.rb +22 -0
  104. data/lib/active_scaffold/actions/core.rb +203 -0
  105. data/lib/active_scaffold/actions/create.rb +139 -0
  106. data/lib/active_scaffold/actions/delete.rb +74 -0
  107. data/lib/active_scaffold/actions/field_search.rb +78 -0
  108. data/lib/active_scaffold/actions/list.rb +208 -0
  109. data/lib/active_scaffold/actions/mark.rb +89 -0
  110. data/lib/active_scaffold/actions/nested.rb +244 -0
  111. data/lib/active_scaffold/actions/search.rb +48 -0
  112. data/lib/active_scaffold/actions/show.rb +61 -0
  113. data/lib/active_scaffold/actions/subform.rb +23 -0
  114. data/lib/active_scaffold/actions/update.rb +156 -0
  115. data/lib/active_scaffold/active_record_permissions.rb +135 -0
  116. data/lib/active_scaffold/attribute_params.rb +200 -0
  117. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +39 -0
  118. data/lib/active_scaffold/bridges/ancestry.rb +5 -0
  119. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +37 -0
  120. data/lib/active_scaffold/bridges/bitfields.rb +6 -0
  121. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +66 -0
  122. data/lib/active_scaffold/bridges/calendar_date_select.rb +24 -0
  123. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +127 -0
  124. data/lib/active_scaffold/bridges/cancan.rb +15 -0
  125. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +31 -0
  126. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb +10 -0
  127. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +45 -0
  128. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +17 -0
  129. data/lib/active_scaffold/bridges/carrierwave.rb +12 -0
  130. data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +358 -0
  131. data/lib/active_scaffold/bridges/country_helper.rb +9 -0
  132. data/lib/active_scaffold/bridges/date_picker/ext.rb +63 -0
  133. data/lib/active_scaffold/bridges/date_picker/helper.rb +180 -0
  134. data/lib/active_scaffold/bridges/date_picker.rb +23 -0
  135. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +34 -0
  136. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb +10 -0
  137. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +27 -0
  138. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +16 -0
  139. data/lib/active_scaffold/bridges/dragonfly.rb +9 -0
  140. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +46 -0
  141. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +57 -0
  142. data/lib/active_scaffold/bridges/file_column/form_ui.rb +34 -0
  143. data/lib/active_scaffold/bridges/file_column/list_ui.rb +26 -0
  144. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
  145. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
  146. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
  147. data/lib/active_scaffold/bridges/file_column.rb +11 -0
  148. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +27 -0
  149. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +16 -0
  150. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +36 -0
  151. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +24 -0
  152. data/lib/active_scaffold/bridges/paperclip.rb +12 -0
  153. data/lib/active_scaffold/bridges/record_select/helpers.rb +92 -0
  154. data/lib/active_scaffold/bridges/record_select.rb +11 -0
  155. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +20 -0
  156. data/lib/active_scaffold/bridges/semantic_attributes.rb +5 -0
  157. data/lib/active_scaffold/bridges/shared/date_bridge.rb +209 -0
  158. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +46 -0
  159. data/lib/active_scaffold/bridges/tiny_mce.rb +17 -0
  160. data/lib/active_scaffold/bridges.rb +61 -0
  161. data/lib/active_scaffold/config/base.rb +75 -0
  162. data/lib/active_scaffold/config/core.rb +236 -0
  163. data/lib/active_scaffold/config/create.rb +32 -0
  164. data/lib/active_scaffold/config/delete.rb +32 -0
  165. data/lib/active_scaffold/config/field_search.rb +79 -0
  166. data/lib/active_scaffold/config/form.rb +64 -0
  167. data/lib/active_scaffold/config/list.rb +247 -0
  168. data/lib/active_scaffold/config/mark.rb +30 -0
  169. data/lib/active_scaffold/config/nested.rb +42 -0
  170. data/lib/active_scaffold/config/search.rb +73 -0
  171. data/lib/active_scaffold/config/show.rb +31 -0
  172. data/lib/active_scaffold/config/subform.rb +35 -0
  173. data/lib/active_scaffold/config/update.rb +33 -0
  174. data/lib/active_scaffold/configurable.rb +29 -0
  175. data/lib/active_scaffold/constraints.rb +171 -0
  176. data/lib/active_scaffold/data_structures/action_columns.rb +142 -0
  177. data/lib/active_scaffold/data_structures/action_link.rb +185 -0
  178. data/lib/active_scaffold/data_structures/action_links.rb +191 -0
  179. data/lib/active_scaffold/data_structures/actions.rb +45 -0
  180. data/lib/active_scaffold/data_structures/bridge.rb +22 -0
  181. data/lib/active_scaffold/data_structures/column.rb +402 -0
  182. data/lib/active_scaffold/data_structures/columns.rb +75 -0
  183. data/lib/active_scaffold/data_structures/error_message.rb +24 -0
  184. data/lib/active_scaffold/data_structures/nested_info.rb +171 -0
  185. data/lib/active_scaffold/data_structures/set.rb +61 -0
  186. data/lib/active_scaffold/data_structures/sorting.rb +167 -0
  187. data/lib/active_scaffold/engine.rb +4 -0
  188. data/lib/active_scaffold/extensions/action_controller_rendering.rb +20 -0
  189. data/lib/active_scaffold/extensions/action_controller_rescueing.rb +7 -0
  190. data/lib/active_scaffold/extensions/action_view_rendering.rb +115 -0
  191. data/lib/active_scaffold/extensions/active_record_offset.rb +12 -0
  192. data/lib/active_scaffold/extensions/array.rb +7 -0
  193. data/lib/active_scaffold/extensions/cache_association.rb +16 -0
  194. data/lib/active_scaffold/extensions/localize.rb +10 -0
  195. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +12 -0
  196. data/lib/active_scaffold/extensions/nil_id_in_url_params.rb +7 -0
  197. data/lib/active_scaffold/extensions/paginator_extensions.rb +26 -0
  198. data/lib/active_scaffold/extensions/reverse_associations.rb +64 -0
  199. data/lib/active_scaffold/extensions/routing_mapper.rb +48 -0
  200. data/lib/active_scaffold/extensions/to_label.rb +8 -0
  201. data/lib/active_scaffold/extensions/unsaved_associated.rb +61 -0
  202. data/lib/active_scaffold/extensions/unsaved_record.rb +20 -0
  203. data/lib/active_scaffold/extensions/usa_state.rb +46 -0
  204. data/lib/active_scaffold/finder.rb +399 -0
  205. data/lib/active_scaffold/helpers/association_helpers.rb +42 -0
  206. data/lib/active_scaffold/helpers/controller_helpers.rb +94 -0
  207. data/lib/active_scaffold/helpers/form_column_helpers.rb +322 -0
  208. data/lib/active_scaffold/helpers/human_condition_helpers.rb +64 -0
  209. data/lib/active_scaffold/helpers/id_helpers.rb +131 -0
  210. data/lib/active_scaffold/helpers/list_column_helpers.rb +374 -0
  211. data/lib/active_scaffold/helpers/pagination_helpers.rb +62 -0
  212. data/lib/active_scaffold/helpers/search_column_helpers.rb +257 -0
  213. data/lib/active_scaffold/helpers/show_column_helpers.rb +44 -0
  214. data/lib/active_scaffold/helpers/view_helpers.rb +398 -0
  215. data/lib/active_scaffold/marked_model.rb +38 -0
  216. data/lib/active_scaffold/paginator.rb +136 -0
  217. data/lib/active_scaffold/responds_to_parent.rb +70 -0
  218. data/lib/active_scaffold/tableless.rb +83 -0
  219. data/lib/active_scaffold/version.rb +9 -0
  220. data/lib/active_scaffold.rb +373 -0
  221. data/lib/active_scaffold_env.rb +13 -0
  222. data/lib/generators/active_scaffold/USAGE +29 -0
  223. data/lib/generators/active_scaffold/active_scaffold_generator.rb +21 -0
  224. data/lib/generators/active_scaffold_controller/USAGE +19 -0
  225. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +29 -0
  226. data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
  227. data/lib/generators/active_scaffold_controller/templates/helper.rb +2 -0
  228. data/public/blank.html +33 -0
  229. data/shoulda_macros/macros.rb +136 -0
  230. data/vendor/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  231. data/vendor/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  232. data/vendor/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
  233. data/vendor/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  234. data/vendor/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  235. data/vendor/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  236. data/vendor/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  237. data/vendor/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  238. data/vendor/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  239. data/vendor/assets/images/ui-icons_222222_256x240.png +0 -0
  240. data/vendor/assets/images/ui-icons_228ef1_256x240.png +0 -0
  241. data/vendor/assets/images/ui-icons_ef8c08_256x240.png +0 -0
  242. data/vendor/assets/images/ui-icons_ffd27a_256x240.png +0 -0
  243. data/vendor/assets/images/ui-icons_ffffff_256x240.png +0 -0
  244. data/vendor/assets/javascripts/jquery-ui-timepicker-addon.js +1276 -0
  245. data/vendor/assets/stylesheets/jquery-ui.css +568 -0
  246. metadata +261 -17
@@ -0,0 +1,29 @@
1
+ module ActiveScaffold
2
+ # Exposes a +configure+ method that accepts a block and runs all contents of the block in two contexts, as opposed to the normal one. First, everything gets evaluated as part of the object including Configurable. Then, as a failover, missing methods and variables are evaluated in the original binding of the block.
3
+ #
4
+ # Note that this only works with "barewords". Constants, instance variables, and class variables are not currently supported in both contexts.
5
+ #
6
+ # May add the given functionality at both the class and instance level. For the former, use +extend+, and for the latter, use +include+.
7
+ module Configurable
8
+ def configure(&configuration_block)
9
+ return unless configuration_block
10
+ @configuration_binding = configuration_block.binding
11
+ ret = instance_exec self, &configuration_block
12
+ @configuration_binding = nil
13
+ return ret
14
+ end
15
+
16
+ # this method will surely need tweaking. for example, i'm not sure if it should call super before or after it tries to eval with the binding.
17
+ def method_missing(name, *args)
18
+ begin
19
+ super
20
+ rescue NoMethodError, NameError
21
+ if @configuration_binding.nil?
22
+ raise $!
23
+ else
24
+ eval("self", @configuration_binding).send(name, *args)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,171 @@
1
+ module ActiveScaffold
2
+ module Constraints
3
+
4
+ protected
5
+
6
+ # Returns the current constraints
7
+ def active_scaffold_constraints
8
+ @active_scaffold_constraints ||= active_scaffold_session_storage[:constraints] || {}
9
+ end
10
+
11
+ # For each enabled action, adds the constrained columns to the ActionColumns object (if it exists).
12
+ # This lets the ActionColumns object skip constrained columns.
13
+ #
14
+ # If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column.
15
+ def register_constraints_with_action_columns(constrained_fields = nil)
16
+ constrained_fields ||= []
17
+ constrained_fields |= active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect(&:to_sym)
18
+ exclude_actions = []
19
+ [:list, :update].each do |action_name|
20
+ if active_scaffold_config.actions.include? action_name
21
+ exclude_actions << action_name unless active_scaffold_config.send(action_name).hide_nested_column
22
+ end
23
+ end
24
+
25
+ if self.class.uses_active_scaffold?
26
+ # we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't
27
+ active_scaffold_config.actions.each do |action_name|
28
+ next if exclude_actions.include?(action_name)
29
+ action = active_scaffold_config.send(action_name)
30
+ next unless action.respond_to? :columns
31
+ action.columns.constraint_columns = constrained_fields
32
+ end
33
+ end
34
+ end
35
+
36
+ # Returns search conditions based on the current scaffold constraints.
37
+ #
38
+ # Supports constraints based on either a column name (in which case it checks for an association
39
+ # or just uses the search_sql) or a database field name.
40
+ #
41
+ # All of this work is primarily to support nested scaffolds in a manner generally useful for other
42
+ # embedded scaffolds.
43
+ def conditions_from_constraints
44
+ hash_conditions = {}
45
+ conditions = [hash_conditions]
46
+ active_scaffold_constraints.each do |k, v|
47
+ column = active_scaffold_config.columns[k]
48
+ if column
49
+ # Assume this is a multi-level association constraint.
50
+ # example:
51
+ # data model: Park -> Den -> Bear
52
+ # constraint: :den => {:park => 5}
53
+ if v.is_a? Hash
54
+ far_association = column.association.klass.reflect_on_association(v.keys.first)
55
+ field = far_association.klass.primary_key
56
+ table = far_association.table_name
57
+
58
+ active_scaffold_includes.concat([{k => far_association.name}]) # e.g. {:den => :park}
59
+ hash_conditions.merge!("#{table}.#{field}" => v.values.first)
60
+
61
+ # association column constraint
62
+ elsif column.association
63
+ if column.association.macro == :has_and_belongs_to_many
64
+ active_scaffold_habtm_joins.concat column.includes
65
+ else
66
+ active_scaffold_includes.concat column.includes
67
+ end
68
+ hash_conditions.merge!(condition_from_association_constraint(column.association, v))
69
+
70
+ # regular column constraints
71
+ elsif column.searchable? && params[column.name] != v
72
+ active_scaffold_includes.concat column.includes
73
+ conditions << [column.search_sql.collect { |search_sql| "#{search_sql} = ?" }.join(' OR '), *([v] * column.search_sql.size)]
74
+ end
75
+ # unknown-to-activescaffold-but-real-database-column constraint
76
+ elsif active_scaffold_config.model.columns_hash[k.to_s] && params[column.name] != v
77
+ hash_conditions.merge!(k => v)
78
+ else
79
+ raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller
80
+ end
81
+ end
82
+ conditions
83
+ end
84
+
85
+ # We do NOT want to use .search_sql. If anything, search_sql will refer
86
+ # to a human-searchable value on the associated record.
87
+ def condition_from_association_constraint(association, value)
88
+ # when the reverse association is a :belongs_to, the id for the associated object only exists as
89
+ # the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),
90
+ # we have to use the other model's primary_key.
91
+ #
92
+ # please see the relevant tests for concrete examples.
93
+ field = if [:has_one, :has_many].include?(association.macro)
94
+ association.klass.primary_key
95
+ elsif [:has_and_belongs_to_many].include?(association.macro)
96
+ association.association_foreign_key
97
+ else
98
+ association.options[:foreign_key] || association.name.to_s.foreign_key
99
+ end
100
+
101
+ table = case association.macro
102
+ when :has_and_belongs_to_many
103
+ association.options[:join_table]
104
+
105
+ when :belongs_to
106
+ active_scaffold_config.model.table_name
107
+
108
+ else
109
+ association.table_name
110
+ end
111
+
112
+ if association.options[:primary_key]
113
+ value = association.klass.find(value).send(association.options[:primary_key])
114
+ end
115
+
116
+ condition = {"#{table}.#{field}" => value}
117
+ if association.options[:polymorphic]
118
+ raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(association), caller unless params[:parent_model]
119
+ condition["#{table}.#{association.name}_type"] = params[:parent_model].constantize.model.to_s
120
+ end
121
+
122
+ condition
123
+ end
124
+
125
+ def polymorphic_constraint_error(association)
126
+ "Malformed constraint. You have added a constraint for #{association.name} polymorphic association but parent_model is not set."
127
+ end
128
+
129
+ def constraint_error(klass, column_name)
130
+ "Malformed constraint `#{klass}##{column_name}'. If it's a legitimate column, and you are using a nested scaffold, please specify or double-check the reverse association name."
131
+ end
132
+
133
+ # Applies constraints to the given record.
134
+ #
135
+ # Searches through the known columns for association columns. If the given constraint is an association,
136
+ # it assumes that the constraint value is an id. It then does a association.klass.find with the value
137
+ # and adds the associated object to the record.
138
+ #
139
+ # For some operations ActiveRecord will automatically update the database. That's not always ok.
140
+ # If it *is* ok (e.g. you're in a transaction), then set :allow_autosave to true.
141
+ def apply_constraints_to_record(record, options = {})
142
+ options[:allow_autosave] = false if options[:allow_autosave].nil?
143
+
144
+ active_scaffold_constraints.each do |k, v|
145
+ column = active_scaffold_config.columns[k]
146
+ if column and column.association
147
+ if column.plural_association?
148
+ record.send("#{k}").send(:<<, column.association.klass.find(v))
149
+ elsif column.association.options[:polymorphic]
150
+ raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(column.association), caller unless params[:parent_model]
151
+ record.send("#{k}=", params[:parent_model].constantize.find(v))
152
+ else # regular singular association
153
+ record.send("#{k}=", column.association.klass.find(v))
154
+
155
+ # setting the belongs_to side of a has_one isn't safe. if the has_one was already
156
+ # specified, rails won't automatically clear out the previous associated record.
157
+ #
158
+ # note that we can't take the extra step to correct this unless we're permitted to
159
+ # run operations where activerecord auto-saves the object.
160
+ reverse = column.association.klass.reflect_on_association(column.association.reverse)
161
+ if reverse.macro == :has_one and options[:allow_autosave]
162
+ record.send(k).send("#{column.association.reverse}=", record)
163
+ end
164
+ end
165
+ else
166
+ record.send("#{k}=", v)
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,142 @@
1
+ module ActiveScaffold::DataStructures
2
+ # A set of columns. These structures can be nested for organization.
3
+ class ActionColumns < ActiveScaffold::DataStructures::Set
4
+ include ActiveScaffold::Configurable
5
+
6
+ # this lets us refer back to the action responsible for this link, if it exists.
7
+ # the immediate need here is to get the crud_type so we can dynamically filter columns from the set.
8
+ attr_accessor :action
9
+
10
+ # labels are useful for the Create/Update forms, when we display columns in a grouped fashion and want to name them separately
11
+ attr_writer :label
12
+ def label
13
+ as_(@label) if @label
14
+ end
15
+ def css_class
16
+ @label.to_s.underscore
17
+ end
18
+
19
+ # Whether this column set is collapsed by default in contexts where collapsing is supported
20
+ attr_accessor :collapsed
21
+
22
+ # nests a subgroup in the column set
23
+ def add_subgroup(label, &proc)
24
+ columns = ActiveScaffold::DataStructures::ActionColumns.new
25
+ columns.label = label
26
+ columns.action = self.action
27
+ columns.configure &proc
28
+ self.exclude columns.collect_columns
29
+ self.add columns
30
+ end
31
+
32
+ def include?(item)
33
+ @set.each do |c|
34
+ return true if !c.is_a? Symbol and c.include? item
35
+ return true if c == item.to_sym
36
+ end
37
+ return false
38
+ end
39
+
40
+ def names
41
+ if @columns
42
+ self.collect(&:name)
43
+ else
44
+ names_without_auth_check
45
+ end
46
+ end
47
+
48
+ def names_without_auth_check
49
+ Array(@set)
50
+ end
51
+
52
+ # A package of stuff to add after the configuration block. This is an attempt at making a certain level of functionality inaccessible during configuration, to reduce possible breakage from misuse.
53
+ # The bulk of the package is a means of connecting the referential column set (ActionColumns) with the actual column objects (Columns). This lets us iterate over the set and yield real column objects.
54
+ #module AfterConfiguration
55
+ # Redefine the each method to yield actual Column objects.
56
+ # It will skip constrained and unauthorized columns.
57
+ #
58
+ # Options:
59
+ # * :flatten - whether to recursively iterate on nested sets. default is false.
60
+ # * :for - the record (or class) being iterated over. used for column-level security. default is the class.
61
+ def each(options = {}, &proc)
62
+ options[:for] ||= @columns.active_record_class unless @columns.nil?
63
+ self.unauthorized_columns = []
64
+ @set.each do |item|
65
+ unless item.is_a?(ActiveScaffold::DataStructures::ActionColumns) || @columns.nil?
66
+ item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class))
67
+ next if self.skip_column?(item, options)
68
+ end
69
+ if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten]
70
+ item.each(options, &proc)
71
+ else
72
+ yield item
73
+ end
74
+ end
75
+ end
76
+
77
+ def collect_visible(options = {}, &proc)
78
+ columns = []
79
+ options[:for] ||= @columns.active_record_class
80
+ self.unauthorized_columns = []
81
+ @set.each do |item|
82
+ unless item.is_a? ActiveScaffold::DataStructures::ActionColumns
83
+ item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class))
84
+ next if self.skip_column?(item, options)
85
+ end
86
+ if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten]
87
+ columns = columns + item.collect(options, &proc)
88
+ else
89
+ columns << item
90
+ end
91
+ end
92
+ columns
93
+ end
94
+
95
+ def skip_column?(column, options)
96
+ result = false
97
+ # skip if this matches a constrained column
98
+ result = true if constraint_columns.include?(column.name.to_sym)
99
+ # skip this field if it's not authorized
100
+ unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => column.name)
101
+ self.unauthorized_columns << column.name.to_sym
102
+ result = true
103
+ end
104
+ return result
105
+ end
106
+
107
+ # registers a set of column objects (recursively, for all nested ActionColumns)
108
+ def set_columns(columns)
109
+ @columns = columns
110
+ # iterate over @set instead of self to avoid dealing with security queries
111
+ @set.each do |item|
112
+ item.set_columns(columns) if item.respond_to? :set_columns
113
+ end
114
+ end
115
+
116
+ attr_writer :constraint_columns
117
+ def constraint_columns
118
+ @constraint_columns ||= []
119
+ end
120
+
121
+ attr_writer :unauthorized_columns
122
+ def unauthorized_columns
123
+ @unauthorized_columns ||= []
124
+ end
125
+
126
+ def length
127
+ ((@set - self.constraint_columns) - self.unauthorized_columns).length
128
+ end
129
+ #end
130
+
131
+ protected
132
+
133
+ def collect_columns
134
+ @set.collect {|col| col.is_a?(ActiveScaffold::DataStructures::ActionColumns) ? col.collect_columns : col}
135
+ end
136
+
137
+ # called during clone or dup. makes the clone/dup deeper.
138
+ def initialize_copy(from)
139
+ @set = from.instance_variable_get('@set').clone
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,185 @@
1
+ module ActiveScaffold::DataStructures
2
+ class ActionLink
3
+ # provides a quick way to set any property of the object from a hash
4
+ def initialize(action, options = {})
5
+ # set defaults
6
+ self.action = action
7
+ self.label = action
8
+ self.confirm = false
9
+ self.type = :collection
10
+ self.inline = true
11
+ self.method = :get
12
+ self.crud_type = :delete if [:destroy].include?(action.try(:to_sym))
13
+ self.crud_type = :create if [:create, :new].include?(action.try(:to_sym))
14
+ self.crud_type = :update if [:edit, :update].include?(action.try(:to_sym))
15
+ self.crud_type ||= :read
16
+ self.parameters = {}
17
+ self.html_options = {}
18
+ self.column = nil
19
+ self.image = nil
20
+ self.dynamic_parameters = nil
21
+
22
+ # apply quick properties
23
+ options.each_pair do |k, v|
24
+ setter = "#{k}="
25
+ self.send(setter, v) if self.respond_to? setter
26
+ end
27
+ end
28
+
29
+ # the action-path for this link. what page to request? this is required!
30
+ attr_accessor :action
31
+
32
+ # the controller for this action link. if nil, the current controller should be assumed.
33
+ attr_writer :controller
34
+
35
+ def controller
36
+ @controller = @controller.call if @controller.is_a?(Proc)
37
+ @controller
38
+ end
39
+
40
+ def static_controller?
41
+ !(@controller.is_a?(Proc) || (@controller == :polymorph))
42
+ end
43
+
44
+ # a hash of request parameters
45
+ attr_accessor :parameters
46
+
47
+ # a block for dynamic_parameters
48
+ attr_accessor :dynamic_parameters
49
+
50
+ # the RESTful method
51
+ attr_accessor :method
52
+
53
+ # what string to use to represent this action
54
+ attr_writer :label
55
+ def label
56
+ @label.is_a?(Symbol) ? as_(@label) : @label
57
+ end
58
+
59
+ # image to use {:name => 'arrow.png', :size => '16x16'}
60
+ attr_accessor :image
61
+
62
+ # if the action requires confirmation
63
+ def confirm=(value)
64
+ @dhtml_confirm = nil if value
65
+ @confirm = value
66
+ end
67
+ def confirm(label = '')
68
+ @confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label)
69
+ end
70
+ def confirm?
71
+ !!@confirm
72
+ end
73
+
74
+ # if the action uses a DHTML based (i.e. 2-phase) confirmation
75
+ attr_accessor :dhtml_confirm
76
+ def dhtml_confirm=(value)
77
+ @confirm = nil if value
78
+ @dhtml_confirm = value
79
+ end
80
+ def dhtml_confirm?
81
+ !!@dhtml_confirm
82
+ end
83
+
84
+ # what method to call on the controller to see if this action_link should be visible
85
+ # if method return false, link will be disabled
86
+ # note that this is only the UI part of the security. to prevent URL hax0rz, you also need security on requests (e.g. don't execute update method unless authorized).
87
+ attr_writer :security_method
88
+ def security_method
89
+ @security_method || "#{self.action}_authorized?"
90
+ end
91
+
92
+ def security_method_set?
93
+ !!@security_method
94
+ end
95
+
96
+ # enable it to refresh the parent row when the view is closed
97
+ attr_accessor :refresh_on_close
98
+
99
+ # what method to call on the controller to see if this action_link should be visible
100
+ # if method return true, link won't be displayed
101
+ attr_accessor :ignore_method
102
+
103
+ # the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent.
104
+ # this is used to determine record-level authorization (e.g. record.authorized_for?(:crud_type => link.crud_type).
105
+ # options are :create, :read, :update, and :delete
106
+ attr_accessor :crud_type
107
+
108
+ # an "inline" link is inserted into the existing page
109
+ # exclusive with popup? and page?
110
+ def inline=(val)
111
+ @inline = (val == true)
112
+ self.popup = self.page = false if @inline
113
+ end
114
+ def inline?; @inline end
115
+
116
+ # a "popup" link displays in a separate (browser?) window. this will eventually take arguments.
117
+ # exclusive with inline? and page?
118
+ def popup=(val)
119
+ @popup = (val == true)
120
+ if @popup
121
+ self.inline = self.page = false
122
+
123
+ # the :method parameter doesn't mix with the :popup parameter
124
+ # when/if we start using DHTML popups, we can bring :method back
125
+ self.method = nil
126
+ end
127
+ end
128
+ def popup?; @popup end
129
+
130
+ # a "page" link displays by reloading the current page
131
+ # exclusive with inline? and popup?
132
+ def page=(val)
133
+ @page = (val == true)
134
+ if @page
135
+ self.inline = self.popup = false
136
+
137
+ # when :method is defined, ActionView adds an onclick to use a form ...
138
+ # so it's best to just empty out :method whenever possible.
139
+ # we only ever need to know @method = :get for things that default to POST.
140
+ # the only things that default to POST are forms and ajax calls.
141
+ # when @page = true, we don't use ajax.
142
+ self.method = nil if method == :get
143
+ end
144
+ end
145
+ def page?; @page end
146
+
147
+ # where the result of this action should insert in the display.
148
+ # for :type => :collection, supported values are:
149
+ # :top
150
+ # :bottom
151
+ # :replace (for updating the entire table)
152
+ # false (no attempt at positioning)
153
+ # for :type => :member, supported values are:
154
+ # :before
155
+ # :replace
156
+ # :after
157
+ # false (no attempt at positioning)
158
+ attr_writer :position
159
+ def position
160
+ return @position unless @position.nil? or @position == true
161
+ return :replace if self.type == :member
162
+ return :top if self.type == :collection
163
+ raise "what should the default position be for #{self.type}?"
164
+ end
165
+
166
+ # what type of link this is. currently supported values are :collection and :member.
167
+ attr_accessor :type
168
+
169
+ # html options for the link
170
+ attr_accessor :html_options
171
+
172
+ # nested action_links are referencing a column
173
+ attr_accessor :column
174
+
175
+ # indicates that this a nested_link
176
+ def nested_link?
177
+ @column || (parameters && parameters[:named_scope])
178
+ end
179
+
180
+ # Internal use: generated eid for this action_link
181
+ attr_accessor :eid
182
+
183
+
184
+ end
185
+ end