active_scaffold 3.0.26 → 3.1.3

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 (236) hide show
  1. data/CHANGELOG +1 -1
  2. data/{frontends/default → app/assets}/images/add.gif +0 -0
  3. data/{frontends/default → app/assets}/images/arrow_down.gif +0 -0
  4. data/{frontends/default → app/assets}/images/arrow_up.gif +0 -0
  5. data/{frontends/default → app/assets}/images/close.gif +0 -0
  6. data/{frontends/default → app/assets}/images/close_touch.png +0 -0
  7. data/{frontends/default → app/assets}/images/config.png +0 -0
  8. data/{frontends/default → app/assets}/images/cross.png +0 -0
  9. data/{frontends/default → app/assets}/images/gears.png +0 -0
  10. data/{frontends/default → app/assets}/images/indicator-small.gif +0 -0
  11. data/{frontends/default → app/assets}/images/indicator.gif +0 -0
  12. data/{frontends/default → app/assets}/images/magnifier.png +0 -0
  13. data/app/assets/javascripts/active_scaffold.js.erb +16 -0
  14. data/{frontends/default → app/assets}/javascripts/jquery/active_scaffold.js +16 -28
  15. data/app/assets/javascripts/jquery/active_scaffold.js~ +1036 -0
  16. data/{lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js → app/assets/javascripts/jquery/date_picker_bridge.js.erb} +3 -1
  17. data/{frontends/default → app/assets}/javascripts/jquery/jquery.editinplace.js +0 -0
  18. data/app/assets/javascripts/prototype/active_scaffold.js +1033 -0
  19. data/{frontends/default/javascripts/prototype/active_scaffold.js → app/assets/javascripts/prototype/active_scaffold.js~} +1 -0
  20. data/{frontends/default → app/assets}/javascripts/prototype/dhtml_history.js +0 -0
  21. data/{frontends/default → app/assets}/javascripts/prototype/form_enhancements.js +0 -0
  22. data/{frontends/default → app/assets}/javascripts/prototype/rico_corner.js +0 -0
  23. data/{frontends/default/stylesheets/stylesheet-ie.css → app/assets/stylesheets/active_scaffold-ie.css} +0 -0
  24. data/{frontends/default/stylesheets/stylesheet.css → app/assets/stylesheets/active_scaffold.css.erb} +29 -24
  25. data/{lib/active_scaffold/locale → config/locales}/de.yml +3 -0
  26. data/{lib/active_scaffold/locale → config/locales}/en.yml +3 -0
  27. data/{lib/active_scaffold/locale → config/locales}/es.yml +5 -0
  28. data/{lib/active_scaffold/locale → config/locales}/fr.yml +3 -0
  29. data/{lib/active_scaffold/locale → config/locales}/hu.yml +13 -2
  30. data/{lib/active_scaffold/locale → config/locales}/ja.yml +9 -0
  31. data/{lib/active_scaffold/locale → config/locales}/ru.yml +3 -0
  32. data/frontends/default/views/_form.html.erb +1 -1
  33. data/frontends/default/views/_form_association.html.erb +1 -5
  34. data/frontends/default/views/_horizontal_subform.html.erb +7 -4
  35. data/frontends/default/views/_horizontal_subform.html.erb~ +2 -5
  36. data/frontends/default/views/_horizontal_subform_footer.html.erb +0 -0
  37. data/frontends/default/views/_horizontal_subform_header.html.erb +1 -1
  38. data/frontends/default/views/_horizontal_subform_header.html.erb~ +1 -1
  39. data/frontends/default/views/_horizontal_subform_record.html.erb~ +1 -1
  40. data/frontends/default/views/_list_actions.html.erb +1 -1
  41. data/frontends/default/views/_list_messages.html.erb +1 -3
  42. data/frontends/default/views/_render_field.js.erb +20 -0
  43. data/frontends/default/views/_row.html.erb +3 -9
  44. data/frontends/default/views/_show.html.erb +2 -2
  45. data/frontends/default/views/add_existing.js.erb +20 -0
  46. data/frontends/default/views/destroy.js.erb +24 -0
  47. data/frontends/default/views/{edit_associated.js.rjs → edit_associated.js.erb} +3 -2
  48. data/frontends/default/views/form_messages.js.erb +1 -0
  49. data/frontends/default/views/list.js.erb +1 -0
  50. data/frontends/default/views/mark.js.rjs +6 -0
  51. data/frontends/default/views/on_action_update.js.erb +13 -0
  52. data/frontends/default/views/{on_create.js.erb~ → on_create.js.erb} +0 -0
  53. data/frontends/default/views/on_mark_all.js.erb +12 -0
  54. data/frontends/default/views/{on_update.js.erb~ → on_update.js.erb} +0 -0
  55. data/frontends/default/views/render_field.js.erb +1 -0
  56. data/frontends/default/views/search.html.erb +1 -1
  57. data/frontends/default/views/{update_column.js.erb~ → update_column.js.erb} +3 -3
  58. data/frontends/default/views/update_row.js.erb +1 -0
  59. data/lib/active_scaffold.rb +22 -46
  60. data/lib/active_scaffold/actions/core.rb +14 -6
  61. data/lib/active_scaffold/actions/core.rb~ +3 -3
  62. data/lib/active_scaffold/actions/create.rb +2 -5
  63. data/lib/active_scaffold/actions/create.rb~ +3 -2
  64. data/lib/active_scaffold/actions/delete.rb +1 -0
  65. data/lib/active_scaffold/actions/field_search.rb +1 -1
  66. data/lib/active_scaffold/actions/list.rb +10 -6
  67. data/lib/active_scaffold/actions/list.rb~ +3 -3
  68. data/lib/active_scaffold/actions/mark.rb +8 -8
  69. data/lib/active_scaffold/actions/nested.rb +2 -9
  70. data/lib/active_scaffold/actions/nested.rb~ +5 -7
  71. data/lib/active_scaffold/actions/search.rb +2 -1
  72. data/lib/active_scaffold/actions/subform.rb +1 -5
  73. data/lib/active_scaffold/actions/update.rb +1 -4
  74. data/lib/active_scaffold/actions/update.rb~ +5 -5
  75. data/lib/active_scaffold/attribute_params.rb +15 -26
  76. data/lib/active_scaffold/attribute_params.rb~ +1 -2
  77. data/lib/active_scaffold/bridges.rb +61 -0
  78. data/lib/active_scaffold/bridges/ancestry.rb +5 -0
  79. data/lib/active_scaffold/bridges/ancestry/{lib/ancestry_bridge.rb → ancestry_bridge.rb} +3 -3
  80. data/lib/active_scaffold/bridges/{calendar_date_select/bridge.rb → calendar_date_select.rb} +13 -5
  81. data/lib/active_scaffold/bridges/calendar_date_select/{lib/as_cds_bridge.rb → as_cds_bridge.rb} +4 -20
  82. data/lib/active_scaffold/bridges/cancan.rb +15 -0
  83. data/lib/active_scaffold/bridges/cancan/{lib/cancan_bridge.rb → cancan_bridge.rb} +2 -2
  84. data/lib/active_scaffold/bridges/carrierwave.rb +12 -0
  85. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +31 -0
  86. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb +10 -0
  87. data/lib/active_scaffold/bridges/carrierwave/{lib/form_ui.rb → form_ui.rb} +0 -0
  88. data/lib/active_scaffold/bridges/carrierwave/{lib/list_ui.rb → list_ui.rb} +1 -1
  89. data/lib/active_scaffold/bridges/country_helper.rb +9 -0
  90. data/lib/active_scaffold/bridges/country_helper/{lib/country_helper_bridge.rb → country_helper_bridge.rb} +5 -5
  91. data/lib/active_scaffold/bridges/date_picker.rb +23 -0
  92. data/lib/active_scaffold/bridges/date_picker/ext.rb +54 -0
  93. data/lib/active_scaffold/bridges/date_picker/helper.rb +188 -0
  94. data/lib/active_scaffold/bridges/dragonfly.rb +9 -0
  95. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +34 -0
  96. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb +10 -0
  97. data/lib/active_scaffold/bridges/dragonfly/{lib/form_ui.rb → form_ui.rb} +0 -0
  98. data/lib/active_scaffold/bridges/dragonfly/{lib/list_ui.rb → list_ui.rb} +2 -2
  99. data/lib/active_scaffold/bridges/file_column.rb +11 -0
  100. data/lib/active_scaffold/bridges/file_column/{lib/as_file_column_bridge.rb → as_file_column_bridge.rb} +2 -2
  101. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +57 -0
  102. data/lib/active_scaffold/bridges/file_column/{lib/form_ui.rb → form_ui.rb} +2 -2
  103. data/lib/active_scaffold/bridges/file_column/{lib/list_ui.rb → list_ui.rb} +0 -0
  104. data/lib/active_scaffold/bridges/paperclip.rb +12 -0
  105. data/lib/active_scaffold/bridges/paperclip/{lib/form_ui.rb → form_ui.rb} +0 -0
  106. data/lib/active_scaffold/bridges/paperclip/{lib/list_ui.rb → list_ui.rb} +3 -3
  107. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +36 -0
  108. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +24 -0
  109. data/lib/active_scaffold/bridges/record_select.rb +11 -0
  110. data/lib/active_scaffold/bridges/record_select/{lib/record_select_bridge.rb → helpers.rb} +5 -16
  111. data/lib/active_scaffold/bridges/record_select/helpers.rb~ +9 -14
  112. data/lib/active_scaffold/bridges/semantic_attributes.rb +5 -0
  113. data/lib/active_scaffold/bridges/semantic_attributes/{lib/semantic_attributes_bridge.rb → column.rb} +3 -3
  114. data/lib/active_scaffold/bridges/tiny_mce.rb +5 -0
  115. data/lib/active_scaffold/bridges/tiny_mce/{lib/tiny_mce_bridge.rb → helpers.rb} +16 -8
  116. data/lib/active_scaffold/config/base.rb +9 -1
  117. data/lib/active_scaffold/config/core.rb +1 -1
  118. data/lib/active_scaffold/config/create.rb +3 -10
  119. data/lib/active_scaffold/config/delete.rb +1 -2
  120. data/lib/active_scaffold/config/field_search.rb +1 -2
  121. data/lib/active_scaffold/config/form.rb +2 -6
  122. data/lib/active_scaffold/config/list.rb +8 -2
  123. data/lib/active_scaffold/config/nested.rb +2 -6
  124. data/lib/active_scaffold/config/search.rb +6 -2
  125. data/lib/active_scaffold/config/show.rb +1 -4
  126. data/lib/active_scaffold/config/subform.rb +1 -1
  127. data/lib/active_scaffold/config/update.rb +1 -6
  128. data/lib/active_scaffold/data_structures/action_columns.rb +3 -0
  129. data/lib/active_scaffold/data_structures/action_link.rb +14 -10
  130. data/lib/active_scaffold/data_structures/bridge.rb +22 -0
  131. data/lib/active_scaffold/data_structures/column.rb +36 -4
  132. data/lib/active_scaffold/data_structures/nested_info.rb +4 -4
  133. data/lib/active_scaffold/data_structures/set.rb +1 -6
  134. data/lib/active_scaffold/data_structures/sorting.rb +2 -2
  135. data/lib/active_scaffold/engine.rb +4 -0
  136. data/lib/active_scaffold/extensions/action_controller_rendering.rb +2 -2
  137. data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +1 -1
  138. data/lib/active_scaffold/extensions/action_view_rendering.rb +90 -93
  139. data/lib/active_scaffold/extensions/action_view_rendering.rb~ +1 -13
  140. data/lib/active_scaffold/extensions/active_association_reflection.rb +16 -7
  141. data/lib/active_scaffold/extensions/cache_association.rb +16 -0
  142. data/lib/active_scaffold/extensions/reverse_associations.rb +15 -13
  143. data/lib/active_scaffold/extensions/unsaved_associated.rb +1 -1
  144. data/lib/active_scaffold/finder.rb +40 -23
  145. data/lib/active_scaffold/finder.rb~ +3 -11
  146. data/lib/active_scaffold/helpers/association_helpers.rb +1 -1
  147. data/lib/active_scaffold/helpers/controller_helpers.rb +9 -1
  148. data/lib/active_scaffold/helpers/controller_helpers.rb~ +12 -5
  149. data/lib/active_scaffold/helpers/form_column_helpers.rb +20 -21
  150. data/lib/active_scaffold/helpers/form_column_helpers.rb~ +2 -1
  151. data/lib/active_scaffold/helpers/id_helpers.rb +5 -5
  152. data/lib/active_scaffold/helpers/list_column_helpers.rb +14 -24
  153. data/lib/active_scaffold/helpers/list_column_helpers.rb~ +15 -20
  154. data/lib/active_scaffold/helpers/search_column_helpers.rb +10 -1
  155. data/lib/active_scaffold/helpers/search_column_helpers.rb~ +1 -1
  156. data/lib/active_scaffold/helpers/view_helpers.rb +14 -40
  157. data/lib/active_scaffold/helpers/view_helpers.rb~ +3 -3
  158. data/lib/active_scaffold/version.rb +2 -2
  159. data/lib/active_scaffold_env.rb +0 -2
  160. data/test/bridges/active_scaffold_dependent_protect_test.rb +34 -0
  161. data/test/bridges/bridge_test.rb +43 -0
  162. data/test/bridges/company.rb +81 -0
  163. data/test/bridges/paperclip_test.rb +68 -0
  164. data/test/bridges/tiny_mce_test.rb +27 -0
  165. data/test/bridges/unobtrusive_date_picker_test.rb +49 -0
  166. data/test/bridges/validation_reflection_test.rb +57 -0
  167. data/test/config/base_test.rb +1 -1
  168. data/test/config/core_test.rb +58 -0
  169. data/test/config/create_test.rb +8 -5
  170. data/test/config/delete_test.rb +33 -0
  171. data/test/config/field_search_test.rb +47 -0
  172. data/test/config/list_test.rb +64 -9
  173. data/test/config/nested_test.rb +62 -0
  174. data/test/config/search_test.rb +60 -0
  175. data/test/config/show_test.rb +5 -5
  176. data/test/config/subform_test.rb +17 -0
  177. data/test/config/update_test.rb +27 -4
  178. data/test/helpers/list_column_helpers_test.rb +16 -5
  179. data/test/helpers/pagination_helpers_test.rb +4 -0
  180. data/test/misc/attribute_params_test.rb +37 -1
  181. data/test/misc/finder_test.rb +0 -1
  182. data/test/misc/lang_test.rb +2 -3
  183. data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +2 -2
  184. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +13 -7
  185. metadata +137 -154
  186. data/frontends/default/views/_list_with_header.html.erb~ +0 -32
  187. data/frontends/default/views/_render_field.js.rjs +0 -14
  188. data/frontends/default/views/_show.html.erb~ +0 -8
  189. data/frontends/default/views/_update_form.html.erb~ +0 -6
  190. data/frontends/default/views/add_existing.js.erb~ +0 -18
  191. data/frontends/default/views/add_existing.js.rjs +0 -17
  192. data/frontends/default/views/destroy.js.rjs +0 -23
  193. data/frontends/default/views/form_messages.js.rjs +0 -1
  194. data/frontends/default/views/list.js.rjs +0 -1
  195. data/frontends/default/views/on_action_update.js.rjs +0 -10
  196. data/frontends/default/views/on_create.js.rjs +0 -41
  197. data/frontends/default/views/on_mark_all.js.rjs +0 -12
  198. data/frontends/default/views/on_update.js.rjs +0 -28
  199. data/frontends/default/views/render_field.js.rjs +0 -1
  200. data/frontends/default/views/update_column.js.rjs +0 -13
  201. data/frontends/default/views/update_row.js.rjs +0 -1
  202. data/lib/active_scaffold.rb~ +0 -362
  203. data/lib/active_scaffold/bridges/ancestry/bridge.rb +0 -5
  204. data/lib/active_scaffold/bridges/bridge.rb +0 -59
  205. data/lib/active_scaffold/bridges/cancan/bridge.rb +0 -12
  206. data/lib/active_scaffold/bridges/carrierwave/bridge.rb +0 -9
  207. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +0 -33
  208. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +0 -12
  209. data/lib/active_scaffold/bridges/country_helper/bridge.rb +0 -9
  210. data/lib/active_scaffold/bridges/date_picker/bridge.rb +0 -24
  211. data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +0 -234
  212. data/lib/active_scaffold/bridges/dragonfly/bridge.rb +0 -9
  213. data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb +0 -36
  214. data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb +0 -12
  215. data/lib/active_scaffold/bridges/file_column/bridge.rb +0 -11
  216. data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +0 -59
  217. data/lib/active_scaffold/bridges/paperclip/bridge.rb +0 -12
  218. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +0 -38
  219. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +0 -26
  220. data/lib/active_scaffold/bridges/record_select/bridge.rb +0 -5
  221. data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +0 -5
  222. data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +0 -209
  223. data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +0 -5
  224. data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +0 -8
  225. data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +0 -21
  226. data/lib/active_scaffold/config/base.rb~ +0 -70
  227. data/lib/active_scaffold/config/nested.rb~ +0 -41
  228. data/lib/active_scaffold/constraints.rb~ +0 -186
  229. data/lib/active_scaffold/data_structures/action_link.rb~ +0 -179
  230. data/lib/active_scaffold/data_structures/nested_info.rb~ +0 -123
  231. data/lib/active_scaffold/extensions/action_view_resolver.rb +0 -7
  232. data/lib/active_scaffold/extensions/active_association_reflection.rb~ +0 -22
  233. data/lib/active_scaffold/extensions/unsaved_associated.rb~ +0 -62
  234. data/lib/active_scaffold_assets.rb +0 -45
  235. data/lib/generators/active_scaffold_setup/USAGE +0 -10
  236. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +0 -59
