active_scaffold 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (272) hide show
  1. data/.autotest +27 -0
  2. data/CHANGELOG +152 -0
  3. data/Gemfile +4 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README +51 -0
  6. data/Rakefile +24 -0
  7. data/active_scaffold.gemspec +24 -0
  8. data/environment.rb +22 -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/cross.png +0 -0
  14. data/frontends/default/images/indicator-small.gif +0 -0
  15. data/frontends/default/images/indicator.gif +0 -0
  16. data/frontends/default/images/magnifier.png +0 -0
  17. data/frontends/default/javascripts/jquery/active_scaffold.js +957 -0
  18. data/frontends/default/javascripts/jquery/jquery.editinplace.js +726 -0
  19. data/frontends/default/javascripts/prototype/active_scaffold.js +954 -0
  20. data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
  21. data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
  22. data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
  23. data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
  24. data/frontends/default/stylesheets/stylesheet.css +858 -0
  25. data/frontends/default/views/_add_existing_form.html.erb +30 -0
  26. data/frontends/default/views/_base_form.html.erb +41 -0
  27. data/frontends/default/views/_create_form.html.erb +6 -0
  28. data/frontends/default/views/_create_form_on_list.html.erb +5 -0
  29. data/frontends/default/views/_field_search.html.erb +32 -0
  30. data/frontends/default/views/_form.html.erb +24 -0
  31. data/frontends/default/views/_form_association.html.erb +14 -0
  32. data/frontends/default/views/_form_association_footer.html.erb +40 -0
  33. data/frontends/default/views/_form_attribute.html.erb +15 -0
  34. data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
  35. data/frontends/default/views/_form_messages.html.erb +5 -0
  36. data/frontends/default/views/_horizontal_subform.html.erb +19 -0
  37. data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
  38. data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
  39. data/frontends/default/views/_human_conditions.html.erb +1 -0
  40. data/frontends/default/views/_list.html.erb +18 -0
  41. data/frontends/default/views/_list_actions.html.erb +16 -0
  42. data/frontends/default/views/_list_calculations.html.erb +16 -0
  43. data/frontends/default/views/_list_column_headings.html.erb +12 -0
  44. data/frontends/default/views/_list_header.html.erb +12 -0
  45. data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
  46. data/frontends/default/views/_list_messages.html.erb +32 -0
  47. data/frontends/default/views/_list_pagination.html.erb +11 -0
  48. data/frontends/default/views/_list_pagination_links.html.erb +9 -0
  49. data/frontends/default/views/_list_record.html.erb +14 -0
  50. data/frontends/default/views/_list_record_columns.html.erb +8 -0
  51. data/frontends/default/views/_list_with_header.html.erb +32 -0
  52. data/frontends/default/views/_messages.html.erb +10 -0
  53. data/frontends/default/views/_render_field.js.rjs +13 -0
  54. data/frontends/default/views/_row.html.erb +12 -0
  55. data/frontends/default/views/_search.html.erb +34 -0
  56. data/frontends/default/views/_search_attribute.html.erb +10 -0
  57. data/frontends/default/views/_show.html.erb +8 -0
  58. data/frontends/default/views/_show_columns.html.erb +12 -0
  59. data/frontends/default/views/_update_actions.html.erb +9 -0
  60. data/frontends/default/views/_update_form.html.erb +5 -0
  61. data/frontends/default/views/_vertical_subform.html.erb +12 -0
  62. data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
  63. data/frontends/default/views/add_existing.js.rjs +17 -0
  64. data/frontends/default/views/add_existing_form.html.erb +5 -0
  65. data/frontends/default/views/create.html.erb +5 -0
  66. data/frontends/default/views/delete.html.erb +13 -0
  67. data/frontends/default/views/destroy.js.rjs +5 -0
  68. data/frontends/default/views/edit_associated.js.rjs +11 -0
  69. data/frontends/default/views/field_search.html.erb +5 -0
  70. data/frontends/default/views/form_messages.js.rjs +1 -0
  71. data/frontends/default/views/list.html.erb +1 -0
  72. data/frontends/default/views/list.js.rjs +1 -0
  73. data/frontends/default/views/on_action_update.js.rjs +8 -0
  74. data/frontends/default/views/on_create.js.rjs +24 -0
  75. data/frontends/default/views/on_update.js.rjs +15 -0
  76. data/frontends/default/views/search.html.erb +5 -0
  77. data/frontends/default/views/show.html.erb +5 -0
  78. data/frontends/default/views/update.html.erb +8 -0
  79. data/frontends/default/views/update_column.js.rjs +13 -0
  80. data/frontends/default/views/update_row.js.rjs +1 -0
  81. data/init.rb +1 -0
  82. data/install_assets.rb +44 -0
  83. data/lib/active_record_permissions.rb +134 -0
  84. data/lib/active_scaffold.rb +279 -0
  85. data/lib/active_scaffold/actions/common_search.rb +22 -0
  86. data/lib/active_scaffold/actions/core.rb +150 -0
  87. data/lib/active_scaffold/actions/create.rb +152 -0
  88. data/lib/active_scaffold/actions/delete.rb +72 -0
  89. data/lib/active_scaffold/actions/field_search.rb +82 -0
  90. data/lib/active_scaffold/actions/list.rb +128 -0
  91. data/lib/active_scaffold/actions/mark.rb +50 -0
  92. data/lib/active_scaffold/actions/nested.rb +241 -0
  93. data/lib/active_scaffold/actions/search.rb +47 -0
  94. data/lib/active_scaffold/actions/show.rb +54 -0
  95. data/lib/active_scaffold/actions/subform.rb +17 -0
  96. data/lib/active_scaffold/actions/update.rb +134 -0
  97. data/lib/active_scaffold/attribute_params.rb +207 -0
  98. data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
  99. data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +38 -0
  100. data/lib/active_scaffold/bridges/bridge.rb +52 -0
  101. data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
  102. data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +79 -0
  103. data/lib/active_scaffold/bridges/carrierwave/bridge.rb +7 -0
  104. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +38 -0
  105. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +26 -0
  106. data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +35 -0
  107. data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
  108. data/lib/active_scaffold/bridges/date_picker/bridge.rb +22 -0
  109. data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
  110. data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
  111. data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
  112. data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
  113. data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
  114. data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
  115. data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
  116. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
  117. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
  118. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
  119. data/lib/active_scaffold/bridges/paperclip/bridge.rb +12 -0
  120. data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
  121. data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
  122. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
  123. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
  124. data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
  125. data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
  126. data/lib/active_scaffold/bridges/shared/date_bridge.rb +187 -0
  127. data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
  128. data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +45 -0
  129. data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
  130. data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
  131. data/lib/active_scaffold/config/base.rb +54 -0
  132. data/lib/active_scaffold/config/core.rb +229 -0
  133. data/lib/active_scaffold/config/create.rb +43 -0
  134. data/lib/active_scaffold/config/delete.rb +25 -0
  135. data/lib/active_scaffold/config/field_search.rb +74 -0
  136. data/lib/active_scaffold/config/form.rb +46 -0
  137. data/lib/active_scaffold/config/list.rb +174 -0
  138. data/lib/active_scaffold/config/mark.rb +22 -0
  139. data/lib/active_scaffold/config/nested.rb +43 -0
  140. data/lib/active_scaffold/config/search.rb +68 -0
  141. data/lib/active_scaffold/config/show.rb +34 -0
  142. data/lib/active_scaffold/config/subform.rb +35 -0
  143. data/lib/active_scaffold/config/update.rb +38 -0
  144. data/lib/active_scaffold/configurable.rb +29 -0
  145. data/lib/active_scaffold/constraints.rb +179 -0
  146. data/lib/active_scaffold/data_structures/action_columns.rb +133 -0
  147. data/lib/active_scaffold/data_structures/action_link.rb +162 -0
  148. data/lib/active_scaffold/data_structures/action_links.rb +59 -0
  149. data/lib/active_scaffold/data_structures/actions.rb +45 -0
  150. data/lib/active_scaffold/data_structures/column.rb +348 -0
  151. data/lib/active_scaffold/data_structures/columns.rb +75 -0
  152. data/lib/active_scaffold/data_structures/error_message.rb +24 -0
  153. data/lib/active_scaffold/data_structures/nested_info.rb +108 -0
  154. data/lib/active_scaffold/data_structures/set.rb +62 -0
  155. data/lib/active_scaffold/data_structures/sorting.rb +168 -0
  156. data/lib/active_scaffold/finder.rb +333 -0
  157. data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
  158. data/lib/active_scaffold/helpers/controller_helpers.rb +40 -0
  159. data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
  160. data/lib/active_scaffold/helpers/form_column_helpers.rb +343 -0
  161. data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
  162. data/lib/active_scaffold/helpers/id_helpers.rb +131 -0
  163. data/lib/active_scaffold/helpers/list_column_helpers.rb +363 -0
  164. data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
  165. data/lib/active_scaffold/helpers/search_column_helpers.rb +238 -0
  166. data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
  167. data/lib/active_scaffold/helpers/view_helpers.rb +315 -0
  168. data/lib/active_scaffold/locale/de.rb +113 -0
  169. data/lib/active_scaffold/locale/en.rb +118 -0
  170. data/lib/active_scaffold/locale/es.yml +112 -0
  171. data/lib/active_scaffold/locale/fr.rb +113 -0
  172. data/lib/active_scaffold/locale/hu.yml +63 -0
  173. data/lib/active_scaffold/locale/ja.yml +64 -0
  174. data/lib/active_scaffold/locale/ru.yml +62 -0
  175. data/lib/active_scaffold/marked_model.rb +38 -0
  176. data/lib/dhtml_confirm.rb +54 -0
  177. data/lib/extensions/action_controller_rendering.rb +20 -0
  178. data/lib/extensions/action_view_rendering.rb +113 -0
  179. data/lib/extensions/action_view_resolver.rb +7 -0
  180. data/lib/extensions/active_record_offset.rb +12 -0
  181. data/lib/extensions/array.rb +7 -0
  182. data/lib/extensions/localize.rb +10 -0
  183. data/lib/extensions/name_option_for_datetime.rb +12 -0
  184. data/lib/extensions/nil_id_in_url_params.rb +7 -0
  185. data/lib/extensions/paginator_extensions.rb +26 -0
  186. data/lib/extensions/reverse_associations.rb +62 -0
  187. data/lib/extensions/routing_mapper.rb +34 -0
  188. data/lib/extensions/to_label.rb +8 -0
  189. data/lib/extensions/unsaved_associated.rb +61 -0
  190. data/lib/extensions/unsaved_record.rb +20 -0
  191. data/lib/extensions/usa_state.rb +46 -0
  192. data/lib/generators/active_scaffold/USAGE +29 -0
  193. data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
  194. data/lib/generators/active_scaffold_controller/USAGE +19 -0
  195. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +28 -0
  196. data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
  197. data/lib/generators/active_scaffold_setup/USAGE +10 -0
  198. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +53 -0
  199. data/lib/paginator.rb +136 -0
  200. data/lib/responds_to_parent.rb +70 -0
  201. data/public/blank.html +33 -0
  202. data/shoulda_macros/macros.rb +136 -0
  203. data/test/bridges/bridge_test.rb +47 -0
  204. data/test/config/base_test.rb +15 -0
  205. data/test/config/create_test.rb +55 -0
  206. data/test/config/list_test.rb +74 -0
  207. data/test/config/show_test.rb +43 -0
  208. data/test/config/update_test.rb +17 -0
  209. data/test/const_mocker.rb +36 -0
  210. data/test/data_structures/action_columns_test.rb +113 -0
  211. data/test/data_structures/action_link_test.rb +78 -0
  212. data/test/data_structures/action_links_test.rb +78 -0
  213. data/test/data_structures/actions_test.rb +25 -0
  214. data/test/data_structures/association_column_test.rb +42 -0
  215. data/test/data_structures/column_test.rb +185 -0
  216. data/test/data_structures/columns_test.rb +69 -0
  217. data/test/data_structures/error_message_test.rb +28 -0
  218. data/test/data_structures/set_test.rb +86 -0
  219. data/test/data_structures/sorting_test.rb +126 -0
  220. data/test/data_structures/standard_column_test.rb +24 -0
  221. data/test/data_structures/virtual_column_test.rb +23 -0
  222. data/test/extensions/active_record_test.rb +45 -0
  223. data/test/extensions/array_test.rb +12 -0
  224. data/test/helpers/form_column_helpers_test.rb +31 -0
  225. data/test/helpers/list_column_helpers_test.rb +31 -0
  226. data/test/helpers/pagination_helpers_test.rb +55 -0
  227. data/test/misc/active_record_permissions_test.rb +154 -0
  228. data/test/misc/attribute_params_test.rb +110 -0
  229. data/test/misc/configurable_test.rb +96 -0
  230. data/test/misc/constraints_test.rb +193 -0
  231. data/test/misc/finder_test.rb +93 -0
  232. data/test/misc/lang_test.rb +12 -0
  233. data/test/mock_app/.gitignore +2 -0
  234. data/test/mock_app/app/controllers/application_controller.rb +10 -0
  235. data/test/mock_app/app/helpers/application_helper.rb +3 -0
  236. data/test/mock_app/config/boot.rb +110 -0
  237. data/test/mock_app/config/database.yml +16 -0
  238. data/test/mock_app/config/environment.rb +43 -0
  239. data/test/mock_app/config/environments/development.rb +17 -0
  240. data/test/mock_app/config/environments/production.rb +28 -0
  241. data/test/mock_app/config/environments/test.rb +28 -0
  242. data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
  243. data/test/mock_app/config/initializers/inflections.rb +10 -0
  244. data/test/mock_app/config/initializers/mime_types.rb +5 -0
  245. data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
  246. data/test/mock_app/config/initializers/session_store.rb +15 -0
  247. data/test/mock_app/config/locales/en.yml +5 -0
  248. data/test/mock_app/config/routes.rb +43 -0
  249. data/test/mock_app/db/test.sqlite3 +1 -0
  250. data/test/mock_app/public/blank.html +33 -0
  251. data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
  252. data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
  253. data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
  254. data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
  255. data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
  256. data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
  257. data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
  258. data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
  259. data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
  260. data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
  261. data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
  262. data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
  263. data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
  264. data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
  265. data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
  266. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
  267. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +839 -0
  268. data/test/model_stub.rb +55 -0
  269. data/test/run_all.rb +8 -0
  270. data/test/test_helper.rb +39 -0
  271. data/uninstall.rb +13 -0
  272. metadata +478 -0
