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,29 @@
|
|
1
|
+
module ActiveScaffold
|
2
|
+
# Exposes a +configure+ method that accepts a block and runs all contents of the block in two contexts, as opposed to the normal one. First, everything gets evaluated as part of the object including Configurable. Then, as a failover, missing methods and variables are evaluated in the original binding of the block.
|
3
|
+
#
|
4
|
+
# Note that this only works with "barewords". Constants, instance variables, and class variables are not currently supported in both contexts.
|
5
|
+
#
|
6
|
+
# May add the given functionality at both the class and instance level. For the former, use +extend+, and for the latter, use +include+.
|
7
|
+
module Configurable
|
8
|
+
def configure(&configuration_block)
|
9
|
+
return unless configuration_block
|
10
|
+
@configuration_binding = configuration_block.binding
|
11
|
+
ret = instance_exec self, &configuration_block
|
12
|
+
@configuration_binding = nil
|
13
|
+
return ret
|
14
|
+
end
|
15
|
+
|
16
|
+
# this method will surely need tweaking. for example, i'm not sure if it should call super before or after it tries to eval with the binding.
|
17
|
+
def method_missing(name, *args)
|
18
|
+
begin
|
19
|
+
super
|
20
|
+
rescue NoMethodError, NameError
|
21
|
+
if @configuration_binding.nil?
|
22
|
+
raise $!
|
23
|
+
else
|
24
|
+
eval("self", @configuration_binding).send(name, *args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
module ActiveScaffold
|
2
|
+
module Constraints
|
3
|
+
|
4
|
+
protected
|
5
|
+
|
6
|
+
# Returns the current constraints
|
7
|
+
def active_scaffold_constraints
|
8
|
+
@active_scaffold_constraints ||= active_scaffold_session_storage[:constraints] || {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_active_scaffold_constraints
|
12
|
+
associations_by_params = {}
|
13
|
+
active_scaffold_config.model.reflect_on_all_associations.each do |association|
|
14
|
+
associations_by_params[association.klass.name.foreign_key] = association.name unless association.options[:polymorphic]
|
15
|
+
end
|
16
|
+
params.each do |key, value|
|
17
|
+
active_scaffold_constraints[associations_by_params[key]] = value if associations_by_params.include? key
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# For each enabled action, adds the constrained columns to the ActionColumns object (if it exists).
|
22
|
+
# This lets the ActionColumns object skip constrained columns.
|
23
|
+
#
|
24
|
+
# If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column.
|
25
|
+
def register_constraints_with_action_columns(association_constrained_fields = [], exclude_actions = [])
|
26
|
+
constrained_fields = active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect{|k| k.to_sym}
|
27
|
+
constrained_fields = constrained_fields | association_constrained_fields
|
28
|
+
if self.class.uses_active_scaffold?
|
29
|
+
# we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't
|
30
|
+
active_scaffold_config.actions.each do |action_name|
|
31
|
+
next if exclude_actions.include?(action_name)
|
32
|
+
action = active_scaffold_config.send(action_name)
|
33
|
+
next unless action.respond_to? :columns
|
34
|
+
action.columns.constraint_columns = constrained_fields
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns search conditions based on the current scaffold constraints.
|
40
|
+
#
|
41
|
+
# Supports constraints based on either a column name (in which case it checks for an association
|
42
|
+
# or just uses the search_sql) or a database field name.
|
43
|
+
#
|
44
|
+
# All of this work is primarily to support nested scaffolds in a manner generally useful for other
|
45
|
+
# embedded scaffolds.
|
46
|
+
def conditions_from_constraints
|
47
|
+
conditions = nil
|
48
|
+
active_scaffold_constraints.each do |k, v|
|
49
|
+
column = active_scaffold_config.columns[k]
|
50
|
+
constraint_condition = if column
|
51
|
+
# Assume this is a multi-level association constraint.
|
52
|
+
# example:
|
53
|
+
# data model: Park -> Den -> Bear
|
54
|
+
# constraint: :den => {:park => 5}
|
55
|
+
if v.is_a? Hash
|
56
|
+
far_association = column.association.klass.reflect_on_association(v.keys.first)
|
57
|
+
field = far_association.klass.primary_key
|
58
|
+
table = far_association.table_name
|
59
|
+
|
60
|
+
active_scaffold_includes.concat([{k => v.keys.first}]) # e.g. {:den => :park}
|
61
|
+
constraint_condition_for("#{table}.#{field}", v.values.first)
|
62
|
+
|
63
|
+
# association column constraint
|
64
|
+
elsif column.association
|
65
|
+
if column.association.macro == :has_and_belongs_to_many
|
66
|
+
active_scaffold_habtm_joins.concat column.includes
|
67
|
+
else
|
68
|
+
active_scaffold_includes.concat column.includes
|
69
|
+
end
|
70
|
+
condition_from_association_constraint(column.association, v)
|
71
|
+
|
72
|
+
# regular column constraints
|
73
|
+
elsif column.searchable?
|
74
|
+
active_scaffold_includes.concat column.includes
|
75
|
+
constraint_condition_for(column.search_sql, v)
|
76
|
+
end
|
77
|
+
# unknown-to-activescaffold-but-real-database-column constraint
|
78
|
+
elsif active_scaffold_config.model.column_names.include? k.to_s
|
79
|
+
constraint_condition_for(k.to_s, v)
|
80
|
+
else
|
81
|
+
raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller
|
82
|
+
end
|
83
|
+
|
84
|
+
conditions = merge_conditions(conditions, constraint_condition)
|
85
|
+
end
|
86
|
+
|
87
|
+
conditions
|
88
|
+
end
|
89
|
+
|
90
|
+
# We do NOT want to use .search_sql. If anything, search_sql will refer
|
91
|
+
# to a human-searchable value on the associated record.
|
92
|
+
def condition_from_association_constraint(association, value)
|
93
|
+
# when the reverse association is a :belongs_to, the id for the associated object only exists as
|
94
|
+
# the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),
|
95
|
+
# we have to use the other model's primary_key.
|
96
|
+
#
|
97
|
+
# please see the relevant tests for concrete examples.
|
98
|
+
field = if [:has_one, :has_many].include?(association.macro)
|
99
|
+
association.klass.primary_key
|
100
|
+
elsif [:has_and_belongs_to_many].include?(association.macro)
|
101
|
+
association.association_foreign_key
|
102
|
+
else
|
103
|
+
association.options[:foreign_key] || association.name.to_s.foreign_key
|
104
|
+
end
|
105
|
+
|
106
|
+
table = case association.macro
|
107
|
+
when :has_and_belongs_to_many
|
108
|
+
association.options[:join_table]
|
109
|
+
|
110
|
+
when :belongs_to
|
111
|
+
active_scaffold_config.model.table_name
|
112
|
+
|
113
|
+
else
|
114
|
+
association.table_name
|
115
|
+
end
|
116
|
+
|
117
|
+
if association.options[:primary_key]
|
118
|
+
value = association.klass.find(value).send(association.options[:primary_key])
|
119
|
+
end
|
120
|
+
|
121
|
+
condition = constraint_condition_for("#{table}.#{field}", value)
|
122
|
+
if association.options[:polymorphic]
|
123
|
+
begin
|
124
|
+
parent_scaffold = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize
|
125
|
+
condition = merge_conditions(
|
126
|
+
condition,
|
127
|
+
constraint_condition_for("#{table}.#{association.name}_type", parent_scaffold.active_scaffold_config.model_id.to_s)
|
128
|
+
)
|
129
|
+
rescue ActiveScaffold::ControllerNotFound
|
130
|
+
nil
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
condition
|
135
|
+
end
|
136
|
+
|
137
|
+
def constraint_error(klass, column_name)
|
138
|
+
"Malformed constraint `#{klass}##{column_name}'. If it's a legitimate column, and you are using a nested scaffold, please specify or double-check the reverse association name."
|
139
|
+
end
|
140
|
+
|
141
|
+
# Applies constraints to the given record.
|
142
|
+
#
|
143
|
+
# Searches through the known columns for association columns. If the given constraint is an association,
|
144
|
+
# it assumes that the constraint value is an id. It then does a association.klass.find with the value
|
145
|
+
# and adds the associated object to the record.
|
146
|
+
#
|
147
|
+
# For some operations ActiveRecord will automatically update the database. That's not always ok.
|
148
|
+
# If it *is* ok (e.g. you're in a transaction), then set :allow_autosave to true.
|
149
|
+
def apply_constraints_to_record(record, options = {})
|
150
|
+
options[:allow_autosave] = false if options[:allow_autosave].nil?
|
151
|
+
|
152
|
+
active_scaffold_constraints.each do |k, v|
|
153
|
+
column = active_scaffold_config.columns[k]
|
154
|
+
if column and column.association
|
155
|
+
if column.plural_association?
|
156
|
+
record.send("#{k}").send(:<<, column.association.klass.find(v))
|
157
|
+
elsif column.association.options[:polymorphic]
|
158
|
+
record.send("#{k}=", params[:parent_model].constantize.find(v))
|
159
|
+
else # regular singular association
|
160
|
+
record.send("#{k}=", column.association.klass.find(v))
|
161
|
+
|
162
|
+
# setting the belongs_to side of a has_one isn't safe. if the has_one was already
|
163
|
+
# specified, rails won't automatically clear out the previous associated record.
|
164
|
+
#
|
165
|
+
# note that we can't take the extra step to correct this unless we're permitted to
|
166
|
+
# run operations where activerecord auto-saves the object.
|
167
|
+
reverse = column.association.klass.reflect_on_association(column.association.reverse)
|
168
|
+
if reverse.macro == :has_one and options[:allow_autosave]
|
169
|
+
record.send(k).send("#{column.association.reverse}=", record)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
else
|
173
|
+
record.send("#{k}=", v)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
private
|
179
|
+
|
180
|
+
def constraint_condition_for(sql, value)
|
181
|
+
value.nil? ? "#{sql} IS NULL" : ["#{sql} = ?", value]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module ActiveScaffold::DataStructures
|
2
|
+
# A set of columns. These structures can be nested for organization.
|
3
|
+
class ActionColumns < ActiveScaffold::DataStructures::Set
|
4
|
+
include ActiveScaffold::Configurable
|
5
|
+
|
6
|
+
# this lets us refer back to the action responsible for this link, if it exists.
|
7
|
+
# the immediate need here is to get the crud_type so we can dynamically filter columns from the set.
|
8
|
+
attr_accessor :action
|
9
|
+
|
10
|
+
# labels are useful for the Create/Update forms, when we display columns in a grouped fashion and want to name them separately
|
11
|
+
attr_writer :label
|
12
|
+
def label
|
13
|
+
as_(@label) if @label
|
14
|
+
end
|
15
|
+
|
16
|
+
# Whether this column set is collapsed by default in contexts where collapsing is supported
|
17
|
+
attr_accessor :collapsed
|
18
|
+
|
19
|
+
# nests a subgroup in the column set
|
20
|
+
def add_subgroup(label, &proc)
|
21
|
+
columns = ActiveScaffold::DataStructures::ActionColumns.new
|
22
|
+
columns.label = label
|
23
|
+
columns.action = self.action
|
24
|
+
columns.configure &proc
|
25
|
+
self.exclude columns.collect_columns
|
26
|
+
self.add columns
|
27
|
+
end
|
28
|
+
|
29
|
+
def include?(item)
|
30
|
+
@set.each do |c|
|
31
|
+
return true if !c.is_a? Symbol and c.include? item
|
32
|
+
return true if c == item.to_sym
|
33
|
+
end
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
|
37
|
+
def names
|
38
|
+
self.collect(&:name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def names_without_auth_check
|
42
|
+
Array(@set)
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def collect_columns
|
48
|
+
@set.collect {|col| col.is_a?(ActiveScaffold::DataStructures::ActionColumns) ? col.collect_columns : col}
|
49
|
+
end
|
50
|
+
|
51
|
+
# called during clone or dup. makes the clone/dup deeper.
|
52
|
+
def initialize_copy(from)
|
53
|
+
@set = from.instance_variable_get('@set').clone
|
54
|
+
end
|
55
|
+
|
56
|
+
# A package of stuff to add after the configuration block. This is an attempt at making a certain level of functionality inaccessible during configuration, to reduce possible breakage from misuse.
|
57
|
+
# The bulk of the package is a means of connecting the referential column set (ActionColumns) with the actual column objects (Columns). This lets us iterate over the set and yield real column objects.
|
58
|
+
module AfterConfiguration
|
59
|
+
# Redefine the each method to yield actual Column objects.
|
60
|
+
# It will skip constrained and unauthorized columns.
|
61
|
+
#
|
62
|
+
# Options:
|
63
|
+
# * :flatten - whether to recursively iterate on nested sets. default is false.
|
64
|
+
# * :for - the record (or class) being iterated over. used for column-level security. default is the class.
|
65
|
+
def each(options = {}, &proc)
|
66
|
+
options[:for] ||= @columns.active_record_class
|
67
|
+
self.unauthorized_columns = []
|
68
|
+
@set.each do |item|
|
69
|
+
unless item.is_a? ActiveScaffold::DataStructures::ActionColumns
|
70
|
+
item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class))
|
71
|
+
next if self.skip_column?(item, options)
|
72
|
+
end
|
73
|
+
if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten]
|
74
|
+
item.each(options, &proc)
|
75
|
+
else
|
76
|
+
yield item
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def collect_visible(options = {}, &proc)
|
82
|
+
columns = []
|
83
|
+
options[:for] ||= @columns.active_record_class
|
84
|
+
self.unauthorized_columns = []
|
85
|
+
@set.each do |item|
|
86
|
+
unless item.is_a? ActiveScaffold::DataStructures::ActionColumns
|
87
|
+
item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class))
|
88
|
+
next if self.skip_column?(item, options)
|
89
|
+
end
|
90
|
+
if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten]
|
91
|
+
columns = columns + item.collect(options, &proc)
|
92
|
+
else
|
93
|
+
columns << item
|
94
|
+
end
|
95
|
+
end
|
96
|
+
columns
|
97
|
+
end
|
98
|
+
|
99
|
+
def skip_column?(column, options)
|
100
|
+
result = false
|
101
|
+
# skip if this matches a constrained column
|
102
|
+
result = true if constraint_columns.include?(column.name.to_sym)
|
103
|
+
# skip if this matches the field_name of a constrained column
|
104
|
+
result = true if column.field_name and constraint_columns.include?(column.field_name.to_sym)
|
105
|
+
# skip this field if it's not authorized
|
106
|
+
unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => column.name)
|
107
|
+
self.unauthorized_columns << column.name.to_sym
|
108
|
+
result = true
|
109
|
+
end
|
110
|
+
return result
|
111
|
+
end
|
112
|
+
|
113
|
+
# registers a set of column objects (recursively, for all nested ActionColumns)
|
114
|
+
def set_columns(columns)
|
115
|
+
@columns = columns
|
116
|
+
# iterate over @set instead of self to avoid dealing with security queries
|
117
|
+
@set.each do |item|
|
118
|
+
item.set_columns(columns) if item.respond_to? :set_columns
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
attr_writer :constraint_columns
|
123
|
+
def constraint_columns
|
124
|
+
@constraint_columns ||= []
|
125
|
+
end
|
126
|
+
|
127
|
+
attr_writer :unauthorized_columns
|
128
|
+
def unauthorized_columns
|
129
|
+
@unauthorized_columns ||= []
|
130
|
+
end
|
131
|
+
|
132
|
+
def length
|
133
|
+
((@set - self.constraint_columns) - self.unauthorized_columns).length
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
module ActiveScaffold::DataStructures
|
2
|
+
class ActionLink
|
3
|
+
# provides a quick way to set any property of the object from a hash
|
4
|
+
def initialize(action, options = {})
|
5
|
+
# set defaults
|
6
|
+
self.action = action.to_s
|
7
|
+
self.label = action
|
8
|
+
self.confirm = false
|
9
|
+
self.type = :collection
|
10
|
+
self.inline = true
|
11
|
+
self.method = :get
|
12
|
+
self.crud_type = :delete if [:destroy].include?(action.to_sym)
|
13
|
+
self.crud_type = :create if [:create, :new].include?(action.to_sym)
|
14
|
+
self.crud_type = :update if [:edit, :update].include?(action.to_sym)
|
15
|
+
self.crud_type ||= :read
|
16
|
+
self.parameters = {}
|
17
|
+
self.html_options = {}
|
18
|
+
self.column = nil
|
19
|
+
self.image = nil
|
20
|
+
self.dynamic_parameters = nil
|
21
|
+
|
22
|
+
# apply quick properties
|
23
|
+
options.each_pair do |k, v|
|
24
|
+
setter = "#{k}="
|
25
|
+
self.send(setter, v) if self.respond_to? setter
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# the action-path for this link. what page to request? this is required!
|
30
|
+
attr_accessor :action
|
31
|
+
|
32
|
+
# the controller for this action link. if nil, the current controller should be assumed.
|
33
|
+
attr_writer :controller
|
34
|
+
|
35
|
+
def controller
|
36
|
+
@controller = @controller.call if @controller.is_a?(Proc)
|
37
|
+
@controller
|
38
|
+
end
|
39
|
+
|
40
|
+
def static_controller?
|
41
|
+
!(@controller.is_a?(Proc) || (@controller == :polymorph))
|
42
|
+
end
|
43
|
+
|
44
|
+
# a hash of request parameters
|
45
|
+
attr_accessor :parameters
|
46
|
+
|
47
|
+
# a block for dynamic_parameters
|
48
|
+
attr_accessor :dynamic_parameters
|
49
|
+
|
50
|
+
# the RESTful method
|
51
|
+
attr_accessor :method
|
52
|
+
|
53
|
+
# what string to use to represent this action
|
54
|
+
attr_writer :label
|
55
|
+
def label
|
56
|
+
@label.is_a?(Symbol) ? as_(@label) : @label
|
57
|
+
end
|
58
|
+
|
59
|
+
# image to use {:name => 'arrow.png', :size => '16x16'}
|
60
|
+
attr_accessor :image
|
61
|
+
|
62
|
+
# if the action requires confirmation
|
63
|
+
attr_writer :confirm
|
64
|
+
def confirm(label = '')
|
65
|
+
@confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label)
|
66
|
+
end
|
67
|
+
def confirm?
|
68
|
+
@confirm ? true : false
|
69
|
+
end
|
70
|
+
|
71
|
+
# if the action uses a DHTML based (i.e. 2-phase) confirmation
|
72
|
+
attr_writer :dhtml_confirm
|
73
|
+
def dhtml_confirm
|
74
|
+
@dhtml_confirm
|
75
|
+
end
|
76
|
+
def dhtml_confirm?
|
77
|
+
@dhtml_confirm
|
78
|
+
end
|
79
|
+
|
80
|
+
# what method to call on the controller to see if this action_link should be visible
|
81
|
+
# note that this is only the UI part of the security. to prevent URL hax0rz, you also need security on requests (e.g. don't execute update method unless authorized).
|
82
|
+
attr_writer :security_method
|
83
|
+
def security_method
|
84
|
+
@security_method || "#{self.action}_authorized?"
|
85
|
+
end
|
86
|
+
|
87
|
+
def security_method_set?
|
88
|
+
!!@security_method
|
89
|
+
end
|
90
|
+
|
91
|
+
attr_accessor :ignore_method
|
92
|
+
|
93
|
+
# the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent.
|
94
|
+
# this is used to determine record-level authorization (e.g. record.authorized_for?(:crud_type => link.crud_type).
|
95
|
+
# options are :create, :read, :update, and :delete
|
96
|
+
attr_accessor :crud_type
|
97
|
+
|
98
|
+
# an "inline" link is inserted into the existing page
|
99
|
+
# exclusive with popup? and page?
|
100
|
+
def inline=(val)
|
101
|
+
@inline = (val == true)
|
102
|
+
self.popup = self.page = false if @inline
|
103
|
+
end
|
104
|
+
def inline?; @inline end
|
105
|
+
|
106
|
+
# a "popup" link displays in a separate (browser?) window. this will eventually take arguments.
|
107
|
+
# exclusive with inline? and page?
|
108
|
+
def popup=(val)
|
109
|
+
@popup = (val == true)
|
110
|
+
if @popup
|
111
|
+
self.inline = self.page = false
|
112
|
+
|
113
|
+
# the :method parameter doesn't mix with the :popup parameter
|
114
|
+
# when/if we start using DHTML popups, we can bring :method back
|
115
|
+
self.method = nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
def popup?; @popup end
|
119
|
+
|
120
|
+
# a "page" link displays by reloading the current page
|
121
|
+
# exclusive with inline? and popup?
|
122
|
+
def page=(val)
|
123
|
+
@page = (val == true)
|
124
|
+
if @page
|
125
|
+
self.inline = self.popup = false
|
126
|
+
|
127
|
+
# when :method is defined, ActionView adds an onclick to use a form ...
|
128
|
+
# so it's best to just empty out :method whenever possible.
|
129
|
+
# we only ever need to know @method = :get for things that default to POST.
|
130
|
+
# the only things that default to POST are forms and ajax calls.
|
131
|
+
# when @page = true, we don't use ajax.
|
132
|
+
self.method = nil if method == :get
|
133
|
+
end
|
134
|
+
end
|
135
|
+
def page?; @page end
|
136
|
+
|
137
|
+
# where the result of this action should insert in the display.
|
138
|
+
# for :type => :collection, supported values are:
|
139
|
+
# :top
|
140
|
+
# :bottom
|
141
|
+
# :replace (for updating the entire table)
|
142
|
+
# false (no attempt at positioning)
|
143
|
+
# for :type => :member, supported values are:
|
144
|
+
# :before
|
145
|
+
# :replace
|
146
|
+
# :after
|
147
|
+
# false (no attempt at positioning)
|
148
|
+
attr_writer :position
|
149
|
+
def position
|
150
|
+
return @position unless @position.nil? or @position == true
|
151
|
+
return :replace if self.type == :member
|
152
|
+
return :top if self.type == :collection
|
153
|
+
raise "what should the default position be for #{self.type}?"
|
154
|
+
end
|
155
|
+
|
156
|
+
# what type of link this is. currently supported values are :collection and :member.
|
157
|
+
attr_accessor :type
|
158
|
+
|
159
|
+
# html options for the link
|
160
|
+
attr_accessor :html_options
|
161
|
+
|
162
|
+
# nested action_links are referencing a column
|
163
|
+
attr_accessor :column
|
164
|
+
|
165
|
+
# indicates that this a nested_link
|
166
|
+
def nested_link?
|
167
|
+
@column || (parameters && parameters[:named_scope])
|
168
|
+
end
|
169
|
+
|
170
|
+
# Internal use: generated eid for this action_link
|
171
|
+
attr_accessor :eid
|
172
|
+
|
173
|
+
|
174
|
+
end
|
175
|
+
end
|