active_scaffold 3.4.17 → 3.4.18
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.
- checksums.yaml +4 -4
- data/CHANGELOG +12 -1
- data/README.md +8 -4
- data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
- data/app/assets/stylesheets/active_scaffold.scss +1 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
- data/app/assets/stylesheets/blue-theme.css +1 -1
- data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
- data/lib/active_scaffold.rb +16 -16
- data/lib/active_scaffold/actions/common_search.rb +13 -11
- data/lib/active_scaffold/actions/core.rb +85 -78
- data/lib/active_scaffold/actions/create.rb +29 -28
- data/lib/active_scaffold/actions/delete.rb +17 -17
- data/lib/active_scaffold/actions/field_search.rb +18 -19
- data/lib/active_scaffold/actions/list.rb +30 -22
- data/lib/active_scaffold/actions/mark.rb +1 -1
- data/lib/active_scaffold/actions/nested.rb +78 -65
- data/lib/active_scaffold/actions/search.rb +13 -10
- data/lib/active_scaffold/actions/show.rb +10 -6
- data/lib/active_scaffold/actions/subform.rb +1 -2
- data/lib/active_scaffold/actions/update.rb +39 -31
- data/lib/active_scaffold/active_record_permissions.rb +14 -15
- data/lib/active_scaffold/attribute_params.rb +42 -43
- data/lib/active_scaffold/bridges.rb +22 -12
- data/lib/active_scaffold/bridges/ancestry.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
- data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
- data/lib/active_scaffold/bridges/cancan.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
- data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
- data/lib/active_scaffold/bridges/chosen.rb +1 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
- data/lib/active_scaffold/bridges/country_helper.rb +1 -1
- data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
- data/lib/active_scaffold/bridges/date_picker.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
- data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
- data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/file_column.rb +5 -5
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
- data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
- data/lib/active_scaffold/bridges/paperclip.rb +5 -5
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
- data/lib/active_scaffold/bridges/record_select.rb +1 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
- data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
- data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
- data/lib/active_scaffold/config/base.rb +9 -10
- data/lib/active_scaffold/config/core.rb +24 -29
- data/lib/active_scaffold/config/create.rb +0 -1
- data/lib/active_scaffold/config/field_search.rb +8 -10
- data/lib/active_scaffold/config/form.rb +5 -5
- data/lib/active_scaffold/config/list.rb +21 -20
- data/lib/active_scaffold/config/mark.rb +3 -3
- data/lib/active_scaffold/config/nested.rb +11 -10
- data/lib/active_scaffold/config/search.rb +2 -3
- data/lib/active_scaffold/config/show.rb +1 -1
- data/lib/active_scaffold/config/update.rb +1 -2
- data/lib/active_scaffold/configurable.rb +9 -11
- data/lib/active_scaffold/constraints.rb +9 -8
- data/lib/active_scaffold/core.rb +72 -84
- data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
- data/lib/active_scaffold/data_structures/action_link.rb +43 -43
- data/lib/active_scaffold/data_structures/action_links.rb +17 -15
- data/lib/active_scaffold/data_structures/actions.rb +5 -5
- data/lib/active_scaffold/data_structures/bridge.rb +6 -3
- data/lib/active_scaffold/data_structures/column.rb +110 -89
- data/lib/active_scaffold/data_structures/columns.rb +3 -3
- data/lib/active_scaffold/data_structures/error_message.rb +4 -6
- data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
- data/lib/active_scaffold/data_structures/set.rb +7 -8
- data/lib/active_scaffold/data_structures/sorting.rb +38 -33
- data/lib/active_scaffold/delayed_setup.rb +5 -6
- data/lib/active_scaffold/engine.rb +4 -4
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
- data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
- data/lib/active_scaffold/extensions/localize.rb +1 -1
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
- data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
- data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
- data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
- data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
- data/lib/active_scaffold/finder.rb +90 -93
- data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
- data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
- data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
- data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
- data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
- data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
- data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
- data/lib/active_scaffold/marked_model.rb +10 -10
- data/lib/active_scaffold/paginator.rb +30 -34
- data/lib/active_scaffold/responds_to_parent.rb +27 -28
- data/lib/active_scaffold/tableless.rb +20 -15
- data/lib/active_scaffold/version.rb +1 -1
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
- data/shoulda_macros/macros.rb +27 -22
- data/test/bridges/bridge_test.rb +38 -29
- data/test/bridges/date_picker_test.rb +1 -1
- data/test/bridges/paper_trail_test.rb +17 -0
- data/test/bridges/paperclip_test.rb +3 -2
- data/test/bridges/tiny_mce_test.rb +5 -2
- data/test/company.rb +25 -30
- data/test/config/base_test.rb +1 -1
- data/test/config/core_test.rb +9 -9
- data/test/config/create_test.rb +14 -8
- data/test/config/delete_test.rb +4 -4
- data/test/config/field_search_test.rb +6 -6
- data/test/config/list_test.rb +16 -16
- data/test/config/nested_test.rb +4 -4
- data/test/config/search_test.rb +8 -8
- data/test/config/show_test.rb +6 -6
- data/test/config/subform_test.rb +1 -1
- data/test/config/update_test.rb +5 -5
- data/test/const_mocker.rb +4 -4
- data/test/data_structures/action_columns_test.rb +4 -5
- data/test/data_structures/action_link_test.rb +1 -0
- data/test/data_structures/action_links_test.rb +5 -5
- data/test/data_structures/column_test.rb +9 -9
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/error_message_test.rb +4 -5
- data/test/data_structures/set_test.rb +1 -2
- data/test/data_structures/sorting_test.rb +10 -10
- data/test/data_structures/validation_reflection_test.rb +8 -0
- data/test/extensions/routing_mapper_test.rb +2 -2
- data/test/helpers/list_column_helpers_test.rb +3 -2
- data/test/helpers/pagination_helpers_test.rb +5 -4
- data/test/helpers/search_column_helpers_test.rb +1 -1
- data/test/misc/active_record_permissions_test.rb +63 -50
- data/test/misc/attribute_params_test.rb +28 -26
- data/test/misc/calculation_test.rb +10 -3
- data/test/misc/configurable_test.rb +12 -13
- data/test/misc/constraints_test.rb +6 -6
- data/test/misc/convert_numbers_format_test.rb +7 -6
- data/test/misc/finder_test.rb +17 -12
- data/test/misc/lang_test.rb +3 -4
- data/test/misc/tableless_test.rb +2 -3
- data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
- data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
- data/test/mock_app/app/controllers/cars_controller.rb +1 -1
- data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
- data/test/mock_app/app/controllers/people_controller.rb +1 -1
- data/test/mock_app/app/models/file_model.rb +2 -2
- data/test/mock_app/app/models/person.rb +1 -1
- data/test/mock_app/config/application.rb +3 -3
- data/test/mock_app/config/boot.rb +1 -1
- data/test/mock_app/config/environment.rb +1 -0
- data/test/mock_app/config/environments/development.rb +0 -1
- data/test/mock_app/config/environments/production.rb +1 -1
- data/test/mock_app/db/schema.rb +14 -15
- data/test/model_stub.rb +13 -16
- data/test/run_all.rb +5 -7
- data/test/test_helper.rb +12 -9
- metadata +19 -3
|
@@ -15,8 +15,9 @@ module ActiveScaffold::Actions
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
protected
|
|
18
|
+
|
|
18
19
|
def response_location
|
|
19
|
-
url_for(params_for(:action =>
|
|
20
|
+
url_for(params_for(:action => 'show', :id => @record.to_param)) if successful?
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def new_respond_to_html
|
|
@@ -26,13 +27,13 @@ module ActiveScaffold::Actions
|
|
|
26
27
|
return_to_main
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
|
-
|
|
30
|
+
|
|
30
31
|
def new_respond_to_js
|
|
31
32
|
render(:partial => 'create_form')
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
def create_respond_to_html
|
|
35
|
-
if params[:iframe]=='true' # was this an iframe post ?
|
|
36
|
+
if params[:iframe] == 'true' # was this an iframe post ?
|
|
36
37
|
do_refresh_list if successful? && active_scaffold_config.create.refresh_list && !render_parent?
|
|
37
38
|
responds_to_parent do
|
|
38
39
|
render :action => 'on_create', :formats => [:js], :layout => false
|
|
@@ -40,10 +41,10 @@ module ActiveScaffold::Actions
|
|
|
40
41
|
else
|
|
41
42
|
if successful?
|
|
42
43
|
flash[:info] = as_(:created_model, :model => @record.to_label)
|
|
43
|
-
if action = active_scaffold_config.create.action_after_create
|
|
44
|
+
if (action = active_scaffold_config.create.action_after_create)
|
|
44
45
|
redirect_to params_for(:action => action, :id => @record.to_param)
|
|
45
46
|
elsif params[:dont_close]
|
|
46
|
-
redirect_to params_for(:action =>
|
|
47
|
+
redirect_to params_for(:action => 'new')
|
|
47
48
|
else
|
|
48
49
|
return_to_main
|
|
49
50
|
end
|
|
@@ -95,28 +96,25 @@ module ActiveScaffold::Actions
|
|
|
95
96
|
# If you want to customize this behavior, consider using the +before_create_save+ and +after_create_save+ callbacks.
|
|
96
97
|
def do_create(options = {})
|
|
97
98
|
attributes = options[:attributes] || params[:record]
|
|
98
|
-
|
|
99
|
-
active_scaffold_config.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
create_save(@record) unless options[:skip_save]
|
|
107
|
-
end
|
|
108
|
-
rescue ActiveRecord::ActiveRecordError => ex
|
|
109
|
-
flash[:error] = ex.message
|
|
110
|
-
self.successful = false
|
|
111
|
-
@record ||= new_model # ensure @record exists or display form will fail
|
|
99
|
+
active_scaffold_config.model.transaction do
|
|
100
|
+
@record = update_record_from_params(new_model, active_scaffold_config.create.columns, attributes)
|
|
101
|
+
apply_constraints_to_record(@record, :allow_autosave => true)
|
|
102
|
+
create_association_with_parent(@record) if nested?
|
|
103
|
+
before_create_save(@record)
|
|
104
|
+
# errors to @record can be added by update_record_from_params when association fails to set and ActiveRecord::RecordNotSaved is raised
|
|
105
|
+
self.successful = [@record.errors.empty? && @record.valid?, @record.associated_valid?].all? # this syntax avoids a short-circuit
|
|
106
|
+
create_save(@record) unless options[:skip_save]
|
|
112
107
|
end
|
|
108
|
+
rescue ActiveRecord::ActiveRecordError => ex
|
|
109
|
+
flash[:error] = ex.message
|
|
110
|
+
self.successful = false
|
|
111
|
+
@record ||= new_model # ensure @record exists or display form will fail
|
|
113
112
|
end
|
|
114
113
|
|
|
115
114
|
def create_save(record)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
end
|
|
115
|
+
return unless successful?
|
|
116
|
+
record.save! && record.save_associated!
|
|
117
|
+
after_create_save(record)
|
|
120
118
|
end
|
|
121
119
|
|
|
122
120
|
# override this method if you want to inject data in the record (or its associated objects) before the save
|
|
@@ -127,26 +125,29 @@ module ActiveScaffold::Actions
|
|
|
127
125
|
|
|
128
126
|
# The default security delegates to ActiveRecordPermissions.
|
|
129
127
|
# You may override the method to customize.
|
|
130
|
-
|
|
128
|
+
|
|
131
129
|
def create_ignore?
|
|
132
130
|
active_scaffold_config.list.always_show_create
|
|
133
131
|
end
|
|
134
|
-
|
|
132
|
+
|
|
135
133
|
def create_authorized?
|
|
136
134
|
if nested?
|
|
137
|
-
|
|
138
|
-
return false unless nested_authorized
|
|
135
|
+
return false if nested.readonly? || nested.readonly_through_association?(active_scaffold_config.create.columns)
|
|
139
136
|
end
|
|
140
137
|
authorized_for?(:crud_type => :create)
|
|
141
138
|
end
|
|
139
|
+
|
|
142
140
|
private
|
|
141
|
+
|
|
143
142
|
def create_authorized_filter
|
|
144
143
|
link = active_scaffold_config.create.link || active_scaffold_config.create.class.link
|
|
145
|
-
raise ActiveScaffold::ActionNotAllowed unless
|
|
144
|
+
raise ActiveScaffold::ActionNotAllowed unless send(link.security_method)
|
|
146
145
|
end
|
|
146
|
+
|
|
147
147
|
def new_formats
|
|
148
148
|
(default_formats + active_scaffold_config.formats).uniq
|
|
149
149
|
end
|
|
150
|
+
|
|
150
151
|
def create_formats
|
|
151
152
|
(default_formats + active_scaffold_config.formats + active_scaffold_config.create.formats).uniq
|
|
152
153
|
end
|
|
@@ -7,18 +7,14 @@ module ActiveScaffold::Actions
|
|
|
7
7
|
def destroy
|
|
8
8
|
params.delete :destroy_action
|
|
9
9
|
process_action_link_action(:destroy) do |record|
|
|
10
|
-
do_destroy
|
|
10
|
+
do_destroy(record)
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
protected
|
|
15
|
+
|
|
15
16
|
def destroy_respond_to_html
|
|
16
|
-
if self.successful?
|
|
17
|
-
flash[:info] = as_(:deleted_model, :model => @record.to_label)
|
|
18
|
-
else
|
|
19
|
-
#error_message_for not available in controller...
|
|
20
|
-
#flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)
|
|
21
|
-
end
|
|
17
|
+
flash[:info] = as_(:deleted_model, :model => @record.to_label) if self.successful?
|
|
22
18
|
return_to_main
|
|
23
19
|
end
|
|
24
20
|
|
|
@@ -28,15 +24,15 @@ module ActiveScaffold::Actions
|
|
|
28
24
|
end
|
|
29
25
|
|
|
30
26
|
def destroy_respond_to_xml
|
|
31
|
-
render :xml => successful? ?
|
|
27
|
+
render :xml => successful? ? '' : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
|
|
32
28
|
end
|
|
33
29
|
|
|
34
30
|
def destroy_respond_to_json
|
|
35
|
-
render :text => successful? ?
|
|
31
|
+
render :text => successful? ? '' : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
|
|
36
32
|
end
|
|
37
33
|
|
|
38
34
|
def destroy_respond_to_yaml
|
|
39
|
-
render :text => successful? ?
|
|
35
|
+
render :text => successful? ? '' : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
|
40
36
|
end
|
|
41
37
|
|
|
42
38
|
def destroy_find_record
|
|
@@ -45,12 +41,12 @@ module ActiveScaffold::Actions
|
|
|
45
41
|
|
|
46
42
|
# A simple method to handle the actual destroying of a record
|
|
47
43
|
# May be overridden to customize the behavior
|
|
48
|
-
def do_destroy
|
|
49
|
-
|
|
44
|
+
def do_destroy(record)
|
|
45
|
+
record ||= destroy_find_record
|
|
50
46
|
begin
|
|
51
|
-
self.successful =
|
|
52
|
-
rescue
|
|
53
|
-
flash[:warning] = as_(:cant_destroy_record, :record =>
|
|
47
|
+
self.successful = record.destroy
|
|
48
|
+
rescue StandardError => ex
|
|
49
|
+
flash[:warning] = as_(:cant_destroy_record, :record => record.to_label)
|
|
54
50
|
self.successful = false
|
|
55
51
|
logger.debug ex.message
|
|
56
52
|
logger.debug ex.backtrace.join("\n")
|
|
@@ -62,14 +58,18 @@ module ActiveScaffold::Actions
|
|
|
62
58
|
def delete_authorized?(record = nil)
|
|
63
59
|
(!nested? || !nested.readonly?) && (record || self).send(:authorized_for?, :crud_type => :delete)
|
|
64
60
|
end
|
|
61
|
+
|
|
65
62
|
def delete_ignore?(record = nil)
|
|
66
|
-
(nested? && nested.readonly?) || !
|
|
63
|
+
(nested? && nested.readonly?) || !send(:authorized_for?, :crud_type => :delete)
|
|
67
64
|
end
|
|
65
|
+
|
|
68
66
|
private
|
|
67
|
+
|
|
69
68
|
def delete_authorized_filter
|
|
70
69
|
link = active_scaffold_config.delete.link || active_scaffold_config.delete.class.link
|
|
71
|
-
raise ActiveScaffold::ActionNotAllowed unless
|
|
70
|
+
raise ActiveScaffold::ActionNotAllowed unless send(link.security_method)
|
|
72
71
|
end
|
|
72
|
+
|
|
73
73
|
def destroy_formats
|
|
74
74
|
(default_formats + active_scaffold_config.formats + active_scaffold_config.delete.formats).uniq
|
|
75
75
|
end
|
|
@@ -5,9 +5,8 @@ module ActiveScaffold::Actions
|
|
|
5
5
|
base.send :include, ActiveScaffold::Actions::CommonSearch
|
|
6
6
|
base.send :include, InstanceMethods
|
|
7
7
|
end
|
|
8
|
-
|
|
9
|
-
module InstanceMethods
|
|
10
8
|
|
|
9
|
+
module InstanceMethods
|
|
11
10
|
# FieldSearch uses params[:search] and not @record because search conditions do not always pass the Model's validations.
|
|
12
11
|
# This facilitates for example, textual searches against associations via .search_sql
|
|
13
12
|
def show_search
|
|
@@ -20,28 +19,27 @@ module ActiveScaffold::Actions
|
|
|
20
19
|
def search_partial
|
|
21
20
|
super || :field_search
|
|
22
21
|
end
|
|
23
|
-
|
|
22
|
+
|
|
24
23
|
def store_search_params_into_session
|
|
25
24
|
set_field_search_default_params(active_scaffold_config.field_search.default_params) unless active_scaffold_config.field_search.default_params.nil?
|
|
26
25
|
super
|
|
27
26
|
end
|
|
28
|
-
|
|
27
|
+
|
|
29
28
|
def set_field_search_default_params(default_params)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
29
|
+
return unless (params[:search].is_a?(String) || search_params.nil?) && params[:search].blank?
|
|
30
|
+
params[:search] = default_params.is_a?(Proc) ? instance_eval(&default_params) : default_params
|
|
33
31
|
end
|
|
34
|
-
|
|
32
|
+
|
|
35
33
|
def field_search_params
|
|
36
34
|
search_params.is_a?(Hash) ? search_params : {}
|
|
37
35
|
end
|
|
38
36
|
|
|
39
37
|
def field_search_respond_to_html
|
|
40
|
-
render(:action =>
|
|
38
|
+
render(:action => 'field_search')
|
|
41
39
|
end
|
|
42
|
-
|
|
40
|
+
|
|
43
41
|
def field_search_respond_to_js
|
|
44
|
-
render(:partial =>
|
|
42
|
+
render(:partial => 'field_search')
|
|
45
43
|
end
|
|
46
44
|
|
|
47
45
|
def do_search
|
|
@@ -53,15 +51,15 @@ module ActiveScaffold::Actions
|
|
|
53
51
|
next unless columns.include? key
|
|
54
52
|
column = active_scaffold_config.columns[key]
|
|
55
53
|
search_condition = self.class.condition_for_column(column, value, text_search)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
self.active_scaffold_conditions << search_condition
|
|
63
|
-
filtered_columns << column
|
|
54
|
+
next if search_condition.blank?
|
|
55
|
+
|
|
56
|
+
if active_scaffold_config.list.user.count_includes.nil? && column.includes.present? && list_columns.include?(column)
|
|
57
|
+
active_scaffold_references << column.includes
|
|
58
|
+
elsif column.search_joins.present?
|
|
59
|
+
active_scaffold_outer_joins << column.search_joins
|
|
64
60
|
end
|
|
61
|
+
active_scaffold_conditions << search_condition
|
|
62
|
+
filtered_columns << column
|
|
65
63
|
end
|
|
66
64
|
unless filtered_columns.blank?
|
|
67
65
|
@filtered = active_scaffold_config.field_search.human_conditions ? filtered_columns : true
|
|
@@ -78,6 +76,7 @@ module ActiveScaffold::Actions
|
|
|
78
76
|
end
|
|
79
77
|
|
|
80
78
|
private
|
|
79
|
+
|
|
81
80
|
def field_search_formats
|
|
82
81
|
(default_formats + active_scaffold_config.formats + active_scaffold_config.field_search.formats).uniq
|
|
83
82
|
end
|
|
@@ -14,6 +14,7 @@ module ActiveScaffold::Actions
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
protected
|
|
17
|
+
|
|
17
18
|
# get just a single row
|
|
18
19
|
def row
|
|
19
20
|
get_row
|
|
@@ -36,6 +37,7 @@ module ActiveScaffold::Actions
|
|
|
36
37
|
render :action => 'list'
|
|
37
38
|
end
|
|
38
39
|
end
|
|
40
|
+
|
|
39
41
|
def list_respond_to_js
|
|
40
42
|
if params[:adapter] || loading_embedded?
|
|
41
43
|
render(:partial => 'list_with_header')
|
|
@@ -44,12 +46,15 @@ module ActiveScaffold::Actions
|
|
|
44
46
|
render :partial => 'refresh_list', :formats => [:js]
|
|
45
47
|
end
|
|
46
48
|
end
|
|
49
|
+
|
|
47
50
|
def list_respond_to_xml
|
|
48
51
|
render :xml => response_object.to_xml(:only => list_columns_names + [active_scaffold_config.model.primary_key], :include => association_columns(list_columns_names), :methods => virtual_columns(list_columns_names)), :content_type => Mime::XML, :status => response_status
|
|
49
52
|
end
|
|
53
|
+
|
|
50
54
|
def list_respond_to_json
|
|
51
55
|
render :text => response_object.to_json(:only => list_columns_names + [active_scaffold_config.model.primary_key], :include => association_columns(list_columns_names), :methods => virtual_columns(list_columns_names)), :content_type => Mime::JSON, :status => response_status
|
|
52
56
|
end
|
|
57
|
+
|
|
53
58
|
def list_respond_to_yaml
|
|
54
59
|
render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names + [active_scaffold_config.model.primary_key], :include => association_columns(list_columns_names), :methods => virtual_columns(list_columns_names))).to_yaml, :content_type => Mime::YAML, :status => response_status
|
|
55
60
|
end
|
|
@@ -65,15 +70,16 @@ module ActiveScaffold::Actions
|
|
|
65
70
|
# The actual algorithm to prepare for the list view
|
|
66
71
|
def set_includes_for_columns(action = :list)
|
|
67
72
|
@cache_associations = true
|
|
68
|
-
columns =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
columns =
|
|
74
|
+
if respond_to?(:"#{action}_columns", true)
|
|
75
|
+
send(:"#{action}_columns")
|
|
76
|
+
else
|
|
77
|
+
active_scaffold_config.send(action).columns.collect_visible(:flatten => true)
|
|
78
|
+
end
|
|
73
79
|
sorting = active_scaffold_config.list.user.sorting
|
|
74
|
-
columns_for_joins, columns_for_includes = columns.select{ |c| c.includes.present? }.partition {|c| sorting.sorts_on? c }
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
columns_for_joins, columns_for_includes = columns.select { |c| c.includes.present? }.partition { |c| sorting.sorts_on? c }
|
|
81
|
+
active_scaffold_preload.concat columns_for_includes.map(&:includes).flatten.uniq
|
|
82
|
+
active_scaffold_references.concat columns_for_joins.map(&:includes).flatten.uniq
|
|
77
83
|
end
|
|
78
84
|
|
|
79
85
|
def get_row(crud_type_or_security_options = :read)
|
|
@@ -85,9 +91,9 @@ module ActiveScaffold::Actions
|
|
|
85
91
|
def do_list
|
|
86
92
|
set_includes_for_columns
|
|
87
93
|
|
|
88
|
-
options = {
|
|
89
|
-
|
|
90
|
-
paginate = (params[:format].nil?) ? (accepts? :html, :js) :
|
|
94
|
+
options = {:sorting => active_scaffold_config.list.user.sorting,
|
|
95
|
+
:count_includes => active_scaffold_config.list.user.count_includes}
|
|
96
|
+
paginate = (params[:format].nil?) ? (accepts? :html, :js) : %w(html js).include?(params[:format])
|
|
91
97
|
options[:pagination] = active_scaffold_config.list.pagination if paginate
|
|
92
98
|
if options[:pagination]
|
|
93
99
|
options.merge!(
|
|
@@ -120,15 +126,15 @@ module ActiveScaffold::Actions
|
|
|
120
126
|
end
|
|
121
127
|
|
|
122
128
|
def each_record_in_page
|
|
123
|
-
|
|
129
|
+
current_page = active_scaffold_config.list.user.page
|
|
124
130
|
do_search if respond_to? :do_search, true
|
|
125
|
-
active_scaffold_config.list.user.page =
|
|
131
|
+
active_scaffold_config.list.user.page = current_page
|
|
126
132
|
do_list
|
|
127
|
-
@page.items.each {|record| yield record}
|
|
133
|
+
@page.items.each { |record| yield record }
|
|
128
134
|
end
|
|
129
135
|
|
|
130
136
|
def each_record_in_scope
|
|
131
|
-
scoped_query.each {|record| yield record}
|
|
137
|
+
scoped_query.each { |record| yield record }
|
|
132
138
|
end
|
|
133
139
|
|
|
134
140
|
def scoped_query
|
|
@@ -150,19 +156,21 @@ module ActiveScaffold::Actions
|
|
|
150
156
|
do_refresh_list unless @record.present?
|
|
151
157
|
super
|
|
152
158
|
end
|
|
153
|
-
|
|
159
|
+
|
|
154
160
|
def objects_for_etag
|
|
155
|
-
objects =
|
|
156
|
-
if
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
objects =
|
|
162
|
+
if @list_columns
|
|
163
|
+
if active_scaffold_config.list.calculate_etag
|
|
164
|
+
@records.to_a
|
|
165
|
+
elsif active_scaffold_config.list.user.sorting
|
|
166
|
+
{:etag => active_scaffold_config.list.user.sorting.clause}
|
|
167
|
+
end
|
|
160
168
|
end
|
|
161
|
-
end
|
|
162
169
|
objects.present? ? objects : super
|
|
163
170
|
end
|
|
164
171
|
|
|
165
172
|
private
|
|
173
|
+
|
|
166
174
|
def list_authorized_filter
|
|
167
175
|
raise ActiveScaffold::ActionNotAllowed unless list_authorized?
|
|
168
176
|
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
module ActiveScaffold::Actions
|
|
2
2
|
module Mark
|
|
3
|
-
|
|
4
3
|
def self.included(base)
|
|
5
4
|
base.before_filter :mark_authorized?, :only => :mark
|
|
6
5
|
base.before_filter :assign_marked_records_to_model
|
|
@@ -19,6 +18,7 @@ module ActiveScaffold::Actions
|
|
|
19
18
|
end
|
|
20
19
|
respond_to_action(:mark)
|
|
21
20
|
end
|
|
21
|
+
|
|
22
22
|
protected
|
|
23
23
|
|
|
24
24
|
def mark_respond_to_html
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
module ActiveScaffold::Actions
|
|
2
2
|
# The Nested module basically handles automatically linking controllers together. It does this by creating column links with the right parameters, and by providing any supporting systems (like a /:controller/nested action for returning associated scaffolds).
|
|
3
3
|
module Nested
|
|
4
|
-
|
|
5
4
|
def self.included(base)
|
|
6
5
|
super
|
|
7
6
|
base.module_eval do
|
|
8
7
|
before_filter :set_nested
|
|
9
8
|
before_filter :configure_nested
|
|
10
|
-
include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many}
|
|
9
|
+
include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? { |a| a.macro == :has_and_belongs_to_many }
|
|
11
10
|
end
|
|
12
11
|
base.before_filter :include_habtm_actions
|
|
13
12
|
base.helper_method :nested
|
|
@@ -15,64 +14,68 @@ module ActiveScaffold::Actions
|
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
protected
|
|
17
|
+
|
|
18
18
|
def nested
|
|
19
19
|
set_nested unless defined? @nested
|
|
20
20
|
@nested
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
def nested?
|
|
24
24
|
!nested.nil?
|
|
25
25
|
end
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
def set_nested
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
end
|
|
28
|
+
return unless params[:parent_scaffold] && (params[:association] || params[:named_scope])
|
|
29
|
+
@nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params)
|
|
30
|
+
register_constraints_with_action_columns(@nested.constrained_fields) unless @nested.nil?
|
|
32
31
|
end
|
|
33
|
-
|
|
32
|
+
|
|
34
33
|
def configure_nested
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
return unless nested?
|
|
35
|
+
active_scaffold_config.list.user.label = nested_label
|
|
36
|
+
active_scaffold_config.list.user.nested_default_sorting = nested_default_sorting if nested.sorted? && !active_scaffold_config.nested.ignore_order_from_association
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def nested_label
|
|
40
|
+
if nested.belongs_to?
|
|
41
|
+
as_(:nested_of_model, :nested_model => active_scaffold_config.model.model_name.human, :parent_model => nested_parent_record.to_label)
|
|
42
|
+
else
|
|
43
|
+
as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label)
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
|
-
|
|
46
|
+
|
|
47
|
+
def nested_default_sorting
|
|
48
|
+
{:table_name => active_scaffold_config.model.model_name, :default_sorting => nested.default_sorting}
|
|
49
|
+
end
|
|
50
|
+
|
|
47
51
|
def nested_authorized?(record = nil)
|
|
48
52
|
true
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
def include_habtm_actions
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
end
|
|
56
|
+
return unless nested?
|
|
57
|
+
if nested.habtm?
|
|
58
|
+
# Production mode is ok with adding a link everytime the scaffold is nested - we are not ok with that.
|
|
59
|
+
active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing']
|
|
60
|
+
if active_scaffold_config.nested.shallow_delete
|
|
61
|
+
active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing']
|
|
62
|
+
if active_scaffold_config.actions.include?(:delete)
|
|
63
|
+
active_scaffold_config.action_links.delete('delete') if active_scaffold_config.action_links['delete']
|
|
61
64
|
end
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
end
|
|
66
|
+
else
|
|
67
|
+
# Production mode is caching this link into a non nested scaffold
|
|
68
|
+
active_scaffold_config.action_links.delete('new_existing') if active_scaffold_config.action_links['new_existing']
|
|
69
|
+
|
|
70
|
+
if active_scaffold_config.nested.shallow_delete
|
|
71
|
+
active_scaffold_config.action_links.delete('destroy_existing') if active_scaffold_config.action_links['destroy_existing']
|
|
72
|
+
if active_scaffold_config.actions.include?(:delete)
|
|
73
|
+
active_scaffold_config.action_links.add(ActiveScaffold::Config::Delete.link) unless active_scaffold_config.action_links['delete']
|
|
71
74
|
end
|
|
72
75
|
end
|
|
73
76
|
end
|
|
74
77
|
end
|
|
75
|
-
|
|
78
|
+
|
|
76
79
|
def beginning_of_chain
|
|
77
80
|
if nested? && nested.association
|
|
78
81
|
if nested.association.collection?
|
|
@@ -85,10 +88,11 @@ module ActiveScaffold::Actions
|
|
|
85
88
|
active_scaffold_config.model.where(nested.child_association.foreign_key => nested_parent_record.send(nested.association.association_primary_key))
|
|
86
89
|
elsif nested.association.belongs_to?
|
|
87
90
|
chain = active_scaffold_config.model.joins(nested.child_association.name)
|
|
88
|
-
table_name =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
table_name =
|
|
92
|
+
if active_scaffold_config.model == nested.association.active_record
|
|
93
|
+
dependency = ActiveRecord::Associations::JoinDependency.new(chain.klass, chain.joins_values, [])
|
|
94
|
+
dependency.join_associations.find { |join| join.try(:reflection).try(:name) == nested.child_association.name }.try(:table).try(:right)
|
|
95
|
+
end
|
|
92
96
|
table_name ||= nested.association.active_record.table_name
|
|
93
97
|
chain.where(table_name => {nested.association.active_record.primary_key => nested_parent_record}).readonly(false)
|
|
94
98
|
end
|
|
@@ -102,23 +106,21 @@ module ActiveScaffold::Actions
|
|
|
102
106
|
def nested_parent_record(crud = :read)
|
|
103
107
|
@nested_parent_record ||= find_if_allowed(nested.parent_id, crud, nested.parent_model)
|
|
104
108
|
end
|
|
105
|
-
|
|
109
|
+
|
|
106
110
|
def create_association_with_parent(record)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
record.send("#{nested.child_association.name}").send(:<<, parent)
|
|
116
|
-
end unless parent.nil?
|
|
117
|
-
end
|
|
111
|
+
# has_many is done by beginning_of_chain and rails
|
|
112
|
+
return unless (nested.belongs_to? || nested.has_one? || nested.habtm?) && nested.child_association
|
|
113
|
+
return if (parent = nested_parent_record).nil?
|
|
114
|
+
case nested.child_association.macro
|
|
115
|
+
when :has_one, :belongs_to
|
|
116
|
+
record.send("#{nested.child_association.name}=", parent)
|
|
117
|
+
when :has_many, :has_and_belongs_to_many
|
|
118
|
+
record.send("#{nested.child_association.name}").send(:<<, parent)
|
|
118
119
|
end
|
|
119
120
|
end
|
|
120
|
-
|
|
121
|
+
|
|
121
122
|
private
|
|
123
|
+
|
|
122
124
|
def nested_formats
|
|
123
125
|
(default_formats + active_scaffold_config.formats + active_scaffold_config.nested.formats).uniq
|
|
124
126
|
end
|
|
@@ -127,7 +129,6 @@ end
|
|
|
127
129
|
|
|
128
130
|
module ActiveScaffold::Actions::Nested
|
|
129
131
|
module ChildMethods
|
|
130
|
-
|
|
131
132
|
def self.included(base)
|
|
132
133
|
super
|
|
133
134
|
end
|
|
@@ -147,8 +148,9 @@ module ActiveScaffold::Actions::Nested
|
|
|
147
148
|
do_destroy_existing
|
|
148
149
|
respond_to_action(:destroy_existing)
|
|
149
150
|
end
|
|
150
|
-
|
|
151
|
+
|
|
151
152
|
protected
|
|
153
|
+
|
|
152
154
|
def new_existing_respond_to_html
|
|
153
155
|
if successful?
|
|
154
156
|
render(:action => 'add_existing_form')
|
|
@@ -156,9 +158,11 @@ module ActiveScaffold::Actions::Nested
|
|
|
156
158
|
return_to_main
|
|
157
159
|
end
|
|
158
160
|
end
|
|
161
|
+
|
|
159
162
|
def new_existing_respond_to_js
|
|
160
163
|
render(:partial => 'add_existing_form')
|
|
161
164
|
end
|
|
165
|
+
|
|
162
166
|
def add_existing_respond_to_html
|
|
163
167
|
if successful?
|
|
164
168
|
flash[:info] = as_(:created_model, :model => @record.to_label)
|
|
@@ -167,6 +171,7 @@ module ActiveScaffold::Actions::Nested
|
|
|
167
171
|
render(:action => 'add_existing_form')
|
|
168
172
|
end
|
|
169
173
|
end
|
|
174
|
+
|
|
170
175
|
def add_existing_respond_to_js
|
|
171
176
|
if successful?
|
|
172
177
|
render :action => 'add_existing'
|
|
@@ -174,15 +179,19 @@ module ActiveScaffold::Actions::Nested
|
|
|
174
179
|
render :action => 'form_messages'
|
|
175
180
|
end
|
|
176
181
|
end
|
|
182
|
+
|
|
177
183
|
def add_existing_respond_to_xml
|
|
178
184
|
render :xml => response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
|
|
179
185
|
end
|
|
186
|
+
|
|
180
187
|
def add_existing_respond_to_json
|
|
181
188
|
render :text => response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
|
|
182
189
|
end
|
|
190
|
+
|
|
183
191
|
def add_existing_respond_to_yaml
|
|
184
192
|
render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
|
185
193
|
end
|
|
194
|
+
|
|
186
195
|
def destroy_existing_respond_to_html
|
|
187
196
|
flash[:info] = as_(:deleted_model, :model => @record.to_label)
|
|
188
197
|
return_to_main
|
|
@@ -193,29 +202,29 @@ module ActiveScaffold::Actions::Nested
|
|
|
193
202
|
end
|
|
194
203
|
|
|
195
204
|
def destroy_existing_respond_to_xml
|
|
196
|
-
render :xml => successful? ?
|
|
205
|
+
render :xml => successful? ? '' : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
|
|
197
206
|
end
|
|
198
207
|
|
|
199
208
|
def destroy_existing_respond_to_json
|
|
200
|
-
render :text => successful? ?
|
|
209
|
+
render :text => successful? ? '' : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
|
|
201
210
|
end
|
|
202
211
|
|
|
203
212
|
def destroy_existing_respond_to_yaml
|
|
204
|
-
render :text => successful? ?
|
|
213
|
+
render :text => successful? ? '' : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
|
205
214
|
end
|
|
206
215
|
|
|
207
216
|
def add_existing_authorized?(record = nil)
|
|
208
217
|
true
|
|
209
218
|
end
|
|
219
|
+
|
|
210
220
|
def delete_existing_authorized?(record = nil)
|
|
211
221
|
true
|
|
212
222
|
end
|
|
213
|
-
|
|
223
|
+
|
|
214
224
|
def after_create_save(record)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
end
|
|
225
|
+
return unless params[:association_macro] == :has_and_belongs_to_many
|
|
226
|
+
params[:associated_id] = record
|
|
227
|
+
do_add_existing
|
|
219
228
|
end
|
|
220
229
|
|
|
221
230
|
# The actual "add_existing" algorithm
|
|
@@ -240,13 +249,17 @@ module ActiveScaffold::Actions::Nested
|
|
|
240
249
|
do_destroy
|
|
241
250
|
end
|
|
242
251
|
end
|
|
252
|
+
|
|
243
253
|
private
|
|
254
|
+
|
|
244
255
|
def new_existing_formats
|
|
245
256
|
(default_formats + active_scaffold_config.formats).uniq
|
|
246
257
|
end
|
|
258
|
+
|
|
247
259
|
def add_existing_formats
|
|
248
260
|
(default_formats + active_scaffold_config.formats).uniq
|
|
249
261
|
end
|
|
262
|
+
|
|
250
263
|
def destroy_existing_formats
|
|
251
264
|
(default_formats + active_scaffold_config.formats).uniq
|
|
252
265
|
end
|