@@ -1,111 +1,108 @@
1
1
  module ActionView
2
2
  class LookupContext
3
3
  module ViewPaths
4
- def find_all_templates(name, prefix = nil, partial = false)
5
- templates = []
6
- @view_paths.each do |resolver|
7
- template = resolver.find_all(*args_for_lookup(name, prefix, partial)).first
8
- templates << template unless template.nil?
9
- end
10
- templates
4
+ def find_all_templates(name, partial = false, locals = {})
5
+ prefixes.collect do |prefix|
6
+ view_paths.collect do |resolver|
7
+ temp_args = *args_for_lookup(name, [prefix], partial, locals)
8
+ temp_args[1] = temp_args[1][0]
9
+ resolver.find_all(*temp_args)
10
+ end
11
+ end.flatten!
11
12
  end
12
13
  end
13
14
  end
14
15
  end
15
16
 
16
17
  # wrap the action rendering for ActiveScaffold views
17
- module ActionView::Rendering #:nodoc:
18
- # Adds two rendering options.
19
- #
20
- # ==render :super
21
- #
22
- # This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates.
23
- # Useful if you want to wrap an existing template. Just call super!
24
- #
25
- # ==render :active_scaffold => #{controller.to_s}, options = {}+
26
- #
27
- # Lets you embed an ActiveScaffold by referencing the controller where it's configured.
28
- #
29
- # You may specify options[:constraints] for the embedded scaffold. These constraints have three effects:
30
- # * the scaffold's only displays records matching the constraint
31
- # * all new records created will be assigned the constrained values
32
- # * constrained columns will be hidden (they're pretty boring at this point)
33
- #
34
- # You may also specify options[:conditions] for the embedded scaffold. These only do 1/3 of what
35
- # constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid.
36
- #
37
- # Defining options[:label] lets you completely customize the list title for the embedded scaffold.
38
- #
39
- def render_with_active_scaffold(*args, &block)
40
- if args.first == :super
41
- last_view = @view_stack.last
42
- options = args[1] || {}
43
- options[:locals] ||= {}
44
- options[:locals].reverse_merge!(last_view[:locals] || {})
45
- if last_view[:templates].nil?
46
- last_view[:templates] = lookup_context.find_all_templates(last_view[:view], controller_path, !last_view[:is_template])
47
- last_view[:templates].shift
48
- end
49
- options[:template] = last_view[:templates].shift
50
- @view_stack << last_view
51
- result = render_without_active_scaffold options
52
- @view_stack.pop
53
- result
54
- elsif args.first.is_a?(Hash) and args.first[:active_scaffold]
55
- require 'digest/md5'
56
- options = args.first
18
+ module ActionView::Helpers #:nodoc:
19
+ module RenderingHelper
20
+ #
21
+ # Adds two rendering options.
22
+ #
23
+ # ==render :super
24
+ #
25
+ # This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates.
26
+ # Useful if you want to wrap an existing template. Just call super!
27
+ #
28
+ # ==render :active_scaffold => #{controller.to_s}, options = {}+
29
+ #
30
+ # Lets you embed an ActiveScaffold by referencing the controller where it's configured.
31
+ #
32
+ # You may specify options[:constraints] for the embedded scaffold. These constraints have three effects:
33
+ # * the scaffold's only displays records matching the constraint
34
+ # * all new records created will be assigned the constrained values
35
+ # * constrained columns will be hidden (they're pretty boring at this point)
36
+ #
37
+ # You may also specify options[:conditions] for the embedded scaffold. These only do 1/3 of what
38
+ # constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid.
39
+ #
40
+ # Defining options[:label] lets you completely customize the list title for the embedded scaffold.
41
+ #
42
+ def render_with_active_scaffold(*args, &block)
43
+ if args.first == :super
44
+ last_view = view_stack.last || {:view => instance_variable_get(:@virtual_path).split('/').last}
45
+ options = args[1] || {}
46
+ options[:locals] ||= {}
47
+ options[:locals].reverse_merge!(last_view[:locals] || {})
48
+ if last_view[:templates].nil?
49
+ last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys)
50
+ last_view[:templates].shift
51
+ end
52
+ options[:template] = last_view[:templates].shift
53
+ view_stack << last_view
54
+ result = render_without_active_scaffold options
55
+ view_stack.pop
56
+ result
57
+ elsif args.first.is_a? Hash and args.first[:active_scaffold]
58
+ require 'digest/md5'
59
+ options = args.first
57
60
 
