active_scaffold 3.7.0 → 3.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +24 -0
  3. data/README.md +2 -0
  4. data/app/assets/javascripts/jquery/active_scaffold.js +68 -62
  5. data/app/assets/stylesheets/active_scaffold_layout.css +1 -1
  6. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +2 -1
  7. data/app/views/active_scaffold_overrides/_render_field.js.erb +9 -6
  8. data/config/locales/de.yml +6 -3
  9. data/config/locales/en.yml +3 -0
  10. data/config/locales/es.yml +3 -0
  11. data/config/locales/fr.yml +9 -6
  12. data/config/locales/hu.yml +20 -17
  13. data/config/locales/ja.yml +25 -22
  14. data/config/locales/ru.yml +17 -14
  15. data/lib/active_scaffold/actions/update.rb +3 -3
  16. data/lib/active_scaffold/attribute_params.rb +7 -17
  17. data/lib/active_scaffold/bridges/active_storage/form_ui.rb +6 -6
  18. data/lib/active_scaffold/bridges/active_storage/list_ui.rb +7 -7
  19. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +2 -2
  20. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +12 -14
  21. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +2 -2
  22. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +1 -1
  23. data/lib/active_scaffold/bridges/chosen/helpers.rb +10 -10
  24. data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +7 -7
  25. data/lib/active_scaffold/bridges/date_picker/ext.rb +20 -9
  26. data/lib/active_scaffold/bridges/date_picker/helper.rb +5 -5
  27. data/lib/active_scaffold/bridges/date_picker.rb +2 -0
  28. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +3 -3
  29. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +5 -5
  30. data/lib/active_scaffold/bridges/file_column/form_ui.rb +1 -1
  31. data/lib/active_scaffold/bridges/file_column/list_ui.rb +3 -3
  32. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +1 -1
  33. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +3 -3
  34. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  35. data/lib/active_scaffold/bridges/record_select/helpers.rb +15 -15
  36. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +6 -6
  37. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +5 -5
  38. data/lib/active_scaffold/bridges.rb +0 -3
  39. data/lib/active_scaffold/constraints.rb +22 -7
  40. data/lib/active_scaffold/core.rb +5 -3
  41. data/lib/active_scaffold/data_structures/column.rb +108 -23
  42. data/lib/active_scaffold/engine.rb +19 -1
  43. data/lib/active_scaffold/extensions/routing_mapper.rb +1 -0
  44. data/lib/active_scaffold/finder.rb +142 -27
  45. data/lib/active_scaffold/helpers/controller_helpers.rb +9 -4
  46. data/lib/active_scaffold/helpers/form_column_helpers.rb +114 -94
  47. data/lib/active_scaffold/helpers/human_condition_helpers.rb +48 -14
  48. data/lib/active_scaffold/helpers/list_column_helpers.rb +34 -18
  49. data/lib/active_scaffold/helpers/search_column_helpers.rb +131 -55
  50. data/lib/active_scaffold/helpers/show_column_helpers.rb +6 -6
  51. data/lib/active_scaffold/orm_checks.rb +21 -1
  52. data/lib/active_scaffold/version.rb +1 -1
  53. data/lib/active_scaffold.rb +4 -2
  54. data/test/bridges/date_picker_test.rb +3 -2
  55. data/test/bridges/paperclip_test.rb +3 -2
  56. data/test/bridges/tiny_mce_test.rb +4 -2
  57. data/test/helpers/form_column_helpers_test.rb +7 -5
  58. data/test/helpers/search_column_helpers_test.rb +2 -1
  59. data/test/misc/constraints_test.rb +1 -0
  60. data/test/misc/finder_test.rb +38 -0
  61. metadata +2 -6
  62. data/config/brakeman.ignore +0 -26
  63. data/config/brakeman.yml +0 -3
  64. data/config/i18n-tasks.yml +0 -121
  65. data/lib/active_scaffold/bridges/shared/date_bridge.rb +0 -221
@@ -185,11 +185,11 @@ module ActiveScaffold::Actions
185
185
 
186
186
  def value_for_update_column(param_value, column, record)
187
187
  unless param_value
188
- param_value = ActiveScaffold::Core.column_type_cast @column.default_for_empty_value, @column.column
188
+ param_value = ActiveScaffold::Core.column_type_cast column.default_for_empty_value, column.column
189
189
  param_value = false if param_value == true
190
190
  end
191
- value = column_value_from_param_value(record, @column, param_value)
192
- value = [] if value.nil? && @column.form_ui && @column.association&.collection?
191
+ value = column_value_from_param_value(record, column, param_value)
192
+ value = [] if value.nil? && column.form_ui && column.association&.collection?
193
193
  value