@@ -0,0 +1,37 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ # Helpers that assist with the rendering of a Form Column
4
+ module FormColumnHelpers
5
+ def active_scaffold_input_file_column(column, options)
6
+ if @record.send(column.name)
7
+ # we already have a value? display the form for deletion.
8
+ if ActiveScaffold.js_framework == :jquery
9
+ js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;";
10
+ else
11
+ js_remove_file_code = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show(); return false;";
12
+ end
13
+ content_tag(
14
+ :div,
15
+ content_tag(
16
+ :div,
17
+ get_column_value(@record, column) + " " +
18
+ hidden_field(:record, "delete_#{column.name}", :value => "false") +
19
+ " | " +
20
+ content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}),
21
+ {}
22
+ ) +
23
+ content_tag(
24
+ :div,
25
+ file_column_field("record", column.name, options),
26
+ :style => "display: none"
27
+ ),
28
+ {}
29
+ )
30
+ else
31
+ # no, just display the file_column_field
32
+ file_column_field("record", column.name, options)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ # Helpers that assist with the rendering of a List Column
4
+ module ListColumnHelpers
5
+ def active_scaffold_column_download_link_with_filename(column, record)
6
+ return nil if record.send(column.name).nil?
7
+ active_scaffold_column_download_link(column, record, File.basename(record.send(column.name)))
8
+ end
9
+
10
+ def active_scaffold_column_download_link(column, record, label = nil)
11
+ return nil if record.send(column.name).nil?
12
+ label||=as_(:download)
13
+ link_to( label, url_for_file_column(record, column.name.to_s), :popup => true)
14
+ end
15
+
16
+ def active_scaffold_column_thumbnail(column, record)
17
+ return nil if record.send(column.name).nil?
18
+ link_to(
19
+ image_tag(url_for_file_column(record, column.name.to_s, "thumb"), :border => 0),
20
+ url_for_file_column(record, column.name.to_s),
21
+ :popup => true)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ require File.join(File.dirname(__FILE__), "../test_helper.rb")
2
+
3
+ class DeleteFileColumnTest < Test::Unit::TestCase
4
+ def setup
5
+ DeleteFileColumn.generate_delete_helpers(MockModel)
6
+ @model = MockModel.new
7
+ @model.band_image = "coolio.jpg"
8
+ end
9
+
10
+ def test__file_column_fields
11
+ assert_equal(1, @model.file_column_fields.length)
12
+ end
13
+
14
+ def test__delete_band_image__boolean__should_delete
15
+ @model.delete_band_image = true
16
+ assert_nil @model.band_image
17
+ end
18
+
19
+ def test__delete_band_image__string__should_delete
20
+ @model.delete_band_image = "true"
21
+ assert_nil @model.band_image
22
+ end
23
+
24
+
25
+ def test__delete_band_image__boolean_false__shouldnt_delete
26
+ @model.delete_band_image = false
27
+ assert_not_nil @model.band_image
28
+ end
29
+
30
+ def test__delete_band_image__string_false__shouldnt_delete
31
+ @model.delete_band_image = "false"
32
+ assert_not_nil @model.band_image
33
+ end
34
+
35
+
36
+ def test__just_uploaded__shouldnt_delete
37
+ @model.band_image_just_uploaded = true
38
+ @model.delete_band_image = "true"
39
+ assert_not_nil(@model.band_image)
40
+ end
41
+
42
+
43
+ end
@@ -0,0 +1,9 @@
1
+ class MockModel
2
+ attr_accessor :name
3
+ attr_accessor :bio
4
+
5
+ attr_accessor :band_image
6
+ attr_accessor :band_image_just_uploaded
7
+ def band_image_just_uploaded?; self.band_image_just_uploaded ? true : false; end
8
+
9
+ end
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+ require "rubygems"
3
+ require 'active_support'
4
+
5
+ for file in ["../lib/delete_file_column.rb", "mock_model.rb"]
6
+ require File.expand_path(File.join(File.dirname(__FILE__), file))
7
+ end
8
+
9
+
10
+
11
+ def dbg
12
+ require 'ruby-debug'
13
+ Debugger.start
14
+ debugger
15
+ end
@@ -0,0 +1,12 @@
1
+ ActiveScaffold::Bridges.bridge "Paperclip" do
2
+ install do
3
+ if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip")
4
+ raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts"
5
+ end
6
+ require File.join(File.dirname(__FILE__), "lib/form_ui")
7
+ require File.join(File.dirname(__FILE__), "lib/list_ui")
8
+ require File.join(File.dirname(__FILE__), "lib/paperclip_bridge")
9
+ require File.join(File.dirname(__FILE__), "lib/paperclip_bridge_helpers")
10
+ ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridge
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ module FormColumnHelpers
4
+ def active_scaffold_input_paperclip(column, options)
5
+ options = active_scaffold_input_text_options(options)
6
+ input = file_field(:record, column.name, options)
7
+ paperclip = @record.send("#{column.name}")
8
+ if paperclip.file?
9
+ if ActiveScaffold.js_framework == :jquery
10
+ js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;";
11
+ else
12
+ js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;";
13
+ end
14
+
15
+ content = active_scaffold_column_paperclip(column, @record)
16
+ content_tag(:div,
17
+ content + " | " +
18
+ hidden_field(:record, "delete_#{column.name}", :value => "false") +
19
+ content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code})
20
+ ) + content_tag(:div, input, :style => "display: none")
21
+ else
22
+ input
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ module ListColumnHelpers
4
+ def active_scaffold_column_paperclip(column, record)
5
+ paperclip = record.send("#{column.name}")
6
+ return nil unless paperclip.file?
7
+ content = if paperclip.styles.include?(ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridgeHelpers.thumbnail_style)
8
+ image_tag(paperclip.url(ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridgeHelpers.thumbnail_style), :border => 0)
9
+ else
10
+ paperclip.original_filename
11
+ end
12
+ link_to(content, paperclip.url, :popup => true)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ module ActiveScaffold
2
+ module Bridges
3
+ module Paperclip
4
+ module Lib
5
+ module PaperclipBridge
6
+ def initialize_with_paperclip(model_id)
7
+ initialize_without_paperclip(model_id)
8
+ return unless self.model.respond_to?(:attachment_definitions) && !self.model.attachment_definitions.nil?
9
+
10
+ self.update.multipart = true
11
+ self.create.multipart = true
12
+
13
+ self.model.attachment_definitions.keys.each do |field|
14
+ configure_paperclip_field(field.to_sym)
15
+ # define the "delete" helper for use with active scaffold, unless it's already defined
16
+ ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridgeHelpers.generate_delete_helper(self.model, field)
17
+ end
18
+ end
19
+
20
+ def self.included(base)
21
+ base.alias_method_chain :initialize, :paperclip
22
+ end
23
+
24
+ private
25
+ def configure_paperclip_field(field)
26
+ self.columns << field
27
+ self.columns[field].form_ui ||= :paperclip
28
+ self.columns[field].params.add "delete_#{field}"
29
+
30
+ [:file_name, :content_type, :file_size, :updated_at].each do |f|
31
+ self.columns.exclude("#{field}_#{f}".to_sym)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ module ActiveScaffold
2
+ module Bridges
3
+ module Paperclip
4
+ module Lib
5
+ module PaperclipBridgeHelpers
6
+ mattr_accessor :thumbnail_style
7
+ self.thumbnail_style = :thumbnail
8
+
9
+ def self.generate_delete_helper(klass, field)
10
+ klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("delete_#{field}=")
11
+ attr_reader :delete_#{field}
12
+
13
+ def delete_#{field}=(value)
14
+ value = (value == "true") if String === value
15
+ return unless value
16
+
17
+ # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file!
18
+ self.#{field} = nil unless self.#{field}.dirty?
19
+ end
20
+ EOF
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ ActiveScaffold::Bridges.bridge "SemanticAttributes" do
2
+ install do
3
+ require File.join(File.dirname(__FILE__), "lib/semantic_attributes_bridge.rb")
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ module ActiveScaffold
2
+ module SemanticAttributesBridge
3
+ def self.included(base)
4
+ base.class_eval { alias_method_chain :initialize, :semantic_attributes }
5
+ end
6
+
7
+ def initialize_with_semantic_attributes(name, active_record_class)
8
+ initialize_without_semantic_attributes(name, active_record_class)
9
+ self.required = !active_record_class.semantic_attributes[self.name].predicates.find {|p| p.allow_empty? == false }.nil?
10
+ active_record_class.semantic_attributes[self.name].predicates.find do |p|
11
+ sem_type = p.class.to_s.split('::')[1].underscore.to_sym
12
+ next if [:required, :association].include?(sem_type)
13
+ @form_ui = sem_type
14
+ end
15
+ end
16
+ end
17
+ end
18
+ ActiveScaffold::DataStructures::Column.class_eval do
19
+ include ActiveScaffold::SemanticAttributesBridge
20
+ end
@@ -0,0 +1,187 @@
1
+ module ActiveScaffold
2
+ module Bridges
3
+ module Shared
4
+ module DateBridge
5
+ module SearchColumnHelpers
6
+ def active_scaffold_search_date_bridge(column, options)
7
+ current_search = {'from' => nil, 'to' => nil, 'opt' => 'BETWEEN',
8
+ 'number' => 1, 'unit' => 'DAYS', 'range' => nil}
9
+ current_search.merge!(options[:value]) unless options[:value].nil?
10
+ tags = []
11
+ tags << active_scaffold_search_date_bridge_comparator_tag(column, options, current_search)
12
+ tags << active_scaffold_search_date_bridge_trend_tag(column, options, current_search)
13
+ tags << active_scaffold_search_date_bridge_numeric_tag(column, options, current_search)
14
+ tags << active_scaffold_search_date_bridge_range_tag(column, options, current_search)
15
+ tags.join("&nbsp;").html_safe
16
+ end
17
+
18
+ def active_scaffold_search_date_bridge_comparator_options(column)
19
+ select_options = ActiveScaffold::Finder::DateComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
20
+ select_options + ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
21
+ end
22
+
23
+ def active_scaffold_search_date_bridge_comparator_tag(column, options, current_search)
24
+ select_tag("#{options[:name]}[opt]", options_for_select(active_scaffold_search_date_bridge_comparator_options(column),current_search['opt']), :id => "#{options[:id]}_opt", :class => "as_search_range_option as_search_date_time_option")
25
+ end
26
+
27
+ def active_scaffold_search_date_bridge_numeric_tag(column, options, current_search)
28
+ numeric_controls = "" <<
29
+ active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'from') <<
30
+ content_tag(:span, (" - " + active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'to')).html_safe,
31
+ :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:#{current_search['opt'] == 'BETWEEN' ? '' : 'none'}")
32
+ content_tag("span", numeric_controls.html_safe, :id => "#{options[:id]}_numeric", :style => "display:#{ActiveScaffold::Finder::NumericComparators.include?(current_search['opt']) ? '' : 'none'}")
33
+ end
34
+
35
+ def active_scaffold_search_date_bridge_trend_tag(column, options, current_search)
36
+ active_scaffold_date_bridge_trend_tag(column, options,
37
+ {:name_prefix => 'search',
38
+ :number_value => current_search['number'],
39
+ :unit_value => current_search["unit"],
40
+ :show => (current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE')})
41
+ end
42
+
43
+ def active_scaffold_date_bridge_trend_tag(column, options, trend_options)
44
+ trend_controls = text_field_tag("#{trend_options[:name_prefix]}[#{column.name}][number]", trend_options[:number_value], :class => 'text-input', :size => 10, :autocomplete => 'off') << " " <<
45
+ select_tag("#{trend_options[:name_prefix]}[#{column.name}][unit]",
46
+ options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:name_prefix]),
47
+ :class => 'text-input')
48
+ content_tag("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :style => "display:#{trend_options[:show] ? '' : 'none'}")
49
+ end
50
+
51
+ def active_scaffold_search_date_bridge_trend_units(column)
52
+ options = ActiveScaffold::Finder::DateUnits.collect{|unit| [as_(unit.downcase.to_sym), unit]}
53
+ options = ActiveScaffold::Finder::TimeUnits.collect{|unit| [as_(unit.downcase.to_sym), unit]} + options if column_datetime?(column)
54
+ options
55
+ end
56
+
57
+ def active_scaffold_search_date_bridge_range_tag(column, options, current_search)
58
+ range_controls = select_tag("search[#{column.name}][range]",
59
+ options_for_select( ActiveScaffold::Finder::DateRanges.collect{|range| [as_(range.downcase.to_sym), range]}, current_search["range"]),
60
+ :class => 'text-input')
61
+ content_tag("span", range_controls.html_safe, :id => "#{options[:id]}_range", :style => "display:#{(current_search['opt'] == 'RANGE') ? '' : 'none'}")
62
+ end
63
+
64
+ def column_datetime?(column)
65
+ (!column.column.nil? && [:datetime, :time].include?(column.column.type))
66
+ end
67
+ end
68
+
69
+ module HumanConditionHelpers
70
+ def active_scaffold_human_condition_date_bridge(column, value)
71
+ case value[:opt]
72
+ when 'RANGE'
73
+ "#{column.active_record_class.human_attribute_name(column.name)} = #{as_(value[:range].downcase).downcase}"
74
+ when 'PAST', 'FUTURE'
75
+ "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{as_(value[:number])} #{as_(value[:unit].downcase)}"
76
+ else
77
+ from, to = controller.class.date_bridge_from_to(column, value)
78
+ "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}"
79
+ end
80
+ end
81
+ end
82
+
83
+ module Finder
84
+ module ClassMethods
85
+ def condition_for_date_bridge_type(column, value, like_pattern)
86
+ operator = ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) && value[:opt] != 'BETWEEN' ? value[:opt] : nil
87
+ from_value, to_value = date_bridge_from_to(column, value)
88
+
89
+ if column.search_sql.is_a? Proc
90
+ column.search_sql.call(from_value, to_value, operator)
91
+ else
92
+ unless operator.nil?
93
+ ["#{column.search_sql} #{value[:opt]} ?", from_value.to_s(:db)] unless from_value.nil?
94
+ else
95
+ ["#{column.search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] unless from_value.nil? && to_value.nil?
96
+ end
97
+ end
98
+ end
99
+
100
+ def date_bridge_from_to(column, value)
101
+ conversion = column.column.type == :date ? :to_date : :to_time
102
+ case value[:opt]
103
+ when 'RANGE'
104
+ date_bridge_from_to_for_range(column, value).collect(&conversion)
105
+ when 'PAST', 'FUTURE'
106
+ date_bridge_from_to_for_trend(column, value).collect(&conversion)
107
+ else
108
+ ['from', 'to'].collect { |field| condition_value_for_datetime(value[field], conversion)}
109
+ end
110
+ end
111
+
112
+ def date_bridge_from_to_for_trend(column, value)
113
+ case value['opt']
114
+ when "PAST"
115
+ trend_number = [value['number'].to_i, 1].max
116
+ now = Time.zone.now
117
+ if date_bridge_column_date?(column)
118
+ from = now.beginning_of_day.ago((trend_number).send(value['unit'].downcase.singularize.to_sym))
119
+ to = now.end_of_day
120
+ else
121
+ from = now.ago((trend_number).send(value['unit'].downcase.singularize.to_sym))
122
+ to = now
123
+ end
124
+ return from, to
125
+ when "FUTURE"
126
+ trend_number = [value['number'].to_i, 1].max
127
+ now = Time.zone.now
128
+ if date_bridge_column_date?(column)
129
+ from = now.beginning_of_day
130
+ to = now.end_of_day.in((trend_number).send(value['unit'].downcase.singularize.to_sym))
131
+ else
132
+ from = now
133
+ to = now.in((trend_number).send(value['unit'].downcase.singularize.to_sym))
134
+ end
135
+ return from, to
136
+ end
137
+ end
138
+
139
+ def date_bridge_from_to_for_range(column, value)
140
+ case value[:range]
141
+ when 'TODAY'
142
+ return Time.zone.now.beginning_of_day, Time.zone.now.end_of_day
143
+ when 'YESTERDAY'
144
+ return Time.zone.now.ago(1.day).beginning_of_day, Time.zone.now.ago(1.day).end_of_day
145
+ when 'TOMMORROW'
146
+ return Time.zone.now.in(1.day).beginning_of_day, Time.zone.now.in(1.day).end_of_day
147
+ else
148
+ range_type, range = value[:range].downcase.split('_')
149
+ raise ArgumentError unless ['week', 'month', 'year'].include?(range)
150
+ case range_type
151
+ when 'this'
152
+ return Time.zone.now.send("beginning_of_#{range}".to_sym), Time.zone.now.send("end_of_#{range}")
153
+ when 'prev'
154
+ return Time.zone.now.ago(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), Time.zone.now.ago(1.send(range.to_sym)).send("end_of_#{range}".to_sym)
155
+ when 'next'
156
+ return Time.zone.now.in(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), Time.zone.now.in(1.send(range.to_sym)).send("end_of_#{range}".to_sym)
157
+ else
158
+ return nil, nil
159
+ end
160
+ end
161
+ end
162
+
163
+ def date_bridge_column_date?(column)
164
+ if [:date_picker, :datetime_picker].include? column.form_ui
165
+ column.form_ui == :date_picker
166
+ else
167
+ (!column.column.nil? && [:date].include?(column.column.type))
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ ActiveScaffold::Finder.const_set('DateComparators', ["PAST", "FUTURE", "RANGE"])
178
+ ActiveScaffold::Finder.const_set('DateUnits', ["DAYS", "WEEKS", "MONTHS", "YEARS"])
179
+ ActiveScaffold::Finder.const_set('TimeUnits', ["SECONDS", "MINUTES", "HOURS"])
180
+ ActiveScaffold::Finder.const_set('DateRanges', ["TODAY", "YESTERDAY", "TOMORROW",
181
+ "THIS_WEEK", "PREV_WEEK", "NEXT_WEEK",
182
+ "THIS_MONTH", "PREV_MONTH", "NEXT_MONTH",
183
+ "THIS_YEAR", "PREV_YEAR", "NEXT_YEAR"])
184
+
185
+
186
+
187
+