58
- remote_controller = options[:active_scaffold]
59
- constraints = options[:constraints]
60
- conditions = options[:conditions]
61
- eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s)
62
- session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}}
63
- options[:params] ||= {}
64
- options[:params].merge! :eid => eid, :embedded => true
65
-
66
- id = "as_#{eid}-content"
67
- url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])
68
-
69
- if controller.respond_to?(:render_component_into_view)
70
- controller.send(:render_component_into_view, url_options)
71
- else
72
- content_tag(:div, :id => id, :class => 'active-scaffold-component') do
73
- url = url_for(url_options)
74
- content_tag(:div, :class => 'active-scaffold-header') do
75
- content_tag :h2, link_to(active_scaffold_config_for(remote_controller).list.label, url, :remote => true, :id => id)
76
- end <<
77
- if ActiveScaffold.js_framework == :prototype
78
- javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});")
79
- elsif ActiveScaffold.js_framework == :jquery
80
- javascript_tag("$('##{id}').load('#{url}');")
61
+ remote_controller = options[:active_scaffold]
62
+ constraints = options[:constraints]
63
+ conditions = options[:conditions]
64
+ eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s)
65
+ session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}}
66
+ options[:params] ||= {}
67
+ options[:params].merge! :eid => eid, :embedded => true
68
+
69
+ id = "as_#{eid}-embedded"
70
+ url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])
71
+
72
+ if controller.respond_to?(:render_component_into_view)
73
+ controller.send(:render_component_into_view, url_options)
74
+ else
75
+ content_tag(:div, :id => id, :class => 'active-scaffold-component') do
76
+ url = url_for(url_options)
77
+ content_tag(:div, :class => 'active-scaffold-header') do
78
+ content_tag :h2, link_to(args.first[:label] || active_scaffold_config_for(remote_controller.to_s.singularize).list.label, url, :remote => true)
79
+ end <<
80
+ if ActiveScaffold.js_framework == :prototype
81
+ javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});")
82
+ elsif ActiveScaffold.js_framework == :jquery
83
+ javascript_tag("$('##{id}').load('#{url}');")
84
+ end
81
85
  end