194
194
  end
195
195
 
@@ -129,7 +129,7 @@ module ActiveScaffold
129
129
 
130
130
  def datetime_conversion_for_value(column)
131
131
  if column.column
132
- column.column.type == :date ? :to_date : :to_time
132
+ column.column_type == :date ? :to_date : :to_time
133
133
  else
134
134
  :to_time
135
135
  end
@@ -150,7 +150,10 @@ module ActiveScaffold
150
150
  def association_value_from_param_simple_value(parent_record, column, value)
151
151
  if column.association.singular?
152
152
  # value may be Array if using update_columns in field_search with multi-select
153
- column.association.klass(parent_record)&.find(value) if value.present? && !value.is_a?(Array)
153
+ klass = column.association.klass(parent_record)
154
+ # find_by needed when using update_columns in type foreign type key of polymorphic association,
155
+ # and foreign key had value, it will try to find record with id of previous type
156
+ klass&.find_by(klass&.primary_key => value) if value.present? && !value.is_a?(Array)
154
157
  else # column.association.collection?
155
158
  column_plural_assocation_value_from_value(column, Array(value))
156
159
  end
@@ -281,22 +284,9 @@ module ActiveScaffold
281
284
  end
282
285
 
283
286
  def default_value?(column_name, klass, value)
284
- column = ActiveScaffold::OrmChecks.columns_hash(klass)[column_name]
285
- default_value = column_default_value(column_name, klass)
286
- casted_value = ActiveScaffold::Core.column_type_cast(value, column)
287
+ casted_value = ActiveScaffold::OrmChecks.cast(klass, column_name, value)
288
+ default_value = ActiveScaffold::OrmChecks.default_value(klass, column_name)
287
289
  casted_value == default_value
288
290
  end
289
-
290
- def column_default_value(column_name, klass)
291
- column = ActiveScaffold::OrmChecks.columns_hash(klass)[column_name]
292
- return unless column
293
- if ActiveScaffold::OrmChecks.mongoid? klass
294
- column.default_val
295
- elsif ActiveScaffold::OrmChecks.active_record? klass
296
- column_type = ActiveScaffold::OrmChecks.column_type(klass, column_name)
297
- cast_type = ActiveRecord::Type.lookup column_type
298
- cast_type ? cast_type.deserialize(column.default) : column.default
299
- end
300
- end
301
291
  end
302
292
  end
@@ -2,20 +2,20 @@ module ActiveScaffold
2
2
  module Helpers
3
3
  # Helpers that assist with the rendering of a Form Column
4
4
  module FormColumnHelpers
5
- def active_scaffold_input_active_storage_has_one(column, options)
5
+ def active_scaffold_input_active_storage_has_one(column, options, ui_options: column.options)
6
6
  record = options[:object]
7
7
  active_storage = record.send(column.name.to_s)
8
- content = active_scaffold_column_active_storage_has_one(record, column) if active_storage.attached?
9
- active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls')
8
+ content = active_scaffold_column_active_storage_has_one(record, column, ui_options: ui_options) if active_storage.attached?
9
+ active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls', ui_options: ui_options)
10
10
  end
11
11
 
12
- def active_scaffold_input_active_storage_has_many(column, options)
12
+ def active_scaffold_input_active_storage_has_many(column, options, ui_options: column.options)
13
13
  record = options[:object]
14
14
  options[:multiple] = 'multiple'
15
15
  options[:name] += '[]'
16
16
  active_storage = record.send(column.name.to_s)
17
- content = active_scaffold_column_active_storage_has_many(record, column) if active_storage.attached?
18
- active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls')
17
+ content = active_scaffold_column_active_storage_has_many(record, column, ui_options: ui_options) if active_storage.attached?
18
+ active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls', ui_options: ui_options)
19
19
  end
20
20
  end
21
21
  end
@@ -1,18 +1,18 @@
1
1
  module ActiveScaffold
2
2
  module Helpers
3
3
  module ListColumnHelpers
4
- def active_scaffold_column_active_storage_has_one(record, column)
4
+ def active_scaffold_column_active_storage_has_one(record, column, ui_options: column.options)
5
5
  attachment = record.send(column.name.to_s)
6
- attachment.attached? ? link_for_attachment(attachment, column) : nil
6
+ attachment.attached? ? link_for_attachment(attachment, column, ui_options: ui_options) : nil
7
7
  end
8
8
 
9
- def active_scaffold_column_active_storage_has_many(record, column)
9
+ def active_scaffold_column_active_storage_has_many(record, column, ui_options: column.options)
10
10
  active_storage_files = record.send(column.name.to_s)
