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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
ActiveScaffold is freely distributable under the terms of an MIT-style license.
|
|
6
6
|
|
|
7
|
-
For details, see the ActiveScaffold web site:
|
|
7
|
+
For details, see the ActiveScaffold web site: https://github.com/activescaffold/active_scaffold
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
@import 'active_scaffold_layout';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
ActiveScaffold is freely distributable under the terms of an MIT-style license.
|
|
6
6
|
|
|
7
|
-
For details, see the ActiveScaffold web site:
|
|
7
|
+
For details, see the ActiveScaffold web site: https://github.com/activescaffold/active_scaffold
|
|
8
8
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
ActiveScaffold is freely distributable under the terms of an MIT-style license.
|
|
6
6
|
|
|
7
|
-
For details, see the ActiveScaffold web site:
|
|
7
|
+
For details, see the ActiveScaffold web site: https://github.com/activescaffold/active_scaffold
|
|
8
8
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%
|
|
2
2
|
ActiveSupport::Deprecation.warn "Relying on @record to render form_asssociation partial with no parent_record local variable is deprecated", caller(1) unless local_assigns[:parent_record]
|
|
3
|
-
parent_record ||= @record # save @record, some partial can change @record
|
|
3
|
+
parent_record ||= @record # TODO: remove when changing @record is removed, save @record, some partial can change @record
|
|
4
4
|
associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a
|
|
5
5
|
#associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order)
|
|
6
6
|
if column.show_blank_record?(associated)
|
|
@@ -15,12 +15,12 @@ subform_div_id = "#{sub_form_id(:association => column.name, :id => parent_recor
|
|
|
15
15
|
<%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%>
|
|
16
16
|
</h5>
|
|
17
17
|
<div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>>
|
|
18
|
-
<%# HACK to be able to delete all associated records %>
|
|
18
|
+
<%# HACK: to be able to delete all associated records %>
|
|
19
19
|
<%= hidden_field_tag "#{active_scaffold_input_options(column, scope, :object => parent_record)[:name]}[0]", '' if column.plural_association? %>
|
|
20
20
|
<%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record, :scope => scope} %>
|
|
21
21
|
<%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated, :scope => scope} -%>
|
|
22
22
|
</div>
|
|
23
23
|
<%
|
|
24
|
-
@record = parent_record # restore @record, some partials can change it
|
|
24
|
+
@record = parent_record # TODO: remove when changing @record is removed, restore @record, some partials can change it
|
|
25
25
|
@disable_required_for_new = disable_required_for_new
|
|
26
26
|
-%>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<%
|
|
2
2
|
record_column = column
|
|
3
3
|
ActiveSupport::Deprecation.warn "Relying on @record to render form_asssociation_record partial with no :object is deprecated", caller(1) unless local_assigns[:form_association_record]
|
|
4
|
-
record = form_association_record ||= @record # TODO remove me, backwards compatibility, no :collection neither object in render
|
|
5
|
-
@record = record # TODO remove me, backward compatibility, helpers using @record
|
|
4
|
+
record = form_association_record ||= @record # TODO: remove me, backwards compatibility, no :collection neither object in render
|
|
5
|
+
@record = record # TODO: remove me, backward compatibility, helpers using @record
|
|
6
6
|
readonly = (record.readonly? or not record.authorized_for?(:crud_type => :update))
|
|
7
7
|
crud_type = record.new_record? ? :create : (readonly ? :read : :update)
|
|
8
8
|
show_actions = false
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
<% columns_groups.each do |column| %>
|
|
82
82
|
<%= content_tag row_tag, :class => 'associated-record' do %>
|
|
83
83
|
<%= content_tag column_tag, :colspan => (columns_length if column_tag == :td) do %>
|
|
84
|
-
<% column.each :for =>
|
|
84
|
+
<% column.each :for => record.class, :crud_type => :read, :flatten => true do |col| %>
|
|
85
85
|
<%= active_scaffold_render_subform_column(col, scope, crud_type, readonly, true, record) %>
|
|
86
86
|
<% end %>
|
|
87
87
|
<% end %>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<% css_class = "#{column.name}-view"
|
|
9
9
|
css_class.concat(" #{column.css_class}") unless column.css_class.nil? %>
|
|
10
10
|
<dd class="<%= css_class.strip %>">
|
|
11
|
-
<%= show_column_value(@record, column) -%>
|
|
11
|
+
<%= show_column_value(@record, column) -%>
|
|
12
12
|
<% end -%>
|
|
13
13
|
</dd>
|
|
14
14
|
<% end -%>
|
data/lib/active_scaffold.rb
CHANGED
|
@@ -12,13 +12,13 @@ module ActiveScaffold
|
|
|
12
12
|
autoload :Tableless, 'active_scaffold/tableless'
|
|
13
13
|
autoload :Version, 'active_scaffold/version'
|
|
14
14
|
|
|
15
|
-
def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__))
|
|
16
|
-
Dir["#{root}/active_scaffold/#{dir}/*.rb"].each
|
|
17
|
-
basename = File.basename(file,
|
|
18
|
-
mod.module_eval
|
|
15
|
+
def self.autoload_subdir(dir, mod = self, root = File.dirname(__FILE__))
|
|
16
|
+
Dir["#{root}/active_scaffold/#{dir}/*.rb"].each do |file|
|
|
17
|
+
basename = File.basename(file, '.rb')
|
|
18
|
+
mod.module_eval do
|
|
19
19
|
autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}"
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
module Actions
|
|
@@ -48,17 +48,18 @@ module ActiveScaffold
|
|
|
48
48
|
self.stylesheets = []
|
|
49
49
|
mattr_accessor :javascripts
|
|
50
50
|
self.javascripts = []
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
def self.js_framework=(framework)
|
|
53
53
|
@@js_framework = framework
|
|
54
54
|
end
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
def self.js_framework
|
|
57
|
-
@@js_framework ||=
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
@@js_framework ||=
|
|
58
|
+
if defined? Jquery
|
|
59
|
+
:jquery
|
|
60
|
+
elsif defined? PrototypeRails
|
|
61
|
+
:prototype
|
|
62
|
+
end
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
def self.js_config=(config)
|
|
@@ -82,14 +83,13 @@ module ActiveScaffold
|
|
|
82
83
|
end
|
|
83
84
|
|
|
84
85
|
def self.root
|
|
85
|
-
File.dirname(__FILE__) +
|
|
86
|
+
File.dirname(__FILE__) + '/..'
|
|
86
87
|
end
|
|
87
88
|
|
|
88
89
|
def self.set_defaults(&block)
|
|
89
|
-
ActiveScaffold::Config::Core.configure
|
|
90
|
+
ActiveScaffold::Config::Core.configure(&block)
|
|
90
91
|
end
|
|
91
92
|
end
|
|
92
93
|
require 'active_scaffold/engine'
|
|
93
94
|
# TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely.
|
|
94
95
|
Dir["#{File.dirname __FILE__}/active_scaffold/extensions/*.rb"].each { |file| require file }
|
|
95
|
-
|
|
@@ -14,19 +14,21 @@ module ActiveScaffold::Actions
|
|
|
14
14
|
def show_search
|
|
15
15
|
respond_to_action(search_partial || :search)
|
|
16
16
|
end
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
protected
|
|
19
|
+
|
|
19
20
|
def do_search
|
|
20
21
|
end
|
|
21
|
-
|
|
22
|
+
|
|
22
23
|
def search_partial
|
|
23
|
-
@_search_partial ||=
|
|
24
|
-
params.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
@_search_partial ||=
|
|
25
|
+
if params[:kind].present? && active_scaffold_config.actions.include?(params[:kind])
|
|
26
|
+
params.delete(:kind)
|
|
27
|
+
else
|
|
28
|
+
active_scaffold_config.list.auto_search_partial
|
|
29
|
+
end
|
|
28
30
|
end
|
|
29
|
-
|
|
31
|
+
|
|
30
32
|
def store_search_params_into_session
|
|
31
33
|
if active_scaffold_config.store_user_settings
|
|
32
34
|
active_scaffold_session_storage['search'] = params.delete :search if params[:search]
|
|
@@ -38,17 +40,17 @@ module ActiveScaffold::Actions
|
|
|
38
40
|
def search_params
|
|
39
41
|
@search_params || active_scaffold_session_storage['search']
|
|
40
42
|
end
|
|
41
|
-
|
|
43
|
+
|
|
42
44
|
# The default security delegates to ActiveRecordPermissions.
|
|
43
45
|
# You may override the method to customize.
|
|
44
46
|
def search_authorized?
|
|
45
47
|
authorized_for?(:crud_type => :read)
|
|
46
48
|
end
|
|
47
|
-
|
|
49
|
+
|
|
48
50
|
def search_authorized_filter
|
|
49
51
|
action = active_scaffold_config.send(search_partial)
|
|
50
52
|
link = action.link || action.class.link
|
|
51
|
-
raise ActiveScaffold::ActionNotAllowed unless
|
|
53
|
+
raise ActiveScaffold::ActionNotAllowed unless send(link.security_method)
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
end
|
|
@@ -29,8 +29,9 @@ module ActiveScaffold::Actions
|
|
|
29
29
|
respond_to { |format| format.js }
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
protected
|
|
34
|
+
|
|
34
35
|
def loading_embedded?
|
|
35
36
|
@loading_embedded ||= params.delete(:embedded)
|
|
36
37
|
end
|
|
@@ -49,65 +50,67 @@ module ActiveScaffold::Actions
|
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
def render_field_for_update_columns
|
|
52
|
-
@column = active_scaffold_config.columns[params.delete(:column)]
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
return if (@column = active_scaffold_config.columns[params.delete(:column)]).nil?
|
|
54
|
+
@source_id = params.delete(:source_id)
|
|
55
|
+
@columns = @column.update_columns || []
|
|
56
|
+
@scope = params.delete(:scope)
|
|
57
|
+
action = :subform if @scope
|
|
58
|
+
action ||= params[:id] ? :update : :create
|
|
59
|
+
@main_columns = active_scaffold_config.send(action).columns
|
|
60
|
+
@columns << @column.name if @column.options[:refresh_link] && @columns.exclude?(@column.name)
|
|
61
|
+
|
|
62
|
+
@record =
|
|
60
63
|
if @column.send_form_on_update_column
|
|
61
|
-
|
|
62
|
-
hash = @scope.gsub('[','').split(']').inject(params[:record]) do |hash, index|
|
|
63
|
-
hash[index]
|
|
64
|
-
end
|
|
65
|
-
id = hash[:id]
|
|
66
|
-
else
|
|
67
|
-
hash = params[:record]
|
|
68
|
-
id = params[:id]
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# check permissions and support overriding to_param
|
|
72
|
-
record = find_if_allowed(id, :read) if id
|
|
73
|
-
# call update_record_from_params with new_model
|
|
74
|
-
# in other case some associations can be saved
|
|
75
|
-
@record = new_model
|
|
76
|
-
copy_attributes(record, @record) if record
|
|
77
|
-
apply_constraints_to_record(@record) unless @scope
|
|
78
|
-
@record = update_record_from_params(@record, @main_columns, hash || {}, true)
|
|
64
|
+
updated_record_with_form(@main_columns, params[:record], @scope)
|
|
79
65
|
else
|
|
80
|
-
@
|
|
81
|
-
if @record.new_record?
|
|
82
|
-
apply_constraints_to_record(@record) unless @scope
|
|
83
|
-
else
|
|
84
|
-
@record = @record.dup
|
|
85
|
-
end
|
|
86
|
-
value = column_value_from_param_value(@record, @column, params.delete(:value))
|
|
87
|
-
@record.send "#{@column.name}=", value
|
|
88
|
-
@record.id = params[:id]
|
|
66
|
+
updated_record_with_column(@column, params.delete(:value), @scope)
|
|
89
67
|
end
|
|
90
|
-
|
|
68
|
+
set_parent(@record) if params[:parent_controller] && @scope
|
|
69
|
+
after_render_field(@record, @column)
|
|
70
|
+
end
|
|
91
71
|
|
|
92
|
-
|
|
72
|
+
def updated_record_with_form(columns, attributes, scope)
|
|
73
|
+
if attributes && scope
|
|
74
|
+
attributes = scope.gsub('[', '').split(']').inject(attributes) { |h, idx| h[idx] }
|
|
75
|
+
id = attributes[:id]
|
|
76
|
+
else
|
|
77
|
+
id = params[:id]
|
|
93
78
|
end
|
|
79
|
+
|
|
80
|
+
# check permissions and support overriding to_param
|
|
81
|
+
saved_record = find_if_allowed(id, :read) if id
|
|
82
|
+
# call update_record_from_params with new_model
|
|
83
|
+
# in other case some associations can be saved
|
|
84
|
+
record = new_model
|
|
85
|
+
copy_attributes(saved_record, record) if saved_record
|
|
86
|
+
apply_constraints_to_record(record) unless scope
|
|
87
|
+
update_record_from_params(record, columns, attributes || {}, true)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def updated_record_with_column(column, value, scope)
|
|
91
|
+
record = params[:id] ? find_if_allowed(params[:id], :read).dup : new_model
|
|
92
|
+
apply_constraints_to_record(record) unless scope || params[:id]
|
|
93
|
+
value = column_value_from_param_value(record, column, value)
|
|
94
|
+
record.send "#{column.name}=", value
|
|
95
|
+
record.id = params[:id]
|
|
96
|
+
record
|
|
94
97
|
end
|
|
95
98
|
|
|
96
99
|
def set_parent(record)
|
|
97
100
|
parent_model = params[:parent_controller].singularize.camelize.constantize
|
|
98
101
|
child_association = params[:child_association].presence || @scope.split(']').first.sub(/^\[/, '')
|
|
99
102
|
association = parent_model.reflect_on_association(child_association.to_sym).try(:reverse)
|
|
100
|
-
if association
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
return if association.nil?
|
|
104
|
+
|
|
105
|
+
parent = parent_model.new
|
|
106
|
+
copy_attributes(parent_model.find(params[:parent_id]), parent) if params[:parent_id]
|
|
107
|
+
parent.id = params[:parent_id]
|
|
108
|
+
parent = update_record_from_params(parent, active_scaffold_config_for(parent_model).send(params[:parent_id] ? :update : :create).columns, params[:record], true) if @column.send_form_on_update_column
|
|
109
|
+
apply_constraints_to_record(parent) unless params[:parent_id]
|
|
110
|
+
if record.class.reflect_on_association(association).collection?
|
|
111
|
+
record.send(association) << parent
|
|
112
|
+
else
|
|
113
|
+
record.send("#{association}=", parent)
|
|
111
114
|
end
|
|
112
115
|
end
|
|
113
116
|
|
|
@@ -124,7 +127,7 @@ module ActiveScaffold::Actions
|
|
|
124
127
|
dst.attributes = attributes
|
|
125
128
|
dst
|
|
126
129
|
end
|
|
127
|
-
|
|
130
|
+
|
|
128
131
|
# override this method if you want to do something after render_field
|
|
129
132
|
def after_render_field(record, column); end
|
|
130
133
|
|
|
@@ -137,20 +140,21 @@ module ActiveScaffold::Actions
|
|
|
137
140
|
end
|
|
138
141
|
|
|
139
142
|
def each_marked_record(&block)
|
|
140
|
-
active_scaffold_config.model.as_marked.each
|
|
143
|
+
active_scaffold_config.model.as_marked.each(&block)
|
|
141
144
|
end
|
|
142
145
|
|
|
143
146
|
def marked_records
|
|
144
147
|
active_scaffold_session_storage['marked_records'] ||= {}
|
|
145
148
|
end
|
|
146
|
-
|
|
149
|
+
|
|
147
150
|
def default_formats
|
|
148
151
|
[:html, :js, :json, :xml, :yaml]
|
|
149
152
|
end
|
|
153
|
+
|
|
150
154
|
# Returns true if the client accepts one of the MIME types passed to it
|
|
151
155
|
# ex: accepts? :html, :xml
|
|
152
156
|
def accepts?(*types)
|
|
153
|
-
|
|
157
|
+
request.accepts.compact.each do |priority|
|
|
154
158
|
if priority == Mime::ALL
|
|
155
159
|
# Because IE always sends */* in the accepts header and we assume
|
|
156
160
|
# that if you really wanted XML or something else you would say so
|
|
@@ -185,7 +189,7 @@ module ActiveScaffold::Actions
|
|
|
185
189
|
@successful
|
|
186
190
|
end
|
|
187
191
|
end
|
|
188
|
-
|
|
192
|
+
|
|
189
193
|
def successful=(val)
|
|
190
194
|
@successful = (val) ? true : false
|
|
191
195
|
end
|
|
@@ -194,12 +198,12 @@ module ActiveScaffold::Actions
|
|
|
194
198
|
def return_to_main
|
|
195
199
|
redirect_to main_path_to_return
|
|
196
200
|
end
|
|
197
|
-
|
|
198
|
-
#Overide this method on your controller to provide model with named scopes
|
|
201
|
+
|
|
202
|
+
# Overide this method on your controller to provide model with named scopes
|
|
199
203
|
def beginning_of_chain
|
|
200
204
|
active_scaffold_config.model
|
|
201
205
|
end
|
|
202
|
-
|
|
206
|
+
|
|
203
207
|
# Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5".
|
|
204
208
|
def conditions_from_params
|
|
205
209
|
@conditions_from_params ||= begin
|
|
@@ -210,12 +214,13 @@ module ActiveScaffold::Actions
|
|
|
210
214
|
key = key.to_sym
|
|
211
215
|
not_string = [:string, :text].exclude?(column.type)
|
|
212
216
|
next if active_scaffold_constraints[key]
|
|
213
|
-
next if nested?
|
|
214
|
-
conditions[key] =
|
|
215
|
-
value.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
next if nested? && nested.param_name == key
|
|
218
|
+
conditions[key] =
|
|
219
|
+
if value.is_a?(Array)
|
|
220
|
+
value.map { |v| v == '' && not_string ? nil : ActiveScaffold::Core.column_type_cast(v, column) }
|
|
221
|
+
else
|
|
222
|
+
value == '' && not_string ? nil : ActiveScaffold::Core.column_type_cast(value, column)
|
|
223
|
+
end
|
|
219
224
|
end
|
|
220
225
|
conditions
|
|
221
226
|
end
|
|
@@ -265,14 +270,14 @@ module ActiveScaffold::Actions
|
|
|
265
270
|
end
|
|
266
271
|
|
|
267
272
|
def check_input_device
|
|
268
|
-
if request.env[
|
|
273
|
+
if request.env['HTTP_USER_AGENT'] && request.env['HTTP_USER_AGENT'][/(iPhone|iPod|iPad)/i]
|
|
269
274
|
session[:input_device_type] = 'TOUCH'
|
|
270
275
|
session[:hover_supported] = false
|
|
271
276
|
else
|
|
272
277
|
session[:input_device_type] = 'MOUSE'
|
|
273
278
|
session[:hover_supported] = true
|
|
274
279
|
end if session[:input_device_type].nil?
|
|
275
|
-
|
|
280
|
+
end
|
|
276
281
|
|
|
277
282
|
def touch_device?
|
|
278
283
|
session[:input_device_type] == 'TOUCH'
|
|
@@ -299,11 +304,11 @@ module ActiveScaffold::Actions
|
|
|
299
304
|
if params[:id]
|
|
300
305
|
crud_type_or_security_options ||= {:crud_type => (request.post? || request.put?) ? :update : :delete, :action => action_name}
|
|
301
306
|
get_row(crud_type_or_security_options)
|
|
302
|
-
|
|
303
|
-
yield @record
|
|
304
|
-
else
|
|
307
|
+
if @record.nil?
|
|
305
308
|
self.successful = false
|
|
306
309
|
flash[:error] = as_(:no_authorization_for_action, :action => action_name)
|
|
310
|
+
else
|
|
311
|
+
yield @record
|
|
307
312
|
end
|
|
308
313
|
else
|
|
309
314
|
yield
|
|
@@ -326,15 +331,15 @@ module ActiveScaffold::Actions
|
|
|
326
331
|
end
|
|
327
332
|
|
|
328
333
|
def action_update_respond_to_xml
|
|
329
|
-
render :xml => successful? ?
|
|
334
|
+
render :xml => successful? ? '' : 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
|
|
330
335
|
end
|
|
331
336
|
|
|
332
337
|
def action_update_respond_to_json
|
|
333
|
-
render :text => successful? ?
|
|
338
|
+
render :text => successful? ? '' : 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
|
|
334
339
|
end
|
|
335
340
|
|
|
336
341
|
def action_update_respond_to_yaml
|
|
337
|
-
render :text => successful? ?
|
|
342
|
+
render :text => successful? ? '' : 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
|
|
338
343
|
end
|
|
339
344
|
|
|
340
345
|
def objects_for_etag
|
|
@@ -360,14 +365,15 @@ module ActiveScaffold::Actions
|
|
|
360
365
|
end
|
|
361
366
|
|
|
362
367
|
def virtual_columns(columns)
|
|
363
|
-
columns.reject {|col| active_scaffold_config.model.columns_hash[col] || active_scaffold_config.model.reflect_on_association(col)}
|
|
368
|
+
columns.reject { |col| active_scaffold_config.model.columns_hash[col] || active_scaffold_config.model.reflect_on_association(col) }
|
|
364
369
|
end
|
|
365
370
|
|
|
366
371
|
def association_columns(columns)
|
|
367
|
-
columns.select {|col| active_scaffold_config.model.reflect_on_association(col)}
|
|
372
|
+
columns.select { |col| active_scaffold_config.model.reflect_on_association(col) }
|
|
368
373
|
end
|
|
369
374
|
|
|
370
375
|
private
|
|
376
|
+
|
|
371
377
|
def respond_to_action(action)
|
|
372
378
|
return unless !conditional_get_support? || view_stale?
|
|
373
379
|
respond_to do |type|
|
|
@@ -382,11 +388,12 @@ module ActiveScaffold::Actions
|
|
|
382
388
|
end
|
|
383
389
|
|
|
384
390
|
def action_formats
|
|
385
|
-
@action_formats ||=
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
391
|
+
@action_formats ||=
|
|
392
|
+
if respond_to? "#{action_name}_formats", true
|
|
393
|
+
send("#{action_name}_formats")
|
|
394
|
+
else
|
|
395
|
+
(default_formats + active_scaffold_config.formats).uniq
|
|
396
|
+
end
|
|
390
397
|
end
|
|
391
398
|
end
|
|
392
399
|
end
|