active_scaffold 3.4.43 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +39 -0
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +27 -19
- data/app/assets/javascripts/active_scaffold.js.erb +1 -1
- data/app/assets/javascripts/jquery/active_scaffold.js +95 -43
- data/app/assets/javascripts/jquery/tiny_mce_bridge.js +30 -6
- data/app/assets/javascripts/prototype/tiny_mce_bridge.js +11 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +2 -2
- data/app/assets/stylesheets/active_scaffold_layout.css +36 -28
- data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -3
- data/app/views/active_scaffold_overrides/_field_search.html.erb +8 -7
- data/app/views/active_scaffold_overrides/_form_association.html.erb +9 -9
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +52 -50
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_human_conditions.html.erb +3 -1
- data/app/views/active_scaffold_overrides/_list_calculations.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_list_column_headings.html.erb +2 -0
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +5 -3
- data/app/views/active_scaffold_overrides/_list_record.html.erb +3 -1
- data/app/views/active_scaffold_overrides/_list_with_header.html.erb +9 -9
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +18 -10
- data/app/views/active_scaffold_overrides/_render_field.js.erb +3 -3
- data/app/views/active_scaffold_overrides/_search.html.erb +7 -6
- data/app/views/active_scaffold_overrides/_show_actions.html.erb +14 -0
- data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_actions.html.erb +6 -2
- data/app/views/active_scaffold_overrides/_update_column.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/destroy.js.erb +2 -3
- data/app/views/active_scaffold_overrides/edit_associated.js.erb +4 -3
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +5 -3
- data/app/views/active_scaffold_overrides/on_create.js.erb +4 -4
- data/app/views/active_scaffold_overrides/on_update.js.erb +6 -6
- data/app/views/active_scaffold_overrides/show.html.erb +6 -0
- data/app/views/active_scaffold_overrides/update.html.erb +1 -1
- data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
- data/config/brakeman.ignore +26 -0
- data/config/brakeman.yml +3 -0
- data/config/i18n-tasks.yml +121 -0
- data/config/locales/de.yml +81 -70
- data/config/locales/en.yml +83 -74
- data/config/locales/es.yml +82 -73
- data/config/locales/fr.yml +86 -75
- data/config/locales/hu.yml +81 -70
- data/config/locales/ja.yml +71 -60
- data/config/locales/ru.yml +85 -74
- data/lib/active_scaffold.rb +3 -0
- data/lib/active_scaffold/actions/common_search.rb +11 -7
- data/lib/active_scaffold/actions/core.rb +119 -47
- data/lib/active_scaffold/actions/create.rb +1 -1
- data/lib/active_scaffold/actions/delete.rb +11 -8
- data/lib/active_scaffold/actions/field_search.rb +104 -6
- data/lib/active_scaffold/actions/list.rb +25 -21
- data/lib/active_scaffold/actions/mark.rb +12 -4
- data/lib/active_scaffold/actions/nested.rb +26 -26
- data/lib/active_scaffold/actions/search.rb +2 -2
- data/lib/active_scaffold/actions/show.rb +4 -5
- data/lib/active_scaffold/actions/subform.rb +9 -7
- data/lib/active_scaffold/actions/update.rb +20 -13
- data/lib/active_scaffold/active_record_permissions.rb +24 -5
- data/lib/active_scaffold/attribute_params.rb +68 -49
- data/lib/active_scaffold/bridges.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +15 -19
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +10 -14
- data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -7
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +19 -22
- data/lib/active_scaffold/bridges/cancan.rb +4 -3
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +11 -21
- data/lib/active_scaffold/bridges/carrierwave.rb +2 -1
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +2 -6
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +6 -39
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/chosen.rb +4 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +3 -2
- data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker.rb +3 -0
- data/lib/active_scaffold/bridges/date_picker/ext.rb +43 -38
- data/lib/active_scaffold/bridges/date_picker/helper.rb +24 -23
- data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +3 -25
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +2 -2
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +6 -8
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +0 -2
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +2 -1
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/actions.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -2
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/paperclip.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +3 -28
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/record_select.rb +2 -0
- data/lib/active_scaffold/bridges/record_select/helpers.rb +14 -18
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +4 -8
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -20
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +7 -22
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +14 -14
- data/lib/active_scaffold/config/base.rb +9 -6
- data/lib/active_scaffold/config/core.rb +30 -21
- data/lib/active_scaffold/config/create.rb +2 -1
- data/lib/active_scaffold/config/delete.rb +2 -2
- data/lib/active_scaffold/config/field_search.rb +9 -3
- data/lib/active_scaffold/config/form.rb +4 -4
- data/lib/active_scaffold/config/list.rb +27 -23
- data/lib/active_scaffold/config/nested.rb +4 -4
- data/lib/active_scaffold/config/search.rb +6 -6
- data/lib/active_scaffold/config/show.rb +11 -1
- data/lib/active_scaffold/config/subform.rb +1 -1
- data/lib/active_scaffold/config/update.rb +4 -2
- data/lib/active_scaffold/constraints.rb +39 -36
- data/lib/active_scaffold/core.rb +36 -15
- data/lib/active_scaffold/data_structures/action_columns.rb +14 -9
- data/lib/active_scaffold/data_structures/action_link.rb +4 -5
- data/lib/active_scaffold/data_structures/action_links.rb +5 -4
- data/lib/active_scaffold/data_structures/actions.rb +2 -2
- data/lib/active_scaffold/data_structures/association.rb +8 -0
- data/lib/active_scaffold/data_structures/association/abstract.rb +147 -0
- data/lib/active_scaffold/data_structures/association/active_mongoid.rb +42 -0
- data/lib/active_scaffold/data_structures/association/active_record.rb +94 -0
- data/lib/active_scaffold/data_structures/association/mongoid.rb +45 -0
- data/lib/active_scaffold/data_structures/bridge.rb +3 -6
- data/lib/active_scaffold/data_structures/column.rb +100 -82
- data/lib/active_scaffold/data_structures/columns.rb +21 -3
- data/lib/active_scaffold/data_structures/nested_info.rb +22 -37
- data/lib/active_scaffold/data_structures/set.rb +4 -4
- data/lib/active_scaffold/data_structures/sorting.rb +29 -15
- data/lib/active_scaffold/engine.rb +3 -1
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +10 -5
- data/lib/active_scaffold/extensions/action_view_rendering.rb +65 -59
- data/lib/active_scaffold/extensions/left_outer_joins.rb +48 -53
- data/lib/active_scaffold/extensions/localize.rb +3 -4
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +7 -11
- data/lib/active_scaffold/extensions/paginator_extensions.rb +20 -18
- data/lib/active_scaffold/extensions/routing_mapper.rb +104 -40
- data/lib/active_scaffold/extensions/to_label.rb +1 -1
- data/lib/active_scaffold/extensions/unsaved_associated.rb +4 -13
- data/lib/active_scaffold/extensions/unsaved_record.rb +12 -1
- data/lib/active_scaffold/finder.rb +200 -134
- data/lib/active_scaffold/helpers/action_link_helpers.rb +398 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +12 -30
- data/lib/active_scaffold/helpers/controller_helpers.rb +74 -24
- data/lib/active_scaffold/helpers/form_column_helpers.rb +205 -112
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +21 -11
- data/lib/active_scaffold/helpers/id_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/list_column_helpers.rb +117 -39
- data/lib/active_scaffold/helpers/pagination_helpers.rb +11 -14
- data/lib/active_scaffold/helpers/search_column_helpers.rb +69 -32
- data/lib/active_scaffold/helpers/show_column_helpers.rb +9 -3
- data/lib/active_scaffold/helpers/view_helpers.rb +41 -426
- data/lib/active_scaffold/orm_checks.rb +109 -0
- data/lib/active_scaffold/paginator.rb +1 -1
- data/lib/active_scaffold/responds_to_parent.rb +12 -10
- data/lib/active_scaffold/tableless.rb +81 -43
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/generators/active_scaffold/controller_generator.rb +49 -0
- data/lib/generators/active_scaffold/install_generator.rb +45 -0
- data/lib/generators/active_scaffold/resource_generator.rb +56 -0
- data/lib/generators/{active_scaffold_controller/templates → templates}/controller.rb +0 -0
- data/lib/generators/{active_scaffold_controller/templates → templates}/helper.rb +0 -0
- data/shoulda_macros/macros.rb +3 -3
- data/test/active_scaffold_config_mock.rb +33 -0
- data/test/bridges/bridge_test.rb +9 -9
- data/test/bridges/date_picker_test.rb +3 -1
- data/test/bridges/paper_trail_test.rb +2 -3
- data/test/bridges/paperclip_test.rb +21 -10
- data/test/bridges/tiny_mce_test.rb +20 -21
- data/test/class_with_finder.rb +42 -0
- data/test/company.rb +6 -4
- data/test/config/core_test.rb +1 -1
- data/test/config/create_test.rb +1 -1
- data/test/config/list_test.rb +3 -3
- data/test/config/update_test.rb +3 -3
- data/test/data_structures/action_columns_test.rb +3 -3
- data/test/data_structures/association_column_test.rb +5 -5
- data/test/data_structures/column_test.rb +14 -14
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/set_test.rb +2 -2
- data/test/data_structures/sorting_test.rb +6 -4
- data/test/extensions/active_record_test.rb +1 -1
- data/test/extensions/routing_mapper_test.rb +64 -13
- data/test/helpers/form_column_helpers_test.rb +6 -6
- data/test/helpers/list_column_helpers_test.rb +9 -5
- data/test/helpers/pagination_helpers_test.rb +1 -0
- data/test/misc/active_record_permissions_test.rb +18 -1
- data/test/misc/attribute_params_test.rb +26 -17
- data/test/misc/calculation_test.rb +8 -31
- data/test/misc/configurable_test.rb +3 -2
- data/test/misc/constraints_test.rb +33 -22
- data/test/misc/convert_numbers_format_test.rb +28 -10
- data/test/misc/finder_test.rb +6 -29
- data/test/misc/parse_datetime_test.rb +160 -0
- data/test/misc/render_test.rb +1 -1
- data/test/misc/tableless_test.rb +24 -0
- data/test/mock_app/app/models/building.rb +2 -1
- data/test/mock_app/config.ru +1 -1
- data/test/mock_app/config/environments/test.rb +1 -1
- data/test/mock_app/config/routes.rb +11 -3
- data/test/model_stub.rb +11 -6
- data/test/run_all.rb +1 -1
- data/test/test_helper.rb +19 -4
- metadata +42 -23
- data/lib/active_scaffold/data_structures/error_message.rb +0 -22
- data/lib/active_scaffold/extensions/reverse_associations.rb +0 -119
- data/lib/generators/active_scaffold/USAGE +0 -29
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +0 -21
- data/lib/generators/active_scaffold_controller/USAGE +0 -19
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +0 -29
- data/test/data_structures/error_message_test.rb +0 -25
@@ -2,7 +2,7 @@ module ActiveScaffold
|
|
2
2
|
module Helpers
|
3
3
|
module ListColumnHelpers
|
4
4
|
def active_scaffold_column_paperclip(record, column)
|
5
|
-
paperclip = record.send(
|
5
|
+
paperclip = record.send(column.name.to_s)
|
6
6
|
return nil unless paperclip.file?
|
7
7
|
content =
|
8
8
|
if paperclip.styles.include?(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style)
|
@@ -2,8 +2,8 @@ module ActiveScaffold
|
|
2
2
|
module Bridges
|
3
3
|
class Paperclip
|
4
4
|
module PaperclipBridge
|
5
|
-
def
|
6
|
-
|
5
|
+
def initialize(model_id)
|
6
|
+
super
|
7
7
|
return unless model.respond_to?(:attachment_definitions) && !model.attachment_definitions.nil?
|
8
8
|
|
9
9
|
update.multipart = true
|
@@ -16,10 +16,6 @@ module ActiveScaffold
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.included(base)
|
20
|
-
base.alias_method_chain :initialize, :paperclip
|
21
|
-
end
|
22
|
-
|
23
19
|
private
|
24
20
|
|
25
21
|
def configure_paperclip_field(field)
|
@@ -27,7 +23,7 @@ module ActiveScaffold
|
|
27
23
|
columns[field].form_ui ||= :paperclip
|
28
24
|
columns[field].params.add "delete_#{field}"
|
29
25
|
|
30
|
-
[
|
26
|
+
%i[file_name content_type file_size updated_at].each do |f|
|
31
27
|
columns.exclude("#{field}_#{f}".to_sym)
|
32
28
|
end
|
33
29
|
end
|
@@ -2,9 +2,11 @@ class ActiveScaffold::Bridges::RecordSelect < ActiveScaffold::DataStructures::Br
|
|
2
2
|
def self.install
|
3
3
|
require File.join(File.dirname(__FILE__), 'record_select/helpers.rb')
|
4
4
|
end
|
5
|
+
|
5
6
|
def self.stylesheets
|
6
7
|
'record_select'
|
7
8
|
end
|
9
|
+
|
8
10
|
def self.javascripts
|
9
11
|
'record_select'
|
10
12
|
end
|
@@ -11,13 +11,11 @@ class ActiveScaffold::Bridges::RecordSelect
|
|
11
11
|
# requires RecordSelect plugin to be installed and configured.
|
12
12
|
def active_scaffold_input_record_select(column, options)
|
13
13
|
record = options.delete(:object)
|
14
|
-
|
15
|
-
record ||= @record # TODO: Remove when relying on @record is removed
|
16
|
-
if column.singular_association?
|
14
|
+
if column.association.try(:singular?)
|
17
15
|
multiple = false
|
18
|
-
multiple = column.options[:html_options][:multiple] if column.options[:html_options] &&
|
16
|
+
multiple = column.options[:html_options][:multiple] if column.options[:html_options] && column.options[:html_options][:multiple]
|
19
17
|
active_scaffold_record_select(record, column, options, record.send(column.name), multiple)
|
20
|
-
elsif column.
|
18
|
+
elsif column.association.try(:collection?)
|
21
19
|
active_scaffold_record_select(record, column, options, record.send(column.name), true)
|
22
20
|
else
|
23
21
|
active_scaffold_record_select_autocomplete(record, column, options)
|
@@ -29,7 +27,7 @@ class ActiveScaffold::Bridges::RecordSelect
|
|
29
27
|
raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)."
|
30
28
|
end
|
31
29
|
klass =
|
32
|
-
if column.
|
30
|
+
if column.association.polymorphic?
|
33
31
|
record.send(column.association.foreign_type).constantize rescue nil
|
34
32
|
else
|
35
33
|
column.association.klass
|
@@ -40,8 +38,8 @@ class ActiveScaffold::Bridges::RecordSelect
|
|
40
38
|
|
41
39
|
# if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many)
|
42
40
|
# then only show records that have not been associated yet
|
43
|
-
if
|
44
|
-
params
|
41
|
+
if column.association.has_one? || column.association.has_many?
|
42
|
+
params[column.association.foreign_key] = ''
|
45
43
|
end
|
46
44
|
|
47
45
|
record_select_options = active_scaffold_input_text_options(options).merge(
|
@@ -51,7 +49,7 @@ class ActiveScaffold::Bridges::RecordSelect
|
|
51
49
|
|
52
50
|
html =
|
53
51
|
if multiple
|
54
|
-
record_multi_select_field(options[:name], value || [], record_select_options)
|
52
|
+
record_multi_select_field(options[:name], value || [], record_select_options.except(:required))
|
55
53
|
else
|
56
54
|
record_select_field(options[:name], value || klass.new, record_select_options)
|
57
55
|
end
|
@@ -71,18 +69,16 @@ class ActiveScaffold::Bridges::RecordSelect
|
|
71
69
|
|
72
70
|
module SearchColumnHelpers
|
73
71
|
def active_scaffold_search_record_select(column, options)
|
74
|
-
value = field_search_record_select_value(column)
|
72
|
+
value = field_search_record_select_value(column, options[:value])
|
75
73
|
active_scaffold_record_select(options[:object], column, options, value, column.options[:multiple])
|
76
74
|
end
|
77
75
|
|
78
|
-
def field_search_record_select_value(column)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
column.association.klass.find(value.to_i)
|
85
|
-
end
|
76
|
+
def field_search_record_select_value(column, value)
|
77
|
+
return if value.blank?
|
78
|
+
if column.options[:multiple]
|
79
|
+
column.association.klass.find value.collect!(&:to_i)
|
80
|
+
else
|
81
|
+
column.association.klass.find(value.to_i)
|
86
82
|
end
|
87
83
|
rescue StandardError => e
|
88
84
|
logger.error "#{e.class.name}: #{e.message} -- Sorry, we are not that smart yet. Attempted to restore search values to search fields :#{column.name} in #{controller.class}"
|
@@ -1,20 +1,16 @@
|
|
1
1
|
class ActiveScaffold::Bridges::SemanticAttributes
|
2
2
|
module Column
|
3
|
-
def
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
def initialize_with_semantic_attributes(name, active_record_class)
|
8
|
-
initialize_without_semantic_attributes(name, active_record_class)
|
3
|
+
def initialize(name, active_record_class)
|
4
|
+
super
|
9
5
|
self.required = !active_record_class.semantic_attributes[self.name].predicates.find { |p| p.allow_empty? == false }.nil?
|
10
6
|
active_record_class.semantic_attributes[self.name].predicates.find do |p|
|
11
7
|
sem_type = p.class.to_s.split('::')[1].underscore.to_sym
|
12
|
-
next if [
|
8
|
+
next if %i[required association].include?(sem_type)
|
13
9
|
@form_ui = sem_type
|
14
10
|
end
|
15
11
|
end
|
16
12
|
end
|
17
13
|
end
|
18
14
|
ActiveScaffold::DataStructures::Column.class_eval do
|
19
|
-
|
15
|
+
prepend ActiveScaffold::Bridges::SemanticAttributes::Column
|
20
16
|
end
|
@@ -12,7 +12,7 @@ module ActiveScaffold
|
|
12
12
|
tags << active_scaffold_search_date_bridge_trend_tag(column, options, current_search)
|
13
13
|
tags << active_scaffold_search_date_bridge_numeric_tag(column, options, current_search)
|
14
14
|
tags << active_scaffold_search_date_bridge_range_tag(column, options, current_search)
|
15
|
-
tags
|
15
|
+
safe_join tags, ' '.html_safe
|
16
16
|
end
|
17
17
|
|
18
18
|
def active_scaffold_search_date_bridge_comparator_options(column)
|
@@ -70,7 +70,7 @@ module ActiveScaffold
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def column_datetime?(column)
|
73
|
-
(!column.column.nil? && [
|
73
|
+
(!column.column.nil? && %i[datetime time].include?(column.column.type))
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -141,7 +141,7 @@ module ActiveScaffold
|
|
141
141
|
values.collect!(&conversion) if conversion != :to_time
|
142
142
|
values
|
143
143
|
else
|
144
|
-
%w
|
144
|
+
%w[from to].collect { |field| condition_value_for_datetime(column, value[field], conversion) }
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
@@ -152,41 +152,41 @@ module ActiveScaffold
|
|
152
152
|
def date_bridge_from_to_for_trend(column, value)
|
153
153
|
case value['opt']
|
154
154
|
when 'PAST'
|
155
|
-
trend_number = [value['number'].to_i,
|
155
|
+
trend_number = [value['number'].to_i, 1].max
|
156
156
|
now = date_bridge_now
|
157
157
|
if date_bridge_column_date?(column)
|
158
|
-
from = now.beginning_of_day.ago(
|
158
|
+
from = now.beginning_of_day.ago(trend_number.send(value['unit'].downcase.singularize.to_sym))
|
159
159
|
to = now.end_of_day
|
160
160
|
else
|
161
|
-
from = now.ago(
|
161
|
+
from = now.ago(trend_number.send(value['unit'].downcase.singularize.to_sym))
|
162
162
|
to = now
|
163
163
|
end
|
164
|
-
|
164
|
+
[from, to]
|
165
165
|
when 'FUTURE'
|
166
|
-
trend_number = [value['number'].to_i,
|
166
|
+
trend_number = [value['number'].to_i, 1].max
|
167
167
|
now = date_bridge_now
|
168
168
|
if date_bridge_column_date?(column)
|
169
169
|
from = now.beginning_of_day
|
170
|
-
to = now.end_of_day.in(
|
170
|
+
to = now.end_of_day.in(trend_number.send(value['unit'].downcase.singularize.to_sym))
|
171
171
|
else
|
172
172
|
from = now
|
173
|
-
to = now.in(
|
173
|
+
to = now.in(trend_number.send(value['unit'].downcase.singularize.to_sym))
|
174
174
|
end
|
175
|
-
|
175
|
+
[from, to]
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
179
|
def date_bridge_from_to_for_range(column, value)
|
180
180
|
case value['range']
|
181
181
|
when 'TODAY'
|
182
|
-
|
182
|
+
[date_bridge_now.beginning_of_day, date_bridge_now.end_of_day]
|
183
183
|
when 'YESTERDAY'
|
184
|
-
|
184
|
+
[date_bridge_now.ago(1.day).beginning_of_day, date_bridge_now.ago(1.day).end_of_day]
|
185
185
|
when 'TOMORROW'
|
186
|
-
|
186
|
+
[date_bridge_now.in(1.day).beginning_of_day, date_bridge_now.in(1.day).end_of_day]
|
187
187
|
else
|
188
188
|
range_type, range = value['range'].downcase.split('_')
|
189
|
-
raise ArgumentError unless %w
|
189
|
+
raise ArgumentError unless %w[week month year].include?(range)
|
190
190
|
case range_type
|
191
191
|
when 'this'
|
192
192
|
return date_bridge_now.send("beginning_of_#{range}".to_sym), date_bridge_now.send("end_of_#{range}")
|
@@ -201,7 +201,7 @@ module ActiveScaffold
|
|
201
201
|
end
|
202
202
|
|
203
203
|
def date_bridge_column_date?(column)
|
204
|
-
if [
|
204
|
+
if %i[date_picker datetime_picker].include? column.form_ui
|
205
205
|
column.form_ui == :date_picker
|
206
206
|
else
|
207
207
|
(!column.column.nil? && [:date].include?(column.column.type))
|
@@ -214,7 +214,7 @@ module ActiveScaffold
|
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
|
-
ActiveScaffold::Finder.const_set('DATE_COMPARATORS', %w
|
218
|
-
ActiveScaffold::Finder.const_set('DATE_UNITS', %w
|
219
|
-
ActiveScaffold::Finder.const_set('TIME_UNITS', %w
|
220
|
-
ActiveScaffold::Finder.const_set('DATE_RANGES', %w
|
217
|
+
ActiveScaffold::Finder.const_set('DATE_COMPARATORS', %w[PAST FUTURE RANGE])
|
218
|
+
ActiveScaffold::Finder.const_set('DATE_UNITS', %w[DAYS WEEKS MONTHS YEARS])
|
219
|
+
ActiveScaffold::Finder.const_set('TIME_UNITS', %w[SECONDS MINUTES HOURS])
|
220
|
+
ActiveScaffold::Finder.const_set('DATE_RANGES', %w[TODAY YESTERDAY TOMORROW THIS_WEEK PREV_WEEK NEXT_WEEK THIS_MONTH PREV_MONTH NEXT_MONTH THIS_YEAR PREV_YEAR NEXT_YEAR])
|
@@ -8,10 +8,6 @@ class ActiveScaffold::Bridges::TinyMce
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module FormColumnHelpers
|
11
|
-
def self.included(base)
|
12
|
-
base.alias_method_chain :onsubmit, :tiny_mce
|
13
|
-
end
|
14
|
-
|
15
11
|
# The two column options that can be set specifically for the text_editor input
|
16
12
|
# is :tinymce, which overrides single values in the tinymce config.
|
17
13
|
# E.g. column[:foo].options[:tinymce] = {theme: 'other'} will change the theme
|
@@ -21,31 +17,20 @@ class ActiveScaffold::Bridges::TinyMce
|
|
21
17
|
def active_scaffold_input_text_editor(column, options)
|
22
18
|
options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip
|
23
19
|
|
24
|
-
settings = tinymce_configuration(column.options[:tinymce_config] || :default).options
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
settings = "tinyMCE.settings = #{settings};"
|
20
|
+
settings = tinymce_configuration(column.options[:tinymce_config] || :default).options
|
21
|
+
.reject { |k, _v| k == 'selector' }
|
22
|
+
.merge(column.options[:tinymce] || {})
|
23
|
+
options['data-tinymce'] = settings.to_json if ActiveScaffold.js_framework != :prototype
|
29
24
|
|
30
25
|
html = []
|
31
26
|
html << send(override_input(:textarea), column, options)
|
32
|
-
html << javascript_tag(settings
|
33
|
-
html
|
34
|
-
end
|
35
|
-
|
36
|
-
def onsubmit_with_tiny_mce
|
37
|
-
case ActiveScaffold.js_framework
|
38
|
-
when :jquery
|
39
|
-
submit_js = 'tinyMCE.triggerSave();jQuery(\'textarea.mceEditor\').each(function(index, elem) { tinyMCE.execCommand(\'mceRemoveEditor\', false, jQuery(elem).attr(\'id\')); });'
|
40
|
-
when :prototype
|
41
|
-
submit_js = 'tinyMCE.triggerSave();this.select(\'textarea.mceEditor\').each(function(elem) { tinyMCE.execCommand(\'mceRemoveEditor\', false, elem.id); });'
|
42
|
-
end
|
43
|
-
[onsubmit_without_tiny_mce, submit_js].compact.join ';'
|
27
|
+
html << javascript_tag("tinyMCE.settings = #{settings.to_json}; tinyMCE.execCommand('mceAddEditor', false, '#{options[:id]}');") if ActiveScaffold.js_framework == :prototype && (request.xhr? || params[:iframe])
|
28
|
+
safe_join html
|
44
29
|
end
|
45
30
|
|
46
31
|
# The implementation is very tinymce specific, so it makes sense allowing :form_ui
|
47
32
|
# to be :tinymce as well
|
48
|
-
|
33
|
+
alias active_scaffold_input_tinymce active_scaffold_input_text_editor
|
49
34
|
end
|
50
35
|
|
51
36
|
module SearchColumnHelpers
|
@@ -2,7 +2,7 @@ module ActiveScaffold::Bridges
|
|
2
2
|
class UsaStateSelect
|
3
3
|
module UsaStateSelectHelpers
|
4
4
|
def usa_state_select_options(options)
|
5
|
-
# TODO remove when rails 3.2 support is dropped
|
5
|
+
# TODO: remove when rails 3.2 support is dropped
|
6
6
|
defined?(ActionView::Helpers::InstanceTag) ? options[:object] : options
|
7
7
|
end
|
8
8
|
|
@@ -17,22 +17,22 @@ module ActiveScaffold::Bridges
|
|
17
17
|
# in case you want to highligh a local area
|
18
18
|
# NOTE: Only the option tags are returned from this method, wrap it in a <select>
|
19
19
|
def usa_state_options_for_select(selected = nil, priority_states = nil)
|
20
|
-
if priority_states
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
state_options = if priority_states
|
21
|
+
options_for_select(priority_states + [['-------------', '']], :selected => selected, :disabled => '')
|
22
|
+
else
|
23
|
+
options_for_select([])
|
24
|
+
end
|
25
25
|
|
26
|
-
if priority_states && priority_states.include?(selected)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
state_options += if priority_states && priority_states.include?(selected)
|
27
|
+
options_for_select(USASTATES - priority_states, :selected => selected)
|
28
|
+
else
|
29
|
+
options_for_select(USASTATES, :selected => selected)
|
30
|
+
end
|
31
31
|
|
32
32
|
state_options
|
33
33
|
end
|
34
34
|
|
35
|
-
USASTATES = [%w
|
35
|
+
USASTATES = [%w[Alabama AL], %w[Alaska AK], %w[Arizona AZ], %w[Arkansas AR], %w[California CA], %w[Colorado CO], %w[Connecticut CT], %w[Delaware DE], ['District of Columbia', 'DC'], %w[Florida FL], %w[Georgia GA], %w[Hawaii HI], %w[Idaho ID], %w[Illinois IL], %w[Indiana IN], %w[Iowa IA], %w[Kansas KS], %w[Kentucky KY], %w[Louisiana LA], %w[Maine ME], %w[Maryland MD], %w[Massachusetts MA], %w[Michigan MI], %w[Minnesota MN], %w[Mississippi MS], %w[Missouri MO], %w[Montana MT], %w[Nebraska NE], %w[Nevada NV], ['New Hampshire', 'NH'], ['New Jersey', 'NJ'], ['New Mexico', 'NM'], ['New York', 'NY'], ['North Carolina', 'NC'], ['North Dakota', 'ND'], %w[Ohio OH], %w[Oklahoma OK], %w[Oregon OR], %w[Pennsylvania PA], ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], %w[Tennessee TN], %w[Texas TX], %w[Utah UT], %w[Vermont VT], %w[Virginia VA], %w[Washington WA], %w[Wisconsin WI], ['West Virginia', 'WV'], %w[Wyoming WY]].freeze unless const_defined?('USASTATES')
|
36
36
|
end
|
37
37
|
|
38
38
|
module InstanceTagMethods
|
@@ -50,7 +50,7 @@ module ActiveScaffold::Bridges
|
|
50
50
|
select_options = {:prompt => as_(:_select_)}
|
51
51
|
select_options.merge!(options)
|
52
52
|
options.reverse_merge!(column.options).except!(:prompt, :priority)
|
53
|
-
|
53
|
+
active_scaffold_select_name_with_multiple options
|
54
54
|
usa_state_select(:record, column.name, column.options[:priority], select_options, options.except(:object))
|
55
55
|
end
|
56
56
|
end
|
@@ -69,7 +69,7 @@ ActionView::Base.class_eval do
|
|
69
69
|
include ActiveScaffold::Bridges::UsaStateSelect::FormColumnHelpers
|
70
70
|
include ActiveScaffold::Bridges::UsaStateSelect::SearchColumnHelpers
|
71
71
|
end
|
72
|
-
if defined? ActionView::Helpers::InstanceTag # TODO remove when rails 3.2 support is dropped
|
72
|
+
if defined? ActionView::Helpers::InstanceTag # TODO: remove when rails 3.2 support is dropped
|
73
73
|
module ActionView::Helpers::Tags
|
74
74
|
class UsaStateSelect < ActionView::Helpers::InstanceTag
|
75
75
|
include ActiveScaffold::Bridges::UsaStateSelect::UsaStateSelectOptionsHelpers
|
@@ -21,7 +21,7 @@ module ActiveScaffold::Config
|
|
21
21
|
protected
|
22
22
|
|
23
23
|
def crud_type=(val)
|
24
|
-
raise ArgumentError, "unknown CRUD type #{val}" unless [
|
24
|
+
raise ArgumentError, "unknown CRUD type #{val}" unless %i[create read update delete].include?(val.to_sym)
|
25
25
|
@crud_type = val.to_sym
|
26
26
|
end
|
27
27
|
end
|
@@ -42,7 +42,7 @@ module ActiveScaffold::Config
|
|
42
42
|
|
43
43
|
# define a default action_group for this action
|
44
44
|
# e.g. 'members.crud'
|
45
|
-
class_attribute :action_group
|
45
|
+
class_attribute :action_group, instance_accessor: false
|
46
46
|
|
47
47
|
# action_group this action should belong to
|
48
48
|
attr_accessor :action_group
|
@@ -97,7 +97,7 @@ module ActiveScaffold::Config
|
|
97
97
|
names.each do |name|
|
98
98
|
var = "@#{name}"
|
99
99
|
define_method "#{name}=" do |val|
|
100
|
-
if
|
100
|
+
if instance_variable_defined?(var)
|
101
101
|
instance_variable_get(var).set_values(*val)
|
102
102
|
else
|
103
103
|
instance_variable_set(var, build_action_columns(val))
|
@@ -105,21 +105,24 @@ module ActiveScaffold::Config
|
|
105
105
|
instance_variable_get(var)
|
106
106
|
end
|
107
107
|
|
108
|
+
return if method_defined? name
|
108
109
|
define_method name do
|
109
|
-
unless
|
110
|
+
unless instance_variable_defined?(var) # lazy evaluation
|
110
111
|
action, columns = options[:copy] if options[:copy]
|
111
112
|
if action && @core.actions.include?(action)
|
112
113
|
action_columns = @core.send(action).send(columns || :columns).clone
|
113
114
|
action_columns.action = self
|
114
115
|
instance_variable_set(var, action_columns)
|
115
116
|
else
|
116
|
-
|
117
|
+
send("#{name}=", @core.columns._inheritable)
|
117
118
|
end
|
118
|
-
instance_exec
|
119
|
+
instance_exec(&block) if block
|
119
120
|
end
|
120
121
|
instance_variable_get(var)
|
121
122
|
end
|
122
123
|
end
|
123
124
|
end
|
125
|
+
|
126
|
+
private_class_method :columns_accessor
|
124
127
|
end
|
125
128
|
end
|
@@ -1,55 +1,55 @@
|
|
1
1
|
module ActiveScaffold::Config
|
2
2
|
# to fix the ckeditor bridge problem inherit from full class name
|
3
3
|
class Core < ActiveScaffold::Config::Base
|
4
|
+
include ActiveScaffold::OrmChecks
|
4
5
|
# global level configuration
|
5
6
|
# --------------------------
|
6
7
|
|
7
8
|
# provides read/write access to the global Actions DataStructure
|
8
|
-
cattr_reader :actions
|
9
|
+
cattr_reader :actions, instance_accessor: false
|
9
10
|
def self.actions=(val)
|
10
11
|
@@actions = ActiveScaffold::DataStructures::Actions.new(*val)
|
11
12
|
end
|
12
|
-
self.actions = [
|
13
|
+
self.actions = %i[create list search update delete show nested subform]
|
13
14
|
|
14
15
|
# configures where the ActiveScaffold plugin itself is located. there is no instance version of this.
|
15
16
|
cattr_accessor :plugin_directory
|
16
17
|
@@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/core.rb})[1]
|
17
18
|
|
18
19
|
# lets you specify a global ActiveScaffold frontend.
|
19
|
-
cattr_accessor :frontend
|
20
|
+
cattr_accessor :frontend, instance_accessor: false
|
20
21
|
@@frontend = :default
|
21
22
|
|
22
23
|
# lets you specify a global ActiveScaffold theme for your frontend.
|
23
|
-
cattr_accessor :theme
|
24
|
+
cattr_accessor :theme, instance_accessor: false
|
24
25
|
@@theme = :default
|
25
26
|
|
26
27
|
# enable caching of action link urls
|
27
|
-
cattr_accessor :cache_action_link_urls
|
28
|
+
cattr_accessor :cache_action_link_urls, instance_accessor: false
|
28
29
|
@@cache_action_link_urls = true
|
29
30
|
|
30
31
|
# enable caching of association options
|
31
|
-
cattr_accessor :cache_association_options
|
32
|
+
cattr_accessor :cache_association_options, instance_accessor: false
|
32
33
|
@@cache_association_options = true
|
33
34
|
|
34
35
|
# enable setting ETag and LastModified on responses and using fresh_when/stale? to respond with 304 and avoid rendering views
|
35
|
-
cattr_accessor :conditional_get_support
|
36
|
+
cattr_accessor :conditional_get_support, instance_accessor: false
|
36
37
|
@@conditional_get_support = false
|
37
38
|
|
38
39
|
# enable saving user settings in session (per_page, limit, page, sort, search params)
|
39
|
-
cattr_accessor :store_user_settings
|
40
|
+
cattr_accessor :store_user_settings, instance_accessor: false
|
40
41
|
@@store_user_settings = true
|
41
42
|
|
42
43
|
# lets you disable the DHTML history
|
43
|
-
|
44
|
-
|
45
|
-
end
|
44
|
+
cattr_writer :dhtml_history, instance_accessor: false
|
45
|
+
|
46
46
|
def self.dhtml_history?
|
47
47
|
@@dhtml_history ? true : false
|
48
48
|
end
|
49
49
|
@@dhtml_history = true
|
50
50
|
|
51
51
|
# action links are used by actions to tie together. you can use them, too! this is a collection of ActiveScaffold::DataStructures::ActionLink objects.
|
52
|
-
cattr_reader :action_links
|
52
|
+
cattr_reader :action_links, instance_reader: false
|
53
53
|
@@action_links = ActiveScaffold::DataStructures::ActionLinks.new
|
54
54
|
|
55
55
|
# access to the permissions configuration.
|
@@ -65,21 +65,22 @@ module ActiveScaffold::Config
|
|
65
65
|
def self.ignore_columns
|
66
66
|
@@ignore_columns
|
67
67
|
end
|
68
|
+
|
68
69
|
def self.ignore_columns=(val)
|
69
70
|
@@ignore_columns = ActiveScaffold::DataStructures::Set.new(*val)
|
70
71
|
end
|
71
72
|
@@ignore_columns = ActiveScaffold::DataStructures::Set.new
|
72
73
|
|
73
74
|
# lets you specify whether add a create link for each sti child
|
74
|
-
cattr_accessor :sti_create_links
|
75
|
+
cattr_accessor :sti_create_links, instance_accessor: false
|
75
76
|
@@sti_create_links = true
|
76
77
|
|
77
78
|
# prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used
|
78
|
-
cattr_accessor :timestamped_messages
|
79
|
+
cattr_accessor :timestamped_messages, instance_accessor: false
|
79
80
|
@@timestamped_messages = false
|
80
81
|
|
81
82
|
# a hash of string (or array of strings) and highlighter string to highlight words in messages. It will use highlight rails helper
|
82
|
-
cattr_accessor :highlight_messages
|
83
|
+
cattr_accessor :highlight_messages, instance_accessor: false
|
83
84
|
@@highlight_messages = nil
|
84
85
|
|
85
86
|
# instance-level configuration
|
@@ -153,12 +154,15 @@ module ActiveScaffold::Config
|
|
153
154
|
@actions = self.class.actions.clone
|
154
155
|
|
155
156
|
# create a new default columns datastructure, since it doesn't make sense before now
|
156
|
-
attribute_names =
|
157
|
-
association_column_names =
|
158
|
-
|
157
|
+
attribute_names = _columns.collect { |c| c.name.to_sym }.sort_by(&:to_s)
|
158
|
+
association_column_names = _reflect_on_all_associations.collect { |a| a.name.to_sym }
|
159
|
+
if defined?(ActiveMongoid) && model < ActiveMongoid::Associations
|
160
|
+
association_column_names.concat model.am_relations.keys.map(&:to_sym)
|
161
|
+
end
|
162
|
+
@columns = ActiveScaffold::DataStructures::Columns.new(model, attribute_names + association_column_names.sort_by(&:to_s))
|
159
163
|
|
160
164
|
# and then, let's remove some columns from the inheritable set.
|
161
|
-
content_columns = Set.new(
|
165
|
+
content_columns = Set.new(_content_columns.map(&:name))
|
162
166
|
@columns.exclude(*self.class.ignore_columns)
|
163
167
|
@columns.exclude(*@columns.find_all { |c| c.column && content_columns.exclude?(c.column.name) }.collect(&:name))
|
164
168
|
@columns.exclude(*model.reflect_on_all_associations.collect { |a| a.foreign_type.to_sym if a.options[:polymorphic] }.compact)
|
@@ -232,6 +236,11 @@ module ActiveScaffold::Config
|
|
232
236
|
def model
|
233
237
|
@model ||= @model_id.to_s.camelize.constantize
|
234
238
|
end
|
239
|
+
alias active_record_class model
|
240
|
+
|
241
|
+
def primary_key
|
242
|
+
mongoid? ? '_id' : model.primary_key
|
243
|
+
end
|
235
244
|
|
236
245
|
# warning - this won't work as a per-request dynamic attribute in rails 2.0. You'll need to interact with Controller#generic_view_paths
|
237
246
|
def inherited_view_paths
|
@@ -248,11 +257,11 @@ module ActiveScaffold::Config
|
|
248
257
|
# note that this is unaffected by per-controller frontend configuration.
|
249
258
|
def self.javascripts(frontend = self.frontend)
|
250
259
|
javascript_dir = File.join(Rails.public_path, 'javascripts', asset_path('', frontend))
|
251
|
-
Dir.entries(javascript_dir).reject { |e| !e.match(/\.js$/) || (!
|
260
|
+
Dir.entries(javascript_dir).reject { |e| !e.match(/\.js$/) || (!dhtml_history? && e.match('dhtml_history')) }
|
252
261
|
end
|
253
262
|
|
254
263
|
def self.available_frontends
|
255
|
-
frontends_dir =
|
264
|
+
frontends_dir = Rails.root.join('vendor', 'plugins', ActiveScaffold::Config::Core.plugin_directory, 'frontends')
|
256
265
|
Dir.entries(frontends_dir).reject { |e| e.match(/^\./) } # Get rid of files that start with .
|
257
266
|
end
|
258
267
|
end
|