11
11
  return nil unless active_storage_files.attached?
12
12
 
13
13
  attachments = active_storage_files.attachments
14
14
  if attachments.size <= 3 # Lets display up to three links, otherwise just show the count.
15
- links = attachments.map { |attachment| link_for_attachment(attachment, column) }
15
+ links = attachments.map { |attachment| link_for_attachment(attachment, column, ui_options: ui_options) }
16
16
  safe_join links, association_join_text(column)
17
17
  else
18
18
  pluralize attachments.size, column.name.to_s
@@ -21,10 +21,10 @@ module ActiveScaffold
21
21
 
22
22
  private
23
23
 
24
- def link_for_attachment(attachment, column)
25
- variant = column.options[:thumb] || ActiveScaffold::Bridges::ActiveStorage.thumbnail_variant
24
+ def link_for_attachment(attachment, column, ui_options: column.options)
25
+ variant = ui_options[:thumb] || ActiveScaffold::Bridges::ActiveStorage.thumbnail_variant
26
26
  content =
27
- if variant && attachment.variable? && column.options[:thumb] != false
27
+ if variant && attachment.variable? && ui_options[:thumb] != false
28
28
  image_tag(attachment.variant(variant))
29
29
  else
30
30
  attachment.filename
@@ -15,12 +15,12 @@ module ActiveScaffold::Bridges
15
15
  end
16
16
 
17
17
  module FormColumnHelpers
18
- def active_scaffold_input_ancestry(column, options)
18
+ def active_scaffold_input_ancestry(column, options, ui_options: column.options)
19
19
  record = options[:object]
20
20
  select_options = []
21
21
  select_control_options = {:selected => record.parent_id}
22
22
  select_control_options[:include_blank] = as_(:_select_) if record.parent_id.nil?
23
- method = column.options[:label_method] || :to_label
23
+ method = ui_options[:label_method] || :to_label
24
24
  traverse_ancestry = proc do |key, value|
25
25
  unless key == record
26
26
  select_options << ["#{'__' * key.depth}#{key.send(method)}", key.id]
@@ -16,19 +16,20 @@ module ActiveScaffold
16
16
 
17
17
  # Helpers that assist with the rendering of a Form Column
18
18
  module FormColumnHelpers
19
- def active_scaffold_input_calendar_date_select(column, options)
19
+ def active_scaffold_input_calendar_date_select(column, options, ui_options: column.options)
20
20
  options[:class] = "#{options[:class]} text-input".strip
21
- calendar_date_select('record', column.name, options.merge(column.options))
21
+ calendar_date_select('record', column.name, options.merge(ui_options))
22
22
  end
23
23
  end
24
24
 
25
25
  module SearchColumnHelpers
