active_scaffold 3.0.26 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- 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,111 +1,108 @@
|
|
1
1
|
module ActionView
|
2
2
|
class LookupContext
|
3
3
|
module ViewPaths
|
4
|
-
def find_all_templates(name,
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
def find_all_templates(name, partial = false, locals = {})
|
5
|
+
prefixes.collect do |prefix|
|
6
|
+
view_paths.collect do |resolver|
|
7
|
+
temp_args = *args_for_lookup(name, [prefix], partial, locals)
|
8
|
+
temp_args[1] = temp_args[1][0]
|
9
|
+
resolver.find_all(*temp_args)
|
10
|
+
end
|
11
|
+
end.flatten!
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
# wrap the action rendering for ActiveScaffold views
|
17
|
-
module ActionView::
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
last_view[:templates].
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
18
|
+
module ActionView::Helpers #:nodoc:
|
19
|
+
module RenderingHelper
|
20
|
+
#
|
21
|
+
# Adds two rendering options.
|
22
|
+
#
|
23
|
+
# ==render :super
|
24
|
+
#
|
25
|
+
# This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates.
|
26
|
+
# Useful if you want to wrap an existing template. Just call super!
|
27
|
+
#
|
28
|
+
# ==render :active_scaffold => #{controller.to_s}, options = {}+
|
29
|
+
#
|
30
|
+
# Lets you embed an ActiveScaffold by referencing the controller where it's configured.
|
31
|
+
#
|
32
|
+
# You may specify options[:constraints] for the embedded scaffold. These constraints have three effects:
|
33
|
+
# * the scaffold's only displays records matching the constraint
|
34
|
+
# * all new records created will be assigned the constrained values
|
35
|
+
# * constrained columns will be hidden (they're pretty boring at this point)
|
36
|
+
#
|
37
|
+
# You may also specify options[:conditions] for the embedded scaffold. These only do 1/3 of what
|
38
|
+
# constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid.
|
39
|
+
#
|
40
|
+
# Defining options[:label] lets you completely customize the list title for the embedded scaffold.
|
41
|
+
#
|
42
|
+
def render_with_active_scaffold(*args, &block)
|
43
|
+
if args.first == :super
|
44
|
+
last_view = view_stack.last || {:view => instance_variable_get(:@virtual_path).split('/').last}
|
45
|
+
options = args[1] || {}
|
46
|
+
options[:locals] ||= {}
|
47
|
+
options[:locals].reverse_merge!(last_view[:locals] || {})
|
48
|
+
if last_view[:templates].nil?
|
49
|
+
last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys)
|
50
|
+
last_view[:templates].shift
|
51
|
+
end
|
52
|
+
options[:template] = last_view[:templates].shift
|
53
|
+
view_stack << last_view
|
54
|
+
result = render_without_active_scaffold options
|
55
|
+
view_stack.pop
|
56
|
+
result
|
57
|
+
elsif args.first.is_a? Hash and args.first[:active_scaffold]
|
58
|
+
require 'digest/md5'
|
59
|
+
options = args.first
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
61
|
+
remote_controller = options[:active_scaffold]
|
62
|
+
constraints = options[:constraints]
|
63
|
+
conditions = options[:conditions]
|
64
|
+
eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s)
|
65
|
+
session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}}
|
66
|
+
options[:params] ||= {}
|
67
|
+
options[:params].merge! :eid => eid, :embedded => true
|
68
|
+
|
69
|
+
id = "as_#{eid}-embedded"
|
70
|
+
url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])
|
71
|
+
|
72
|
+
if controller.respond_to?(:render_component_into_view)
|
73
|
+
controller.send(:render_component_into_view, url_options)
|
74
|
+
else
|
75
|
+
content_tag(:div, :id => id, :class => 'active-scaffold-component') do
|
76
|
+
url = url_for(url_options)
|
77
|
+
content_tag(:div, :class => 'active-scaffold-header') do
|
78
|
+
content_tag :h2, link_to(args.first[:label] || active_scaffold_config_for(remote_controller.to_s.singularize).list.label, url, :remote => true)
|
79
|
+
end <<
|
80
|
+
if ActiveScaffold.js_framework == :prototype
|
81
|
+
javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});")
|
82
|
+
elsif ActiveScaffold.js_framework == :jquery
|
83
|
+
javascript_tag("$('##{id}').load('#{url}');")
|
84
|
+
end
|
81
85
|
end
|
82
86
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
if current_view.present?
|
92
|
-
@view_stack ||= []
|
93
|
-
@view_stack << current_view
|
87
|
+
|
88
|
+
else
|
89
|
+
options = args.first
|
90
|
+
if options.is_a?(Hash)
|
91
|
+
current_view = {:view => options[:partial], :partial => true} if options[:partial]
|
92
|
+
current_view = {:view => options[:template], :partial => false} if current_view.nil? && options[:template]
|
93
|
+
current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals]
|
94
|
+
view_stack << current_view if current_view.present?
|
94
95
|
end
|
96
|
+
result = render_without_active_scaffold(*args, &block)
|
97
|
+
view_stack.pop if current_view.present?
|
98
|
+
result
|
95
99
|
end
|
96
|
-
result = render_without_active_scaffold(*args, &block)
|
97
|
-
@view_stack.pop if current_view.present?
|
98
|
-
result
|
99
100
|
end
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
def partial_pieces(partial_path)
|
105
|
-
if partial_path.include?('/')
|
106
|
-
return File.dirname(partial_path), File.basename(partial_path)
|
107
|
-
else
|
108
|
-
return controller.class.controller_path, partial_path
|
101
|
+
alias_method_chain :render, :active_scaffold
|
102
|
+
|
103
|
+
def view_stack
|
104
|
+
@_view_stack ||= []
|
109
105
|
end
|
106
|
+
|
110
107
|
end
|
111
108
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module ActionView
|
2
2
|
class LookupContext
|
3
|
-
attr_accessor :uses_active_scaffold
|
4
3
|
module ViewPaths
|
5
4
|
def find_all_templates(name, partial = false, locals = {})
|
6
5
|
prefixes.collect do |prefix|
|
@@ -12,17 +11,6 @@ module ActionView
|
|
12
11
|
end.flatten!
|
13
12
|
end
|
14
13
|
end
|
15
|
-
|
16
|
-
# Overload formats= to expand ["*/*"] values and automatically
|
17
|
-
# add :html as fallback to :js.
|
18
|
-
def formats=(values)
|
19
|
-
debugger
|
20
|
-
if values == [:js] && uses_active_scaffold
|
21
|
-
_set_detail(:formats, values) if values != @details[:formats]
|
22
|
-
else
|
23
|
-
super(values)
|
24
|
-
end
|
25
|
-
end
|
26
14
|
end
|
27
15
|
end
|
28
16
|
|
@@ -61,7 +49,7 @@ module ActionView::Helpers #:nodoc:
|
|
61
49
|
last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys)
|
62
50
|
last_view[:templates].shift
|
63
51
|
end
|
64
|
-
options[:
|
52
|
+
options[:file] = last_view[:templates].shift
|
65
53
|
view_stack << last_view
|
66
54
|
result = render_without_active_scaffold options
|
67
55
|
view_stack.pop
|
@@ -1,13 +1,22 @@
|
|
1
1
|
# Bugfix: building an sti model from an association fails
|
2
2
|
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6306-collection-associations-build-method-not-supported-for-sti
|
3
|
+
# https://github.com/rails/rails/issues/815
|
4
|
+
# https://github.com/rails/rails/pull/1686
|
3
5
|
ActiveRecord::Reflection::AssociationReflection.class_eval do
|
4
|
-
def
|
5
|
-
|
6
|
-
if
|
7
|
-
|
8
|
-
sti_model.to_s.camelize.constantize.new(*opts)
|
6
|
+
def klass_with_sti(*opts)
|
7
|
+
sti_col = klass.inheritance_column
|
8
|
+
if (h = opts.first).is_a? Hash and (passed_type = ( h[sti_col] || h[sti_col.to_sym] )) and (new_klass = active_record.send(:compute_type, passed_type)) < klass
|
9
|
+
new_klass
|
9
10
|
else
|
10
|
-
klass
|
11
|
+
klass
|
11
12
|
end
|
12
13
|
end
|
13
|
-
|
14
|
+
def build_association(*opts, &block)
|
15
|
+
self.original_build_association_called = true
|
16
|
+
klass_with_sti(*opts).new(*opts, &block)
|
17
|
+
end
|
18
|
+
def create_association(*opts, &block)
|
19
|
+
self.original_build_association_called = true
|
20
|
+
klass_with_sti(*opts).create(*opts, &block)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Relation
|
3
|
+
def target=(records)
|
4
|
+
@loaded = true
|
5
|
+
@records = records
|
6
|
+
@records
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
module ActiveRecord
|
11
|
+
module Associations
|
12
|
+
class CollectionProxy
|
13
|
+
delegate :target=, :to => :@association
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,26 +1,28 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module Reflection
|
3
3
|
class AssociationReflection #:nodoc:
|
4
|
-
def
|
5
|
-
|
4
|
+
def inverse_for?(klass)
|
5
|
+
inverse_class = inverse_of.try(:active_record)
|
6
|
+
inverse_class.present? && (inverse_class == klass || klass < inverse_class)
|
6
7
|
end
|
7
8
|
|
8
9
|
attr_writer :reverse
|
9
10
|
def reverse
|
10
|
-
|
11
|
-
reverse_matches = reverse_matches_for(self.class_name.constantize) rescue nil
|
12
|
-
# grab first association, or make a wild guess
|
13
|
-
@reverse = reverse_matches.blank? ? false : reverse_matches.first.name
|
14
|
-
end
|
15
|
-
@reverse
|
11
|
+
@reverse ||= inverse_of.try(:name)
|
16
12
|
end
|
17
13
|
|
14
|
+
def inverse_of_with_autodetect
|
15
|
+
inverse_of_without_autodetect || autodetect_inverse
|
16
|
+
end
|
17
|
+
alias_method_chain :inverse_of, :autodetect
|
18
|
+
|
18
19
|
protected
|
19
20
|
|
20
|
-
def
|
21
|
+
def autodetect_inverse
|
22
|
+
return nil if options[:polymorphic]
|
21
23
|
reverse_matches = []
|
22
24
|
|
23
|
-
# stage 1 filter: collect associations that point back to this model and use the same
|
25
|
+
# stage 1 filter: collect associations that point back to this model and use the same foreign_key
|
24
26
|
klass.reflect_on_all_associations.each do |assoc|
|
25
27
|
if self.options[:through]
|
26
28
|
# only iterate has_many :through associations
|
@@ -40,9 +42,9 @@ module ActiveRecord
|
|
40
42
|
when 1
|
41
43
|
next
|
42
44
|
|
43
|
-
# otherwise, match them based on the
|
45
|
+
# otherwise, match them based on the foreign_key
|
44
46
|
when 0
|
45
|
-
next unless assoc.
|
47
|
+
next unless assoc.foreign_key.to_sym == self.foreign_key.to_sym
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
@@ -54,7 +56,7 @@ module ActiveRecord
|
|
54
56
|
self.active_record.to_s.underscore.include? assoc.name.to_s.pluralize.singularize
|
55
57
|
end if reverse_matches.length > 1
|
56
58
|
|
57
|
-
reverse_matches
|
59
|
+
reverse_matches.first
|
58
60
|
end
|
59
61
|
|
60
62
|
end
|
@@ -48,7 +48,7 @@ class ActiveRecord::Base
|
|
48
48
|
# returns true otherwise, even when none of the associations have been instantiated. build wrapper methods accordingly.
|
49
49
|
def with_unsaved_associated
|
50
50
|
associations_for_update.all? do |association|
|
51
|
-
association_proxy =
|
51
|
+
association_proxy = send(association.name)
|
52
52
|
if association_proxy
|
53
53
|
records = association_proxy
|
54
54
|
records = [records] unless records.is_a? Array # convert singular associations into collections for ease of use
|
@@ -34,12 +34,13 @@ module ActiveScaffold
|
|
34
34
|
# TODO: this should reside on the column, not the controller
|
35
35
|
def condition_for_column(column, value, text_search = :full)
|
36
36
|
like_pattern = like_pattern(text_search)
|
37
|
+
if self.respond_to?("condition_for_#{column.name}_column")
|
38
|
+
return self.send("condition_for_#{column.name}_column", column, value, like_pattern)
|
39
|
+
end
|
37
40
|
return unless column and column.search_sql and not value.blank?
|
38
|
-
search_ui = column.search_ui || column.column.type
|
41
|
+
search_ui = column.search_ui || column.column.try(:type)
|
39
42
|
begin
|
40
|
-
if self.respond_to?("condition_for_#{
|
41
|
-
self.send("condition_for_#{column.name}_column", column, value, like_pattern)
|
42
|
-
elsif self.respond_to?("condition_for_#{search_ui}_type")
|
43
|
+
if search_ui && self.respond_to?("condition_for_#{search_ui}_type")
|
43
44
|
self.send("condition_for_#{search_ui}_type", column, value, like_pattern)
|
44
45
|
else
|
45
46
|
unless column.search_sql.instance_of? Proc
|
@@ -95,7 +96,7 @@ module ActiveScaffold
|
|
95
96
|
elsif value[:from].blank?
|
96
97
|
nil
|
97
98
|
elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt])
|
98
|
-
["#{column.search_sql}
|
99
|
+
["#{column.search_sql} LIKE ?", value[:opt].sub('?', value[:from])]
|
99
100
|
elsif value[:opt] == 'BETWEEN'
|
100
101
|
["#{column.search_sql} BETWEEN ? AND ?", value[:from], value[:to]]
|
101
102
|
elsif ActiveScaffold::Finder::NumericComparators.include?(value[:opt])
|
@@ -245,51 +246,67 @@ module ActiveScaffold
|
|
245
246
|
return record
|
246
247
|
end
|
247
248
|
|
248
|
-
# returns a
|
249
|
-
# options may include:
|
249
|
+
# returns a hash with options to find records
|
250
|
+
# valid options may include:
|
250
251
|
# * :sorting - a Sorting DataStructure (basically an array of hashes of field => direction, e.g. [{:field1 => 'asc'}, {:field2 => 'desc'}]). please note that multi-column sorting has some limitations: if any column in a multi-field sort uses method-based sorting, it will be ignored. method sorting only works for single-column sorting.
|
251
252
|
# * :per_page
|
252
253
|
# * :page
|
253
|
-
|
254
|
-
|
255
|
-
options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination
|
254
|
+
def finder_options(options = {})
|
255
|
+
options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination, :select
|
256
256
|
|
257
257
|
search_conditions = all_conditions
|
258
258
|
full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes)
|
259
|
-
options[:per_page] ||= 999999999
|
260
|
-
options[:page] ||= 1
|
261
|
-
options[:count_includes] ||= full_includes unless search_conditions.nil?
|
262
259
|
|
263
|
-
klass = beginning_of_chain
|
264
|
-
|
265
260
|
# create a general-use options array that's compatible with Rails finders
|
266
261
|
finder_options = { :order => options[:sorting].try(:clause),
|
267
262
|
:where => search_conditions,
|
268
263
|
:joins => joins_for_finder,
|
269
|
-
:includes =>
|
264
|
+
:includes => full_includes}
|
270
265
|
|
271
266
|
finder_options.merge! custom_finder_options
|
267
|
+
finder_options
|
268
|
+
end
|
269
|
+
|
270
|
+
# Returns a hash with options to count records, rejecting select and order options
|
271
|
+
# See finder_options for valid options
|
272
|
+
def count_options(find_options = {}, count_includes = nil)
|
273
|
+
count_includes ||= find_options[:includes] unless find_options[:where].nil?
|
274
|
+
options = find_options.reject{|k,v| [:select, :order].include? k}
|
275
|
+
options[:includes] = count_includes
|
276
|
+
options
|
277
|
+
end
|
278
|
+
|
279
|
+
# returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters
|
280
|
+
# See finder_options for valid options
|
281
|
+
# TODO: this should reside on the model, not the controller
|
282
|
+
def find_page(options = {})
|
283
|
+
options[:per_page] ||= 999999999
|
284
|
+
options[:page] ||= 1
|
272
285
|
|
286
|
+
find_options = finder_options(options)
|
287
|
+
klass = beginning_of_chain
|
288
|
+
|
273
289
|
# NOTE: we must use :include in the count query, because some conditions may reference other tables
|
274
|
-
|
275
|
-
|
290
|
+
if options[:pagination] && options[:pagination] != :infinite
|
291
|
+
count_query = append_to_query(klass, count_options(find_options, options[:count_includes]))
|
292
|
+
count = count_query.count unless options[:pagination] == :infinite
|
293
|
+
end
|
276
294
|
|
277
295
|
# Converts count to an integer if ActiveRecord returned an OrderedHash
|
278
|
-
# that happens when
|
296
|
+
# that happens when find_options contains a :group key
|
279
297
|
count = count.length if count.is_a? ActiveSupport::OrderedHash
|
280
|
-
finder_options.merge! :includes => full_includes
|
281
298
|
|
282
299
|
# we build the paginator differently for method- and sql-based sorting
|
283
300
|
if options[:sorting] and options[:sorting].sorts_by_method?
|
284
301
|
pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
|
285
|
-
sorted_collection = sort_collection_by_column(append_to_query(klass,
|
302
|
+
sorted_collection = sort_collection_by_column(append_to_query(klass, find_options).all, *options[:sorting].first)
|
286
303
|
sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination]
|
287
304
|
sorted_collection
|
288
305
|
end
|
289
306
|
else
|
290
307
|
pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
|
291
|
-
|
292
|
-
append_to_query(klass,
|
308
|
+
find_options.merge!(:offset => offset, :limit => per_page) if options[:pagination]
|
309
|
+
append_to_query(klass, find_options).all
|
293
310
|
end
|
294
311
|
end
|
295
312
|
pager.page(options[:page])
|