82
86
  end
83
- end
84
-
85
- else
86
- options = args.first
87
- if options.is_a?(Hash)
88
- current_view = {:view => options[:partial], :is_template => false} if options[:partial]
89
- current_view = {:view => options[:template], :is_template => !!options[:template]} if current_view.nil? && options[:template]
90
- current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals]
91
- if current_view.present?
92
- @view_stack ||= []
93
- @view_stack << current_view
87
+
88
+ else
89
+ options = args.first
90
+ if options.is_a?(Hash)
91
+ current_view = {:view => options[:partial], :partial => true} if options[:partial]
92
+ current_view = {:view => options[:template], :partial => false} if current_view.nil? && options[:template]
93
+ current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals]
94
+ view_stack << current_view if current_view.present?
94
95
  end
96
+ result = render_without_active_scaffold(*args, &block)
97
+ view_stack.pop if current_view.present?
98
+ result
95
99
  end
96
- result = render_without_active_scaffold(*args, &block)
97
- @view_stack.pop if current_view.present?
98
- result
99
100
  end
100
- end
101
- alias_method_chain :render, :active_scaffold
102
-
103
-
104
- def partial_pieces(partial_path)
105
- if partial_path.include?('/')
106
- return File.dirname(partial_path), File.basename(partial_path)
107
- else
108
- return controller.class.controller_path, partial_path
101
+ alias_method_chain :render, :active_scaffold
102
+
103
+ def view_stack
104
+ @_view_stack ||= []
109
105
  end