26
- def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name)
27
- value = if current_search.is_a? Hash
28
- controller.class.condition_value_for_datetime(column, current_search[name], column.column.type == :date ? :to_date : :to_time)
29
- else
30
- current_search
31
- end
26
+ def active_scaffold_search_calendar_date_select_field(column, options, current_search, name, ui_options: column.options)
27
+ value =
28
+ if current_search.is_a? Hash
29
+ controller.class.condition_value_for_datetime(column, current_search[name], column.column_type == :date ? :to_date : :to_time)
30
+ else
31
+ current_search
32
+ end
32
33
  calendar_date_select(
33
34
  'record', column.name,
34
35
  :name => "#{options[:name]}[#{name}]",
@@ -46,15 +47,12 @@ end
46
47
 
47
48
  ActionView::Base.class_eval do
48
49
  include ActiveScaffold::Bridges::CalendarDateSelect::FormColumnHelpers
49
- include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers
50
- alias_method :active_scaffold_search_calendar_date_select, :active_scaffold_search_date_bridge
51
- include ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers
52
- alias_method :active_scaffold_human_condition_calendar_date_select, :active_scaffold_human_condition_date_bridge
50
+ alias_method :active_scaffold_search_calendar_date_select, :active_scaffold_search_datetime
51
+ alias_method :active_scaffold_human_condition_calendar_date_select, :active_scaffold_human_condition_datetime
53
52
  include ActiveScaffold::Bridges::CalendarDateSelect::SearchColumnHelpers
54
53
  end
55
54
 
56
55
  ActiveScaffold::Finder::ClassMethods.module_eval do
57
- include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods
58
- alias_method :condition_for_calendar_date_select_type, :condition_for_date_bridge_type
56
+ alias_method :condition_for_calendar_date_select_type, :condition_for_datetime
59
57
  end
60
58
  ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::CalendarDateSelect::CalendarDateSelectBridge
@@ -1,11 +1,11 @@
1
1
  module ActiveScaffold
2
2
  module Helpers
3
3
  module FormColumnHelpers
4
- def active_scaffold_input_carrierwave(column, options)
4
+ def active_scaffold_input_carrierwave(column, options, ui_options: column.options)
5
5
  record = options[:object]
6
6
  carrierwave = record.send(column.name.to_s)
7
7
  content = get_column_value(record, column) if carrierwave.file.present?
8
- active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'carrierwave_controls') do
8
+ active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'carrierwave_controls', ui_options: ui_options) do
9
9
  cache_field_options = {
10
10
  name: options[:name].gsub(/\[#{column.name}\]$/, "[#{column.name}_cache]"),
11
11
  id: options[:id] + '_cache'
@@ -1,7 +1,7 @@
1
1
  module ActiveScaffold
2
2
  module Helpers
3
3
  module ListColumnHelpers
4
- def active_scaffold_column_carrierwave(record, column)
4
+ def active_scaffold_column_carrierwave(record, column, ui_options: column.options)
5
5
  carrierwave = record.send(column.name.to_s)
6
6
  return nil if carrierwave.file.blank?
7
7
  thumbnail_style = ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridgeHelpers.thumbnail_style
@@ -10,39 +10,39 @@ class ActiveScaffold::Bridges::Chosen
10
10
 
11
11
  module FormColumnHelpers
12
12
  # requires RecordSelect plugin to be installed and configured.
13
- def active_scaffold_input_chosen(column, html_options)
13
+ def active_scaffold_input_chosen(column, html_options, ui_options: column.options)
14
14
  html_options[:class] << ' chosen'
15
15
  if column.association&.collection?
16
16
  record = html_options.delete(:object)
17
17
  associated_options, select_options = active_scaffold_plural_association_options(column, record)
18
18
  options = {selected: associated_options.collect(&:id), include_blank: as_(:_select_), object: record}
19
19
 
20
- html_options.update(multiple: true).update(column.options[:html_options] || {})
21
- options.update(column.options)
20
+ html_options.update(multiple: true).update(ui_options[:html_options] || {})
21
+ options.update(ui_options)
22
22
  active_scaffold_select_name_with_multiple html_options
23
23
 
24
24
  if (optgroup = options.delete(:optgroup))
25
25
  select(:record, column.name, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options)
26
26
  else
27
- collection_select(:record, column.name, select_options, :id, column.options[:label_method] || :to_label, options, html_options)
27
+ collection_select(:record, column.name, select_options, :id, ui_options[:label_method] || :to_label, options, html_options)
28
28
  end
29
29
  else
30
- active_scaffold_input_select(column, html_options)
30
+ active_scaffold_input_select(column, html_options, ui_options: ui_options)
31
31
  end
32
32
  end
33
33
  end
34
34
 
35
35
  module SearchColumnHelpers
36
- def active_scaffold_search_chosen(column, options)
36
+ def active_scaffold_search_chosen(column, options, ui_options: column.options)
37
37
  options[:class] << ' chosen'
38
- active_scaffold_search_select(column, options)
38
+ active_scaffold_search_select(column, options, ui_options: ui_options)
39
39
  end
40
40
 
41
- def active_scaffold_search_multi_chosen(column, options)
41
+ def active_scaffold_search_multi_chosen(column, options, ui_options: column.options)
42
42
  options[:class] << ' chosen'
43
43
  options[:multiple] = true
44
- options[:'data-placeholder'] = column.options[:placeholder] || as_(:_select_)
45
- active_scaffold_search_select(column, options)
44
+ options[:'data-placeholder'] = ui_options[:placeholder] || as_(:_select_)
45
+ active_scaffold_search_select(column, options, ui_options: ui_options)
46
46
  end
47
47
  end
48
48
  end
@@ -1,18 +1,18 @@
1
1
  module ActiveScaffold::Bridges
2
2
  class CountrySelect
3
3
  module FormColumnHelpers
4
- def active_scaffold_input_country(column, options)
5
- select_options = {:prompt => as_(:_select_), :priority_countries => column.options[:priority] || [:us]}
6
- select_options[:format] = column.options[:format] if column.options[:format]
4
+ def active_scaffold_input_country(column, options, ui_options: column.options)
5
+ select_options = {:prompt => as_(:_select_), :priority_countries => ui_options[:priority] || [:us]}
6
+ select_options[:format] = ui_options[:format] if ui_options[:format]
7
7
  select_options.merge!(options)
8
- options.reverse_merge!(column.options).except!(:prompt, :priority, :format)
8
+ options.reverse_merge!(ui_options).except!(:prompt, :priority, :format)
9
9
  active_scaffold_select_name_with_multiple options
10
10
  country_select(:record, column.name, select_options, options.except(:object))
11
11
  end
12
12
  end
13
13
 
14
14
  module ListColumnHelpers
15
- def active_scaffold_column_country(record, column)
15
+ def active_scaffold_column_country(record, column, ui_options: column.options)
16
16
  country_code = record.send(column.name)
17
17
  return if country_code.blank?
18
18
  country = ISO3166::Country[country_code]
@@ -22,8 +22,8 @@ module ActiveScaffold::Bridges
22
22
  end
23
23
 
24
24
  module SearchColumnHelpers
25
- def active_scaffold_search_country(column, options)
26
- active_scaffold_input_country(column, options.merge!(:selected => options.delete(:value)))
25
+ def active_scaffold_search_country(column, options, ui_options: column.options)
26
+ active_scaffold_input_country(column, options.merge!(:selected => options.delete(:value)), ui_options: ui_options)
27
27
  end
28
28
  end
29
29
  end
@@ -10,6 +10,7 @@ class ActiveScaffold::Bridges::DatePicker
10
10
  module DatePickerBridge
11
11
  def initialize(model_id)
12
12
  super
13
+ return unless ActiveScaffold::Bridges::DatePicker.default_ui
13
14
 
14
15
  date_picker_fields = _columns.collect { |c| {:name => c.name.to_sym, :type => c.type} if %i[date datetime].include?(c.type) }.compact
15
16
  # check to see if file column was used on the model
@@ -31,6 +32,18 @@ class ActiveScaffold::Bridges::DatePicker
31
32
  super
32
33
  end
33
34
  end
35
+
36
+ def datetime_column_date?(column)
37
+ if %i[date_picker datetime_picker].include? column.search_ui
38
+ column.search_ui == :date_picker
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ def format_for_date(column, value, format_name = column.options[:format])
45
+ super column, value, format_name || (:default if column.search_ui == :date_picker)
46
+ end
34
47
  end
35
48
 
36
49
  module AttributeParams
@@ -46,22 +59,20 @@ end
46
59
 
47
60
  ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::DatePicker::DatePickerBridge
48
61
  ActionView::Base.class_eval do
49
- include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers
50
- alias_method :active_scaffold_search_date_picker, :active_scaffold_search_date_bridge
51
- alias_method :active_scaffold_search_datetime_picker, :active_scaffold_search_date_bridge
52
- include ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers
53
- alias_method :active_scaffold_human_condition_date_picker, :active_scaffold_human_condition_date_bridge
54
- alias_method :active_scaffold_human_condition_datetime_picker, :active_scaffold_human_condition_date_bridge
62
+ alias_method :active_scaffold_search_date_picker, :active_scaffold_search_datetime
63
+ alias_method :active_scaffold_search_datetime_picker, :active_scaffold_search_datetime
64
+ alias_method :active_scaffold_human_condition_date_picker, :active_scaffold_human_condition_datetime
65
+ alias_method :active_scaffold_human_condition_datetime_picker, :active_scaffold_human_condition_datetime
55
66
  include ActiveScaffold::Bridges::DatePicker::Helper::SearchColumnHelpers
67
+ alias_method :active_scaffold_search_datetime_picker_field, :active_scaffold_search_date_picker_field
56
68
  include ActiveScaffold::Bridges::DatePicker::Helper::FormColumnHelpers
57
69
  alias_method :active_scaffold_input_datetime_picker, :active_scaffold_input_date_picker
58
70
  include ActiveScaffold::Bridges::DatePicker::Helper::DatepickerColumnHelpers
59
71
  end
60
72
  ActiveScaffold::Finder::ClassMethods.module_eval do
61
73
  prepend ActiveScaffold::Bridges::DatePicker::Finder
62
- include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods
63
- alias_method :condition_for_date_picker_type, :condition_for_date_bridge_type
64
- alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type
74
+ alias_method :condition_for_date_picker_type, :condition_for_datetime
75
+ alias_method :condition_for_datetime_picker_type, :condition_for_datetime
65
76
  end
66
77
  ActiveScaffold::AttributeParams.module_eval do
67
78
  prepend ActiveScaffold::Bridges::DatePicker::AttributeParams
@@ -148,15 +148,15 @@ module ActiveScaffold::Bridges
148
148
  end
149
149
 
150
150
  module SearchColumnHelpers
151
- def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name)
151
+ def active_scaffold_search_date_picker_field(column, options, current_search, name, ui_options: column.options)
152
152
  value =
153
153
  if current_search.is_a? Hash
154
154
  controller.class.condition_value_for_datetime(column, current_search[name], column.search_ui == :date_picker ? :to_date : :to_time)
155
155
  else
156
156
  current_search
157
157
  end
158
- options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value)
159
- options = active_scaffold_input_text_options(options.merge(column.options))
158
+ options = ui_options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value)
159
+ options = active_scaffold_input_text_options(options)
160
160
  format = datepicker_format(options, column.search_ui)
