active_scaffold_vho 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. data/.autotest +27 -0
  2. data/.document +5 -0
  3. data/CHANGELOG +179 -0
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +20 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README +63 -0
  8. data/Rakefile +53 -0
  9. data/frontends/default/images/add.gif +0 -0
  10. data/frontends/default/images/arrow_down.gif +0 -0
  11. data/frontends/default/images/arrow_up.gif +0 -0
  12. data/frontends/default/images/close.gif +0 -0
  13. data/frontends/default/images/config.png +0 -0
  14. data/frontends/default/images/cross.png +0 -0
  15. data/frontends/default/images/gears.png +0 -0
  16. data/frontends/default/images/indicator-small.gif +0 -0
  17. data/frontends/default/images/indicator.gif +0 -0
  18. data/frontends/default/images/magnifier.png +0 -0
  19. data/frontends/default/javascripts/jquery/active_scaffold.js +957 -0
  20. data/frontends/default/javascripts/jquery/jquery.editinplace.js +743 -0
  21. data/frontends/default/javascripts/prototype/active_scaffold.js +957 -0
  22. data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
  23. data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
  24. data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
  25. data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
  26. data/frontends/default/stylesheets/stylesheet.css +964 -0
  27. data/frontends/default/views/_action_group.html.erb +20 -0
  28. data/frontends/default/views/_add_existing_form.html.erb +30 -0
  29. data/frontends/default/views/_base_form.html.erb +45 -0
  30. data/frontends/default/views/_create_form.html.erb +8 -0
  31. data/frontends/default/views/_create_form_on_list.html.erb +6 -0
  32. data/frontends/default/views/_field_search.html.erb +32 -0
  33. data/frontends/default/views/_form.html.erb +24 -0
  34. data/frontends/default/views/_form_association.html.erb +14 -0
  35. data/frontends/default/views/_form_association_footer.html.erb +40 -0
  36. data/frontends/default/views/_form_attribute.html.erb +15 -0
  37. data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
  38. data/frontends/default/views/_form_messages.html.erb +5 -0
  39. data/frontends/default/views/_horizontal_subform.html.erb +19 -0
  40. data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
  41. data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
  42. data/frontends/default/views/_human_conditions.html.erb +1 -0
  43. data/frontends/default/views/_list.html.erb +18 -0
  44. data/frontends/default/views/_list_actions.html.erb +15 -0
  45. data/frontends/default/views/_list_calculations.html.erb +16 -0
  46. data/frontends/default/views/_list_column_headings.html.erb +12 -0
  47. data/frontends/default/views/_list_header.html.erb +10 -0
  48. data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
  49. data/frontends/default/views/_list_messages.html.erb +32 -0
  50. data/frontends/default/views/_list_pagination.html.erb +11 -0
  51. data/frontends/default/views/_list_pagination_links.html.erb +9 -0
  52. data/frontends/default/views/_list_record.html.erb +14 -0
  53. data/frontends/default/views/_list_record_columns.html.erb +8 -0
  54. data/frontends/default/views/_list_with_header.html.erb +32 -0
  55. data/frontends/default/views/_messages.html.erb +10 -0
  56. data/frontends/default/views/_render_field.js.rjs +13 -0
  57. data/frontends/default/views/_row.html.erb +12 -0
  58. data/frontends/default/views/_search.html.erb +34 -0
  59. data/frontends/default/views/_search_attribute.html.erb +10 -0
  60. data/frontends/default/views/_show.html.erb +8 -0
  61. data/frontends/default/views/_show_columns.html.erb +15 -0
  62. data/frontends/default/views/_update_actions.html.erb +9 -0
  63. data/frontends/default/views/_update_form.html.erb +6 -0
  64. data/frontends/default/views/_vertical_subform.html.erb +12 -0
  65. data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
  66. data/frontends/default/views/action_confirmation.html.erb +13 -0
  67. data/frontends/default/views/add_existing.js.rjs +17 -0
  68. data/frontends/default/views/add_existing_form.html.erb +5 -0
  69. data/frontends/default/views/create.html.erb +5 -0
  70. data/frontends/default/views/delete.html.erb +13 -0
  71. data/frontends/default/views/destroy.js.rjs +11 -0
  72. data/frontends/default/views/edit_associated.js.rjs +11 -0
  73. data/frontends/default/views/field_search.html.erb +5 -0
  74. data/frontends/default/views/form_messages.js.rjs +1 -0
  75. data/frontends/default/views/list.html.erb +1 -0
  76. data/frontends/default/views/list.js.rjs +1 -0
  77. data/frontends/default/views/on_action_update.js.rjs +8 -0
  78. data/frontends/default/views/on_create.js.rjs +41 -0
  79. data/frontends/default/views/on_update.js.rjs +28 -0
  80. data/frontends/default/views/search.html.erb +5 -0
  81. data/frontends/default/views/show.html.erb +5 -0
  82. data/frontends/default/views/update.html.erb +8 -0
  83. data/frontends/default/views/update_column.js.rjs +13 -0
  84. data/frontends/default/views/update_row.js.rjs +1 -0
  85. data/init.rb +9 -0
  86. data/lib/active_record_permissions.rb +134 -0
  87. data/lib/active_scaffold/actions/common_search.rb +22 -0
  88. data/lib/active_scaffold/actions/core.rb +170 -0
  89. data/lib/active_scaffold/actions/create.rb +145 -0
  90. data/lib/active_scaffold/actions/delete.rb +75 -0
  91. data/lib/active_scaffold/actions/field_search.rb +82 -0
  92. data/lib/active_scaffold/actions/list.rb +184 -0
  93. data/lib/active_scaffold/actions/mark.rb +50 -0
  94. data/lib/active_scaffold/actions/nested.rb +250 -0
  95. data/lib/active_scaffold/actions/search.rb +47 -0
  96. data/lib/active_scaffold/actions/show.rb +61 -0
  97. data/lib/active_scaffold/actions/subform.rb +17 -0
  98. data/lib/active_scaffold/actions/update.rb +141 -0
  99. data/lib/active_scaffold/attribute_params.rb +207 -0
  100. data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
  101. data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +39 -0
  102. data/lib/active_scaffold/bridges/bridge.rb +52 -0
  103. data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
  104. data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +79 -0
  105. data/lib/active_scaffold/bridges/carrierwave/bridge.rb +7 -0
  106. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +38 -0
  107. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +26 -0
  108. data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +35 -0
  109. data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
  110. data/lib/active_scaffold/bridges/date_picker/bridge.rb +22 -0
  111. data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
  112. data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
  113. data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
  114. data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
  115. data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
  116. data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
  117. data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
  118. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
  119. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
  120. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
  121. data/lib/active_scaffold/bridges/paperclip/bridge.rb +10 -0
  122. data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
  123. data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
  124. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
  125. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
  126. data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
  127. data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
  128. data/lib/active_scaffold/bridges/shared/date_bridge.rb +187 -0
  129. data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
  130. data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +45 -0
  131. data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
  132. data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
  133. data/lib/active_scaffold/config/base.rb +62 -0
  134. data/lib/active_scaffold/config/core.rb +220 -0
  135. data/lib/active_scaffold/config/create.rb +51 -0
  136. data/lib/active_scaffold/config/delete.rb +34 -0
  137. data/lib/active_scaffold/config/field_search.rb +75 -0
  138. data/lib/active_scaffold/config/form.rb +47 -0
  139. data/lib/active_scaffold/config/list.rb +174 -0
  140. data/lib/active_scaffold/config/mark.rb +22 -0
  141. data/lib/active_scaffold/config/nested.rb +44 -0
  142. data/lib/active_scaffold/config/search.rb +69 -0
  143. data/lib/active_scaffold/config/show.rb +35 -0
  144. data/lib/active_scaffold/config/subform.rb +35 -0
  145. data/lib/active_scaffold/config/update.rb +46 -0
  146. data/lib/active_scaffold/configurable.rb +29 -0
  147. data/lib/active_scaffold/constraints.rb +184 -0
  148. data/lib/active_scaffold/data_structures/action_columns.rb +133 -0
  149. data/lib/active_scaffold/data_structures/action_link.rb +171 -0
  150. data/lib/active_scaffold/data_structures/action_links.rb +175 -0
  151. data/lib/active_scaffold/data_structures/actions.rb +45 -0
  152. data/lib/active_scaffold/data_structures/column.rb +351 -0
  153. data/lib/active_scaffold/data_structures/columns.rb +75 -0
  154. data/lib/active_scaffold/data_structures/error_message.rb +24 -0
  155. data/lib/active_scaffold/data_structures/nested_info.rb +123 -0
  156. data/lib/active_scaffold/data_structures/set.rb +62 -0
  157. data/lib/active_scaffold/data_structures/sorting.rb +168 -0
  158. data/lib/active_scaffold/finder.rb +333 -0
  159. data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
  160. data/lib/active_scaffold/helpers/controller_helpers.rb +82 -0
  161. data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
  162. data/lib/active_scaffold/helpers/form_column_helpers.rb +347 -0
  163. data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
  164. data/lib/active_scaffold/helpers/id_helpers.rb +127 -0
  165. data/lib/active_scaffold/helpers/list_column_helpers.rb +361 -0
  166. data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
  167. data/lib/active_scaffold/helpers/search_column_helpers.rb +243 -0
  168. data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
  169. data/lib/active_scaffold/helpers/view_helpers.rb +356 -0
  170. data/lib/active_scaffold/locale/de.rb +120 -0
  171. data/lib/active_scaffold/locale/en.rb +119 -0
  172. data/lib/active_scaffold/locale/es.yml +115 -0
  173. data/lib/active_scaffold/locale/fr.rb +116 -0
  174. data/lib/active_scaffold/locale/hu.yml +63 -0
  175. data/lib/active_scaffold/locale/ja.yml +64 -0
  176. data/lib/active_scaffold/locale/ru.yml +119 -0
  177. data/lib/active_scaffold/marked_model.rb +38 -0
  178. data/lib/active_scaffold/version.rb +9 -0
  179. data/lib/active_scaffold.rb +345 -0
  180. data/lib/active_scaffold_assets.rb +45 -0
  181. data/lib/dhtml_confirm.rb +54 -0
  182. data/lib/environment.rb +14 -0
  183. data/lib/extensions/action_controller_rendering.rb +20 -0
  184. data/lib/extensions/action_view_rendering.rb +113 -0
  185. data/lib/extensions/action_view_resolver.rb +7 -0
  186. data/lib/extensions/active_association_reflection.rb +13 -0
  187. data/lib/extensions/active_record_offset.rb +12 -0
  188. data/lib/extensions/array.rb +7 -0
  189. data/lib/extensions/localize.rb +10 -0
  190. data/lib/extensions/name_option_for_datetime.rb +12 -0
  191. data/lib/extensions/nil_id_in_url_params.rb +7 -0
  192. data/lib/extensions/paginator_extensions.rb +26 -0
  193. data/lib/extensions/reverse_associations.rb +62 -0
  194. data/lib/extensions/routing_mapper.rb +34 -0
  195. data/lib/extensions/to_label.rb +8 -0
  196. data/lib/extensions/unsaved_associated.rb +61 -0
  197. data/lib/extensions/unsaved_record.rb +20 -0
  198. data/lib/extensions/usa_state.rb +46 -0
  199. data/lib/generators/active_scaffold/USAGE +29 -0
  200. data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
  201. data/lib/generators/active_scaffold_controller/USAGE +19 -0
  202. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +28 -0
  203. data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
  204. data/lib/generators/active_scaffold_setup/USAGE +10 -0
  205. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +53 -0
  206. data/lib/paginator.rb +136 -0
  207. data/lib/responds_to_parent.rb +70 -0
  208. data/public/blank.html +33 -0
  209. data/shoulda_macros/macros.rb +136 -0
  210. data/test/bridges/bridge_test.rb +47 -0
  211. data/test/config/base_test.rb +15 -0
  212. data/test/config/create_test.rb +55 -0
  213. data/test/config/list_test.rb +74 -0
  214. data/test/config/show_test.rb +43 -0
  215. data/test/config/update_test.rb +17 -0
  216. data/test/const_mocker.rb +36 -0
  217. data/test/data_structures/action_columns_test.rb +113 -0
  218. data/test/data_structures/action_link_test.rb +78 -0
  219. data/test/data_structures/action_links_test.rb +78 -0
  220. data/test/data_structures/actions_test.rb +25 -0
  221. data/test/data_structures/association_column_test.rb +42 -0
  222. data/test/data_structures/column_test.rb +185 -0
  223. data/test/data_structures/columns_test.rb +69 -0
  224. data/test/data_structures/error_message_test.rb +28 -0
  225. data/test/data_structures/set_test.rb +86 -0
  226. data/test/data_structures/sorting_test.rb +126 -0
  227. data/test/data_structures/standard_column_test.rb +24 -0
  228. data/test/data_structures/virtual_column_test.rb +23 -0
  229. data/test/extensions/active_record_test.rb +45 -0
  230. data/test/extensions/array_test.rb +12 -0
  231. data/test/helpers/form_column_helpers_test.rb +31 -0
  232. data/test/helpers/list_column_helpers_test.rb +31 -0
  233. data/test/helpers/pagination_helpers_test.rb +55 -0
  234. data/test/misc/active_record_permissions_test.rb +154 -0
  235. data/test/misc/attribute_params_test.rb +110 -0
  236. data/test/misc/configurable_test.rb +96 -0
  237. data/test/misc/constraints_test.rb +193 -0
  238. data/test/misc/finder_test.rb +93 -0
  239. data/test/misc/lang_test.rb +12 -0
  240. data/test/mock_app/.gitignore +2 -0
  241. data/test/mock_app/app/controllers/application_controller.rb +10 -0
  242. data/test/mock_app/app/helpers/application_helper.rb +3 -0
  243. data/test/mock_app/config/boot.rb +110 -0
  244. data/test/mock_app/config/database.yml +16 -0
  245. data/test/mock_app/config/environment.rb +43 -0
  246. data/test/mock_app/config/environments/development.rb +17 -0
  247. data/test/mock_app/config/environments/production.rb +28 -0
  248. data/test/mock_app/config/environments/test.rb +28 -0
  249. data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
  250. data/test/mock_app/config/initializers/inflections.rb +10 -0
  251. data/test/mock_app/config/initializers/mime_types.rb +5 -0
  252. data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
  253. data/test/mock_app/config/initializers/session_store.rb +15 -0
  254. data/test/mock_app/config/locales/en.yml +5 -0
  255. data/test/mock_app/config/routes.rb +43 -0
  256. data/test/mock_app/db/test.sqlite3 +1 -0
  257. data/test/mock_app/public/blank.html +33 -0
  258. data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
  259. data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
  260. data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
  261. data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
  262. data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
  263. data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
  264. data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
  265. data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
  266. data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
  267. data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
  268. data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
  269. data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
  270. data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
  271. data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
  272. data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
  273. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
  274. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +839 -0
  275. data/test/model_stub.rb +55 -0
  276. data/test/run_all.rb +8 -0
  277. data/test/test_helper.rb +39 -0
  278. data/uninstall.rb +13 -0
  279. metadata +492 -0