106
+
110
107
  end
111
108
  end
@@ -1,6 +1,5 @@
1
1
  module ActionView
2
2
  class LookupContext
3
- attr_accessor :uses_active_scaffold
4
3
  module ViewPaths
5
4
  def find_all_templates(name, partial = false, locals = {})
6
5
  prefixes.collect do |prefix|
@@ -12,17 +11,6 @@ module ActionView
12
11
  end.flatten!
13
12
  end
14
13
  end
15
-
16
- # Overload formats= to expand ["*/*"] values and automatically
17
- # add :html as fallback to :js.
18
- def formats=(values)
19
- debugger
20
- if values == [:js] && uses_active_scaffold
21
- _set_detail(:formats, values) if values != @details[:formats]
22
- else
23
- super(values)
24
- end
25
- end
26
14
  end
27
15
  end
28
16
 
@@ -61,7 +49,7 @@ module ActionView::Helpers #:nodoc:
61
49
  last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys)
62
50
  last_view[:templates].shift
63
51
  end
64
- options[:template] = last_view[:templates].shift
52
+ options[:file] = last_view[:templates].shift
65
53
  view_stack << last_view
66
54
  result = render_without_active_scaffold options
67
55
  view_stack.pop
@@ -1,13 +1,22 @@
1
1
  # Bugfix: building an sti model from an association fails