161
161
  options[:class] << " #{column.search_ui}"
162
162
  options[:style] = 'display: none' if options[:show] == false # hide only if asked to hide
@@ -168,9 +168,9 @@ module ActiveScaffold::Bridges
168
168
  end
169
169
 
170
170
  module FormColumnHelpers
171
- def active_scaffold_input_date_picker(column, options)
171
+ def active_scaffold_input_date_picker(column, options, ui_options: column.options)
172
172
  record = options[:object]
173
- options = active_scaffold_input_text_options(options.merge(column.options))
173
+ options = active_scaffold_input_text_options(options.merge(ui_options))
174
174
  options[:class] << " #{column.form_ui}"
175
175
 
176
176
  format = datepicker_format(options, column.form_ui)
@@ -12,6 +12,8 @@ module ActiveScaffold::Bridges
12
12
  def self.jquery_ui_included?
13
13
  Jquery::Rails.const_defined?('JQUERY_UI_VERSION') || Jquery.const_defined?('Ui') if Object.const_defined?('Jquery')
14
14
  end
15
+ mattr_accessor :default_ui
16
+ @@default_ui = true
15
17
 
16
18
  def self.stylesheets
17
19
  'jquery-ui-timepicker-addon'
@@ -1,11 +1,11 @@
1
1
  module ActiveScaffold
