active_scaffold_san 3.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +27 -0
- data/.document +5 -0
- data/CHANGELOG +179 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +20 -0
- data/MIT-LICENSE +20 -0
- data/README +69 -0
- data/Rakefile +53 -0
- data/active_scaffold_vho.gemspec +388 -0
- data/frontends/default/images/add.gif +0 -0
- data/frontends/default/images/arrow_down.gif +0 -0
- data/frontends/default/images/arrow_up.gif +0 -0
- data/frontends/default/images/close.gif +0 -0
- data/frontends/default/images/config.png +0 -0
- data/frontends/default/images/cross.png +0 -0
- data/frontends/default/images/gears.png +0 -0
- data/frontends/default/images/indicator-small.gif +0 -0
- data/frontends/default/images/indicator.gif +0 -0
- data/frontends/default/images/magnifier.png +0 -0
- data/frontends/default/javascripts/jquery/active_scaffold.js +1004 -0
- data/frontends/default/javascripts/jquery/jquery.editinplace.js +743 -0
- data/frontends/default/javascripts/prototype/active_scaffold.js +1003 -0
- data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
- data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
- data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
- data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
- data/frontends/default/stylesheets/stylesheet.css +973 -0
- data/frontends/default/views/_action_group.html.erb +20 -0
- data/frontends/default/views/_add_existing_form.html.erb +30 -0
- data/frontends/default/views/_base_form.html.erb +51 -0
- data/frontends/default/views/_create_form.html.erb +8 -0
- data/frontends/default/views/_create_form_on_list.html.erb +6 -0
- data/frontends/default/views/_field_search.html.erb +32 -0
- data/frontends/default/views/_form.html.erb +24 -0
- data/frontends/default/views/_form_association.html.erb +19 -0
- data/frontends/default/views/_form_association_footer.html.erb +40 -0
- data/frontends/default/views/_form_attribute.html.erb +15 -0
- data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
- data/frontends/default/views/_form_messages.html.erb +5 -0
- data/frontends/default/views/_horizontal_subform.html.erb +29 -0
- data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
- data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
- data/frontends/default/views/_human_conditions.html.erb +1 -0
- data/frontends/default/views/_list.html.erb +18 -0
- data/frontends/default/views/_list_actions.html.erb +15 -0
- data/frontends/default/views/_list_calculations.html.erb +16 -0
- data/frontends/default/views/_list_column_headings.html.erb +12 -0
- data/frontends/default/views/_list_header.html.erb +10 -0
- data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
- data/frontends/default/views/_list_messages.html.erb +32 -0
- data/frontends/default/views/_list_pagination.html.erb +11 -0
- data/frontends/default/views/_list_pagination_links.html.erb +9 -0
- data/frontends/default/views/_list_record.html.erb +14 -0
- data/frontends/default/views/_list_record_columns.html.erb +8 -0
- data/frontends/default/views/_list_with_header.html.erb +32 -0
- data/frontends/default/views/_messages.html.erb +10 -0
- data/frontends/default/views/_render_field.js.rjs +10 -0
- data/frontends/default/views/_row.html.erb +12 -0
- data/frontends/default/views/_search.html.erb +34 -0
- data/frontends/default/views/_search_attribute.html.erb +10 -0
- data/frontends/default/views/_show.html.erb +8 -0
- data/frontends/default/views/_show_columns.html.erb +15 -0
- data/frontends/default/views/_update_actions.html.erb +9 -0
- data/frontends/default/views/_update_form.html.erb +6 -0
- data/frontends/default/views/_vertical_subform.html.erb +12 -0
- data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
- data/frontends/default/views/action_confirmation.html.erb +13 -0
- data/frontends/default/views/add_existing.js.rjs +17 -0
- data/frontends/default/views/add_existing_form.html.erb +5 -0
- data/frontends/default/views/create.html.erb +5 -0
- data/frontends/default/views/delete.html.erb +13 -0
- data/frontends/default/views/destroy.js.rjs +23 -0
- data/frontends/default/views/edit_associated.js.rjs +11 -0
- data/frontends/default/views/field_search.html.erb +5 -0
- data/frontends/default/views/form_messages.js.rjs +1 -0
- data/frontends/default/views/list.html.erb +1 -0
- data/frontends/default/views/list.js.rjs +1 -0
- data/frontends/default/views/on_action_update.js.rjs +8 -0
- data/frontends/default/views/on_create.js.rjs +41 -0
- data/frontends/default/views/on_mark_all.js.rjs +4 -0
- data/frontends/default/views/on_update.js.rjs +28 -0
- data/frontends/default/views/search.html.erb +5 -0
- data/frontends/default/views/show.html.erb +5 -0
- data/frontends/default/views/update.html.erb +8 -0
- data/frontends/default/views/update_column.js.rjs +13 -0
- data/frontends/default/views/update_row.js.rjs +1 -0
- data/init.rb +8 -0
- data/lib/active_scaffold.rb +360 -0
- data/lib/active_scaffold/actions/common_search.rb +22 -0
- data/lib/active_scaffold/actions/core.rb +180 -0
- data/lib/active_scaffold/actions/create.rb +149 -0
- data/lib/active_scaffold/actions/delete.rb +75 -0
- data/lib/active_scaffold/actions/field_search.rb +82 -0
- data/lib/active_scaffold/actions/list.rb +184 -0
- data/lib/active_scaffold/actions/mark.rb +63 -0
- data/lib/active_scaffold/actions/nested.rb +250 -0
- data/lib/active_scaffold/actions/search.rb +47 -0
- data/lib/active_scaffold/actions/show.rb +61 -0
- data/lib/active_scaffold/actions/subform.rb +27 -0
- data/lib/active_scaffold/actions/update.rb +151 -0
- data/lib/active_scaffold/active_record_permissions.rb +134 -0
- data/lib/active_scaffold/attribute_params.rb +211 -0
- data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +39 -0
- data/lib/active_scaffold/bridges/bridge.rb +59 -0
- data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
- data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +83 -0
- data/lib/active_scaffold/bridges/cancan/bridge.rb +12 -0
- data/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb +107 -0
- data/lib/active_scaffold/bridges/carrierwave/bridge.rb +9 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +33 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +12 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +45 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
- data/lib/active_scaffold/bridges/date_picker/bridge.rb +24 -0
- data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
- data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
- data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
- data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
- data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
- data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
- data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
- data/lib/active_scaffold/bridges/paperclip/bridge.rb +12 -0
- data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
- data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +209 -0
- data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +61 -0
- data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
- data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
- data/lib/active_scaffold/config/base.rb +62 -0
- data/lib/active_scaffold/config/core.rb +220 -0
- data/lib/active_scaffold/config/create.rb +51 -0
- data/lib/active_scaffold/config/delete.rb +34 -0
- data/lib/active_scaffold/config/field_search.rb +75 -0
- data/lib/active_scaffold/config/form.rb +47 -0
- data/lib/active_scaffold/config/list.rb +174 -0
- data/lib/active_scaffold/config/mark.rb +22 -0
- data/lib/active_scaffold/config/nested.rb +44 -0
- data/lib/active_scaffold/config/search.rb +69 -0
- data/lib/active_scaffold/config/show.rb +35 -0
- data/lib/active_scaffold/config/subform.rb +35 -0
- data/lib/active_scaffold/config/update.rb +46 -0
- data/lib/active_scaffold/configurable.rb +29 -0
- data/lib/active_scaffold/constraints.rb +184 -0
- data/lib/active_scaffold/data_structures/action_columns.rb +137 -0
- data/lib/active_scaffold/data_structures/action_link.rb +175 -0
- data/lib/active_scaffold/data_structures/action_links.rb +185 -0
- data/lib/active_scaffold/data_structures/actions.rb +45 -0
- data/lib/active_scaffold/data_structures/column.rb +355 -0
- data/lib/active_scaffold/data_structures/columns.rb +75 -0
- data/lib/active_scaffold/data_structures/error_message.rb +24 -0
- data/lib/active_scaffold/data_structures/nested_info.rb +123 -0
- data/lib/active_scaffold/data_structures/set.rb +62 -0
- data/lib/active_scaffold/data_structures/sorting.rb +168 -0
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +20 -0
- data/lib/active_scaffold/extensions/action_view_rendering.rb +123 -0
- data/lib/active_scaffold/extensions/action_view_resolver.rb +7 -0
- data/lib/active_scaffold/extensions/active_association_reflection.rb +13 -0
- data/lib/active_scaffold/extensions/active_record_offset.rb +12 -0
- data/lib/active_scaffold/extensions/array.rb +7 -0
- data/lib/active_scaffold/extensions/localize.rb +10 -0
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +12 -0
- data/lib/active_scaffold/extensions/nil_id_in_url_params.rb +7 -0
- data/lib/active_scaffold/extensions/paginator_extensions.rb +26 -0
- data/lib/active_scaffold/extensions/reverse_associations.rb +62 -0
- data/lib/active_scaffold/extensions/routing_mapper.rb +34 -0
- data/lib/active_scaffold/extensions/to_label.rb +8 -0
- data/lib/active_scaffold/extensions/unsaved_associated.rb +61 -0
- data/lib/active_scaffold/extensions/unsaved_record.rb +20 -0
- data/lib/active_scaffold/extensions/usa_state.rb +46 -0
- data/lib/active_scaffold/finder.rb +343 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/controller_helpers.rb +87 -0
- data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
- data/lib/active_scaffold/helpers/form_column_helpers.rb +350 -0
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
- data/lib/active_scaffold/helpers/id_helpers.rb +127 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +361 -0
- data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
- data/lib/active_scaffold/helpers/search_column_helpers.rb +249 -0
- data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +360 -0
- data/lib/active_scaffold/locale/de.rb +120 -0
- data/lib/active_scaffold/locale/en.rb +119 -0
- data/lib/active_scaffold/locale/es.yml +115 -0
- data/lib/active_scaffold/locale/fr.rb +122 -0
- data/lib/active_scaffold/locale/hu.yml +63 -0
- data/lib/active_scaffold/locale/ja.yml +64 -0
- data/lib/active_scaffold/locale/ru.yml +119 -0
- data/lib/active_scaffold/marked_model.rb +38 -0
- data/lib/active_scaffold/paginator.rb +136 -0
- data/lib/active_scaffold/responds_to_parent.rb +70 -0
- data/lib/active_scaffold/version.rb +9 -0
- data/lib/active_scaffold_assets.rb +45 -0
- data/lib/active_scaffold_env.rb +14 -0
- data/lib/active_scaffold_vho.rb +2 -0
- data/lib/generators/active_scaffold/USAGE +29 -0
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
- data/lib/generators/active_scaffold_controller/USAGE +19 -0
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +29 -0
- data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
- data/lib/generators/active_scaffold_controller/templates/helper.rb +2 -0
- data/lib/generators/active_scaffold_setup/USAGE +10 -0
- data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +61 -0
- data/public/blank.html +33 -0
- data/shoulda_macros/macros.rb +136 -0
- data/test/bridges/bridge_test.rb +47 -0
- data/test/config/base_test.rb +15 -0
- data/test/config/create_test.rb +55 -0
- data/test/config/list_test.rb +74 -0
- data/test/config/show_test.rb +43 -0
- data/test/config/update_test.rb +17 -0
- data/test/const_mocker.rb +36 -0
- data/test/data_structures/action_columns_test.rb +113 -0
- data/test/data_structures/action_link_test.rb +78 -0
- data/test/data_structures/action_links_test.rb +78 -0
- data/test/data_structures/actions_test.rb +25 -0
- data/test/data_structures/association_column_test.rb +42 -0
- data/test/data_structures/column_test.rb +185 -0
- data/test/data_structures/columns_test.rb +69 -0
- data/test/data_structures/error_message_test.rb +28 -0
- data/test/data_structures/set_test.rb +86 -0
- data/test/data_structures/sorting_test.rb +126 -0
- data/test/data_structures/standard_column_test.rb +24 -0
- data/test/data_structures/virtual_column_test.rb +23 -0
- data/test/extensions/active_record_test.rb +45 -0
- data/test/extensions/array_test.rb +12 -0
- data/test/helpers/form_column_helpers_test.rb +31 -0
- data/test/helpers/list_column_helpers_test.rb +31 -0
- data/test/helpers/pagination_helpers_test.rb +55 -0
- data/test/misc/active_record_permissions_test.rb +154 -0
- data/test/misc/attribute_params_test.rb +110 -0
- data/test/misc/configurable_test.rb +96 -0
- data/test/misc/constraints_test.rb +193 -0
- data/test/misc/finder_test.rb +93 -0
- data/test/misc/lang_test.rb +12 -0
- data/test/mock_app/.gitignore +2 -0
- data/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/test/mock_app/app/helpers/application_helper.rb +3 -0
- data/test/mock_app/config/boot.rb +110 -0
- data/test/mock_app/config/database.yml +16 -0
- data/test/mock_app/config/environment.rb +43 -0
- data/test/mock_app/config/environments/development.rb +17 -0
- data/test/mock_app/config/environments/production.rb +28 -0
- data/test/mock_app/config/environments/test.rb +28 -0
- data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/mock_app/config/initializers/inflections.rb +10 -0
- data/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/test/mock_app/config/initializers/session_store.rb +15 -0
- data/test/mock_app/config/locales/en.yml +5 -0
- data/test/mock_app/config/routes.rb +43 -0
- data/test/mock_app/db/test.sqlite3 +1 -0
- data/test/mock_app/public/blank.html +33 -0
- data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
- data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
- data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +842 -0
- data/test/model_stub.rb +55 -0
- data/test/run_all.rb +8 -0
- data/test/test_helper.rb +39 -0
- data/uninstall.rb +13 -0
- metadata +497 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
form_selector = "#{element_form_id(:action => :update)}"
|
2
|
+
|
3
|
+
page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');"
|
4
|
+
page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');"
|
5
|
+
if controller.send :successful?
|
6
|
+
if render_parent? && controller.respond_to?(:render_component_into_view)
|
7
|
+
parent_rendered = controller.send(:render_component_into_view, render_parent_options)
|
8
|
+
if nested_singular_association?
|
9
|
+
page << "action_link.close('#{escape_javascript(parent_rendered)}');"
|
10
|
+
else
|
11
|
+
if render_parent_action == :row
|
12
|
+
page << "action_link.close('#{escape_javascript(parent_rendered)}');"
|
13
|
+
elsif render_parent_action == :index
|
14
|
+
page << parent_rendered
|
15
|
+
end
|
16
|
+
end
|
17
|
+
#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
|
18
|
+
elsif update_refresh_list?
|
19
|
+
page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false)
|
20
|
+
else
|
21
|
+
updated_row = render :partial => 'list_record', :locals => {:record => @record}
|
22
|
+
page << "action_link.close('#{escape_javascript(updated_row)}');"
|
23
|
+
page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
|
24
|
+
end
|
25
|
+
else
|
26
|
+
page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'update_form', :locals => {:xhr => true})
|
27
|
+
page.call 'ActiveScaffold.scroll_to', form_selector
|
28
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<div class="active-scaffold">
|
2
|
+
<div class="update-view <%= "#{params[:controller]}-view" %> view">
|
3
|
+
<% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.member.empty? -%>
|
4
|
+
<%= render :partial => 'update_actions', :locals => {:record => @record, :url_options => params_for(:action => :list, :id => @record.id)} %>
|
5
|
+
<% end -%>
|
6
|
+
<%= render :partial => 'update_form' -%>
|
7
|
+
</div>
|
8
|
+
</div>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column])
|
2
|
+
unless controller.send :successful?
|
3
|
+
page.call 'alert', @record.errors.full_messages(active_scaffold_config).join("\n")
|
4
|
+
@record.reload
|
5
|
+
end
|
6
|
+
column = active_scaffold_config.columns[params[:column]]
|
7
|
+
if column.inplace_edit
|
8
|
+
page.call 'ActiveScaffold.replace_html', column_span_id, format_inplace_edit_column(@record, column)
|
9
|
+
else
|
10
|
+
formatted_value = get_column_value(@record, column)
|
11
|
+
page.call 'ActiveScaffold.replace_html', column_span_id, formatted_value
|
12
|
+
end
|
13
|
+
page.call 'ActiveScaffold.replace_html', active_scaffold_calculations_id(column), render_column_calculation(column) if column.calculation?
|
@@ -0,0 +1 @@
|
|
1
|
+
page.call 'ActiveScaffold.update_row', element_row_id(:action => 'list', :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record})
|
data/init.rb
ADDED
@@ -0,0 +1,360 @@
|
|
1
|
+
unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 0
|
2
|
+
raise "This version of ActiveScaffold requires Rails 3.0 or higher. Please use an earlier version."
|
3
|
+
end
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'render_component'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
begin
|
10
|
+
require 'verification'
|
11
|
+
rescue LoadError
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'active_scaffold_assets'
|
15
|
+
require 'active_scaffold/active_record_permissions'
|
16
|
+
require 'active_scaffold/paginator'
|
17
|
+
require 'active_scaffold/responds_to_parent'
|
18
|
+
|
19
|
+
require 'active_scaffold/version'
|
20
|
+
|
21
|
+
module ActiveScaffold
|
22
|
+
autoload :AttributeParams, 'active_scaffold/attribute_params'
|
23
|
+
autoload :Configurable, 'active_scaffold/configurable'
|
24
|
+
autoload :Constraints, 'active_scaffold/constraints'
|
25
|
+
autoload :Finder, 'active_scaffold/finder'
|
26
|
+
autoload :MarkedModel, 'active_scaffold/marked_model'
|
27
|
+
|
28
|
+
def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__))
|
29
|
+
Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file|
|
30
|
+
basename = File.basename(file, ".rb")
|
31
|
+
mod.module_eval {
|
32
|
+
autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
module Actions
|
38
|
+
ActiveScaffold.autoload_subdir('actions', self)
|
39
|
+
end
|
40
|
+
|
41
|
+
module Bridges
|
42
|
+
autoload :Bridge, 'active_scaffold/bridges/bridge'
|
43
|
+
end
|
44
|
+
|
45
|
+
module Config
|
46
|
+
ActiveScaffold.autoload_subdir('config', self)
|
47
|
+
end
|
48
|
+
|
49
|
+
module DataStructures
|
50
|
+
ActiveScaffold.autoload_subdir('data_structures', self)
|
51
|
+
end
|
52
|
+
|
53
|
+
module Helpers
|
54
|
+
ActiveScaffold.autoload_subdir('helpers', self)
|
55
|
+
end
|
56
|
+
|
57
|
+
class ControllerNotFound < RuntimeError; end
|
58
|
+
class DependencyFailure < RuntimeError; end
|
59
|
+
class MalformedConstraint < RuntimeError; end
|
60
|
+
class RecordNotAllowed < SecurityError; end
|
61
|
+
class ActionNotAllowed < SecurityError; end
|
62
|
+
class ReverseAssociationRequired < RuntimeError; end
|
63
|
+
|
64
|
+
def self.included(base)
|
65
|
+
base.extend(ClassMethods)
|
66
|
+
base.module_eval do
|
67
|
+
# TODO: these should be in actions/core
|
68
|
+
before_filter :handle_user_settings
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.set_defaults(&block)
|
73
|
+
ActiveScaffold::Config::Core.configure &block
|
74
|
+
end
|
75
|
+
|
76
|
+
def active_scaffold_config
|
77
|
+
self.class.active_scaffold_config
|
78
|
+
end
|
79
|
+
|
80
|
+
def active_scaffold_config_for(klass)
|
81
|
+
self.class.active_scaffold_config_for(klass)
|
82
|
+
end
|
83
|
+
|
84
|
+
def active_scaffold_session_storage(id = (params[:eid] || params[:controller]))
|
85
|
+
session_index = "as:#{id}"
|
86
|
+
session[session_index] ||= {}
|
87
|
+
session[session_index]
|
88
|
+
end
|
89
|
+
|
90
|
+
# at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
|
91
|
+
def handle_user_settings
|
92
|
+
if self.class.uses_active_scaffold?
|
93
|
+
active_scaffold_config.actions.each do |action_name|
|
94
|
+
conf_instance = active_scaffold_config.send(action_name) rescue next
|
95
|
+
next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it
|
96
|
+
active_scaffold_session_storage[action_name] ||= {}
|
97
|
+
conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage[action_name], params)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.js_framework=(framework)
|
103
|
+
@@js_framework = framework
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.js_framework
|
107
|
+
@@js_framework ||= :prototype
|
108
|
+
end
|
109
|
+
|
110
|
+
# exclude bridges you do not need
|
111
|
+
# name of bridge subdir should be used to exclude it
|
112
|
+
# eg
|
113
|
+
# ActiveScaffold.exclude_bridges = [:cancan, :ancestry]
|
114
|
+
# if you are using Activescaffold as a gem add to initializer
|
115
|
+
# if you are using Activescaffold as a plugin add to active_scaffold_env.rb
|
116
|
+
def self.exclude_bridges=(bridges)
|
117
|
+
@@exclude_bridges = bridges
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.exclude_bridges
|
121
|
+
@@exclude_bridges ||= []
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.root
|
125
|
+
File.dirname(__FILE__) + "/.."
|
126
|
+
end
|
127
|
+
|
128
|
+
module ClassMethods
|
129
|
+
def active_scaffold(model_id = nil, &block)
|
130
|
+
# initialize bridges here
|
131
|
+
ActiveScaffold::Bridges::Bridge.run_all
|
132
|
+
|
133
|
+
# converts Foo::BarController to 'bar' and FooBarsController to 'foo_bar' and AddressController to 'address'
|
134
|
+
model_id = self.to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore unless model_id
|
135
|
+
|
136
|
+
# run the configuration
|
137
|
+
@active_scaffold_config = ActiveScaffold::Config::Core.new(model_id)
|
138
|
+
@active_scaffold_config_block = block
|
139
|
+
self.links_for_associations
|
140
|
+
|
141
|
+
@active_scaffold_overrides = []
|
142
|
+
ActionController::Base.view_paths.each do |dir|
|
143
|
+
active_scaffold_overrides_dir = File.join(dir.to_s,"active_scaffold_overrides")
|
144
|
+
@active_scaffold_overrides << active_scaffold_overrides_dir if File.exists?(active_scaffold_overrides_dir)
|
145
|
+
end
|
146
|
+
@active_scaffold_overrides.uniq! # Fix rails duplicating some view_paths
|
147
|
+
@active_scaffold_frontends = []
|
148
|
+
if active_scaffold_config.frontend.to_sym != :default
|
149
|
+
active_scaffold_custom_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', active_scaffold_config.frontend.to_s , 'views')
|
150
|
+
@active_scaffold_frontends << active_scaffold_custom_frontend_path
|
151
|
+
end
|
152
|
+
active_scaffold_default_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', 'default' , 'views')
|
153
|
+
@active_scaffold_frontends << active_scaffold_default_frontend_path
|
154
|
+
@active_scaffold_custom_paths = []
|
155
|
+
|
156
|
+
self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock}
|
157
|
+
self.active_scaffold_config.sti_children = nil # reset sti_children if set in parent block
|
158
|
+
self.active_scaffold_config.configure &block if block_given?
|
159
|
+
self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil?
|
160
|
+
self.active_scaffold_config._load_action_columns
|
161
|
+
|
162
|
+
# defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead
|
163
|
+
klass = self.active_scaffold_config.model
|
164
|
+
klass.define_attribute_methods unless klass.attribute_methods_generated?
|
165
|
+
# include the rest of the code into the controller: the action core and the included actions
|
166
|
+
module_eval do
|
167
|
+
include ActiveScaffold::Finder
|
168
|
+
include ActiveScaffold::Constraints
|
169
|
+
include ActiveScaffold::AttributeParams
|
170
|
+
include ActiveScaffold::Actions::Core
|
171
|
+
active_scaffold_config.actions.each do |mod|
|
172
|
+
name = mod.to_s.camelize
|
173
|
+
include "ActiveScaffold::Actions::#{name}".constantize
|
174
|
+
|
175
|
+
# sneak the action links from the actions into the main set
|
176
|
+
if link = active_scaffold_config.send(mod).link rescue nil
|
177
|
+
if link.is_a? Array
|
178
|
+
link.each {|current| active_scaffold_config.action_links.add_to_group(current, active_scaffold_config.send(mod).action_group)}
|
179
|
+
elsif link.is_a? ActiveScaffold::DataStructures::ActionLink
|
180
|
+
active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
active_scaffold_paths.each do |path|
|
186
|
+
self.append_view_path(ActionView::ActiveScaffoldResolver.new(path))
|
187
|
+
end
|
188
|
+
self._add_sti_create_links if self.active_scaffold_config.add_sti_create_links?
|
189
|
+
end
|
190
|
+
|
191
|
+
# To be called after include action modules
|
192
|
+
def _add_sti_create_links
|
193
|
+
new_action_link = active_scaffold_config.action_links.collection['new']
|
194
|
+
unless new_action_link.nil? || active_scaffold_config.sti_children.empty?
|
195
|
+
active_scaffold_config.action_links.collection.delete('new')
|
196
|
+
active_scaffold_config.sti_children.each do |child|
|
197
|
+
new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone
|
198
|
+
new_sti_link.label = child.to_s.camelize.constantize.model_name.human
|
199
|
+
new_sti_link.parameters = {:parent_sti => controller_path}
|
200
|
+
new_sti_link.controller = Proc.new { active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path }
|
201
|
+
active_scaffold_config.action_links.collection.create.add(new_sti_link)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it?
|
207
|
+
def links_for_associations
|
208
|
+
return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested
|
209
|
+
active_scaffold_config.columns.each do |column|
|
210
|
+
next unless column.link.nil? and column.autolink?
|
211
|
+
#lazy load of action_link, cause it was really slowing down app in dev mode
|
212
|
+
#and might lead to trouble cause of cyclic constantization of controllers
|
213
|
+
#and might be unnecessary cause it is done before columns are configured
|
214
|
+
column.set_link(Proc.new {|col| link_for_association(col)})
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def link_for_association(column, options = {})
|
219
|
+
begin
|
220
|
+
controller = if column.polymorphic_association?
|
221
|
+
:polymorph
|
222
|
+
elsif options.include?(:controller)
|
223
|
+
"#{options[:controller].to_s.camelize}Controller".constantize
|
224
|
+
else
|
225
|
+
active_scaffold_controller_for(column.association.klass)
|
226
|
+
end
|
227
|
+
rescue ActiveScaffold::ControllerNotFound
|
228
|
+
controller = nil
|
229
|
+
end
|
230
|
+
|
231
|
+
unless controller.nil?
|
232
|
+
options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column
|
233
|
+
options[:parameters] ||= {}
|
234
|
+
options[:parameters].reverse_merge! :parent_scaffold => controller_path, :association => column.association.name
|
235
|
+
if column.plural_association?
|
236
|
+
# note: we can't create nested scaffolds on :through associations because there's no reverse association.
|
237
|
+
|
238
|
+
ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association?
|
239
|
+
else
|
240
|
+
actions = [:create, :update, :show]
|
241
|
+
actions = controller.active_scaffold_config.actions unless controller == :polymorph
|
242
|
+
column.actions_for_association_links.delete :new unless actions.include? :create
|
243
|
+
column.actions_for_association_links.delete :edit unless actions.include? :update
|
244
|
+
column.actions_for_association_links.delete :show unless actions.include? :show
|
245
|
+
ActiveScaffold::DataStructures::ActionLink.new(:none, options.merge({:crud_type => nil, :html_options => {:class => column.name}}))
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def link_for_association_as_scope(scope, options = {})
|
251
|
+
options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path
|
252
|
+
options[:parameters] ||= {}
|
253
|
+
options[:parameters].reverse_merge! :parent_scaffold => controller_path, :named_scope => scope
|
254
|
+
ActiveScaffold::DataStructures::ActionLink.new('index', options)
|
255
|
+
end
|
256
|
+
|
257
|
+
def add_active_scaffold_path(path)
|
258
|
+
@active_scaffold_paths = nil # Force active_scaffold_paths to rebuild
|
259
|
+
@active_scaffold_custom_paths << path
|
260
|
+
end
|
261
|
+
|
262
|
+
def add_active_scaffold_override_path(path)
|
263
|
+
@active_scaffold_paths = nil # Force active_scaffold_paths to rebuild
|
264
|
+
@active_scaffold_overrides.unshift path
|
265
|
+
end
|
266
|
+
|
267
|
+
def active_scaffold_paths
|
268
|
+
return @active_scaffold_paths unless @active_scaffold_paths.nil?
|
269
|
+
|
270
|
+
#@active_scaffold_paths = ActionView::PathSet.new
|
271
|
+
@active_scaffold_paths = []
|
272
|
+
@active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil?
|
273
|
+
@active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil?
|
274
|
+
@active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil?
|
275
|
+
@active_scaffold_paths
|
276
|
+
end
|
277
|
+
|
278
|
+
def active_scaffold_config
|
279
|
+
if @active_scaffold_config.nil?
|
280
|
+
self.superclass.active_scaffold_config if self.superclass.respond_to? :active_scaffold_config
|
281
|
+
else
|
282
|
+
@active_scaffold_config
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
def active_scaffold_config_block
|
287
|
+
@active_scaffold_config_block
|
288
|
+
end
|
289
|
+
|
290
|
+
def active_scaffold_superclasses_blocks
|
291
|
+
blocks = []
|
292
|
+
klass = self.superclass
|
293
|
+
while klass.respond_to? :active_scaffold_superclasses_blocks
|
294
|
+
blocks << klass.active_scaffold_config_block
|
295
|
+
klass = klass.superclass
|
296
|
+
end
|
297
|
+
blocks.compact.reverse
|
298
|
+
end
|
299
|
+
|
300
|
+
def active_scaffold_config_for(klass)
|
301
|
+
begin
|
302
|
+
controller = active_scaffold_controller_for(klass)
|
303
|
+
rescue ActiveScaffold::ControllerNotFound
|
304
|
+
config = ActiveScaffold::Config::Core.new(klass)
|
305
|
+
config._load_action_columns
|
306
|
+
config
|
307
|
+
else
|
308
|
+
controller.active_scaffold_config
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
# Tries to find a controller for the given ActiveRecord model.
|
313
|
+
# Searches in the namespace of the current controller for singular and plural versions of the conventional "#{model}Controller" syntax.
|
314
|
+
# You may override this method to customize the search routine.
|
315
|
+
def active_scaffold_controller_for(klass)
|
316
|
+
controller_namespace = self.to_s.split('::')[0...-1].join('::') + '::'
|
317
|
+
error_message = []
|
318
|
+
[controller_namespace, ''].each do |namespace|
|
319
|
+
["#{klass.to_s.underscore.pluralize}", "#{klass.to_s.underscore.pluralize.singularize}"].each do |controller_name|
|
320
|
+
begin
|
321
|
+
controller = "#{namespace}#{controller_name.camelize}Controller".constantize
|
322
|
+
rescue NameError => error
|
323
|
+
# Only rescue NameError associated with the controller constant not existing - not other compile errors
|
324
|
+
if error.message["uninitialized constant #{controller}"]
|
325
|
+
error_message << "#{namespace}#{controller_name.camelize}Controller"
|
326
|
+
next
|
327
|
+
else
|
328
|
+
raise
|
329
|
+
end
|
330
|
+
end
|
331
|
+
raise ActiveScaffold::ControllerNotFound, "#{controller} missing ActiveScaffold", caller unless controller.uses_active_scaffold?
|
332
|
+
raise ActiveScaffold::ControllerNotFound, "ActiveScaffold on #{controller} is not for #{klass} model.", caller unless controller.active_scaffold_config.model == klass
|
333
|
+
return controller
|
334
|
+
end
|
335
|
+
end
|
336
|
+
raise ActiveScaffold::ControllerNotFound, "Could not find " + error_message.join(" or "), caller
|
337
|
+
end
|
338
|
+
|
339
|
+
def uses_active_scaffold?
|
340
|
+
!active_scaffold_config.nil?
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
require 'active_scaffold_env'
|
346
|
+
|
347
|
+
##
|
348
|
+
## Run the install assets script, too, just to make sure
|
349
|
+
## But at least rescue the action in production
|
350
|
+
##
|
351
|
+
|
352
|
+
Rails::Application.initializer("active_scaffold.install_assets") do
|
353
|
+
begin
|
354
|
+
ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true})
|
355
|
+
rescue Exception => e
|
356
|
+
# Heroku: Read only file system
|
357
|
+
logger.info e.message
|
358
|
+
end
|
359
|
+
end if defined?(ACTIVE_SCAFFOLD_GEM)
|
360
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActiveScaffold::Actions
|
2
|
+
module CommonSearch
|
3
|
+
protected
|
4
|
+
def store_search_params_into_session
|
5
|
+
active_scaffold_session_storage[:search] = params.delete :search if params[:search]
|
6
|
+
end
|
7
|
+
|
8
|
+
def search_params
|
9
|
+
active_scaffold_session_storage[:search]
|
10
|
+
end
|
11
|
+
|
12
|
+
def search_ignore?
|
13
|
+
active_scaffold_config.list.always_show_search
|
14
|
+
end
|
15
|
+
|
16
|
+
# The default security delegates to ActiveRecordPermissions.
|
17
|
+
# You may override the method to customize.
|
18
|
+
def search_authorized?
|
19
|
+
authorized_for?(:crud_type => :read)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|