active_scaffold 3.7.12 → 4.0.0.rc1
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.rdoc +9 -23
- data/README.md +3 -2
- data/app/assets/config/active_scaffold_manifest.js +3 -0
- data/app/assets/javascripts/active_scaffold.js.erb +24 -34
- data/app/assets/javascripts/jquery/active_scaffold.js +41 -58
- data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +1 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +0 -7
- data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -2
- data/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +7 -7
- data/app/assets/stylesheets/active_scaffold_layout.css +57 -30
- data/app/views/active_scaffold_overrides/_add_existing_form.html.erb +10 -10
- data/app/views/active_scaffold_overrides/_base_form.html.erb +21 -21
- data/app/views/active_scaffold_overrides/_create_form.html.erb +10 -7
- data/app/views/active_scaffold_overrides/_create_form_on_list.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_field_search.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_form.html.erb +11 -14
- data/app/views/active_scaffold_overrides/_form_association.html.erb +21 -12
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +19 -10
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +15 -21
- data/app/views/active_scaffold_overrides/_form_messages.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +7 -6
- data/app/views/active_scaffold_overrides/_human_conditions.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_list.html.erb +15 -8
- data/app/views/active_scaffold_overrides/_list_calculations.html.erb +2 -3
- data/app/views/active_scaffold_overrides/_list_header.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +12 -3
- data/app/views/active_scaffold_overrides/_list_pagination.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_list_pagination_links.html.erb +4 -4
- data/app/views/active_scaffold_overrides/_list_record.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_list_with_header.html.erb +4 -4
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +2 -2
- data/app/views/active_scaffold_overrides/_render_field.js.erb +4 -4
- data/app/views/active_scaffold_overrides/_row.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_search.html.erb +6 -5
- data/app/views/active_scaffold_overrides/_show.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_show_actions.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_association_vertical.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_actions.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_calculations.js.erb +2 -2
- data/app/views/active_scaffold_overrides/_update_column.js.erb +8 -7
- data/app/views/active_scaffold_overrides/_update_form.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_update_messages.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_vertical_subform.html.erb +4 -3
- data/app/views/active_scaffold_overrides/action_confirmation.html.erb +3 -3
- data/app/views/active_scaffold_overrides/add_existing.js.erb +6 -6
- data/app/views/active_scaffold_overrides/add_existing_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/add_tab.js.erb +15 -0
- data/app/views/active_scaffold_overrides/create.html.erb +1 -1
- data/app/views/active_scaffold_overrides/delete.html.erb +4 -4
- data/app/views/active_scaffold_overrides/destroy.js.erb +15 -13
- data/app/views/active_scaffold_overrides/edit_associated.js.erb +3 -3
- data/app/views/active_scaffold_overrides/field_search.html.erb +1 -1
- data/app/views/active_scaffold_overrides/form_messages.js.erb +1 -1
- data/app/views/active_scaffold_overrides/list.html.erb +1 -1
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +13 -8
- data/app/views/active_scaffold_overrides/on_create.js.erb +34 -6
- data/app/views/active_scaffold_overrides/on_mark.js.erb +3 -3
- data/app/views/active_scaffold_overrides/on_update.js.erb +9 -9
- data/app/views/active_scaffold_overrides/render_field.js.erb +1 -1
- data/app/views/active_scaffold_overrides/render_field_inplace.html.erb +1 -1
- data/app/views/active_scaffold_overrides/row.js.erb +2 -2
- data/app/views/active_scaffold_overrides/search.html.erb +1 -1
- data/app/views/active_scaffold_overrides/show.html.erb +3 -3
- data/app/views/active_scaffold_overrides/update.html.erb +2 -2
- data/app/views/active_scaffold_overrides/update_column.js.erb +4 -4
- data/app/views/active_scaffold_overrides/update_row.js.erb +1 -1
- data/lib/active_scaffold/actions/common_search.rb +5 -3
- data/lib/active_scaffold/actions/core.rb +57 -32
- data/lib/active_scaffold/actions/create.rb +19 -17
- data/lib/active_scaffold/actions/delete.rb +10 -12
- data/lib/active_scaffold/actions/field_search.rb +28 -13
- data/lib/active_scaffold/actions/list.rb +34 -34
- data/lib/active_scaffold/actions/mark.rb +5 -5
- data/lib/active_scaffold/actions/nested.rb +64 -56
- data/lib/active_scaffold/actions/search.rb +2 -2
- data/lib/active_scaffold/actions/show.rb +5 -5
- data/lib/active_scaffold/actions/subform.rb +15 -4
- data/lib/active_scaffold/actions/update.rb +20 -20
- data/lib/active_scaffold/active_record_permissions.rb +4 -3
- data/lib/active_scaffold/attribute_params.rb +51 -50
- data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +4 -4
- data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +6 -2
- data/lib/active_scaffold/bridges/active_storage.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +3 -3
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +4 -1
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/cancan.rb +8 -8
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +1 -1
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +4 -3
- data/lib/active_scaffold/bridges/carrierwave.rb +2 -2
- data/lib/active_scaffold/bridges/chosen.rb +1 -5
- data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +4 -2
- data/lib/active_scaffold/bridges/date_picker/ext.rb +20 -12
- data/lib/active_scaffold/bridges/date_picker/helper.rb +37 -33
- data/lib/active_scaffold/bridges/date_picker.rb +1 -4
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +3 -2
- data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +3 -2
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +2 -1
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +4 -9
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +6 -3
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +1 -4
- data/lib/active_scaffold/bridges/file_column.rb +1 -0
- data/lib/active_scaffold/bridges/paper_trail/actions.rb +4 -2
- data/lib/active_scaffold/bridges/paper_trail/config.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +2 -1
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +3 -2
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +10 -9
- data/lib/active_scaffold/bridges/paperclip.rb +2 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +10 -11
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +3 -1
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -7
- data/lib/active_scaffold/bridges/tiny_mce.rb +2 -7
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +7 -7
- data/lib/active_scaffold/bridges.rb +7 -5
- data/lib/active_scaffold/config/base.rb +20 -24
- data/lib/active_scaffold/config/core.rb +27 -39
- data/lib/active_scaffold/config/create.rb +1 -1
- data/lib/active_scaffold/config/delete.rb +9 -9
- data/lib/active_scaffold/config/field_search.rb +4 -9
- data/lib/active_scaffold/config/form.rb +3 -1
- data/lib/active_scaffold/config/list.rb +19 -15
- data/lib/active_scaffold/config/nested.rb +2 -2
- data/lib/active_scaffold/config/search.rb +5 -5
- data/lib/active_scaffold/config/show.rb +1 -1
- data/lib/active_scaffold/config/subform.rb +1 -1
- data/lib/active_scaffold/config/update.rb +4 -5
- data/lib/active_scaffold/configurable.rb +2 -1
- data/lib/active_scaffold/constraints.rb +16 -11
- data/lib/active_scaffold/core.rb +25 -27
- data/lib/active_scaffold/data_structures/action_columns.rb +10 -3
- data/lib/active_scaffold/data_structures/action_link.rb +19 -9
- data/lib/active_scaffold/data_structures/action_links.rb +20 -26
- data/lib/active_scaffold/data_structures/actions.rb +3 -3
- data/lib/active_scaffold/data_structures/association/abstract.rb +8 -4
- data/lib/active_scaffold/data_structures/association/active_mongoid.rb +1 -0
- data/lib/active_scaffold/data_structures/association/active_record.rb +1 -4
- data/lib/active_scaffold/data_structures/column.rb +368 -327
- data/lib/active_scaffold/data_structures/columns.rb +3 -2
- data/lib/active_scaffold/data_structures/nested_info.rb +6 -5
- data/lib/active_scaffold/data_structures/proxy_column.rb +68 -0
- data/lib/active_scaffold/data_structures/set.rb +7 -4
- data/lib/active_scaffold/data_structures/sorting.rb +21 -12
- data/lib/active_scaffold/engine.rb +12 -12
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +5 -5
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +29 -31
- data/lib/active_scaffold/extensions/ice_nine.rb +2 -1
- data/lib/active_scaffold/extensions/localize.rb +2 -2
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
- data/lib/active_scaffold/extensions/routing_mapper.rb +5 -4
- data/lib/active_scaffold/extensions/unsaved_associated.rb +3 -2
- data/lib/active_scaffold/finder.rb +71 -78
- data/lib/active_scaffold/helpers/action_link_helpers.rb +37 -49
- data/lib/active_scaffold/helpers/association_helpers.rb +3 -2
- data/lib/active_scaffold/helpers/controller_helpers.rb +18 -16
- data/lib/active_scaffold/helpers/form_column_helpers.rb +69 -53
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +17 -15
- data/lib/active_scaffold/helpers/id_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/list_column_helpers.rb +35 -38
- data/lib/active_scaffold/helpers/pagination_helpers.rb +4 -4
- data/lib/active_scaffold/helpers/search_column_helpers.rb +25 -34
- data/lib/active_scaffold/helpers/show_column_helpers.rb +7 -4
- data/lib/active_scaffold/helpers/tabs_helpers.rb +88 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +15 -13
- data/lib/active_scaffold/marked_model.rb +1 -2
- data/lib/active_scaffold/orm_checks.rb +6 -4
- data/lib/active_scaffold/paginator.rb +3 -2
- data/lib/active_scaffold/registry.rb +5 -0
- data/lib/active_scaffold/tableless.rb +24 -14
- data/lib/active_scaffold/version.rb +4 -4
- data/lib/active_scaffold.rb +8 -34
- data/lib/generators/active_scaffold/controller_generator.rb +20 -20
- data/lib/generators/active_scaffold/install_generator.rb +4 -8
- data/lib/generators/active_scaffold/resource_generator.rb +31 -31
- data/lib/tasks/brakeman.rake +1 -1
- data/shoulda_macros/macros.rb +14 -14
- metadata +11 -232
- data/app/assets/javascripts/prototype/active_scaffold.js +0 -1249
- data/app/assets/javascripts/prototype/active_scaffold_chosen.js +0 -0
- data/app/assets/javascripts/prototype/dhtml_history.js +0 -870
- data/app/assets/javascripts/prototype/form_enhancements.js +0 -117
- data/app/assets/javascripts/prototype/tiny_mce_bridge.js +0 -17
- data/app/views/active_scaffold_overrides/_list_messages_content.html.erb +0 -8
- data/app/views/active_scaffold_overrides/_new_record.js.erb +0 -15
- data/app/views/active_scaffold_overrides/_popup_adapter.html.erb +0 -20
- data/app/views/active_scaffold_overrides/_refresh_create_form.js.erb +0 -12
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +0 -58
- data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -17
- data/lib/active_scaffold/data_structures/action_link_separator.rb +0 -13
- data/lib/active_scaffold/extensions/cow_proxy.rb +0 -102
- data/test/active_scaffold_config_mock.rb +0 -33
- data/test/bridges/bridge_test.rb +0 -88
- data/test/bridges/date_picker_test.rb +0 -31
- data/test/bridges/paper_trail_test.rb +0 -16
- data/test/bridges/paperclip_test.rb +0 -85
- data/test/bridges/tiny_mce_test.rb +0 -61
- data/test/class_with_finder.rb +0 -42
- data/test/company.rb +0 -97
- data/test/config/base_test.rb +0 -17
- data/test/config/core_test.rb +0 -66
- data/test/config/create_test.rb +0 -72
- data/test/config/delete_test.rb +0 -35
- data/test/config/field_search_test.rb +0 -49
- data/test/config/list_test.rb +0 -134
- data/test/config/nested_test.rb +0 -55
- data/test/config/search_test.rb +0 -62
- data/test/config/show_test.rb +0 -45
- data/test/config/subform_test.rb +0 -19
- data/test/config/update_test.rb +0 -52
- data/test/const_mocker.rb +0 -32
- data/test/data_structures/action_columns_test.rb +0 -112
- data/test/data_structures/action_link_test.rb +0 -79
- data/test/data_structures/action_links_test.rb +0 -78
- data/test/data_structures/actions_test.rb +0 -25
- data/test/data_structures/association_column_test.rb +0 -41
- data/test/data_structures/column_test.rb +0 -186
- data/test/data_structures/columns_test.rb +0 -68
- data/test/data_structures/set_test.rb +0 -84
- data/test/data_structures/sorting_test.rb +0 -148
- data/test/data_structures/standard_column_test.rb +0 -23
- data/test/data_structures/validation_reflection_test.rb +0 -69
- data/test/data_structures/virtual_column_test.rb +0 -23
- data/test/extensions/action_view_rendering_test.rb +0 -20
- data/test/extensions/active_record_test.rb +0 -44
- data/test/extensions/routing_mapper_test.rb +0 -73
- data/test/helpers/form_column_helpers_test.rb +0 -34
- data/test/helpers/list_column_helpers_test.rb +0 -53
- data/test/helpers/pagination_helpers_test.rb +0 -65
- data/test/helpers/search_column_helpers_test.rb +0 -15
- data/test/misc/active_record_permissions_test.rb +0 -193
- data/test/misc/attribute_params_test.rb +0 -460
- data/test/misc/calculation_test.rb +0 -39
- data/test/misc/configurable_test.rb +0 -97
- data/test/misc/constraints_test.rb +0 -209
- data/test/misc/convert_numbers_format_test.rb +0 -171
- data/test/misc/finder_test.rb +0 -124
- data/test/misc/lang_test.rb +0 -10
- data/test/misc/parse_datetime_test.rb +0 -159
- data/test/misc/render_test.rb +0 -9
- data/test/misc/tableless_test.rb +0 -56
- data/test/mock_app/.gitignore +0 -2
- data/test/mock_app/Rakefile +0 -7
- data/test/mock_app/app/assets/config/manifest.js +0 -0
- data/test/mock_app/app/controllers/addresses_controller.rb +0 -4
- data/test/mock_app/app/controllers/application_controller.rb +0 -10
- data/test/mock_app/app/controllers/buildings_controller.rb +0 -4
- data/test/mock_app/app/controllers/cars_controller.rb +0 -5
- data/test/mock_app/app/controllers/contacts_controller.rb +0 -4
- data/test/mock_app/app/controllers/floors_controller.rb +0 -6
- data/test/mock_app/app/controllers/people_controller.rb +0 -8
- data/test/mock_app/app/controllers/roles_controller.rb +0 -4
- data/test/mock_app/app/helpers/application_helper.rb +0 -3
- data/test/mock_app/app/models/address.rb +0 -3
- data/test/mock_app/app/models/building.rb +0 -9
- data/test/mock_app/app/models/car.rb +0 -3
- data/test/mock_app/app/models/contact.rb +0 -3
- data/test/mock_app/app/models/file_model.rb +0 -31
- data/test/mock_app/app/models/floor.rb +0 -8
- data/test/mock_app/app/models/person.rb +0 -12
- data/test/mock_app/app/models/role.rb +0 -3
- data/test/mock_app/app/views/active_scaffold_overrides/_form.html.erb +0 -2
- data/test/mock_app/app/views/active_scaffold_overrides/list.html.erb +0 -2
- data/test/mock_app/app/views/people/_first_name_form_column.html.erb +0 -2
- data/test/mock_app/app/views/people/_form.html.erb +0 -2
- data/test/mock_app/app/views/people/list.html.erb +0 -2
- data/test/mock_app/config/application.rb +0 -14
- data/test/mock_app/config/boot.rb +0 -7
- data/test/mock_app/config/database.yml +0 -16
- data/test/mock_app/config/environment.rb +0 -6
- data/test/mock_app/config/environments/development.rb +0 -24
- data/test/mock_app/config/environments/production.rb +0 -49
- data/test/mock_app/config/environments/test.rb +0 -34
- data/test/mock_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/mock_app/config/initializers/inflections.rb +0 -10
- data/test/mock_app/config/initializers/mime_types.rb +0 -5
- data/test/mock_app/config/initializers/secret_token.rb +0 -11
- data/test/mock_app/config/initializers/session_store.rb +0 -8
- data/test/mock_app/config/initializers/wrap_parameters.rb +0 -14
- data/test/mock_app/config/locales/en.yml +0 -5
- data/test/mock_app/config/routes.rb +0 -17
- data/test/mock_app/config.ru +0 -4
- data/test/mock_app/db/schema.rb +0 -68
- data/test/mock_app/db/test.sqlite3 +0 -1
- data/test/model_stub.rb +0 -64
- data/test/performance/list_cars_performance_test.rb +0 -34
- data/test/performance/list_people_performance_test.rb +0 -31
- data/test/performance_test_help.rb +0 -3
- data/test/run_all.rb +0 -6
- data/test/test_helper.rb +0 -71
- data/vendor/assets/javascripts/getprototypeof.js +0 -12
@@ -1,341 +1,436 @@
|
|
1
1
|
module ActiveScaffold::DataStructures
|
2
2
|
class Column
|
3
|
-
|
4
|
-
|
5
|
-
NO_PARAMS = Set.new.freeze
|
6
|
-
NO_OPTIONS = {}.freeze
|
3
|
+
module ProxyableMethods
|
4
|
+
extend ActiveSupport::Concern
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
included do # rubocop:disable Metrics/BlockLength
|
7
|
+
# Whether to enable inplace editing for this column. Currently works for text columns, in the List.
|
8
|
+
attr_reader :inplace_edit
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
# :table to refresh list
|
11
|
+
# true or :row to refresh row
|
12
|
+
attr_accessor :inplace_edit_update
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
def inplace_edit=(value)
|
17
|
-
clear_link if value
|
18
|
-
@inplace_edit = value
|
19
|
-
end
|
14
|
+
# Whether this column set is collapsed by default in contexts where collapsing is supported
|
15
|
+
attr_accessor :collapsed
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
attr_accessor :inplace_edit_update
|
17
|
+
# Whether to enable add_existing for this column
|
18
|
+
attr_accessor :allow_add_existing
|
24
19
|
|
25
|
-
|
26
|
-
|
20
|
+
# What columns load from main table
|
21
|
+
attr_accessor :select_columns
|
27
22
|
|
28
|
-
|
29
|
-
|
23
|
+
# define a calculation for the column. anything that ActiveRecord::Calculations::ClassMethods#calculate accepts will do.
|
24
|
+
attr_accessor :calculate
|
30
25
|
|
31
|
-
|
32
|
-
|
26
|
+
# A placeholder text, to be used inside blank text fields to describe, what should be typed in
|
27
|
+
attr_accessor :placeholder
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
return @params || NO_PARAMS if frozen?
|
37
|
-
@params ||= NO_PARAMS.dup
|
38
|
-
end
|
29
|
+
# this will be /joined/ to the :name for the td's class attribute. useful if you want to style columns on different ActiveScaffolds the same way, but the columns have different names.
|
30
|
+
attr_accessor :css_class
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
32
|
+
# whether the field is required or not. used on the form for visually indicating the fact to the user.
|
33
|
+
attr_writer :required
|
43
34
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
35
|
+
# the display-name of the column. this will be used, for instance, as the column title in the table and as the field name in the form.
|
36
|
+
# if left alone it will utilize human_attribute_name which includes localization
|
37
|
+
attr_writer :label
|
48
38
|
|
49
|
-
|
50
|
-
|
51
|
-
|
39
|
+
# a textual description of the column and its contents. this will be displayed with any associated form input widget, so you may want to consider adding a content example.
|
40
|
+
attr_writer :description
|
41
|
+
|
42
|
+
attr_reader :update_columns
|
43
|
+
|
44
|
+
# send all the form instead of only new value when this column changes
|
45
|
+
attr_accessor :send_form_on_update_column
|
46
|
+
|
47
|
+
# add a custom attr_accessor that can contain a Proc (or boolean or symbol)
|
48
|
+
# that will be called when the column renders, such that we can dynamically
|
49
|
+
# hide or show the column with an element that can be replaced by
|
50
|
+
# update_columns, but won't affect the form submission.
|
51
|
+
# The value can be set in the scaffold controller as follows to dynamically
|
52
|
+
# hide the column based on a Proc's output:
|
53
|
+
# config.columns[:my_column].hide_form_column_if = Proc.new { |record, column, scope| record.vehicle_type == 'tractor' }
|
54
|
+
# OR to always hide the column:
|
55
|
+
# config.columns[:my_column].hide_form_column_if = true
|
56
|
+
# OR to call a method on the record to determine whether to hide the column:
|
57
|
+
# config.columns[:my_column].hide_form_column_if = :hide_tractor_fields?
|
58
|
+
attr_accessor :hide_form_column_if
|
52
59
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
# a collection of columns to load from the association when eager loading is disabled, if it's nil all columns will be loaded
|
61
|
+
attr_accessor :select_associated_columns
|
62
|
+
|
63
|
+
# to modify the default order of columns
|
64
|
+
attr_accessor :weight
|
65
|
+
|
66
|
+
attr_accessor :associated_limit
|
67
|
+
|
68
|
+
attr_writer :associated_number
|
69
|
+
|
70
|
+
# what string to use to join records from plural associations
|
71
|
+
attr_accessor :association_join_text
|
72
|
+
|
73
|
+
attr_writer :show_blank_record
|
74
|
+
|
75
|
+
attr_accessor :actions_for_association_links
|
76
|
+
|
77
|
+
attr_writer :number
|
78
|
+
|
79
|
+
# supported options:
|
80
|
+
# * for association columns
|
81
|
+
# * :select - displays a simple <select> or a collection of checkboxes to (dis)associate records
|
82
|
+
attr_reader :form_ui
|
83
|
+
|
84
|
+
attr_reader :form_ui_options
|
85
|
+
|
86
|
+
# a collection of associations to pre-load when finding the records on a page
|
87
|
+
attr_reader :includes
|
88
|
+
|
89
|
+
# a place to store dev's column specific options
|
90
|
+
attr_writer :options
|
91
|
+
end
|
92
|
+
|
93
|
+
def inplace_edit=(value)
|
94
|
+
clear_link if value
|
95
|
+
@inplace_edit = value
|
96
|
+
end
|
97
|
+
|
98
|
+
# this should not only delete any existing link but also prevent column links from being automatically added by later routines
|
99
|
+
def clear_link
|
100
|
+
@link = nil
|
101
|
+
@autolink = false
|
102
|
+
end
|
103
|
+
|
104
|
+
# get whether to run a calculation on this column
|
105
|
+
def calculation?
|
106
|
+
!(calculate == false || calculate.nil?)
|
107
|
+
end
|
108
|
+
|
109
|
+
def required?(action = nil)
|
110
|
+
if action && @required
|
111
|
+
@required == true || @required.include?(action)
|
60
112
|
else
|
61
|
-
|
62
|
-
# headers). In this case fall back to the humanized attribute name
|
63
|
-
# instead of the Proc
|
64
|
-
active_record_class.human_attribute_name(name.to_s)
|
113
|
+
@required
|
65
114
|
end
|
66
|
-
else
|
67
|
-
as_(@label) || active_record_class.human_attribute_name(name.to_s)
|
68
115
|
end
|
69
|
-
end
|
70
116
|
|
71
|
-
|
72
|
-
|
73
|
-
def description(record = nil, scope = nil)
|
74
|
-
if @description&.respond_to?(:call)
|
75
|
-
@description.call(record, self, scope)
|
76
|
-
elsif @description
|
77
|
-
@description
|
78
|
-
else
|
79
|
-
I18n.t name, :scope => [:activerecord, :description, active_record_class.to_s.underscore.to_sym], :default => ''
|
117
|
+
def placeholder
|
118
|
+
@placeholder || I18n.t(name, scope: [:activerecord, :placeholder, active_record_class.to_s.underscore.to_sym], default: '')
|
80
119
|
end
|
81
|
-
end
|
82
120
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
121
|
+
def label(record = nil, scope = nil)
|
122
|
+
label =
|
123
|
+
if @label.respond_to?(:call)
|
124
|
+
# sometimes label is called without a record in context (ie, from table
|
125
|
+
# headers). In this case fall back to the default instead of the Proc.
|
126
|
+
@label.call(record, self, scope) if record
|
127
|
+
elsif @label
|
128
|
+
as_(@label)
|
129
|
+
end
|
130
|
+
label || active_record_class.human_attribute_name(name.to_s)
|
131
|
+
end
|
88
132
|
|
89
|
-
|
90
|
-
|
133
|
+
def description(record = nil, scope = nil)
|
134
|
+
if @description.respond_to?(:call)
|
135
|
+
@description.call(record, self, scope)
|
136
|
+
elsif @description
|
137
|
+
@description
|
138
|
+
else
|
139
|
+
I18n.t name, scope: [:activerecord, :description, active_record_class.to_s.underscore.to_sym], default: ''
|
140
|
+
end
|
141
|
+
end
|
91
142
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
@required == true || @required.include?(action)
|
98
|
-
else
|
99
|
-
@required
|
143
|
+
# update dependent columns after value change in form
|
144
|
+
# update_columns = :name
|
145
|
+
# update_columns = [:name, :age]
|
146
|
+
def update_columns=(column_names)
|
147
|
+
@update_columns = Array(column_names)
|
100
148
|
end
|
101
|
-
end
|
102
149
|
|
103
|
-
|
150
|
+
# sorting on a column can be configured four ways:
|
151
|
+
# sort = true default, uses intelligent sorting sql default
|
152
|
+
# sort = false sometimes sorting doesn't make sense
|
153
|
+
# sort = {sql: ""} define your own sql for sorting. this should be result in a sortable value in SQL. ActiveScaffold will handle the ascending/descending.
|
154
|
+
# sort = {method: ""} define ruby-side code for sorting. this is SLOW with large recordsets!
|
155
|
+
def sort=(value)
|
156
|
+
if value.is_a? Hash
|
157
|
+
value.assert_valid_keys(:sql, :method)
|
158
|
+
@sort = value
|
159
|
+
else
|
160
|
+
@sort = value ? true : false # force true or false
|
161
|
+
end
|
162
|
+
end
|
104
163
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
@update_columns = Array(column_names)
|
110
|
-
end
|
164
|
+
def sort
|
165
|
+
initialize_sort if @sort == true
|
166
|
+
@sort
|
167
|
+
end
|
111
168
|
|
112
|
-
|
113
|
-
|
114
|
-
attr_accessor :send_form_on_update_column
|
115
|
-
|
116
|
-
# add a custom attr_accessor that can contain a Proc (or boolean or symbol)
|
117
|
-
# that will be called when the column renders, such that we can dynamically
|
118
|
-
# hide or show the column with an element that can be replaced by
|
119
|
-
# update_columns, but won't affect the form submission.
|
120
|
-
# The value can be set in the scaffold controller as follows to dynamically
|
121
|
-
# hide the column based on a Proc's output:
|
122
|
-
# config.columns[:my_column].hide_form_column_if = Proc.new { |record, column, scope| record.vehicle_type == 'tractor' }
|
123
|
-
# OR to always hide the column:
|
124
|
-
# config.columns[:my_column].hide_form_column_if = true
|
125
|
-
# OR to call a method on the record to determine whether to hide the column:
|
126
|
-
# config.columns[:my_column].hide_form_column_if = :hide_tractor_fields?
|
127
|
-
attr_accessor :hide_form_column_if
|
128
|
-
|
129
|
-
# sorting on a column can be configured four ways:
|
130
|
-
# sort = true default, uses intelligent sorting sql default
|
131
|
-
# sort = false sometimes sorting doesn't make sense
|
132
|
-
# sort = {:sql => ""} define your own sql for sorting. this should be result in a sortable value in SQL. ActiveScaffold will handle the ascending/descending.
|
133
|
-
# sort = {:method => ""} define ruby-side code for sorting. this is SLOW with large recordsets!
|
134
|
-
def sort=(value)
|
135
|
-
if value.is_a? Hash
|
136
|
-
value.assert_valid_keys(:sql, :method)
|
137
|
-
@sort = value
|
138
|
-
else
|
139
|
-
@sort = value ? true : false # force true or false
|
169
|
+
def sortable?
|
170
|
+
sort != false && !sort.nil?
|
140
171
|
end
|
141
|
-
end
|
142
172
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
173
|
+
# a configuration helper for the self.sort property. simply provides a method syntax instead of setter syntax.
|
174
|
+
def sort_by(options)
|
175
|
+
self.sort = options
|
176
|
+
end
|
147
177
|
|
148
|
-
|
149
|
-
|
150
|
-
|
178
|
+
def associated_number?
|
179
|
+
@associated_number
|
180
|
+
end
|
151
181
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
182
|
+
def show_blank_record?(associated)
|
183
|
+
return false unless @show_blank_record
|
184
|
+
return false unless association.klass.authorized_for?(crud_type: :create) && !association.readonly?
|
156
185
|
|
157
|
-
|
158
|
-
|
159
|
-
# * :select - displays a simple <select> or a collection of checkboxes to (dis)associate records
|
160
|
-
attr_reader :form_ui
|
186
|
+
association.collection? || (association.singular? && associated.blank?)
|
187
|
+
end
|
161
188
|
|
162
|
-
|
189
|
+
def number?
|
190
|
+
@number
|
191
|
+
end
|
163
192
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
193
|
+
def <=>(other)
|
194
|
+
order_weight = weight <=> other.weight
|
195
|
+
order_weight.nonzero? ? order_weight : name.to_s <=> other.name.to_s
|
196
|
+
end
|
169
197
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
@list_ui, @list_ui_options = *value
|
174
|
-
end
|
198
|
+
def convert_to_native?
|
199
|
+
number? && options[:format] && form_ui != :number
|
200
|
+
end
|
175
201
|
|
176
|
-
|
177
|
-
|
178
|
-
|
202
|
+
def number_to_native(value)
|
203
|
+
return value if value.blank? || !value.is_a?(String)
|
204
|
+
|
205
|
+
native = '.' # native ruby separator
|
206
|
+
format = {separator: '', delimiter: ''}.merge! I18n.t('number.format', default: {})
|
207
|
+
specific =
|
208
|
+
case options[:format]
|
209
|
+
when :currency
|
210
|
+
I18n.t('number.currency.format', default: nil)
|
211
|
+
when :size
|
212
|
+
I18n.t('number.human.format', default: nil)
|
213
|
+
when :percentage
|
214
|
+
I18n.t('number.percentage.format', default: nil)
|
215
|
+
end
|
216
|
+
format.merge! specific unless specific.nil?
|
217
|
+
if format[:separator].blank? || (value.exclude?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/))
|
218
|
+
value
|
219
|
+
else
|
220
|
+
value.gsub(/[^0-9\-#{format[:separator]}]/, '').gsub(format[:separator], native)
|
221
|
+
end
|
222
|
+
end
|
179
223
|
|
180
|
-
|
181
|
-
|
182
|
-
|
224
|
+
# value must be a Symbol, or an Array of form_ui and options hash which will be used with form_ui only
|
225
|
+
def form_ui=(value)
|
226
|
+
check_valid_action_ui_params(value)
|
227
|
+
@form_ui, @form_ui_options = *value
|
228
|
+
end
|
183
229
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
230
|
+
# value must be a Symbol, or an Array of list_ui and options hash which will be used with list_ui only
|
231
|
+
def list_ui=(value)
|
232
|
+
check_valid_action_ui_params(value)
|
233
|
+
@list_ui, @list_ui_options = *value
|
234
|
+
end
|
189
235
|
|
190
|
-
|
191
|
-
|
192
|
-
|
236
|
+
def list_ui
|
237
|
+
@list_ui || form_ui
|
238
|
+
end
|
193
239
|
|
194
|
-
|
195
|
-
|
196
|
-
|
240
|
+
def list_ui_options
|
241
|
+
@list_ui ? @list_ui_options : form_ui_options
|
242
|
+
end
|
197
243
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
244
|
+
# value must be a Symbol, or an Array of show_ui and options hash which will be used with show_ui only
|
245
|
+
def show_ui=(value)
|
246
|
+
check_valid_action_ui_params(value)
|
247
|
+
@show_ui, @show_ui_options = *value
|
248
|
+
end
|
203
249
|
|
204
|
-
|
205
|
-
|
206
|
-
|
250
|
+
def show_ui
|
251
|
+
@show_ui || list_ui
|
252
|
+
end
|
207
253
|
|
208
|
-
|
209
|
-
|
210
|
-
|
254
|
+
def show_ui_options
|
255
|
+
@show_ui ? @show_ui_options : list_ui_options
|
256
|
+
end
|
211
257
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
end
|
258
|
+
# value must be a Symbol, or an Array of search_ui and options hash which will be used with search_ui only
|
259
|
+
def search_ui=(value)
|
260
|
+
check_valid_action_ui_params(value)
|
261
|
+
@search_ui, @search_ui_options = *value
|
262
|
+
end
|
218
263
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
@link
|
223
|
-
end
|
264
|
+
def search_ui
|
265
|
+
@search_ui || form_ui || (:select if association && !association.polymorphic?)
|
266
|
+
end
|
224
267
|
|
225
|
-
|
226
|
-
|
227
|
-
if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc)
|
228
|
-
@link = action
|
229
|
-
else
|
230
|
-
options[:label] ||= label
|
231
|
-
options[:position] ||= :after unless options.key?(:position)
|
232
|
-
options[:type] ||= :member
|
233
|
-
@link = ActiveScaffold::DataStructures::ActionLink.new(action, options)
|
268
|
+
def search_ui_options
|
269
|
+
@search_ui ? @search_ui_options : form_ui_options
|
234
270
|
end
|
235
|
-
end
|
236
271
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
272
|
+
def includes=(value)
|
273
|
+
@includes =
|
274
|
+
case value
|
275
|
+
when Array then value
|
276
|
+
else value ? [value] : value # not convert nil to [nil]
|
277
|
+
end
|
278
|
+
end
|
241
279
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
end
|
280
|
+
# a collection of associations to do left join when this column is included on search
|
281
|
+
def search_joins
|
282
|
+
@search_joins || includes
|
283
|
+
end
|
247
284
|
|
248
|
-
|
249
|
-
|
285
|
+
def search_joins=(value)
|
286
|
+
@search_joins =
|
287
|
+
case value
|
288
|
+
when Array then value
|
289
|
+
else [value] # automatically convert to an array
|
290
|
+
end
|
291
|
+
end
|
250
292
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
293
|
+
# describes how to search on a column
|
294
|
+
# search = true default, uses intelligent search sql
|
295
|
+
# search = "CONCAT(a, b)" define your own sql for searching. this should be the "left-side" of a WHERE condition. the operator and value will be supplied by ActiveScaffold.
|
296
|
+
# search = [:a, :b] searches in both fields
|
297
|
+
def search_sql=(value)
|
298
|
+
@search_sql =
|
299
|
+
if value
|
300
|
+
value == true || value.is_a?(Proc) ? value : Array(value)
|
301
|
+
else
|
302
|
+
value
|
303
|
+
end
|
304
|
+
end
|
255
305
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
306
|
+
def search_sql
|
307
|
+
initialize_search_sql if @search_sql == true
|
308
|
+
@search_sql
|
309
|
+
end
|
310
|
+
|
311
|
+
def searchable?
|
312
|
+
search_sql.present?
|
313
|
+
end
|
314
|
+
|
315
|
+
def link
|
316
|
+
if frozen? && @link.is_a?(Proc)
|
317
|
+
ActiveScaffold::Registry.cache(:column_links, cache_key) { @link.call(self).deep_freeze! }
|
318
|
+
else
|
319
|
+
@link = @link.call(self) if @link.is_a? Proc
|
320
|
+
@link
|
263
321
|
end
|
322
|
+
end
|
323
|
+
|
324
|
+
# associate an action_link with this column
|
325
|
+
def set_link(action, options = {})
|
326
|
+
if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc)
|
327
|
+
@link = action
|
328
|
+
else
|
329
|
+
options[:label] ||= label
|
330
|
+
options[:position] ||= :after unless options.key?(:position)
|
331
|
+
options[:type] ||= :member
|
332
|
+
@link = ActiveScaffold::DataStructures::ActionLink.new(action, options)
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
def cache_count?
|
337
|
+
includes.blank? && associated_number? && association&.cache_count?
|
338
|
+
end
|
339
|
+
|
340
|
+
def attributes=(opts)
|
341
|
+
opts.each do |setting, value|
|
342
|
+
send :"#{setting}=", value
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
protected
|
347
|
+
|
348
|
+
def initialize_sort
|
349
|
+
self.sort =
|
350
|
+
if column && !tableless?
|
351
|
+
{sql: field}
|
352
|
+
else
|
353
|
+
false
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
def initialize_search_sql
|
358
|
+
self.search_sql =
|
359
|
+
unless virtual?
|
360
|
+
if association.nil?
|
361
|
+
field.to_s unless tableless?
|
362
|
+
elsif association.allow_join?
|
363
|
+
[association.quoted_table_name, association.quoted_primary_key].join('.') unless association.klass < ActiveScaffold::Tableless
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
264
367
|
end
|
265
368
|
|
266
|
-
|
267
|
-
|
268
|
-
|
369
|
+
include ActiveScaffold::Configurable
|
370
|
+
include ActiveScaffold::OrmChecks
|
371
|
+
NO_PARAMS = Set.new.freeze
|
372
|
+
NO_OPTIONS = {}.freeze
|
373
|
+
|
374
|
+
attr_reader :active_record_class
|
375
|
+
alias model active_record_class
|
376
|
+
|
377
|
+
# this is the name of the getter on the ActiveRecord model. it is the only absolutely required attribute ... all others will be inferred from this name.
|
378
|
+
attr_reader :name
|
379
|
+
|
380
|
+
include ProxyableMethods
|
381
|
+
|
382
|
+
# Any extra parameters this particular column uses. This is for create/update purposes.
|
383
|
+
def params
|
384
|
+
return @params || NO_PARAMS if frozen?
|
385
|
+
|
386
|
+
@params ||= NO_PARAMS.dup
|
269
387
|
end
|
270
388
|
|
271
|
-
def
|
272
|
-
@
|
273
|
-
case value
|
274
|
-
when Array then value
|
275
|
-
else [value] # automatically convert to an array
|
276
|
-
end
|
389
|
+
def default_value
|
390
|
+
@default_value || @db_default_value
|
277
391
|
end
|
278
392
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
# search = true default, uses intelligent search sql
|
284
|
-
# search = "CONCAT(a, b)" define your own sql for searching. this should be the "left-side" of a WHERE condition. the operator and value will be supplied by ActiveScaffold.
|
285
|
-
# search = [:a, :b] searches in both fields
|
286
|
-
def search_sql=(value)
|
287
|
-
@search_sql =
|
288
|
-
if value
|
289
|
-
value == true || value.is_a?(Proc) ? value : Array(value)
|
290
|
-
else
|
291
|
-
value
|
292
|
-
end
|
393
|
+
def default_value=(value)
|
394
|
+
raise ArgumentError, "Can't set default value for non-DB columns (virtual columns or associations)" unless column
|
395
|
+
|
396
|
+
@default_value = value
|
293
397
|
end
|
294
398
|
|
295
|
-
def
|
296
|
-
|
297
|
-
@search_sql
|
399
|
+
def default_value?
|
400
|
+
defined? @default_value
|
298
401
|
end
|
299
402
|
|
300
|
-
|
301
|
-
|
403
|
+
# default to send all the form instead of only new value when a column changes
|
404
|
+
cattr_accessor :send_form_on_update_column, instance_accessor: false
|
405
|
+
|
406
|
+
def options
|
407
|
+
return @options || NO_OPTIONS if frozen?
|
408
|
+
|
409
|
+
@options ||= NO_OPTIONS.dup
|
302
410
|
end
|
303
411
|
|
304
|
-
# to
|
305
|
-
|
412
|
+
# set an action_link to nested list or inline form in this column
|
413
|
+
def autolink?
|
414
|
+
@autolink
|
415
|
+
end
|
306
416
|
|
307
417
|
# to set how many associated records a column with plural association must show in list
|
308
418
|
cattr_accessor :associated_limit, instance_accessor: false
|
309
419
|
@@associated_limit = 3
|
310
|
-
attr_accessor :associated_limit
|
311
420
|
|
312
421
|
# whether the number of associated records must be shown or not
|
313
422
|
cattr_accessor :associated_number, instance_accessor: false
|
314
423
|
@@associated_number = true
|
315
|
-
attr_writer :associated_number
|
316
|
-
def associated_number?
|
317
|
-
@associated_number
|
318
|
-
end
|
319
|
-
|
320
|
-
# what string to use to join records from plural associations
|
321
|
-
attr_accessor :association_join_text
|
322
424
|
|
323
425
|
# whether a blank row must be shown in the subform
|
324
426
|
cattr_accessor :show_blank_record, instance_accessor: false
|
325
427
|
@@show_blank_record = true
|
326
|
-
attr_writer :show_blank_record
|
327
|
-
def show_blank_record?(associated)
|
328
|
-
return false unless @show_blank_record
|
329
|
-
return false unless association.klass.authorized_for?(:crud_type => :create) && !association.readonly?
|
330
|
-
association.collection? || (association.singular? && associated.blank?)
|
331
|
-
end
|
332
428
|
|
333
429
|
# methods for automatic links in singular association columns
|
334
430
|
cattr_accessor :actions_for_association_links, instance_accessor: false
|
335
431
|
@@actions_for_association_links = %i[new edit show]
|
336
|
-
attr_accessor :actions_for_association_links
|
337
432
|
|
338
|
-
cattr_accessor :association_form_ui
|
433
|
+
cattr_accessor :association_form_ui, instance_accessor: false
|
339
434
|
@@association_form_ui = nil
|
340
435
|
|
341
436
|
# ----------------------------------------------------------------- #
|
@@ -356,17 +451,12 @@ module ActiveScaffold::DataStructures
|
|
356
451
|
column.nil? && association.nil?
|
357
452
|
end
|
358
453
|
|
359
|
-
attr_writer :number
|
360
|
-
def number?
|
361
|
-
@number
|
362
|
-
end
|
363
|
-
|
364
454
|
def text?
|
365
455
|
@text
|
366
456
|
end
|
367
457
|
|
368
458
|
# this is so that array.delete and array.include?, etc., will work by column name
|
369
|
-
def ==(other)
|
459
|
+
def ==(other) # :nodoc:
|
370
460
|
# another column
|
371
461
|
if other.respond_to?(:name) && other.class == self.class
|
372
462
|
name == other.name.to_sym
|
@@ -383,7 +473,7 @@ module ActiveScaffold::DataStructures
|
|
383
473
|
attr_reader :cache_key
|
384
474
|
|
385
475
|
# instantiation is handled internally through the DataStructures::Columns object
|
386
|
-
def initialize(name, active_record_class, delegated_association = nil)
|
476
|
+
def initialize(name, active_record_class, delegated_association = nil) # :nodoc:
|
387
477
|
@name = name.to_sym
|
388
478
|
@active_record_class = active_record_class
|
389
479
|
@column = _columns_hash[name.to_s]
|
@@ -419,9 +509,9 @@ module ActiveScaffold::DataStructures
|
|
419
509
|
# default all the configurable variables
|
420
510
|
self.css_class = ''
|
421
511
|
validators_force_require_on = active_record_class.validators_on(name)
|
422
|
-
|
423
|
-
|
424
|
-
self.required = validators_force_require_on.any?
|
512
|
+
.map { |val| validator_force_required?(val) }
|
513
|
+
.compact_blank
|
514
|
+
self.required = validators_force_require_on.any?(true) ||
|
425
515
|
validators_force_require_on.reject { |opt| opt == true }.flatten.presence
|
426
516
|
self.sort = true
|
427
517
|
self.search_sql = true
|
@@ -432,41 +522,13 @@ module ActiveScaffold::DataStructures
|
|
432
522
|
# just the field (not table.field)
|
433
523
|
def field_name
|
434
524
|
return nil if virtual?
|
435
|
-
@field_name ||= column ? quoted_field_name(column.name) : quoted_field_name(association.foreign_key)
|
436
|
-
end
|
437
|
-
|
438
|
-
def <=>(other)
|
439
|
-
order_weight = weight <=> other.weight
|
440
|
-
order_weight.nonzero? ? order_weight : name.to_s <=> other.name.to_s
|
441
|
-
end
|
442
525
|
|
443
|
-
|
444
|
-
number? && options[:format] && form_ui != :number
|
445
|
-
end
|
446
|
-
|
447
|
-
def number_to_native(value)
|
448
|
-
return value if value.blank? || !value.is_a?(String)
|
449
|
-
native = '.' # native ruby separator
|
450
|
-
format = {:separator => '', :delimiter => ''}.merge! I18n.t('number.format', :default => {})
|
451
|
-
specific =
|
452
|
-
case options[:format]
|
453
|
-
when :currency
|
454
|
-
I18n.t('number.currency.format', :default => nil)
|
455
|
-
when :size
|
456
|
-
I18n.t('number.human.format', :default => nil)
|
457
|
-
when :percentage
|
458
|
-
I18n.t('number.percentage.format', :default => nil)
|
459
|
-
end
|
460
|
-
format.merge! specific unless specific.nil?
|
461
|
-
if format[:separator].blank? || !value.include?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/)
|
462
|
-
value
|
463
|
-
else
|
464
|
-
value.gsub(/[^0-9\-#{format[:separator]}]/, '').gsub(format[:separator], native)
|
465
|
-
end
|
526
|
+
@field_name ||= column ? quoted_field_name(column.name) : quoted_field_name(association.foreign_key)
|
466
527
|
end
|
467
528
|
|
468
529
|
def default_for_empty_value
|
469
530
|
return nil unless column
|
531
|
+
|
470
532
|
if column.is_a?(ActiveModel::Attribute)
|
471
533
|
column.value
|
472
534
|
elsif active_record? && null?
|
@@ -501,12 +563,6 @@ module ActiveScaffold::DataStructures
|
|
501
563
|
ActiveScaffold::OrmChecks.column_type active_record_class, name
|
502
564
|
end
|
503
565
|
|
504
|
-
def attributes=(opts)
|
505
|
-
opts.each do |setting, value|
|
506
|
-
send "#{setting}=", value
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
566
|
def cast(value)
|
511
567
|
ActiveScaffold::OrmChecks.cast active_record_class, name, value
|
512
568
|
end
|
@@ -516,11 +572,11 @@ module ActiveScaffold::DataStructures
|
|
516
572
|
def setup_defaults_for_column
|
517
573
|
if active_record_class.respond_to?(:defined_enums) && active_record_class.defined_enums[name.to_s]
|
518
574
|
@form_ui = :select
|
519
|
-
@options = {:
|
575
|
+
@options = {options: active_record_class.send(name.to_s.pluralize).keys.map(&:to_sym)}
|
520
576
|
elsif column_number?
|
521
577
|
@number = true
|
522
578
|
@form_ui = :number
|
523
|
-
@options = {:
|
579
|
+
@options = {format: :i18n_number}
|
524
580
|
else
|
525
581
|
@form_ui =
|
526
582
|
case column_type
|
@@ -547,6 +603,7 @@ module ActiveScaffold::DataStructures
|
|
547
603
|
|
548
604
|
def validator_force_required?(val)
|
549
605
|
return false if val.options[:if] || val.options[:unless]
|
606
|
+
|
550
607
|
case val
|
551
608
|
when ActiveModel::Validations::PresenceValidator
|
552
609
|
validator_required_on(val)
|
@@ -588,8 +645,11 @@ module ActiveScaffold::DataStructures
|
|
588
645
|
end
|
589
646
|
|
590
647
|
def column_number?
|
591
|
-
|
592
|
-
|
648
|
+
if active_record?
|
649
|
+
%i[float decimal integer].include? column_type
|
650
|
+
elsif mongoid?
|
651
|
+
@column.type < Numeric
|
652
|
+
end
|
593
653
|
end
|
594
654
|
|
595
655
|
def quoted_field_name(column_name)
|
@@ -604,26 +664,6 @@ module ActiveScaffold::DataStructures
|
|
604
664
|
active_record? ? [_quoted_table_name, name].compact.join('.') : name
|
605
665
|
end
|
606
666
|
|
607
|
-
def initialize_sort
|
608
|
-
self.sort =
|
609
|
-
if column && !tableless?
|
610
|
-
{:sql => field}
|
611
|
-
else
|
612
|
-
false
|
613
|
-
end
|
614
|
-
end
|
615
|
-
|
616
|
-
def initialize_search_sql
|
617
|
-
self.search_sql =
|
618
|
-
unless virtual?
|
619
|
-
if association.nil?
|
620
|
-
field.to_s unless tableless?
|
621
|
-
elsif association.allow_join?
|
622
|
-
[association.quoted_table_name, association.quoted_primary_key].join('.') unless association.klass < ActiveScaffold::Tableless
|
623
|
-
end
|
624
|
-
end
|
625
|
-
end
|
626
|
-
|
627
667
|
# the table name from the ActiveRecord class
|
628
668
|
attr_reader :table
|
629
669
|
|
@@ -645,6 +685,7 @@ module ActiveScaffold::DataStructures
|
|
645
685
|
|
646
686
|
def check_valid_action_ui_params(value)
|
647
687
|
return true if valid_action_ui_params?(value)
|
688
|
+
|
648
689
|
raise ArgumentError, 'value must be a Symbol, or an array of Symbol and Hash'
|
649
690
|
end
|
650
691
|
|