2
2
  module Helpers
3
3
  module FormColumnHelpers
4
- def active_scaffold_input_dragonfly(column, options)
4
+ def active_scaffold_input_dragonfly(column, options, ui_options: column.options)
5
5
  record = options[:object]
6
6
  dragonfly = record.send(column.name.to_s)
7
- content = active_scaffold_column_dragonfly(record, column) if dragonfly.present?
8
- active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'dragonfly_controls')
7
+ content = active_scaffold_column_dragonfly(record, column, ui_options: ui_options) if dragonfly.present?
8
+ active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'dragonfly_controls', ui_options: ui_options)
9
9
  end
10
10
  end
11
11
  end
@@ -1,20 +1,20 @@
1
1
  module ActiveScaffold
2
2
  module Helpers
3
3
  module ListColumnHelpers
4
- def active_scaffold_column_dragonfly(record, column)
4
+ def active_scaffold_column_dragonfly(record, column, ui_options: column.options)
5
5
  attachment = record.send(column.name.to_s)
6
6
  return nil if attachment.blank?
7
7
  content =
8
8
  if attachment.image?
9
- image_tag(attachment.thumb(column.options[:thumb] || ActiveScaffold::Bridges::Dragonfly::DragonflyBridgeHelpers.thumbnail_style).url, :border => 0)
9
+ image_tag(attachment.thumb(ui_options[:thumb] || ActiveScaffold::Bridges::Dragonfly::DragonflyBridgeHelpers.thumbnail_style).url, :border => 0)
10
10
  else
11
11
  attachment.name
12
12
  end
13
- link_to(content, dragonfly_url_for_attachment(attachment, record, column), :target => '_blank', rel: 'noopener noreferrer')
13
+ link_to(content, dragonfly_url_for_attachment(attachment, record, column, ui_options: ui_options), :target => '_blank', rel: 'noopener noreferrer')
14
14
  end
15
15
 
16
- def dragonfly_url_for_attachment(attachment, record, column)
17
- url_method = column.options[:private_store] ? :url : :remote_url
16
+ def dragonfly_url_for_attachment(attachment, record, column, ui_options: column.options)
17
+ url_method = ui_options[:private_store] ? :url : :remote_url
18
18
  attachment.send(url_method)
19
19
  end
20
20
  end
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Helpers
3
3
  # Helpers that assist with the rendering of a Form Column
4
4
  module FormColumnHelpers
5
- def active_scaffold_input_file_column(column, options)
5
+ def active_scaffold_input_file_column(column, options, ui_options: column.options)
6
6
  record = options[:object]
7
7
  if record.send(column.name)
8
8
  # we already have a value? display the form for deletion.
@@ -2,18 +2,18 @@ module ActiveScaffold
2
2
  module Helpers
3
3
  # Helpers that assist with the rendering of a List Column
4
4
  module ListColumnHelpers