2
2
  # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6306-collection-associations-build-method-not-supported-for-sti
3
+ # https://github.com/rails/rails/issues/815
4
+ # https://github.com/rails/rails/pull/1686
3
5
  ActiveRecord::Reflection::AssociationReflection.class_eval do
4
- def build_association(*opts)
5
- col = klass.inheritance_column.to_sym
6
- if !col.nil? && opts.first.is_a?(Hash) && (opts.first.symbolize_keys[col])
7
- sti_model = opts.first.delete(col)
8
- sti_model.to_s.camelize.constantize.new(*opts)
6
+ def klass_with_sti(*opts)
7
+ sti_col = klass.inheritance_column
8
+ if (h = opts.first).is_a? Hash and (passed_type = ( h[sti_col] || h[sti_col.to_sym] )) and (new_klass = active_record.send(:compute_type, passed_type)) < klass
9
+ new_klass
9
10
  else
10
- klass.new(*opts)
11
+ klass
11
12
  end
12
13
  end
13
- end
14
+ def build_association(*opts, &block)
15
+ self.original_build_association_called = true
16
+ klass_with_sti(*opts).new(*opts, &block)
17
+ end
18
+ def create_association(*opts, &block)
19
+ self.original_build_association_called = true
20
+ klass_with_sti(*opts).create(*opts, &block)
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module ActiveRecord
2
+ class Relation
3
+ def target=(records)
4
+ @loaded = true
5
+ @records = records
6
+ @records
7
+ end
8
+ end
9
+ end
10
+ module ActiveRecord
11
+ module Associations
12
+ class CollectionProxy
13
+ delegate :target=, :to => :@association
14
+ end
15
+ end
16
+ end
@@ -1,26 +1,28 @@
1
1
  module ActiveRecord