@@ -0,0 +1,50 @@
1
+ module ActiveScaffold::Actions
2
+ module Mark
3
+
4
+ def self.included(base)
5
+ base.before_filter :mark_authorized?, :only => [:mark_all]
6
+ base.prepend_before_filter :assign_marked_records_to_model
7
+ base.helper_method :marked_records
8
+ end
9
+
10
+ def mark_all
11
+ if mark_all?
12
+ do_mark_all
13
+ else
14
+ do_demark_all
15
+ end
16
+ do_list
17
+ respond_to_action(:list)
18
+ end
19
+ protected
20
+
21
+ # We need to give the ActiveRecord classes a handle to currently marked records. We don't want to just pass the object,
22
+ # because the object may change. So we give ActiveRecord a proc that ties to the
23
+ # marked_records_method on this ApplicationController.
24
+ def assign_marked_records_to_model
25
+ active_scaffold_config.model.marked_records = marked_records
26
+ end
27
+
28
+ def marked_records
29
+ active_scaffold_session_storage[:marked_records] ||= Set.new
30
+ end
31
+
32
+ def mark_all?
33
+ @mark_all ||= [true, 'true', 1, '1', 'T', 't'].include?(params[:value].class == String ? params[:value].downcase : params[:value])
34
+ end
35
+
36
+ def do_mark_all
37
+ each_record_in_scope {|record| marked_records << record.id}
38
+ end
39
+
40
+ def do_demark_all
41
+ each_record_in_scope {|record| marked_records.delete(record.id)}
42
+ end
43
+
44
+ # The default security delegates to ActiveRecordPermissions.
45
+ # You may override the method to customize.
46
+ def mark_authorized?
47
+ authorized_for?(:action => :read)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,250 @@
1
+ module ActiveScaffold::Actions
2
+ # The Nested module basically handles automatically linking controllers together. It does this by creating column links with the right parameters, and by providing any supporting systems (like a /:controller/nested action for returning associated scaffolds).
3
+ module Nested
4
+
5
+ def self.included(base)
6
+ super
7
+ base.module_eval do
8
+ before_filter :register_constraints_with_action_columns
9
+ before_filter :set_nested
10
+ before_filter :configure_nested
11
+ include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many}
12
+ end
13
+ base.before_filter :include_habtm_actions
14
+ base.helper_method :nested
15
+ base.helper_method :nested_parent_record
16
+ end
17
+
18
+ protected
19
+ def nested
20
+ @nested ||= ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, active_scaffold_session_storage)
21
+ if !@nested.nil? && @nested.new_instance?
22
+ register_constraints_with_action_columns(@nested.constrained_fields)
23
+ active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to?
24
+ end
25
+ @nested
26
+ end
27
+
28
+ def nested?
29
+ !nested.nil?
30
+ end
31
+
32
+ def set_nested
33
+ if params[:parent_scaffold] && ((params[:association] && params[:assoc_id]) || params[:named_scope])
34
+ @nested = nil
35
+ active_scaffold_session_storage[:nested] = {:parent_scaffold => params[:parent_scaffold].to_s,
36
+ :name => (params[:association] || params[:named_scope]).to_sym,
37
+ :parent_id => params[:assoc_id]}
38
+ params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym}
39
+ end
40
+ end
41
+
42
+ def configure_nested
43
+ if nested?
44
+ active_scaffold_session_storage[:list][:label] = if nested.belongs_to?
45
+ as_(:nested_of_model, :nested_model => active_scaffold_config.model.model_name.human, :parent_model => nested_parent_record.to_label)
46
+ else
47
+ as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label)
48
+ end
49
+ if nested.sorted?
50
+ active_scaffold_config.list.user.nested_default_sorting = {:table_name => active_scaffold_config.model.model_name, :default_sorting => nested.default_sorting}
51
+ end
52
+ end
53
+ end
54
+
55
+ def nested_authorized?(record = nil)
56
+ true
57
+ end
58
+
59
+ def include_habtm_actions
60
+ if nested?
61
+ if nested.habtm?
62
+ # Production mode is ok with adding a link everytime the scaffold is nested - we ar not ok with that.
63
+ active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing']
64
+ if active_scaffold_config.nested.shallow_delete
65
+ active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing']
66
+ if active_scaffold_config.actions.include?(:delete)
67
+ active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete']
68
+ end
69
+ end
70
+ else
71
+ # Production mode is caching this link into a non nested scaffold
72
+ active_scaffold_config.action_links.delete('new_existing') if active_scaffold_config.action_links['new_existing']
73
+
74
+ if active_scaffold_config.nested.shallow_delete
75
+ active_scaffold_config.action_links.delete("destroy_existing") if active_scaffold_config.action_links['destroy_existing']
76
+ if active_scaffold_config.actions.include?(:delete)
77
+ active_scaffold_config.action_links.add(ActiveScaffold::Config::Delete.link) unless active_scaffold_config.action_links['delete']
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def beginning_of_chain
85
+ if nested? && nested.association && nested.association.collection?
86
+ nested.parent_scope.send(nested.association.name)
87
+ elsif nested? && nested.scope
88
+ nested.parent_scope.send(nested.scope)
89
+ else
90
+ active_scaffold_config.model
91
+ end
92
+ end
93
+
94
+ def nested_parent_record(crud = :read)
95
+ @nested_parent_record ||= find_if_allowed(nested.parent_id, crud, nested.parent_model)
96
+ end
97
+
98
+ def create_association_with_parent(record)
99
+ if nested?
100
+ if (nested.belongs_to? || nested.has_one? || nested.habtm?) && nested.child_association
101
+ parent = nested_parent_record(:read)
102
+ case nested.child_association.macro
103
+ when :has_one
104
+ record.send("#{nested.child_association.name}=", parent)
105
+ when :belongs_to
106
+ record.send("#{nested.child_association.name}=", parent)
107
+ when :has_many, :has_and_belongs_to_many
108
+ record.send("#{nested.child_association.name}").send(:<<, parent)
109
+ end unless parent.nil?
110
+ end
111
+ end
112
+ end
113
+
114
+ private
115
+ def nested_formats
116
+ (default_formats + active_scaffold_config.formats + active_scaffold_config.nested.formats).uniq
117
+ end
118
+ end
119
+ end
120
+
121
+ module ActiveScaffold::Actions::Nested
122
+ module ChildMethods
123
+
124
+ def self.included(base)
125
+ super
126
+ base.verify :method => :post,
127
+ :only => :add_existing,
128
+ :redirect_to => { :action => :index }
129
+ end
130
+
131
+ def new_existing
132
+ do_new
133
+ respond_to_action(:new_existing)
134
+ end
135
+
136
+ def add_existing
137
+ do_add_existing
138
+ respond_to_action(:add_existing)
139
+ end
140
+
141
+ def destroy_existing
142
+ return redirect_to(params.merge(:action => :delete)) if request.get?
143
+ do_destroy_existing
144
+ respond_to_action(:destroy_existing)
145
+ end
146
+
147
+ protected
148
+ def new_existing_respond_to_html
149
+ if successful?
150
+ render(:action => 'add_existing_form')
151
+ else
152
+ return_to_main
153
+ end
154
+ end
155
+ def new_existing_respond_to_js
156
+ render(:partial => 'add_existing_form')
157
+ end
158
+ def add_existing_respond_to_html
159
+ if successful?
160
+ flash[:info] = as_(:created_model, :model => @record.to_label)
161
+ return_to_main
162
+ else
163
+ render(:action => 'add_existing_form')
164
+ end
165
+ end
166
+ def add_existing_respond_to_js
167
+ if successful?
168
+ render :action => 'add_existing'
169
+ else
170
+ render :action => 'form_messages'
171
+ end
172
+ end
173
+ def add_existing_respond_to_xml
174
+ render :xml => response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
175
+ end
176
+ def add_existing_respond_to_json
177
+ render :text => response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
178
+ end
179
+ def add_existing_respond_to_yaml
180
+ render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
181
+ end
182
+ def destroy_existing_respond_to_html
183
+ flash[:info] = as_(:deleted_model, :model => @record.to_label)
184
+ return_to_main
185
+ end
186
+
187
+ def destroy_existing_respond_to_js
188
+ render(:action => 'destroy')
189
+ end
190
+
191
+ def destroy_existing_respond_to_xml
192
+ render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
193
+ end
194
+
195
+ def destroy_existing_respond_to_json
196
+ render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
197
+ end
198
+
199
+ def destroy_existing_respond_to_yaml
200
+ render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
201
+ end
202
+
203
+ def add_existing_authorized?(record = nil)
204
+ true
205
+ end
206
+ def delete_existing_authorized?(record = nil)
207
+ true
208
+ end
209
+
210
+ def after_create_save(record)
211
+ if params[:association_macro] == :has_and_belongs_to_many
212
+ params[:associated_id] = record
213
+ do_add_existing
214
+ end
215
+ end
216
+
217
+ # The actual "add_existing" algorithm
218
+ def do_add_existing
219
+ parent_record = nested_parent_record(:update)
220
+ @record = active_scaffold_config.model.find(params[:associated_id])
221
+ if parent_record && @record
222
+ parent_record.send(nested.association.name) << @record
223
+ parent_record.save
224
+ else
225
+ false
226
+ end
227
+ end
228
+
229
+ def do_destroy_existing
230
+ if active_scaffold_config.nested.shallow_delete
231
+ @record = nested_parent_record(:update)
232
+ collection = @record.send(nested.association.name)
233
+ assoc_record = collection.find(params[:id])
234
+ collection.delete(assoc_record)
235
+ else
236
+ do_destroy
237
+ end
238
+ end
239
+ private
240
+ def new_existing_formats
241
+ (default_formats + active_scaffold_config.formats).uniq
242
+ end
243
+ def add_existing_formats
244
+ (default_formats + active_scaffold_config.formats).uniq
245
+ end
246
+ def destroy_existing_formats
247
+ (default_formats + active_scaffold_config.formats).uniq
248
+ end
249
+ end
250
+ end
@@ -0,0 +1,47 @@
1
+ module ActiveScaffold::Actions
2
+ module Search
3
+ include ActiveScaffold::Actions::CommonSearch
4
+ def self.included(base)
5
+ base.before_filter :search_authorized_filter, :only => :show_search
6
+ base.before_filter :store_search_params_into_session, :only => [:index]
7
+ base.before_filter :do_search, :only => [:index]
8
+ base.helper_method :search_params
9
+ end
10
+
11
+ def show_search
12
+ respond_to_action(:search)
13
+ end
14
+
15
+ protected
16
+ def search_respond_to_html
17
+ render(:action => "search")
18
+ end
19
+ def search_respond_to_js
20
+ render(:partial => "search")
21
+ end
22
+ def do_search
23
+ query = search_params.to_s.strip rescue ''
24
+ unless query.empty?
25
+ columns = active_scaffold_config.search.columns
26
+ text_search = active_scaffold_config.search.text_search
27
+ search_conditions = self.class.create_conditions_for_columns(query.split(' '), columns, text_search)
28
+ self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, search_conditions)
29
+ @filtered = !search_conditions.blank?
30
+
31
+ includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact
32
+ self.active_scaffold_includes.concat includes_for_search_columns
33
+
34
+ active_scaffold_config.list.user.page = nil
35
+ end
36
+ end
37
+
38
+ private
39
+ def search_authorized_filter
40
+ link = active_scaffold_config.search.link || active_scaffold_config.search.class.link
41
+ raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
42
+ end
43
+ def search_formats
44
+ (default_formats + active_scaffold_config.formats + active_scaffold_config.search.formats).uniq
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,61 @@
1
+ module ActiveScaffold::Actions
2
+ module Show
3
+ def self.included(base)
4
+ base.before_filter :show_authorized_filter, :only => :show
5
+ end
6
+
7
+ def show
8
+ # rest destroy falls back to rest show in case of disabled javascript
9
+ # just render action_confirmation message for destroy
10
+ unless params.delete :destroy_action
11
+ do_show
12
+ successful?
13
+ respond_to_action(:show)
14
+ else
15
+ @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0
16
+ action_confirmation_respond_to_html(:destroy)
17
+ end
18
+ end
19
+
20
+ protected
21
+
22
+ def show_respond_to_json
23
+ render :text => response_object.to_json(:only => active_scaffold_config.show.columns.names), :content_type => Mime::JSON, :status => response_status
24
+ end
25
+
26
+ def show_respond_to_yaml
27
+ render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.show.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
28
+ end
29
+
30
+ def show_respond_to_xml
31
+ render :xml => response_object.to_xml(:only => active_scaffold_config.show.columns.names), :content_type => Mime::XML, :status => response_status
32
+ end
33
+
34
+ def show_respond_to_js
35
+ render :partial => 'show'
36
+ end
37
+
38
+ def show_respond_to_html
39
+ render :action => 'show'
40
+ end
41
+ # A simple method to retrieve and prepare a record for showing.
42
+ # May be overridden to customize show routine
43
+ def do_show
44
+ @record = find_if_allowed(params[:id], :read)
45
+ end
46
+
47
+ # The default security delegates to ActiveRecordPermissions.
48
+ # You may override the method to customize.
49
+ def show_authorized?(record = nil)
50
+ authorized_for?(:crud_type => :read)
51
+ end
52
+ private
53
+ def show_authorized_filter
54
+ link = active_scaffold_config.show.link || active_scaffold_config.show.class.link
55
+ raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
56
+ end
57
+ def show_formats
58
+ (default_formats + active_scaffold_config.formats + active_scaffold_config.show.formats).uniq
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ module ActiveScaffold::Actions
2
+ module Subform
3
+ def edit_associated
4
+ @parent_record = params[:id].nil? ? active_scaffold_config.model.new : find_if_allowed(params[:id], :update)
5
+ @column = active_scaffold_config.columns[params[:association]]
6
+
7
+ # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all.
8
+ @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id]
9
+ @record ||= @column.association.klass.new
10
+
11
+ @scope = "[#{@column.name}]"
12
+ @scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association?
13
+
14
+ render :action => 'edit_associated'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,141 @@
1
+ module ActiveScaffold::Actions
2
+ module Update
3
+ def self.included(base)
4
+ base.before_filter :update_authorized_filter, :only => [:edit, :update]
5
+ base.verify :method => [:post, :put],
6
+ :only => :update,
7
+ :redirect_to => { :action => :index }
8
+ end
9
+
10
+ def edit
11
+ do_edit
12
+ respond_to_action(:edit)
13
+ end
14
+
15
+ def update
16
+ do_update
17
+ respond_to_action(:update)
18
+ end
19
+
20
+ # for inline (inlist) editing
21
+ def update_column
22
+ do_update_column
23
+ render :action => 'update_column', :locals => {:column_span_id => params[:editor_id] || params[:editorId]}
24
+ end
25
+
26
+ protected
27
+ def edit_respond_to_html
28
+ if successful?
29
+ render(:action => 'update')
30
+ else
31
+ return_to_main
32
+ end
33
+ end
34
+ def edit_respond_to_js
35
+ render(:partial => 'update_form')
36
+ end
37
+ def update_respond_to_html
38
+ if params[:iframe]=='true' # was this an iframe post ?
39
+ responds_to_parent do
40
+ render :action => 'on_update.js', :layout => false
41
+ end
42
+ else # just a regular post
43
+ if successful?
44
+ flash[:info] = as_(:updated_model, :model => @record.to_label)
45
+ return_to_main
46
+ else
47
+ render(:action => 'update')
48
+ end
49
+ end
50
+ end
51
+ def update_respond_to_js
52
+ if active_scaffold_config.update.refresh_list && successful?
53
+ do_search if respond_to? :do_search
54
+ do_list
55
+ end
56
+ render :action => 'on_update'
57
+ end
58
+ def update_respond_to_xml
59
+ render :xml => response_object.to_xml(:only => active_scaffold_config.update.columns.names), :content_type => Mime::XML, :status => response_status
60
+ end
61
+ def update_respond_to_json
62
+ render :text => response_object.to_json(:only => active_scaffold_config.update.columns.names), :content_type => Mime::JSON, :status => response_status
63
+ end
64
+ def update_respond_to_yaml
65
+ render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.update.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
66
+ end
67
+ # A simple method to find and prepare a record for editing
68
+ # May be overridden to customize the record (set default values, etc.)
69
+ def do_edit
70
+ register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested?
71
+ @record = find_if_allowed(params[:id], :update)
72
+ end
73
+
74
+ # A complex method to update a record. The complexity comes from the support for subforms, and saving associated records.
75
+ # If you want to customize this algorithm, consider using the +before_update_save+ callback
76
+ def do_update
77
+ do_edit
78
+ @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record])
79
+ update_save
80
+ end
81
+
82
+ def update_save
83
+ begin
84
+ active_scaffold_config.model.transaction do
85
+ before_update_save(@record)
86
+ self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit
87
+ if successful?
88
+ @record.save! and @record.save_associated!
89
+ after_update_save(@record)
90
+ end
91
+ end
92
+ rescue ActiveRecord::RecordInvalid
93
+ rescue ActiveRecord::StaleObjectError
94
+ @record.errors.add(:base, as_(:version_inconsistency))
95
+ self.successful=false
96
+ rescue ActiveRecord::RecordNotSaved
97
+ @record.errors.add(:base, as_(:record_not_saved)) if @record.errors.empty?
98
+ self.successful = false
99
+ end
100
+ end
101
+
102
+ def do_update_column
103
+ @record = active_scaffold_config.model.find(params[:id])
104
+ if @record.authorized_for?(:crud_type => :update, :column => params[:column])
105
+ column = active_scaffold_config.columns[params[:column].to_sym]
106
+ params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null
107
+ unless column.nil?
108
+ params[:value] = column_value_from_param_value(@record, column, params[:value])
109
+ params[:value] = [] if params[:value].nil? && column.form_ui && column.plural_association?
110
+ end
111
+ @record.send("#{params[:column]}=", params[:value])
112
+ before_update_save(@record)
113
+ @record.save
114
+ after_update_save(@record)
115
+ end
116
+ end
117
+
118
+ # override this method if you want to inject data in the record (or its associated objects) before the save
119
+ def before_update_save(record); end
120
+
121
+ # override this method if you want to do something after the save
122
+ def after_update_save(record); end
123
+
124
+ # The default security delegates to ActiveRecordPermissions.
125
+ # You may override the method to customize.
126
+ def update_authorized?(record = nil)
127
+ (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :update)
128
+ end
129
+ private
130
+ def update_authorized_filter
131
+ link = active_scaffold_config.update.link || active_scaffold_config.update.class.link
132
+ raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
133
+ end
134
+ def edit_formats
135
+ (default_formats + active_scaffold_config.formats).uniq
136
+ end
137
+ def update_formats
138
+ (default_formats + active_scaffold_config.formats + active_scaffold_config.update.formats).uniq
139
+ end
140
+ end
141
+ end