5
- def active_scaffold_column_download_link_with_filename(record, column)
5
+ def active_scaffold_column_download_link_with_filename(record, column, ui_options: column.options)
6
6
  return nil if record.send(column.name).nil?
7
7
  active_scaffold_column_download_link(record, column, File.basename(record.send(column.name)))
8
8
  end
9
9
 
10
- def active_scaffold_column_download_link(record, column, label = nil)
10
+ def active_scaffold_column_download_link(record, column, label = nil, ui_options: column.options)
11
11
  return nil if record.send(column.name).nil?
12
12
  label ||= as_(:download)
13
13
  link_to(label, url_for_file_column(record, column.name.to_s), :popup => true)
14
14
  end
15
15
 
16
- def active_scaffold_column_thumbnail(record, column)
16
+ def active_scaffold_column_thumbnail(record, column, ui_options: column.options)
17
17
  return nil if record.send(column.name).nil?
18
18
  link_to(
19
19
  image_tag(url_for_file_column(record, column.name.to_s, 'thumb'), :border => 0),
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
  require File.expand_path('../mock_model.rb', __dir__)
3
3
  require File.expand_path('../../file_column_helpers.rb', __dir__)
4
4
 
5
- class DeleteFileColumnTest < MiniTest::Test
5
+ class DeleteFileColumnTest < Minitest::Test
6
6
  def setup
7
7
  MockModel.extend ActiveScaffold::Bridges::FileColumn::FileColumnHelpers
8
8
  ActiveScaffold::Bridges::FileColumn::FileColumnHelpers.generate_delete_helpers(MockModel)
@@ -1,11 +1,11 @@
1
1
  module ActiveScaffold
2
2
  module Helpers
3
3
  module FormColumnHelpers
4
- def active_scaffold_input_paperclip(column, options)
4
+ def active_scaffold_input_paperclip(column, options, ui_options: column.options)
5
5
  record = options[:object]
6
6
  paperclip = record.send(column.name.to_s)
7
- content = active_scaffold_column_paperclip(record, column) if paperclip.file?
8
- active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'paperclip_controls')
7
+ content = active_scaffold_column_paperclip(record, column, ui_options: ui_options) if paperclip.file?
8
+ active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'paperclip_controls', ui_options: ui_options)
9
9
  end
10
10
  end
11
11
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveScaffold
2
2
  module Helpers
3
3
  module ListColumnHelpers
4
- def active_scaffold_column_paperclip(record, column)
4
+ def active_scaffold_column_paperclip(record, column, ui_options: column.options)
5
5
  paperclip = record.send(column.name.to_s)
6
6
  return nil unless paperclip.file?
7
7
  content =
@@ -10,21 +10,21 @@ class ActiveScaffold::Bridges::RecordSelect
10
10
 
11
11
  module FormColumnHelpers
12
12
  # requires RecordSelect plugin to be installed and configured.
13
- def active_scaffold_input_record_select(column, options)
13
+ def active_scaffold_input_record_select(column, options, ui_options: column.options)
14
14
  record = options.delete(:object)
15
15
  if column.association&.singular?
16
- multiple = column.options.dig(:html_options, :multiple)
17
- html = active_scaffold_record_select(record, column, options, record.send(column.name), multiple)
18
- html << active_scaffold_new_record_subform(column, record, options) if column.options[:add_new]
16
+ multiple = ui_options.dig(:html_options, :multiple)
17
+ html = active_scaffold_record_select(record, column, options, record.send(column.name), multiple, ui_options: ui_options)
18
+ html << active_scaffold_new_record_subform(column, record, options, ui_options: ui_options) if ui_options[:add_new]
19
19
  html
20
20
  elsif column.association&.collection?
21
- active_scaffold_record_select(record, column, options, record.send(column.name), true)
21
+ active_scaffold_record_select(record, column, options, record.send(column.name), true, ui_options: ui_options)
22
22
  else
23
- active_scaffold_record_select_autocomplete(record, column, options)
23
+ active_scaffold_record_select_autocomplete(record, column, options, ui_options: ui_options)
24
24
  end
25
25
  end
26
26
 
27
- def active_scaffold_record_select(record, column, options, value, multiple)
27
+ def active_scaffold_record_select(record, column, options, value, multiple, ui_options: column.options)
28
28
  unless column.association
29
29
  raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). "\
30
30
  'A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user).'
@@ -43,7 +43,7 @@ class ActiveScaffold::Bridges::RecordSelect
43
43
  record_select_options = active_scaffold_input_text_options(options).merge(
44
44
  :controller => remote_controller
45
45
  )
46
- record_select_options.merge!(column.options)
46
+ record_select_options.merge!(ui_options)
47
47
 
48
48
  html =
49
49
  if multiple