2
2
  module Reflection
3
3
  class AssociationReflection #:nodoc:
4
- def reverse_for?(klass)
5
- reverse_matches_for(klass).empty? ? false : true
4
+ def inverse_for?(klass)
5
+ inverse_class = inverse_of.try(:active_record)
6
+ inverse_class.present? && (inverse_class == klass || klass < inverse_class)
6
7
  end
7
8
 
8
9
  attr_writer :reverse
9
10
  def reverse
10
- if @reverse.nil? and not self.options[:polymorphic]
11
- reverse_matches = reverse_matches_for(self.class_name.constantize) rescue nil
12
- # grab first association, or make a wild guess
13
- @reverse = reverse_matches.blank? ? false : reverse_matches.first.name
14
- end
15
- @reverse
11
+ @reverse ||= inverse_of.try(:name)
16
12
  end
17
13
 
14
+ def inverse_of_with_autodetect
15
+ inverse_of_without_autodetect || autodetect_inverse
16
+ end
17
+ alias_method_chain :inverse_of, :autodetect
18
+
18
19
  protected
19
20
 
20
- def reverse_matches_for(klass)
21
+ def autodetect_inverse
22
+ return nil if options[:polymorphic]
21
23
  reverse_matches = []
22
24
 
23
- # stage 1 filter: collect associations that point back to this model and use the same primary_key_name
25
+ # stage 1 filter: collect associations that point back to this model and use the same foreign_key
24
26
  klass.reflect_on_all_associations.each do |assoc|
25
27
  if self.options[:through]
26
28
  # only iterate has_many :through associations
@@ -40,9 +42,9 @@ module ActiveRecord
40
42
  when 1
41
43
  next
42
44
 
43
- # otherwise, match them based on the primary_key_name
45
+ # otherwise, match them based on the foreign_key
44
46
  when 0
45
- next unless assoc.primary_key_name.to_sym == self.primary_key_name.to_sym
47
+ next unless assoc.foreign_key.to_sym == self.foreign_key.to_sym
46
48
  end
47
49
  end
48
50
 
@@ -54,7 +56,7 @@ module ActiveRecord
54
56
  self.active_record.to_s.underscore.include? assoc.name.to_s.pluralize.singularize
55
57
  end if reverse_matches.length > 1
56
58
 
57
- reverse_matches
59
+ reverse_matches.first
58
60
  end
59
61
 
60
62
  end
@@ -48,7 +48,7 @@ class ActiveRecord::Base
48
48
  # returns true otherwise, even when none of the associations have been instantiated. build wrapper methods accordingly.
49
49
  def with_unsaved_associated
50
50
  associations_for_update.all? do |association|
51
- association_proxy = instance_variable_get("@#{association.name}")
51
+ association_proxy = send(association.name)
52
52
  if association_proxy
53
53
  records = association_proxy
54
54
  records = [records] unless records.is_a? Array # convert singular associations into collections for ease of use
@@ -34,12 +34,13 @@ module ActiveScaffold
34
34
  # TODO: this should reside on the column, not the controller
35
35
  def condition_for_column(column, value, text_search = :full)
36
36
  like_pattern = like_pattern(text_search)
37
+ if self.respond_to?("condition_for_#{column.name}_column")
38
+ return self.send("condition_for_#{column.name}_column", column, value, like_pattern)
39
+ end
37
40
  return unless column and column.search_sql and not value.blank?
38
- search_ui = column.search_ui || column.column.type
41
+ search_ui = column.search_ui || column.column.try(:type)
39
42
  begin
40
- if self.respond_to?("condition_for_#{column.name}_column")
41
- self.send("condition_for_#{column.name}_column", column, value, like_pattern)
42
- elsif self.respond_to?("condition_for_#{search_ui}_type")
43
+ if search_ui && self.respond_to?("condition_for_#{search_ui}_type")
43
44
  self.send("condition_for_#{search_ui}_type", column, value, like_pattern)
