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,5 @@
1
+ ActiveScaffold::Bridges.bridge "TinyMCE" do
2
+ install do
3
+ require File.join(File.dirname(__FILE__), "lib/tiny_mce_bridge.rb")
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ module ActiveScaffold
2
+ module TinyMceBridge
3
+ module ViewHelpers
4
+ def active_scaffold_includes(*args)
5
+ tiny_mce_js = javascript_tag(%|
6
+ var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close;
7
+ ActiveScaffold.ActionLink.Abstract.prototype.close = function() {
8
+ this.adapter.select('textarea.mceEditor').each(function(elem) {
9
+ tinyMCE.execCommand('mceRemoveControl', false, elem.id);
10
+ });
11
+ action_link_close.apply(this);
12
+ };
13
+ |) if using_tiny_mce?
14
+ super(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '')
15
+ end
16
+ end
17
+
18
+ module FormColumnHelpers
19
+ def active_scaffold_input_text_editor(column, options)
20
+ options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip
21
+ html = []
22
+ html << send(override_input(:textarea), column, options)
23
+ html << javascript_tag("tinyMCE.execCommand('mceAddControl', false, '#{options[:id]}');") if request.xhr?
24
+ html.join "\n"
25
+ end
26
+
27
+ def onsubmit
28
+ submit_js = 'tinyMCE.triggerSave();this.select("textarea.mceEditor").each(function(elem) { tinyMCE.execCommand("mceRemoveControl", false, elem.id); });' if using_tiny_mce?
29
+ [super, submit_js].compact.join ';'
30
+ end
31
+ end
32
+
33
+ module SearchColumnHelpers
34
+ def self.included(base)
35
+ base.class_eval { alias_method :active_scaffold_search_text_editor, :active_scaffold_search_text }
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ ActionView::Base.class_eval do
42
+ include ActiveScaffold::TinyMceBridge::FormColumnHelpers
43
+ include ActiveScaffold::TinyMceBridge::SearchColumnHelpers
44
+ include ActiveScaffold::TinyMceBridge::ViewHelpers
45
+ end
@@ -0,0 +1,8 @@
1
+ ActiveScaffold::Bridges.bridge "ValidationReflection" do
2
+ install do
3
+ require File.join(File.dirname(__FILE__), "lib/validation_reflection_bridge.rb")
4
+ end
5
+ install? do
6
+ ActiveRecord::Base.respond_to? :reflect_on_validations_for
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ module ActiveScaffold
2
+ module ValidationReflectionBridge
3
+ def self.included(base)
4
+ base.class_eval { alias_method_chain :initialize, :validation_reflection }
5
+ end
6
+
7
+ def initialize_with_validation_reflection(name, active_record_class)
8
+ initialize_without_validation_reflection(name, active_record_class)
9
+ column_names = [name]
10
+ column_names << @association.primary_key_name if @association
11
+ self.required = column_names.any? do |column_name|
12
+ active_record_class.reflect_on_validations_for(column_name.to_sym).any? do |val|
13
+ val.macro == :validates_presence_of or (val.macro == :validates_inclusion_of and not val.options[:allow_nil] and not val.options[:allow_blank])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ ActiveScaffold::DataStructures::Column.class_eval do
20
+ include ActiveScaffold::ValidationReflectionBridge
21
+ end
@@ -0,0 +1,54 @@
1
+ module ActiveScaffold::Config
2
+ class Base
3
+ include ActiveScaffold::Configurable
4
+ extend ActiveScaffold::Configurable
5
+
6
+ def self.inherited(subclass)
7
+ class << subclass
8
+ # the crud type of the action. possible values are :create, :read, :update, :delete, and nil.
9
+ # this is not a setting for the developer. it's self-description for the actions.
10
+ def crud_type; @crud_type; end
11
+
12
+ protected
13
+
14
+ def crud_type=(val)
15
+ raise ArgumentError, "unknown CRUD type #{val}" unless [:create, :read, :update, :delete].include?(val.to_sym)
16
+ @crud_type = val.to_sym
17
+ end
18
+ end
19
+ end
20
+ # delegate
21
+ def crud_type; self.class.crud_type end
22
+
23
+ # the user property gets set to the instantiation of the local UserSettings class during the automatic instantiation of this class.
24
+ attr_accessor :user
25
+
26
+ class UserSettings
27
+ def initialize(conf, storage, params)
28
+ # the session hash relevant to this action
29
+ @session = storage
30
+ # all the request params
31
+ @params = params
32
+ # the configuration object for this action
33
+ @conf = conf
34
+ end
35
+ end
36
+
37
+ def formats
38
+ @formats ||= []
39
+ end
40
+
41
+ def formats=(val)
42
+ @formats=val
43
+ end
44
+
45
+ private
46
+
47
+ def columns=(val)
48
+ @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val)
49
+ @columns.action = self
50
+ @columns.set_columns(@core.columns) if @columns.respond_to?(:set_columns)
51
+ @columns
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,229 @@
1
+ module ActiveScaffold::Config
2
+ # to fix the ckeditor bridge problem
3
+ class Core < ActiveScaffold::Config::Base
4
+ # code commented out (see above)
5
+ #class Core < Base
6
+ # global level configuration
7
+ # --------------------------
8
+
9
+ # provides read/write access to the global Actions DataStructure
10
+ cattr_reader :actions
11
+ def self.actions=(val)
12
+ @@actions = ActiveScaffold::DataStructures::Actions.new(*val)
13
+ end
14
+ self.actions = [:create, :list, :search, :update, :delete, :show, :nested, :subform]
15
+
16
+ # configures where the ActiveScaffold plugin itself is located. there is no instance version of this.
17
+ cattr_accessor :plugin_directory
18
+ @@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/core.rb})[1]
19
+
20
+ # lets you specify a global ActiveScaffold frontend.
21
+ cattr_accessor :frontend
22
+ @@frontend = :default
23
+
24
+ # lets you specify a global ActiveScaffold theme for your frontend.
25
+ cattr_accessor :theme
26
+ @@theme = :default
27
+
28
+ # lets you disable the DHTML history
29
+ def self.dhtml_history=(val)
30
+ @@dhtml_history = val
31
+ end
32
+ def self.dhtml_history?
33
+ @@dhtml_history ? true : false
34
+ end
35
+ @@dhtml_history = true
36
+
37
+ # action links are used by actions to tie together. you can use them, too! this is a collection of ActiveScaffold::DataStructures::ActionLink objects.
38
+ cattr_reader :action_links
39
+ @@action_links = ActiveScaffold::DataStructures::ActionLinks.new
40
+
41
+ # access to the permissions configuration.
42
+ # configuration options include:
43
+ # * current_user_method - what method on the controller returns the current user. default: :current_user
44
+ # * default_permission - what the default permission is. default: true
45
+ def self.security
46
+ ActiveRecordPermissions
47
+ end
48
+
49
+ # columns that should be ignored for every model. these should be metadata columns like change dates, versions, etc.
50
+ # values in this array may be symbols or strings.
51
+ def self.ignore_columns
52
+ @@ignore_columns
53
+ end
54
+ def self.ignore_columns=(val)
55
+ @@ignore_columns = ActiveScaffold::DataStructures::Set.new(*val)
56
+ end
57
+ @@ignore_columns = ActiveScaffold::DataStructures::Set.new
58
+
59
+ # lets you specify whether add a create link for each sti child
60
+ cattr_accessor :sti_create_links
61
+
62
+ # instance-level configuration
63
+ # ----------------------------
64
+
65
+ # provides read/write access to the local Actions DataStructure
66
+ attr_reader :actions
67
+ def actions=(args)
68
+ @actions = ActiveScaffold::DataStructures::Actions.new(*args)
69
+ end
70
+
71
+ # provides read/write access to the local Columns DataStructure
72
+ attr_reader :columns
73
+ def columns=(val)
74
+ @columns._inheritable = val.collect {|c| c.to_sym}
75
+ # Add virtual columns
76
+ @columns << val.collect {|c| c.to_sym unless @columns[c.to_sym]}.compact
77
+ end
78
+
79
+ # lets you override the global ActiveScaffold frontend for a specific controller
80
+ attr_accessor :frontend
81
+
82
+ # lets you override the global ActiveScaffold theme for a specific controller
83
+ attr_accessor :theme
84
+
85
+ # lets you specify whether add a create link for each sti child for a specific controller
86
+ attr_accessor :sti_create_links
87
+ def add_sti_create_links?
88
+ self.sti_create_links and not self.sti_children.nil?
89
+ end
90
+
91
+ # action links are used by actions to tie together. they appear as links for each record, or general links for the ActiveScaffold.
92
+ attr_reader :action_links
93
+
94
+ # a generally-applicable name for this ActiveScaffold ... will be used for generating page/section headers
95
+ attr_writer :label
96
+ def label(options={})
97
+ as_(@label, options) || model.model_name.human(options.merge(options[:count].to_i == 1 ? {} : {:default => model.name.pluralize}))
98
+ end
99
+
100
+ # STI children models, use an array of model names
101
+ attr_accessor :sti_children
102
+
103
+ ##
104
+ ## internal usage only below this point
105
+ ## ------------------------------------
106
+
107
+ def initialize(model_id)
108
+ # model_id is the only absolutely required configuration value. it is also not publicly accessible.
109
+ @model_id = model_id.to_s.pluralize.singularize
110
+
111
+ # inherit the actions list directly from the global level
112
+ @actions = self.class.actions.clone
113
+
114
+ # create a new default columns datastructure, since it doesn't make sense before now
115
+ attribute_names = self.model.columns.collect{ |c| c.name.to_sym }.sort_by { |c| c.to_s }
116
+ association_column_names = self.model.reflect_on_all_associations.collect{ |a| a.name.to_sym }.sort_by { |c| c.to_s }
117
+ @columns = ActiveScaffold::DataStructures::Columns.new(self.model, attribute_names + association_column_names)
118
+
119
+ # and then, let's remove some columns from the inheritable set.
120
+ @columns.exclude(*self.class.ignore_columns)
121
+ @columns.exclude(*@columns.find_all { |c| c.column and (c.column.primary or c.column.name =~ /(_id|_count)$/) }.collect {|c| c.name})
122
+ @columns.exclude(*self.model.reflect_on_all_associations.collect{|a| :"#{a.name}_type" if a.options[:polymorphic]}.compact)
123
+
124
+ # inherit the global frontend
125
+ @frontend = self.class.frontend
126
+ @theme = self.class.theme
127
+ @sti_create_links = self.class.sti_create_links
128
+
129
+ # inherit from the global set of action links
130
+ @action_links = self.class.action_links.clone
131
+ end
132
+
133
+ # To be called after your finished configuration
134
+ def _load_action_columns
135
+ ActiveScaffold::DataStructures::ActionColumns.class_eval {include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration}
136
+
137
+ # then, register the column objects
138
+ self.actions.each do |action_name|
139
+ action = self.send(action_name)
140
+ next unless action.respond_to? :columns
141
+ action.columns.set_columns(self.columns)
142
+ end
143
+ end
144
+
145
+ # To be called after your finished configuration
146
+ def _configure_sti
147
+ column = self.model.inheritance_column
148
+ if sti_create_links
149
+ self.columns[column].form_ui ||= :hidden
150
+ else
151
+ self.columns[column].form_ui ||= :select
152
+ self.columns[column].options ||= {}
153
+ self.columns[column].options[:options] = self.sti_children.collect do |model_name|
154
+ [model_name.to_s.camelize.constantize.human_name, model_name.to_s.camelize]
155
+ end
156
+ end
157
+ end
158
+
159
+ # To be called after include action modules
160
+ def _add_sti_create_links
161
+ new_action_link = @action_links['new']
162
+ unless new_action_link.nil?
163
+ @action_links.delete('new')
164
+ self.sti_children.each do |child|
165
+ new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone
166
+ new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.human_name)
167
+ new_sti_link.parameters = {model.inheritance_column => child}
168
+ @action_links.add(new_sti_link)
169
+ end
170
+ end
171
+ end
172
+
173
+ # configuration routing.
174
+ # we want to route calls named like an activated action to that action's global or local Config class.
175
+ # ---------------------------
176
+ def method_missing(name, *args)
177
+ @action_configs ||= {}
178
+ titled_name = name.to_s.camelcase
179
+ underscored_name = name.to_s.underscore.to_sym
180
+ klass = "ActiveScaffold::Config::#{titled_name}".constantize rescue nil
181
+ if klass
182
+ if @actions.include? underscored_name
183
+ return @action_configs[underscored_name] ||= klass.new(self)
184
+ else
185
+ raise "#{titled_name} is not enabled. Please enable it or remove any references in your configuration (e.g. config.#{underscored_name}.columns = [...])."
186
+ end
187
+ end
188
+ super
189
+ end
190
+
191
+ def self.method_missing(name, *args)
192
+ klass = "ActiveScaffold::Config::#{name.to_s.titleize}".constantize rescue nil
193
+ if @@actions.include? name.to_s.underscore and klass
194
+ return eval("ActiveScaffold::Config::#{name.to_s.titleize}")
195
+ end
196
+ super
197
+ end
198
+ # some utility methods
199
+ # --------------------
200
+
201
+ def model_id
202
+ @model_id
203
+ end
204
+
205
+ def model
206
+ @model ||= @model_id.to_s.camelize.constantize
207
+ end
208
+
209
+ # warning - this won't work as a per-request dynamic attribute in rails 2.0. You'll need to interact with Controller#generic_view_paths
210
+ def inherited_view_paths
211
+ @inherited_view_paths||=[]
212
+ end
213
+
214
+ # must be a class method so the layout doesn't depend on a controller that uses active_scaffold
215
+ # note that this is unaffected by per-controller frontend configuration.
216
+ def self.asset_path(filename, frontend = self.frontend)
217
+ "active_scaffold/#{frontend}/#{filename}"
218
+ end
219
+
220
+ # must be a class method so the layout doesn't depend on a controller that uses active_scaffold
221
+ # note that this is unaffected by per-controller frontend configuration.
222
+ def self.javascripts(frontend = self.frontend)
223
+ javascript_dir = File.join(Rails.public_path, "javascripts", asset_path('', frontend))
224
+ Dir.entries(javascript_dir).reject { |e| !e.match(/\.js$/) or (!self.dhtml_history? and e.match('dhtml_history')) }
225
+ end
226
+
227
+ end
228
+ end
229
+
@@ -0,0 +1,43 @@
1
+ module ActiveScaffold::Config
2
+ class Create < ActiveScaffold::Config::Form
3
+ self.crud_type = :create
4
+ def initialize(*args)
5
+ super
6
+ self.persistent = self.class.persistent
7
+ self.edit_after_create = self.class.edit_after_create
8
+ end
9
+
10
+ # global level configuration
11
+ # --------------------------
12
+ # the ActionLink for this action
13
+ def self.link
14
+ @@link
15
+ end
16
+ def self.link=(val)
17
+ @@link = val
18
+ end
19
+ @@link = ActiveScaffold::DataStructures::ActionLink.new('new', :label => :create_new, :type => :collection, :security_method => :create_authorized?, :ignore_method => :create_ignore?)
20
+
21
+ # whether the form stays open after a create or not
22
+ cattr_accessor :persistent
23
+ @@persistent = false
24
+
25
+ # whether update form is opened after a create or not
26
+ cattr_accessor :edit_after_create
27
+ @@edit_after_create = false
28
+
29
+ # instance-level configuration
30
+ # ----------------------------
31
+ # the label= method already exists in the Form base class
32
+ def label(model = nil)
33
+ model ||= @core.label(:count => 1)
34
+ @label ? as_(@label) : as_(:create_model, :model => model)
35
+ end
36
+
37
+ # whether the form stays open after a create or not
38
+ attr_accessor :persistent
39
+
40
+ # whether the form stays open after a create or not
41
+ attr_accessor :edit_after_create
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ module ActiveScaffold::Config
2
+ class Delete < Base
3
+ self.crud_type = :delete
4
+
5
+ def initialize(core_config)
6
+ @core = core_config
7
+
8
+ # start with the ActionLink defined globally
9
+ @link = self.class.link.clone
10
+ end
11
+
12
+ # global level configuration
13
+ # --------------------------
14
+
15
+ # the ActionLink for this action
16
+ cattr_accessor :link
17
+ @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :crud_type => :delete, :position => false, :security_method => :delete_authorized?)
18
+
19
+ # instance-level configuration
20
+ # ----------------------------
21
+
22
+ # the ActionLink for this action
23
+ attr_accessor :link
24
+ end
25
+ end
@@ -0,0 +1,74 @@
1
+ module ActiveScaffold::Config
2
+ class FieldSearch < Base
3
+ self.crud_type = :read
4
+
5
+ def initialize(core_config)
6
+ @core = core_config
7
+
8
+ @text_search = self.class.text_search
9
+
10
+ # start with the ActionLink defined globally
11
+ @link = self.class.link.clone
12
+ end
13
+
14
+
15
+ # global level configuration
16
+ # --------------------------
17
+ # the ActionLink for this action
18
+ cattr_reader :link
19
+ @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?, :ignore_method => :search_ignore?)
20
+
21
+ # A flag for how the search should do full-text searching in the database:
22
+ # * :full: LIKE %?%
23
+ # * :start: LIKE ?%
24
+ # * :end: LIKE %?
25
+ # * false: LIKE ?
26
+ # Default is :full
27
+ cattr_accessor :text_search
28
+ @@text_search = :full
29
+
30
+ # instance-level configuration
31
+ # ----------------------------
32
+
33
+ # provides access to the list of columns specifically meant for the Search to use
34
+ def columns
35
+ # we want to delay initializing to the @core.columns set for as long as possible. Too soon and .search_sql will not be available to .searchable?
36
+ unless @columns
37
+ self.columns = @core.columns._inheritable
38
+ self.columns.exclude @core.columns.active_record_class.locking_column.to_sym
39
+ end
40
+ @columns
41
+ end
42
+
43
+ public :columns=
44
+
45
+ # A flag for how the search should do full-text searching in the database:
46
+ # * :full: LIKE %?%
47
+ # * :start: LIKE ?%
48
+ # * :end: LIKE %?
49
+ # * false: LIKE ?
50
+ # Default is :full
51
+ attr_accessor :text_search
52
+
53
+ # the ActionLink for this action
54
+ attr_accessor :link
55
+
56
+ # rarely searched columns may be placed in a hidden subgroup
57
+ def optional_columns=(optionals)
58
+ @optional_columns= Array(optionals)
59
+ end
60
+
61
+ def optional_columns
62
+ @optional_columns ||= []
63
+ end
64
+
65
+ # default search params
66
+ # default_params = {:title => {"from"=>"test", "to"=>"", "opt"=>"%?%"}}
67
+ attr_accessor :default_params
68
+
69
+ # human conditions
70
+ # instead of just filtered you may show the user a humanized search condition statment
71
+ attr_accessor :human_conditions
72
+
73
+ end
74
+ end