active_scaffold 3.0.26 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +1 -1
- data/{frontends/default → app/assets}/images/add.gif +0 -0
- data/{frontends/default → app/assets}/images/arrow_down.gif +0 -0
- data/{frontends/default → app/assets}/images/arrow_up.gif +0 -0
- data/{frontends/default → app/assets}/images/close.gif +0 -0
- data/{frontends/default → app/assets}/images/close_touch.png +0 -0
- data/{frontends/default → app/assets}/images/config.png +0 -0
- data/{frontends/default → app/assets}/images/cross.png +0 -0
- data/{frontends/default → app/assets}/images/gears.png +0 -0
- data/{frontends/default → app/assets}/images/indicator-small.gif +0 -0
- data/{frontends/default → app/assets}/images/indicator.gif +0 -0
- data/{frontends/default → app/assets}/images/magnifier.png +0 -0
- data/app/assets/javascripts/active_scaffold.js.erb +16 -0
- data/{frontends/default → app/assets}/javascripts/jquery/active_scaffold.js +16 -28
- data/app/assets/javascripts/jquery/active_scaffold.js~ +1036 -0
- data/{lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js → app/assets/javascripts/jquery/date_picker_bridge.js.erb} +3 -1
- data/{frontends/default → app/assets}/javascripts/jquery/jquery.editinplace.js +0 -0
- data/app/assets/javascripts/prototype/active_scaffold.js +1033 -0
- data/{frontends/default/javascripts/prototype/active_scaffold.js → app/assets/javascripts/prototype/active_scaffold.js~} +1 -0
- data/{frontends/default → app/assets}/javascripts/prototype/dhtml_history.js +0 -0
- data/{frontends/default → app/assets}/javascripts/prototype/form_enhancements.js +0 -0
- data/{frontends/default → app/assets}/javascripts/prototype/rico_corner.js +0 -0
- data/{frontends/default/stylesheets/stylesheet-ie.css → app/assets/stylesheets/active_scaffold-ie.css} +0 -0
- data/{frontends/default/stylesheets/stylesheet.css → app/assets/stylesheets/active_scaffold.css.erb} +29 -24
- data/{lib/active_scaffold/locale → config/locales}/de.yml +3 -0
- data/{lib/active_scaffold/locale → config/locales}/en.yml +3 -0
- data/{lib/active_scaffold/locale → config/locales}/es.yml +5 -0
- data/{lib/active_scaffold/locale → config/locales}/fr.yml +3 -0
- data/{lib/active_scaffold/locale → config/locales}/hu.yml +13 -2
- data/{lib/active_scaffold/locale → config/locales}/ja.yml +9 -0
- data/{lib/active_scaffold/locale → config/locales}/ru.yml +3 -0
- data/frontends/default/views/_form.html.erb +1 -1
- data/frontends/default/views/_form_association.html.erb +1 -5
- data/frontends/default/views/_horizontal_subform.html.erb +7 -4
- data/frontends/default/views/_horizontal_subform.html.erb~ +2 -5
- data/frontends/default/views/_horizontal_subform_footer.html.erb +0 -0
- data/frontends/default/views/_horizontal_subform_header.html.erb +1 -1
- data/frontends/default/views/_horizontal_subform_header.html.erb~ +1 -1
- data/frontends/default/views/_horizontal_subform_record.html.erb~ +1 -1
- data/frontends/default/views/_list_actions.html.erb +1 -1
- data/frontends/default/views/_list_messages.html.erb +1 -3
- data/frontends/default/views/_render_field.js.erb +20 -0
- data/frontends/default/views/_row.html.erb +3 -9
- data/frontends/default/views/_show.html.erb +2 -2
- data/frontends/default/views/add_existing.js.erb +20 -0
- data/frontends/default/views/destroy.js.erb +24 -0
- data/frontends/default/views/{edit_associated.js.rjs → edit_associated.js.erb} +3 -2
- data/frontends/default/views/form_messages.js.erb +1 -0
- data/frontends/default/views/list.js.erb +1 -0
- data/frontends/default/views/mark.js.rjs +6 -0
- data/frontends/default/views/on_action_update.js.erb +13 -0
- data/frontends/default/views/{on_create.js.erb~ → on_create.js.erb} +0 -0
- data/frontends/default/views/on_mark_all.js.erb +12 -0
- data/frontends/default/views/{on_update.js.erb~ → on_update.js.erb} +0 -0
- data/frontends/default/views/render_field.js.erb +1 -0
- data/frontends/default/views/search.html.erb +1 -1
- data/frontends/default/views/{update_column.js.erb~ → update_column.js.erb} +3 -3
- data/frontends/default/views/update_row.js.erb +1 -0
- data/lib/active_scaffold.rb +22 -46
- data/lib/active_scaffold/actions/core.rb +14 -6
- data/lib/active_scaffold/actions/core.rb~ +3 -3
- data/lib/active_scaffold/actions/create.rb +2 -5
- data/lib/active_scaffold/actions/create.rb~ +3 -2
- data/lib/active_scaffold/actions/delete.rb +1 -0
- data/lib/active_scaffold/actions/field_search.rb +1 -1
- data/lib/active_scaffold/actions/list.rb +10 -6
- data/lib/active_scaffold/actions/list.rb~ +3 -3
- data/lib/active_scaffold/actions/mark.rb +8 -8
- data/lib/active_scaffold/actions/nested.rb +2 -9
- data/lib/active_scaffold/actions/nested.rb~ +5 -7
- data/lib/active_scaffold/actions/search.rb +2 -1
- data/lib/active_scaffold/actions/subform.rb +1 -5
- data/lib/active_scaffold/actions/update.rb +1 -4
- data/lib/active_scaffold/actions/update.rb~ +5 -5
- data/lib/active_scaffold/attribute_params.rb +15 -26
- data/lib/active_scaffold/attribute_params.rb~ +1 -2
- data/lib/active_scaffold/bridges.rb +61 -0
- data/lib/active_scaffold/bridges/ancestry.rb +5 -0
- data/lib/active_scaffold/bridges/ancestry/{lib/ancestry_bridge.rb → ancestry_bridge.rb} +3 -3
- data/lib/active_scaffold/bridges/{calendar_date_select/bridge.rb → calendar_date_select.rb} +13 -5
- data/lib/active_scaffold/bridges/calendar_date_select/{lib/as_cds_bridge.rb → as_cds_bridge.rb} +4 -20
- data/lib/active_scaffold/bridges/cancan.rb +15 -0
- data/lib/active_scaffold/bridges/cancan/{lib/cancan_bridge.rb → cancan_bridge.rb} +2 -2
- data/lib/active_scaffold/bridges/carrierwave.rb +12 -0
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +31 -0
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb +10 -0
- data/lib/active_scaffold/bridges/carrierwave/{lib/form_ui.rb → form_ui.rb} +0 -0
- data/lib/active_scaffold/bridges/carrierwave/{lib/list_ui.rb → list_ui.rb} +1 -1
- data/lib/active_scaffold/bridges/country_helper.rb +9 -0
- data/lib/active_scaffold/bridges/country_helper/{lib/country_helper_bridge.rb → country_helper_bridge.rb} +5 -5
- data/lib/active_scaffold/bridges/date_picker.rb +23 -0
- data/lib/active_scaffold/bridges/date_picker/ext.rb +54 -0
- data/lib/active_scaffold/bridges/date_picker/helper.rb +188 -0
- data/lib/active_scaffold/bridges/dragonfly.rb +9 -0
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +34 -0
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb +10 -0
- data/lib/active_scaffold/bridges/dragonfly/{lib/form_ui.rb → form_ui.rb} +0 -0
- data/lib/active_scaffold/bridges/dragonfly/{lib/list_ui.rb → list_ui.rb} +2 -2
- data/lib/active_scaffold/bridges/file_column.rb +11 -0
- data/lib/active_scaffold/bridges/file_column/{lib/as_file_column_bridge.rb → as_file_column_bridge.rb} +2 -2
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +57 -0
- data/lib/active_scaffold/bridges/file_column/{lib/form_ui.rb → form_ui.rb} +2 -2
- data/lib/active_scaffold/bridges/file_column/{lib/list_ui.rb → list_ui.rb} +0 -0
- data/lib/active_scaffold/bridges/paperclip.rb +12 -0
- data/lib/active_scaffold/bridges/paperclip/{lib/form_ui.rb → form_ui.rb} +0 -0
- data/lib/active_scaffold/bridges/paperclip/{lib/list_ui.rb → list_ui.rb} +3 -3
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +36 -0
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +24 -0
- data/lib/active_scaffold/bridges/record_select.rb +11 -0
- data/lib/active_scaffold/bridges/record_select/{lib/record_select_bridge.rb → helpers.rb} +5 -16
- data/lib/active_scaffold/bridges/record_select/helpers.rb~ +9 -14
- data/lib/active_scaffold/bridges/semantic_attributes.rb +5 -0
- data/lib/active_scaffold/bridges/semantic_attributes/{lib/semantic_attributes_bridge.rb → column.rb} +3 -3
- data/lib/active_scaffold/bridges/tiny_mce.rb +5 -0
- data/lib/active_scaffold/bridges/tiny_mce/{lib/tiny_mce_bridge.rb → helpers.rb} +16 -8
- data/lib/active_scaffold/config/base.rb +9 -1
- data/lib/active_scaffold/config/core.rb +1 -1
- data/lib/active_scaffold/config/create.rb +3 -10
- data/lib/active_scaffold/config/delete.rb +1 -2
- data/lib/active_scaffold/config/field_search.rb +1 -2
- data/lib/active_scaffold/config/form.rb +2 -6
- data/lib/active_scaffold/config/list.rb +8 -2
- data/lib/active_scaffold/config/nested.rb +2 -6
- data/lib/active_scaffold/config/search.rb +6 -2
- data/lib/active_scaffold/config/show.rb +1 -4
- data/lib/active_scaffold/config/subform.rb +1 -1
- data/lib/active_scaffold/config/update.rb +1 -6
- data/lib/active_scaffold/data_structures/action_columns.rb +3 -0
- data/lib/active_scaffold/data_structures/action_link.rb +14 -10
- data/lib/active_scaffold/data_structures/bridge.rb +22 -0
- data/lib/active_scaffold/data_structures/column.rb +36 -4
- data/lib/active_scaffold/data_structures/nested_info.rb +4 -4
- data/lib/active_scaffold/data_structures/set.rb +1 -6
- data/lib/active_scaffold/data_structures/sorting.rb +2 -2
- data/lib/active_scaffold/engine.rb +4 -0
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +2 -2
- data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +90 -93
- data/lib/active_scaffold/extensions/action_view_rendering.rb~ +1 -13
- data/lib/active_scaffold/extensions/active_association_reflection.rb +16 -7
- data/lib/active_scaffold/extensions/cache_association.rb +16 -0
- data/lib/active_scaffold/extensions/reverse_associations.rb +15 -13
- data/lib/active_scaffold/extensions/unsaved_associated.rb +1 -1
- data/lib/active_scaffold/finder.rb +40 -23
- data/lib/active_scaffold/finder.rb~ +3 -11
- data/lib/active_scaffold/helpers/association_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/controller_helpers.rb +9 -1
- data/lib/active_scaffold/helpers/controller_helpers.rb~ +12 -5
- data/lib/active_scaffold/helpers/form_column_helpers.rb +20 -21
- data/lib/active_scaffold/helpers/form_column_helpers.rb~ +2 -1
- data/lib/active_scaffold/helpers/id_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/list_column_helpers.rb +14 -24
- data/lib/active_scaffold/helpers/list_column_helpers.rb~ +15 -20
- data/lib/active_scaffold/helpers/search_column_helpers.rb +10 -1
- data/lib/active_scaffold/helpers/search_column_helpers.rb~ +1 -1
- data/lib/active_scaffold/helpers/view_helpers.rb +14 -40
- data/lib/active_scaffold/helpers/view_helpers.rb~ +3 -3
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/active_scaffold_env.rb +0 -2
- data/test/bridges/active_scaffold_dependent_protect_test.rb +34 -0
- data/test/bridges/bridge_test.rb +43 -0
- data/test/bridges/company.rb +81 -0
- data/test/bridges/paperclip_test.rb +68 -0
- data/test/bridges/tiny_mce_test.rb +27 -0
- data/test/bridges/unobtrusive_date_picker_test.rb +49 -0
- data/test/bridges/validation_reflection_test.rb +57 -0
- data/test/config/base_test.rb +1 -1
- data/test/config/core_test.rb +58 -0
- data/test/config/create_test.rb +8 -5
- data/test/config/delete_test.rb +33 -0
- data/test/config/field_search_test.rb +47 -0
- data/test/config/list_test.rb +64 -9
- data/test/config/nested_test.rb +62 -0
- data/test/config/search_test.rb +60 -0
- data/test/config/show_test.rb +5 -5
- data/test/config/subform_test.rb +17 -0
- data/test/config/update_test.rb +27 -4
- data/test/helpers/list_column_helpers_test.rb +16 -5
- data/test/helpers/pagination_helpers_test.rb +4 -0
- data/test/misc/attribute_params_test.rb +37 -1
- data/test/misc/finder_test.rb +0 -1
- data/test/misc/lang_test.rb +2 -3
- data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +2 -2
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +13 -7
- metadata +137 -154
- data/frontends/default/views/_list_with_header.html.erb~ +0 -32
- data/frontends/default/views/_render_field.js.rjs +0 -14
- data/frontends/default/views/_show.html.erb~ +0 -8
- data/frontends/default/views/_update_form.html.erb~ +0 -6
- data/frontends/default/views/add_existing.js.erb~ +0 -18
- data/frontends/default/views/add_existing.js.rjs +0 -17
- data/frontends/default/views/destroy.js.rjs +0 -23
- data/frontends/default/views/form_messages.js.rjs +0 -1
- data/frontends/default/views/list.js.rjs +0 -1
- data/frontends/default/views/on_action_update.js.rjs +0 -10
- data/frontends/default/views/on_create.js.rjs +0 -41
- data/frontends/default/views/on_mark_all.js.rjs +0 -12
- data/frontends/default/views/on_update.js.rjs +0 -28
- data/frontends/default/views/render_field.js.rjs +0 -1
- data/frontends/default/views/update_column.js.rjs +0 -13
- data/frontends/default/views/update_row.js.rjs +0 -1
- data/lib/active_scaffold.rb~ +0 -362
- data/lib/active_scaffold/bridges/ancestry/bridge.rb +0 -5
- data/lib/active_scaffold/bridges/bridge.rb +0 -59
- data/lib/active_scaffold/bridges/cancan/bridge.rb +0 -12
- data/lib/active_scaffold/bridges/carrierwave/bridge.rb +0 -9
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +0 -33
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +0 -12
- data/lib/active_scaffold/bridges/country_helper/bridge.rb +0 -9
- data/lib/active_scaffold/bridges/date_picker/bridge.rb +0 -24
- data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +0 -234
- data/lib/active_scaffold/bridges/dragonfly/bridge.rb +0 -9
- data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb +0 -36
- data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb +0 -12
- data/lib/active_scaffold/bridges/file_column/bridge.rb +0 -11
- data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +0 -59
- data/lib/active_scaffold/bridges/paperclip/bridge.rb +0 -12
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +0 -38
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +0 -26
- data/lib/active_scaffold/bridges/record_select/bridge.rb +0 -5
- data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +0 -5
- data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +0 -209
- data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +0 -5
- data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +0 -8
- data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +0 -21
- data/lib/active_scaffold/config/base.rb~ +0 -70
- data/lib/active_scaffold/config/nested.rb~ +0 -41
- data/lib/active_scaffold/constraints.rb~ +0 -186
- data/lib/active_scaffold/data_structures/action_link.rb~ +0 -179
- data/lib/active_scaffold/data_structures/nested_info.rb~ +0 -123
- data/lib/active_scaffold/extensions/action_view_resolver.rb +0 -7
- data/lib/active_scaffold/extensions/active_association_reflection.rb~ +0 -22
- data/lib/active_scaffold/extensions/unsaved_associated.rb~ +0 -62
- data/lib/active_scaffold_assets.rb +0 -45
- data/lib/generators/active_scaffold_setup/USAGE +0 -10
- data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +0 -59
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
module ActiveScaffold::Config
|
|
2
|
-
class Nested < Base
|
|
3
|
-
self.crud_type = :read
|
|
4
|
-
|
|
5
|
-
def initialize(core_config)
|
|
6
|
-
super
|
|
7
|
-
@label = :add_existing_model
|
|
8
|
-
self.shallow_delete = self.class.shallow_delete
|
|
9
|
-
@action_group = self.class.action_group.clone if self.class.action_group
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# global level configuration
|
|
13
|
-
# --------------------------
|
|
14
|
-
cattr_accessor :shallow_delete
|
|
15
|
-
@@shallow_delete = true
|
|
16
|
-
|
|
17
|
-
# instance-level configuration
|
|
18
|
-
# ----------------------------
|
|
19
|
-
attr_accessor :shallow_delete
|
|
20
|
-
|
|
21
|
-
# Add a nested ActionLink
|
|
22
|
-
def add_link(attribute, options = {})
|
|
23
|
-
column = @core.columns[attribute.to_sym]
|
|
24
|
-
unless column.nil? || column.association.nil?
|
|
25
|
-
options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize})
|
|
26
|
-
action_link = @core.link_for_association(column, options)
|
|
27
|
-
@core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
|
|
28
|
-
else
|
|
29
|
-
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def add_scoped_link(named_scope, options = {})
|
|
34
|
-
action_link = @core.link_for_association_as_scope(named_scope.to_sym, options)
|
|
35
|
-
@core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# the label for this Nested action. used for the header.
|
|
39
|
-
attr_writer :label
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,186 +0,0 @@
|
|
|
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
|
-
debugger
|
|
27
|
-
constrained_fields = active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect{|k| k.to_sym}
|
|
28
|
-
constrained_fields = constrained_fields | association_constrained_fields
|
|
29
|
-
if self.class.uses_active_scaffold?
|
|
30
|
-
# we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't
|
|
31
|
-
active_scaffold_config.actions.each do |action_name|
|
|
32
|
-
next if exclude_actions.include?(action_name)
|
|
33
|
-
action = active_scaffold_config.send(action_name)
|
|
34
|
-
next unless action.respond_to? :columns
|
|
35
|
-
action.columns.constraint_columns = constrained_fields
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Returns search conditions based on the current scaffold constraints.
|
|
41
|
-
#
|
|
42
|
-
# Supports constraints based on either a column name (in which case it checks for an association
|
|
43
|
-
# or just uses the search_sql) or a database field name.
|
|
44
|
-
#
|
|
45
|
-
# All of this work is primarily to support nested scaffolds in a manner generally useful for other
|
|
46
|
-
# embedded scaffolds.
|
|
47
|
-
def conditions_from_constraints
|
|
48
|
-
conditions = nil
|
|
49
|
-
debugger
|
|
50
|
-
active_scaffold_constraints.each do |k, v|
|
|
51
|
-
column = active_scaffold_config.columns[k]
|
|
52
|
-
constraint_condition = if column
|
|
53
|
-
# Assume this is a multi-level association constraint.
|
|
54
|
-
# example:
|
|
55
|
-
# data model: Park -> Den -> Bear
|
|
56
|
-
# constraint: :den => {:park => 5}
|
|
57
|
-
if v.is_a? Hash
|
|
58
|
-
far_association = column.association.klass.reflect_on_association(v.keys.first)
|
|
59
|
-
field = far_association.klass.primary_key
|
|
60
|
-
table = far_association.table_name
|
|
61
|
-
|
|
62
|
-
active_scaffold_includes.concat([{k => v.keys.first}]) # e.g. {:den => :park}
|
|
63
|
-
constraint_condition_for("#{table}.#{field}", v.values.first)
|
|
64
|
-
|
|
65
|
-
# association column constraint
|
|
66
|
-
elsif column.association
|
|
67
|
-
if column.association.macro == :has_and_belongs_to_many
|
|
68
|
-
active_scaffold_habtm_joins.concat column.includes
|
|
69
|
-
else
|
|
70
|
-
active_scaffold_includes.concat column.includes
|
|
71
|
-
end
|
|
72
|
-
condition_from_association_constraint(column.association, v)
|
|
73
|
-
|
|
74
|
-
# regular column constraints
|
|
75
|
-
elsif column.searchable?
|
|
76
|
-
active_scaffold_includes.concat column.includes
|
|
77
|
-
constraint_condition_for(column.search_sql, v)
|
|
78
|
-
end
|
|
79
|
-
# unknown-to-activescaffold-but-real-database-column constraint
|
|
80
|
-
elsif active_scaffold_config.model.column_names.include? k.to_s
|
|
81
|
-
constraint_condition_for(k.to_s, v)
|
|
82
|
-
else
|
|
83
|
-
raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
conditions = merge_conditions(conditions, constraint_condition)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
conditions
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# We do NOT want to use .search_sql. If anything, search_sql will refer
|
|
93
|
-
# to a human-searchable value on the associated record.
|
|
94
|
-
def condition_from_association_constraint(association, value)
|
|
95
|
-
# when the reverse association is a :belongs_to, the id for the associated object only exists as
|
|
96
|
-
# the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),
|
|
97
|
-
# we have to use the other model's primary_key.
|
|
98
|
-
#
|
|
99
|
-
# please see the relevant tests for concrete examples.
|
|
100
|
-
field = if [:has_one, :has_many].include?(association.macro)
|
|
101
|
-
association.klass.primary_key
|
|
102
|
-
elsif [:has_and_belongs_to_many].include?(association.macro)
|
|
103
|
-
association.association_foreign_key
|
|
104
|
-
else
|
|
105
|
-
association.options[:foreign_key] || association.name.to_s.foreign_key
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
table = case association.macro
|
|
109
|
-
when :has_and_belongs_to_many
|
|
110
|
-
association.options[:join_table]
|
|
111
|
-
|
|
112
|
-
when :belongs_to
|
|
113
|
-
active_scaffold_config.model.table_name
|
|
114
|
-
|
|
115
|
-
else
|
|
116
|
-
association.table_name
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
if association.options[:primary_key]
|
|
120
|
-
value = association.klass.find(value).send(association.options[:primary_key])
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
condition = constraint_condition_for("#{table}.#{field}", value)
|
|
124
|
-
if association.options[:polymorphic]
|
|
125
|
-
begin
|
|
126
|
-
parent_scaffold = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize
|
|
127
|
-
condition = merge_conditions(
|
|
128
|
-
condition,
|
|
129
|
-
constraint_condition_for("#{table}.#{association.name}_type", parent_scaffold.active_scaffold_config.model_id.to_s)
|
|
130
|
-
)
|
|
131
|
-
rescue ActiveScaffold::ControllerNotFound
|
|
132
|
-
nil
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
condition
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def constraint_error(klass, column_name)
|
|
140
|
-
"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."
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# Applies constraints to the given record.
|
|
144
|
-
#
|
|
145
|
-
# Searches through the known columns for association columns. If the given constraint is an association,
|
|
146
|
-
# it assumes that the constraint value is an id. It then does a association.klass.find with the value
|
|
147
|
-
# and adds the associated object to the record.
|
|
148
|
-
#
|
|
149
|
-
# For some operations ActiveRecord will automatically update the database. That's not always ok.
|
|
150
|
-
# If it *is* ok (e.g. you're in a transaction), then set :allow_autosave to true.
|
|
151
|
-
def apply_constraints_to_record(record, options = {})
|
|
152
|
-
options[:allow_autosave] = false if options[:allow_autosave].nil?
|
|
153
|
-
|
|
154
|
-
active_scaffold_constraints.each do |k, v|
|
|
155
|
-
column = active_scaffold_config.columns[k]
|
|
156
|
-
if column and column.association
|
|
157
|
-
if column.plural_association?
|
|
158
|
-
record.send("#{k}").send(:<<, column.association.klass.find(v))
|
|
159
|
-
elsif column.association.options[:polymorphic]
|
|
160
|
-
record.send("#{k}=", params[:parent_model].constantize.find(v))
|
|
161
|
-
else # regular singular association
|
|
162
|
-
record.send("#{k}=", column.association.klass.find(v))
|
|
163
|
-
|
|
164
|
-
# setting the belongs_to side of a has_one isn't safe. if the has_one was already
|
|
165
|
-
# specified, rails won't automatically clear out the previous associated record.
|
|
166
|
-
#
|
|
167
|
-
# note that we can't take the extra step to correct this unless we're permitted to
|
|
168
|
-
# run operations where activerecord auto-saves the object.
|
|
169
|
-
reverse = column.association.klass.reflect_on_association(column.association.reverse)
|
|
170
|
-
if reverse.macro == :has_one and options[:allow_autosave]
|
|
171
|
-
record.send(k).send("#{column.association.reverse}=", record)
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
else
|
|
175
|
-
record.send("#{k}=", v)
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
private
|
|
181
|
-
|
|
182
|
-
def constraint_condition_for(sql, value)
|
|
183
|
-
value.nil? ? "#{sql} IS NULL" : ["#{sql} = ?", value]
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
end
|
|
@@ -1,179 +0,0 @@
|
|
|
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.try(:to_sym))
|
|
13
|
-
self.crud_type = :create if [:create, :new].include?(action.try(:to_sym))
|
|
14
|
-
self.crud_type = :update if [:edit, :update].include?(action.try(: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
|
-
def confirm=(value)
|
|
64
|
-
@dhtml_confirm = nil if value
|
|
65
|
-
@confirm = value
|
|
66
|
-
end
|
|
67
|
-
def confirm(label = '')
|
|
68
|
-
@confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label)
|
|
69
|
-
end
|
|
70
|
-
def confirm?
|
|
71
|
-
!!@confirm
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# if the action uses a DHTML based (i.e. 2-phase) confirmation
|
|
75
|
-
attr_accessor :dhtml_confirm
|
|
76
|
-
def dhtml_confirm=(value)
|
|
77
|
-
@confirm = nil if value
|
|
78
|
-
@dhtml_confirm = value
|
|
79
|
-
end
|
|
80
|
-
def dhtml_confirm?
|
|
81
|
-
!!@dhtml_confirm
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# what method to call on the controller to see if this action_link should be visible
|
|
85
|
-
# 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).
|
|
86
|
-
attr_writer :security_method
|
|
87
|
-
def security_method
|
|
88
|
-
@security_method || "#{self.action}_authorized?"
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def security_method_set?
|
|
92
|
-
!!@security_method
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
attr_accessor :ignore_method
|
|
96
|
-
|
|
97
|
-
# the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent.
|
|
98
|
-
# this is used to determine record-level authorization (e.g. record.authorized_for?(:crud_type => link.crud_type).
|
|
99
|
-
# options are :create, :read, :update, and :delete
|
|
100
|
-
attr_accessor :crud_type
|
|
101
|
-
|
|
102
|
-
# an "inline" link is inserted into the existing page
|
|
103
|
-
# exclusive with popup? and page?
|
|
104
|
-
def inline=(val)
|
|
105
|
-
@inline = (val == true)
|
|
106
|
-
self.popup = self.page = false if @inline
|
|
107
|
-
end
|
|
108
|
-
def inline?; @inline end
|
|
109
|
-
|
|
110
|
-
# a "popup" link displays in a separate (browser?) window. this will eventually take arguments.
|
|
111
|
-
# exclusive with inline? and page?
|
|
112
|
-
def popup=(val)
|
|
113
|
-
@popup = (val == true)
|
|
114
|
-
if @popup
|
|
115
|
-
self.inline = self.page = false
|
|
116
|
-
|
|
117
|
-
# the :method parameter doesn't mix with the :popup parameter
|
|
118
|
-
# when/if we start using DHTML popups, we can bring :method back
|
|
119
|
-
self.method = nil
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
def popup?; @popup end
|
|
123
|
-
|
|
124
|
-
# a "page" link displays by reloading the current page
|
|
125
|
-
# exclusive with inline? and popup?
|
|
126
|
-
def page=(val)
|
|
127
|
-
@page = (val == true)
|
|
128
|
-
if @page
|
|
129
|
-
self.inline = self.popup = false
|
|
130
|
-
|
|
131
|
-
# when :method is defined, ActionView adds an onclick to use a form ...
|
|
132
|
-
# so it's best to just empty out :method whenever possible.
|
|
133
|
-
# we only ever need to know @method = :get for things that default to POST.
|
|
134
|
-
# the only things that default to POST are forms and ajax calls.
|
|
135
|
-
# when @page = true, we don't use ajax.
|
|
136
|
-
self.method = nil if method == :get
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
def page?; @page end
|
|
140
|
-
|
|
141
|
-
# where the result of this action should insert in the display.
|
|
142
|
-
# for :type => :collection, supported values are:
|
|
143
|
-
# :top
|
|
144
|
-
# :bottom
|
|
145
|
-
# :replace (for updating the entire table)
|
|
146
|
-
# false (no attempt at positioning)
|
|
147
|
-
# for :type => :member, supported values are:
|
|
148
|
-
# :before
|
|
149
|
-
# :replace
|
|
150
|
-
# :after
|
|
151
|
-
# false (no attempt at positioning)
|
|
152
|
-
attr_writer :position
|
|
153
|
-
def position
|
|
154
|
-
return @position unless @position.nil? or @position == true
|
|
155
|
-
return :replace if self.type == :member
|
|
156
|
-
return :top if self.type == :collection
|
|
157
|
-
raise "what should the default position be for #{self.type}?"
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# what type of link this is. currently supported values are :collection and :member.
|
|
161
|
-
attr_accessor :type
|
|
162
|
-
|
|
163
|
-
# html options for the link
|
|
164
|
-
attr_accessor :html_options
|
|
165
|
-
|
|
166
|
-
# nested action_links are referencing a column
|
|
167
|
-
attr_accessor :column
|
|
168
|
-
|
|
169
|
-
# indicates that this a nested_link
|
|
170
|
-
def nested_link?
|
|
171
|
-
@column || (parameters && parameters[:named_scope])
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
# Internal use: generated eid for this action_link
|
|
175
|
-
attr_accessor :eid
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
end
|
|
179
|
-
end
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
module ActiveScaffold::DataStructures
|
|
2
|
-
class NestedInfo
|
|
3
|
-
def self.get(model, session_storage)
|
|
4
|
-
if session_storage[:nested].nil?
|
|
5
|
-
nil
|
|
6
|
-
else
|
|
7
|
-
session_info = session_storage[:nested].clone
|
|
8
|
-
begin
|
|
9
|
-
session_info[:parent_scaffold] = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize
|
|
10
|
-
session_info[:parent_model] = session_info[:parent_scaffold].active_scaffold_config.model
|
|
11
|
-
session_info[:association] = session_info[:parent_model].reflect_on_association(session_info[:name])
|
|
12
|
-
unless session_info[:association].nil?
|
|
13
|
-
ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, session_info)
|
|
14
|
-
else
|
|
15
|
-
ActiveScaffold::DataStructures::NestedInfoScope.new(model, session_info)
|
|
16
|
-
end
|
|
17
|
-
rescue ActiveScaffold::ControllerNotFound
|
|
18
|
-
nil
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :scope
|
|
24
|
-
|
|
25
|
-
def initialize(model, session_info)
|
|
26
|
-
@parent_model = session_info[:parent_model]
|
|
27
|
-
@parent_id = session_info[:parent_id]
|
|
28
|
-
@parent_scaffold = session_info[:parent_scaffold]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def new_instance?
|
|
32
|
-
result = @new_instance.nil?
|
|
33
|
-
@new_instance = false
|
|
34
|
-
result
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def parent_scope
|
|
38
|
-
parent_model.find(parent_id)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def habtm?
|
|
42
|
-
false
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def belongs_to?
|
|
46
|
-
false
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def has_one?
|
|
50
|
-
false
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def readonly?
|
|
54
|
-
false
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def sorted?
|
|
58
|
-
false
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
class NestedInfoAssociation < NestedInfo
|
|
63
|
-
def initialize(model, session_info)
|
|
64
|
-
super(model, session_info)
|
|
65
|
-
@association = session_info[:association]
|
|
66
|
-
iterate_model_associations(model)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def habtm?
|
|
70
|
-
association.macro == :has_and_belongs_to_many
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def belongs_to?
|
|
74
|
-
association.belongs_to?
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def has_one?
|
|
78
|
-
association.macro == :has_one
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def readonly?
|
|
82
|
-
if association.options.has_key? :readonly
|
|
83
|
-
association.options[:readonly]
|
|
84
|
-
else
|
|
85
|
-
association.options.has_key? :through
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def sorted?
|
|
90
|
-
association.options.has_key? :order
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def default_sorting
|
|
94
|
-
association.options[:order]
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
protected
|
|
98
|
-
|
|
99
|
-
def iterate_model_associations(model)
|
|
100
|
-
@constrained_fields = []
|
|
101
|
-
@constrained_fields << association.primary_key_name.to_sym unless association.belongs_to?
|
|
102
|
-
model.reflect_on_all_associations.each do |current|
|
|
103
|
-
if !current.belongs_to? && association.primary_key_name == current.association_foreign_key
|
|
104
|
-
constrained_fields << current.name.to_sym
|
|
105
|
-
@child_association = current if current.klass == @parent_model
|
|
106
|
-
end
|
|
107
|
-
if association.primary_key_name == current.primary_key_name
|
|
108
|
-
# show columns for has_many and has_one child associationes
|
|
109
|
-
constrained_fields << current.name.to_sym if current.belongs_to?
|
|
110
|
-
@child_association = current
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
class NestedInfoScope < NestedInfo
|
|
117
|
-
def initialize(model, session_info)
|
|
118
|
-
super(model, session_info)
|
|
119
|
-
@scope = session_info[:name]
|
|
120
|
-
@constrained_fields = []
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|