44
45
  else
45
46
  unless column.search_sql.instance_of? Proc
@@ -95,7 +96,7 @@ module ActiveScaffold
95
96
  elsif value[:from].blank?
96
97
  nil
97
98
  elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt])
98
- ["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", value[:opt].sub('?', value[:from])]
99
+ ["#{column.search_sql} LIKE ?", value[:opt].sub('?', value[:from])]
99
100
  elsif value[:opt] == 'BETWEEN'
100
101
  ["#{column.search_sql} BETWEEN ? AND ?", value[:from], value[:to]]
101
102
  elsif ActiveScaffold::Finder::NumericComparators.include?(value[:opt])
@@ -245,51 +246,67 @@ module ActiveScaffold
245
246
  return record
246
247
  end
247
248
 
248
- # returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters
249
- # options may include:
249
+ # returns a hash with options to find records
250
+ # valid options may include:
250
251
  # * :sorting - a Sorting DataStructure (basically an array of hashes of field => direction, e.g. [{:field1 => 'asc'}, {:field2 => 'desc'}]). please note that multi-column sorting has some limitations: if any column in a multi-field sort uses method-based sorting, it will be ignored. method sorting only works for single-column sorting.
251
252
  # * :per_page
252
253
  # * :page
253
- # TODO: this should reside on the model, not the controller
254
- def find_page(options = {})
255
- options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination
254
+ def finder_options(options = {})
255
+ options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination, :select
256
256
 
257
257
  search_conditions = all_conditions
258
258
  full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes)
259
- options[:per_page] ||= 999999999
260
- options[:page] ||= 1
261
- options[:count_includes] ||= full_includes unless search_conditions.nil?
262
259
 
263
- klass = beginning_of_chain
264
-
265
260
  # create a general-use options array that's compatible with Rails finders
266
261
  finder_options = { :order => options[:sorting].try(:clause),
267
262
  :where => search_conditions,
268
263
  :joins => joins_for_finder,
269
- :includes => options[:count_includes]}
264
+ :includes => full_includes}
270
265
 
271
266
  finder_options.merge! custom_finder_options
267
+ finder_options
268
+ end
269
+
270
+ # Returns a hash with options to count records, rejecting select and order options
271
+ # See finder_options for valid options
272
+ def count_options(find_options = {}, count_includes = nil)
273
+ count_includes ||= find_options[:includes] unless find_options[:where].nil?
274
+ options = find_options.reject{|k,v| [:select, :order].include? k}
275
+ options[:includes] = count_includes
276
+ options
277
+ end
278
+
279
+ # returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters
280
+ # See finder_options for valid options
281
+ # TODO: this should reside on the model, not the controller
282
+ def find_page(options = {})
283
+ options[:per_page] ||= 999999999
284
+ options[:page] ||= 1
272
285
 
286
+ find_options = finder_options(options)
287
+ klass = beginning_of_chain
288
+
273
289
  # NOTE: we must use :include in the count query, because some conditions may reference other tables
274
- count_query = append_to_query(klass, finder_options.reject{|k, v| [:select, :order].include?(k)})
275
- count = count_query.count unless options[:pagination] == :infinite
290
+ if options[:pagination] && options[:pagination] != :infinite
291
+ count_query = append_to_query(klass, count_options(find_options, options[:count_includes]))
292
+ count = count_query.count unless options[:pagination] == :infinite
293
+ end
276
294
 
277
295
  # Converts count to an integer if ActiveRecord returned an OrderedHash
278
- # that happens when finder_options contains a :group key
296
+ # that happens when find_options contains a :group key
279
297
  count = count.length if count.is_a? ActiveSupport::OrderedHash
280
- finder_options.merge! :includes => full_includes
281
298
 
282
299
  # we build the paginator differently for method- and sql-based sorting
283
300
  if options[:sorting] and options[:sorting].sorts_by_method?
284
301
  pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
285
- sorted_collection = sort_collection_by_column(append_to_query(klass, finder_options).all, *options[:sorting].first)
302
+ sorted_collection = sort_collection_by_column(append_to_query(klass, find_options).all, *options[:sorting].first)
286
303
  sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination]
287
304
  sorted_collection
288
305
  end
289
306
  else
290
307
  pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
291
- finder_options.merge!(:offset => offset, :limit => per_page) if options[:pagination]
292
- append_to_query(klass, finder_options).all
308
+ find_options.merge!(:offset => offset, :limit => per_page) if options[:pagination]
309
+ append_to_query(klass, find_options).all
293
310
  end
294
311
  end
295
312
  pager.page(options[:page])