@@ -55,10 +55,10 @@ class ActiveScaffold::Bridges::RecordSelect
55
55
  html
56
56
  end
57
57
 
58
- def active_scaffold_record_select_autocomplete(record, column, options)
58
+ def active_scaffold_record_select_autocomplete(record, column, options, ui_options: column.options)
59
59
  record_select_options = active_scaffold_input_text_options(options).reverse_merge(
60
60
  :controller => active_scaffold_controller_for(record.class).controller_path
61
- ).merge(column.options)
61
+ ).merge(ui_options)
62
62
  html = record_select_autocomplete(options[:name], record, record_select_options)
63
63
  html = instance_exec(html, self, &self.class.field_error_proc) if record.errors[column.name].any?
64
64
  html
@@ -66,14 +66,14 @@ class ActiveScaffold::Bridges::RecordSelect
66
66
  end
67
67
 
68
68
  module SearchColumnHelpers
69
- def active_scaffold_search_record_select(column, options)
70
- value = field_search_record_select_value(column, options[:value])
71
- active_scaffold_record_select(options[:object], column, options, value, column.options[:multiple])
69
+ def active_scaffold_search_record_select(column, options, ui_options: column.options)
70
+ value = field_search_record_select_value(column, options[:value], ui_options: ui_options)
71
+ active_scaffold_record_select(options[:object], column, options, value, ui_options[:multiple], ui_options: ui_options)
72
72
  end
73
73
 
74
- def field_search_record_select_value(column, value)
74
+ def field_search_record_select_value(column, value, ui_options: column.options)
75
75
  return if value.blank?
76
- if column.options[:multiple]
76
+ if ui_options[:multiple]
77
77
  column.association.klass.find value.collect!(&:to_i)
78
78
  else
79
79
  column.association.klass.find(value.to_i)
@@ -14,16 +14,16 @@ class ActiveScaffold::Bridges::TinyMce
14
14
  # but not the plugins, toolbars etc.
15
15
  # The other one is :tinymce_config, which selects the config to use from tinymce.yml.
16
16
  # See the tinymce-rails gem documentation for usage.
17
- def active_scaffold_input_text_editor(column, options)
18
- options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip
17
+ def active_scaffold_input_text_editor(column, options, ui_options: column.options)
18
+ options[:class] = "#{options[:class]} mceEditor #{ui_options[:class]}".strip
19
19
 
20
- settings = tinymce_configuration(column.options[:tinymce_config] || :default).options
21
- .reject { |k, _v| k == 'selector' }
22
- .merge(column.options[:tinymce] || {})
20
+ settings = tinymce_configuration(ui_options[:tinymce_config] || :default).options
21
+ .reject { |k, _v| k == 'selector' }
22
+ .merge(ui_options[:tinymce] || {})
23
23
  options['data-tinymce'] = settings.to_json if ActiveScaffold.js_framework != :prototype
24
24
 
25
25
  html = []
26
- html << send(override_input(:textarea), column, options)
26
+ html << send(override_input(:textarea), column, options, ui_options: ui_options)
27
27
  if ActiveScaffold.js_framework == :prototype && (request.xhr? || params[:iframe])
28
28
  html << javascript_tag("tinyMCE.settings = #{settings.to_json}; tinyMCE.execCommand('mceAddEditor', false, '#{options[:id]}');")
29
29
  end
@@ -58,18 +58,18 @@ module ActiveScaffold::Bridges
58
58
  end
59
59
 
60
60
  module FormColumnHelpers
61
- def active_scaffold_input_usa_state(column, options)
61
+ def active_scaffold_input_usa_state(column, options, ui_options: column.options)
62
62
  select_options = {:prompt => as_(:_select_)}
63
63
  select_options.merge!(options)
64
- options.reverse_merge!(column.options).except!(:prompt, :priority)
64
+ options.reverse_merge!(ui_options).except!(:prompt, :priority)
65
65
  active_scaffold_select_name_with_multiple options
66
- usa_state_select(:record, column.name, column.options[:priority], select_options, options.except(:object))
66
+ usa_state_select(:record, column.name, ui_options[:priority], select_options, options.except(:object))
67
67
  end
68
68
  end
69
69
 
70
70
  module SearchColumnHelpers
71
- def active_scaffold_search_usa_state(column, options)
72
- active_scaffold_input_usa_state(column, options.merge!(:selected => options.delete(:value)))
71
+ def active_scaffold_search_usa_state(column, options, ui_options: column.options)
72
+ active_scaffold_input_usa_state(column, options.merge!(:selected => options.delete(:value)), ui_options: ui_options)
73
73
  end
74
74
  end
75
75
  end