active_scaffold 3.4.17 → 3.4.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +12 -1
  3. data/README.md +8 -4
  4. data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
  5. data/app/assets/stylesheets/active_scaffold.scss +1 -1
  6. data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
  7. data/app/assets/stylesheets/blue-theme.css +1 -1
  8. data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
  9. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
  10. data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
  11. data/lib/active_scaffold.rb +16 -16
  12. data/lib/active_scaffold/actions/common_search.rb +13 -11
  13. data/lib/active_scaffold/actions/core.rb +85 -78
  14. data/lib/active_scaffold/actions/create.rb +29 -28
  15. data/lib/active_scaffold/actions/delete.rb +17 -17
  16. data/lib/active_scaffold/actions/field_search.rb +18 -19
  17. data/lib/active_scaffold/actions/list.rb +30 -22
  18. data/lib/active_scaffold/actions/mark.rb +1 -1
  19. data/lib/active_scaffold/actions/nested.rb +78 -65
  20. data/lib/active_scaffold/actions/search.rb +13 -10
  21. data/lib/active_scaffold/actions/show.rb +10 -6
  22. data/lib/active_scaffold/actions/subform.rb +1 -2
  23. data/lib/active_scaffold/actions/update.rb +39 -31
  24. data/lib/active_scaffold/active_record_permissions.rb +14 -15
  25. data/lib/active_scaffold/attribute_params.rb +42 -43
  26. data/lib/active_scaffold/bridges.rb +22 -12
  27. data/lib/active_scaffold/bridges/ancestry.rb +1 -1
  28. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
  29. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  30. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
  31. data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
  32. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
  33. data/lib/active_scaffold/bridges/cancan.rb +1 -1
  34. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
  35. data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
  36. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
  37. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
  38. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
  39. data/lib/active_scaffold/bridges/chosen.rb +1 -1
  40. data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
  41. data/lib/active_scaffold/bridges/country_helper.rb +1 -1
  42. data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
  43. data/lib/active_scaffold/bridges/date_picker.rb +2 -2
  44. data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
  45. data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
  46. data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
  47. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
  48. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
  49. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
  50. data/lib/active_scaffold/bridges/file_column.rb +5 -5
  51. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
  52. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
  53. data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
  54. data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
  55. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
  56. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
  57. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
  58. data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
  59. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
  60. data/lib/active_scaffold/bridges/paperclip.rb +5 -5
  61. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
  62. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
  63. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
  64. data/lib/active_scaffold/bridges/record_select.rb +1 -1
  65. data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
  66. data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
  67. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
  68. data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
  69. data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
  70. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
  71. data/lib/active_scaffold/config/base.rb +9 -10
  72. data/lib/active_scaffold/config/core.rb +24 -29
  73. data/lib/active_scaffold/config/create.rb +0 -1
  74. data/lib/active_scaffold/config/field_search.rb +8 -10
  75. data/lib/active_scaffold/config/form.rb +5 -5
  76. data/lib/active_scaffold/config/list.rb +21 -20
  77. data/lib/active_scaffold/config/mark.rb +3 -3
  78. data/lib/active_scaffold/config/nested.rb +11 -10
  79. data/lib/active_scaffold/config/search.rb +2 -3
  80. data/lib/active_scaffold/config/show.rb +1 -1
  81. data/lib/active_scaffold/config/update.rb +1 -2
  82. data/lib/active_scaffold/configurable.rb +9 -11
  83. data/lib/active_scaffold/constraints.rb +9 -8
  84. data/lib/active_scaffold/core.rb +72 -84
  85. data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
  86. data/lib/active_scaffold/data_structures/action_link.rb +43 -43
  87. data/lib/active_scaffold/data_structures/action_links.rb +17 -15
  88. data/lib/active_scaffold/data_structures/actions.rb +5 -5
  89. data/lib/active_scaffold/data_structures/bridge.rb +6 -3
  90. data/lib/active_scaffold/data_structures/column.rb +110 -89
  91. data/lib/active_scaffold/data_structures/columns.rb +3 -3
  92. data/lib/active_scaffold/data_structures/error_message.rb +4 -6
  93. data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
  94. data/lib/active_scaffold/data_structures/set.rb +7 -8
  95. data/lib/active_scaffold/data_structures/sorting.rb +38 -33
  96. data/lib/active_scaffold/delayed_setup.rb +5 -6
  97. data/lib/active_scaffold/engine.rb +4 -4
  98. data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
  99. data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
  100. data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
  101. data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
  102. data/lib/active_scaffold/extensions/localize.rb +1 -1
  103. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
  104. data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
  105. data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
  106. data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
  107. data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
  108. data/lib/active_scaffold/finder.rb +90 -93
  109. data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
  110. data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
  111. data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
  112. data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
  113. data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
  114. data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
  115. data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
  116. data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
  117. data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
  118. data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
  119. data/lib/active_scaffold/marked_model.rb +10 -10
  120. data/lib/active_scaffold/paginator.rb +30 -34
  121. data/lib/active_scaffold/responds_to_parent.rb +27 -28
  122. data/lib/active_scaffold/tableless.rb +20 -15
  123. data/lib/active_scaffold/version.rb +1 -1
  124. data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
  125. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
  126. data/shoulda_macros/macros.rb +27 -22
  127. data/test/bridges/bridge_test.rb +38 -29
  128. data/test/bridges/date_picker_test.rb +1 -1
  129. data/test/bridges/paper_trail_test.rb +17 -0
  130. data/test/bridges/paperclip_test.rb +3 -2
  131. data/test/bridges/tiny_mce_test.rb +5 -2
  132. data/test/company.rb +25 -30
  133. data/test/config/base_test.rb +1 -1
  134. data/test/config/core_test.rb +9 -9
  135. data/test/config/create_test.rb +14 -8
  136. data/test/config/delete_test.rb +4 -4
  137. data/test/config/field_search_test.rb +6 -6
  138. data/test/config/list_test.rb +16 -16
  139. data/test/config/nested_test.rb +4 -4
  140. data/test/config/search_test.rb +8 -8
  141. data/test/config/show_test.rb +6 -6
  142. data/test/config/subform_test.rb +1 -1
  143. data/test/config/update_test.rb +5 -5
  144. data/test/const_mocker.rb +4 -4
  145. data/test/data_structures/action_columns_test.rb +4 -5
  146. data/test/data_structures/action_link_test.rb +1 -0
  147. data/test/data_structures/action_links_test.rb +5 -5
  148. data/test/data_structures/column_test.rb +9 -9
  149. data/test/data_structures/columns_test.rb +2 -2
  150. data/test/data_structures/error_message_test.rb +4 -5
  151. data/test/data_structures/set_test.rb +1 -2
  152. data/test/data_structures/sorting_test.rb +10 -10
  153. data/test/data_structures/validation_reflection_test.rb +8 -0
  154. data/test/extensions/routing_mapper_test.rb +2 -2
  155. data/test/helpers/list_column_helpers_test.rb +3 -2
  156. data/test/helpers/pagination_helpers_test.rb +5 -4
  157. data/test/helpers/search_column_helpers_test.rb +1 -1
  158. data/test/misc/active_record_permissions_test.rb +63 -50
  159. data/test/misc/attribute_params_test.rb +28 -26
  160. data/test/misc/calculation_test.rb +10 -3
  161. data/test/misc/configurable_test.rb +12 -13
  162. data/test/misc/constraints_test.rb +6 -6
  163. data/test/misc/convert_numbers_format_test.rb +7 -6
  164. data/test/misc/finder_test.rb +17 -12
  165. data/test/misc/lang_test.rb +3 -4
  166. data/test/misc/tableless_test.rb +2 -3
  167. data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
  168. data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
  169. data/test/mock_app/app/controllers/cars_controller.rb +1 -1
  170. data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
  171. data/test/mock_app/app/controllers/people_controller.rb +1 -1
  172. data/test/mock_app/app/models/file_model.rb +2 -2
  173. data/test/mock_app/app/models/person.rb +1 -1
  174. data/test/mock_app/config/application.rb +3 -3
  175. data/test/mock_app/config/boot.rb +1 -1
  176. data/test/mock_app/config/environment.rb +1 -0
  177. data/test/mock_app/config/environments/development.rb +0 -1
  178. data/test/mock_app/config/environments/production.rb +1 -1
  179. data/test/mock_app/db/schema.rb +14 -15
  180. data/test/model_stub.rb +13 -16
  181. data/test/run_all.rb +5 -7
  182. data/test/test_helper.rb +12 -9
  183. metadata +19 -3
@@ -4,7 +4,7 @@ module ActiveScaffold
4
4
  # Cache the options for select
5
5
  def cache_association_options(association, conditions, klass, cache = true)
6
6
  if active_scaffold_config.cache_association_options && cache
7
- @_associations_cache ||= Hash.new { |h,k| h[k] = {} }
7
+ @_associations_cache ||= Hash.new { |h, k| h[k] = {} }
8
8
  key = [association.name, association.active_record.name, klass.name].join('/')
9
9
  @_associations_cache[key][conditions] ||= yield
10
10
  else
@@ -14,8 +14,8 @@ module ActiveScaffold
14
14
 
15
15
  # Provides a way to honor the :conditions on an association while searching the association's klass
16
16
  def association_options_find(association, conditions = nil, klass = nil, record = nil)
17
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, call with record.", caller if record.nil? # TODO Remove when relying on @record is removed
18
- record ||= @record # TODO Remove when relying on @record is removed
17
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, call with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
18
+ record ||= @record # TODO: Remove when relying on @record is removed
19
19
  if klass.nil? && association.options[:polymorphic]
20
20
  class_name = record.send(association.foreign_type)
21
21
  if class_name.present?
@@ -33,7 +33,7 @@ module ActiveScaffold
33
33
  if method(:options_for_association_conditions).arity.abs == 2
34
34
  conditions = options_for_association_conditions(association, record)
35
35
  else
36
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include record in your options_for_association_conditions overrided method.", caller if record.nil? # TODO Remove when relying on @record is removed
36
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include record in your options_for_association_conditions overrided method.', caller if record.nil? # TODO: Remove when relying on @record is removed
37
37
  conditions = options_for_association_conditions(association)
38
38
  end
39
39
  end
@@ -89,7 +89,7 @@ module ActiveScaffold
89
89
  if method(:options_for_association_conditions).arity.abs == 2
90
90
  conditions = options_for_association_conditions(association, record)
91
91
  else
92
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include record in your options_for_association_conditions overrided method.", caller if record.nil? # TODO Remove when relying on @record is removed
92
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include record in your options_for_association_conditions overrided method.', caller if record.nil? # TODO: Remove when relying on @record is removed
93
93
  conditions = options_for_association_conditions(association)
94
94
  end
95
95
  association_options_count(association, conditions)
@@ -2,13 +2,13 @@ module ActiveScaffold
2
2
  module Helpers
3
3
  module ControllerHelpers
4
4
  def self.included(controller)
5
- controller.class_eval { helper_method :params_for, :conditions_from_params, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated, :generate_temporary_id, :generated_id}
5
+ controller.class_eval { helper_method :params_for, :conditions_from_params, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated, :generate_temporary_id, :generated_id }
6
6
  end
7
-
7
+
8
8
  include ActiveScaffold::Helpers::IdHelpers
9
-
9
+
10
10
  def generate_temporary_id(record = nil, generated_id = nil)
11
- (generated_id || (Time.now.to_f*1000).to_i.to_s).tap do |id|
11
+ (generated_id || (Time.now.to_f * 1000).to_i.to_s).tap do |id|
12
12
  (@temporary_ids ||= {})[record.class.name] = id if record
13
13
  end
14
14
  end
@@ -25,7 +25,7 @@ module ActiveScaffold
25
25
  blacklist = [:adapter, :position, :sort, :sort_direction, :page, :auto_pagination, :record, :commit, :_method, :authenticity_token, :iframe, :associated_id, :dont_close]
26
26
  unless @params_for
27
27
  @params_for = {}
28
- params.except(*blacklist).each {|key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value}
28
+ params.except(*blacklist).each { |key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value }
29
29
  @params_for[:controller] = '/' + @params_for[:controller].to_s unless @params_for[:controller].to_s.first(1) == '/' # for namespaced controllers
30
30
  @params_for.delete(:id) if @params_for[:id].nil?
31
31
  end
@@ -42,14 +42,14 @@ module ActiveScaffold
42
42
  if params[:parent_scaffold] && nested? && nested.singular_association?
43
43
  parameters[:controller] = params[:parent_scaffold]
44
44
  exclude_parameters.concat [nested.param_name, :association, :parent_scaffold]
45
- #parameters[:eid] = params[:parent_scaffold] # not neeeded anymore?
45
+ # parameters[:eid] = params[:parent_scaffold] # not neeeded anymore?
46
46
  end
47
47
  parameters.merge! nested.to_params if nested?
48
48
  if params[:parent_sti]
49
49
  parameters[:controller] = params[:parent_sti]
50
- #parameters[:eid] = nil # not neeeded anymore?
50
+ # parameters[:eid] = nil # not neeeded anymore?
51
51
  end
52
- parameters[:action] = "index"
52
+ parameters[:action] = 'index'
53
53
  parameters[:id] = nil
54
54
  params_for(parameters).except(*exclude_parameters)
55
55
  end
@@ -73,20 +73,23 @@ module ActiveScaffold
73
73
  end
74
74
 
75
75
  def render_parent_action
76
- begin
77
- @parent_action = :row
78
- if params[:parent_sti]
79
- parent_controller = "#{params[:parent_sti].to_s.camelize}Controller".constantize
80
- @parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list == true
81
- @parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list == true
82
- @parent_action = :index if action_name == 'destroy' && parent_controller.active_scaffold_config.actions.include?(:delete) && parent_controller.active_scaffold_config.delete.refresh_list == true
76
+ if @parent_action.nil?
77
+ begin
78
+ @parent_action = :row
79
+ if params[:parent_sti]
80
+ parent_controller = "#{params[:parent_sti].to_s.camelize}Controller".constantize
81
+ @parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list == true
82
+ @parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list == true
83
+ @parent_action = :index if action_name == 'destroy' && parent_controller.active_scaffold_config.actions.include?(:delete) && parent_controller.active_scaffold_config.delete.refresh_list == true
84
+ end
85
+ rescue ActiveScaffold::ControllerNotFound => ex
86
+ logger.warn "#{ex.message} for parent_sti #{params[:parent_sti]}"
83
87
  end
84
- rescue ActiveScaffold::ControllerNotFound
85
- end if @parent_action.nil?
88
+ end
86
89
  @parent_action
87
90
  end
88
-
89
- # build an associated record for association
91
+
92
+ # build an associated record for association
90
93
  def build_associated(association, parent_record)
91
94
  if association.options[:through]
92
95
  # build full chain, only check create_associated on initial parent_record
@@ -12,14 +12,14 @@ module ActiveScaffold
12
12
 
13
13
  def active_scaffold_render_input(column, options)
14
14
  record = options[:object]
15
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
16
- record ||= @record # TODO Remove when relying on @record is removed
15
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include :object in options with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
16
+ record ||= @record # TODO: Remove when relying on @record is removed
17
17
 
18
18
  # first, check if the dev has created an override for this specific field
19
19
  if (method = override_form_field(column))
20
20
  send(method, record, options)
21
21
  # second, check if the dev has specified a valid form_ui for this column
22
- elsif column.form_ui and (method = override_input(column.form_ui))
22
+ elsif column.form_ui && (method = override_input(column.form_ui))
23
23
  send(method, column, options)
24
24
  # fallback: we get to make the decision
25
25
  else
@@ -48,20 +48,20 @@ module ActiveScaffold
48
48
  options[:maxlength] = column.column.limit
49
49
  options[:size] ||= options[:maxlength].to_i > 30 ? 30 : options[:maxlength]
50
50
  end
51
- options[:include_blank] = true if column.column.null and [:date, :datetime, :time].include?(column.column.type)
51
+ options[:include_blank] = true if column.column.null && [:date, :datetime, :time].include?(column.column.type)
52
52
  options[:value] = format_number_value(record.send(column.name), column.options) if column.number?
53
53
  text_field(:record, column.name, options.merge(column.options))
54
54
  end
55
55
  end
56
56
  end
57
- rescue Exception => e
57
+ rescue StandardError => e
58
58
  logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}"
59
59
  raise e
60
60
  end
61
-
61
+
62
62
  def active_scaffold_render_subform_column(column, scope, crud_type, readonly, add_class = false, record = nil)
63
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, call with record.", caller if record.nil? # TODO Remove when relying on @record is removed
64
- record ||= @record # TODO Remove when relying on @record is removed
63
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, call with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
64
+ record ||= @record # TODO: Remove when relying on @record is removed
65
65
  if add_class
66
66
  col_class = []
67
67
  col_class << 'required' if column.required?
@@ -70,15 +70,15 @@ module ActiveScaffold
70
70
  col_class << 'checkbox' if column.form_ui == :checkbox
71
71
  col_class = col_class.join(' ')
72
72
  end
73
- unless readonly and not record.new_record? or not record.authorized_for?(:crud_type => crud_type, :column => column.name)
73
+ if readonly && !record.new_record? || !record.authorized_for?(:crud_type => crud_type, :column => column.name)
74
+ options = active_scaffold_input_options(column, scope).except(:name)
75
+ options[:class] = "#{options[:class]} #{col_class}" if col_class
76
+ content_tag :span, get_column_value(record, column), options
77
+ else
74
78
  renders_as = column_renders_as(column)
75
79
  html = render_column(column, record, renders_as, scope, false, col_class)
76
80
  html = content_tag(:div, html, active_scaffold_subform_attributes(column)) if renders_as == :subform
77
81
  html
78
- else
79
- options = active_scaffold_input_options(column, scope).except(:name)
80
- options[:class] = "#{options[:class]} #{col_class}" if col_class
81
- content_tag :span, get_column_value(record, column), options
82
82
  end
83
83
  end
84
84
 
@@ -110,11 +110,11 @@ module ActiveScaffold
110
110
  # Fix for keeping unique IDs in subform
111
111
  id_control = "record_#{column.name}_#{[params[:eid], params[:parent_id] || params[:id]].compact.join '_'}"
112
112
  id_control += scope_id(scope) if scope
113
-
113
+
114
114
  classes = "#{column.name}-input"
115
115
  classes += ' numeric-input' if column.number?
116
116
 
117
- { :name => name, :class => classes, :id => id_control}.merge(options)
117
+ {:name => name, :class => classes, :id => id_control}.merge(options)
118
118
  end
119
119
 
120
120
  def current_form_columns(record, scope, subform_controller = nil)
@@ -127,8 +127,8 @@ module ActiveScaffold
127
127
 
128
128
  def update_columns_options(column, scope, options, force = false)
129
129
  record = options[:object]
130
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
131
- record ||= @record # TODO Remove when relying on @record is removed
130
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include :object in options with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
131
+ record ||= @record # TODO: Remove when relying on @record is removed
132
132
  subform_controller = controller.class.active_scaffold_controller_for(record.class) if scope
133
133
  form_columns = @main_columns.try(:names) if scope.nil? || subform_controller == controller.class
134
134
  form_columns ||= current_form_columns(record, scope, subform_controller)
@@ -154,35 +154,36 @@ module ActiveScaffold
154
154
  def field_attributes(column, record)
155
155
  {}
156
156
  end
157
-
157
+
158
158
  def render_column(column, record, renders_as, scope = nil, only_value = false, col_class = nil)
159
159
  if override_form_field_partial?(column)
160
- render :partial => override_form_field_partial(column), :locals => { :column => column, :only_value => only_value, :scope => scope, :col_class => col_class, :record => record }
160
+ render :partial => override_form_field_partial(column), :locals => {:column => column, :only_value => only_value, :scope => scope, :col_class => col_class, :record => record}
161
161
  elsif renders_as == :field || override_form_field?(column)
162
162
  form_attribute(column, record, scope, only_value, col_class)
163
163
  elsif renders_as == :subform
164
- render :partial => 'form_association', :locals => { :column => column, :scope => scope, :parent_record => record }
164
+ render :partial => 'form_association', :locals => {:column => column, :scope => scope, :parent_record => record}
165
165
  else
166
166
  form_hidden_attribute(column, record, scope)
167
167
  end
168
168
  end
169
-
169
+
170
170
  def form_attribute(column, record, scope = nil, only_value = false, col_class = nil)
171
171
  column_options = active_scaffold_input_options(column, scope, :object => record)
172
172
  attributes = field_attributes(column, record)
173
173
  attributes[:class] = "#{attributes[:class]} #{col_class}" if col_class.present?
174
- field = unless only_value
175
- active_scaffold_input_for column, scope, column_options
176
- else
177
- content_tag(:span, get_column_value(record, column), column_options.except(:name, :object)) <<
178
- hidden_field(:record, column.association ? column.association.foreign_key : column.name, column_options)
179
- end
180
-
174
+ field =
175
+ if only_value
176
+ content_tag(:span, get_column_value(record, column), column_options.except(:name, :object)) <<
177
+ hidden_field(:record, column.association ? column.association.foreign_key : column.name, column_options)
178
+ else
179
+ active_scaffold_input_for column, scope, column_options
180
+ end
181
+
181
182
  content_tag :dl, attributes do
182
- %|<dt>#{label_tag label_for(column, column_options), column.label}</dt><dd>#{field}
183
+ %(<dt>#{label_tag label_for(column, column_options), column.label}</dt><dd>#{field}
183
184
  #{loading_indicator_tag(:action => :render_field, :id => params[:id]) if column.update_columns}
184
185
  #{content_tag :span, column.description, :class => 'description' if column.description.present?}
185
- </dd>|.html_safe
186
+ </dd>).html_safe
186
187
  end
187
188
  end
188
189
 
@@ -193,11 +194,11 @@ module ActiveScaffold
193
194
  def subform_label(column, hidden)
194
195
  column.label unless hidden
195
196
  end
196
-
197
+
197
198
  def form_hidden_attribute(column, record, scope = nil)
198
- %|<dl style="display: none;"><dt></dt><dd>
199
+ %(<dl style="display: none;"><dt></dt><dd>
199
200
  #{hidden_field :record, column.name, active_scaffold_input_options(column, scope).merge(:object => record)}
200
- </dd></dl>|.html_safe
201
+ </dd></dl>).html_safe
201
202
  end
202
203
 
203
204
  # Should this column be displayed in the subform?
@@ -210,13 +211,13 @@ module ActiveScaffold
210
211
  # A column shouldn't be in the subform if it's the reverse association to the parent
211
212
  return false if column.association.inverse_for?(parent_record.class)
212
213
 
213
- return true
214
+ true
214
215
  end
215
216
 
216
217
  def column_show_add_existing(column, record = nil)
217
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, call with record.", caller if record.nil? # TODO Remove when relying on @record is removed
218
- record ||= @record # TODO Remove when relying on @record is removed
219
- (column.allow_add_existing and options_for_association_count(column.association, record) > 0)
218
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, call with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
219
+ record ||= @record # TODO: Remove when relying on @record is removed
220
+ (column.allow_add_existing && options_for_association_count(column.association, record) > 0)
220
221
  end
221
222
 
222
223
  def column_show_add_new(column, associated, record)
@@ -228,13 +229,13 @@ module ActiveScaffold
228
229
  ##
229
230
  ## Form input methods
230
231
  ##
231
-
232
+
232
233
  def active_scaffold_grouped_options(column, select_options, optgroup)
233
234
  group_column = active_scaffold_config_for(column.association.klass).columns[optgroup]
234
235
  group_label = group_column.options[:label_method] if group_column
235
236
  group_label ||= group_column.try(:association) ? :to_label : :to_s
236
237
  select_options.group_by(&optgroup.to_sym).collect do |group, options|
237
- [group.send(group_label), options.collect {|r| [r.send(column.options[:label_method] || :to_label), r.id]}]
238
+ [group.send(group_label), options.collect { |r| [r.send(column.options[:label_method] || :to_label), r.id] }]
238
239
  end
239
240
  end
240
241
 
@@ -243,11 +244,11 @@ module ActiveScaffold
243
244
  options[:prompt] = as_(options[:prompt].to_s) if options[:prompt].is_a? Symbol
244
245
  options
245
246
  end
246
-
247
+
247
248
  def active_scaffold_input_singular_association(column, html_options)
248
249
  record = html_options.delete(:object)
249
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in html_options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
250
- record ||= @record # TODO Remove when relying on @record is removed
250
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include :object in html_options with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
251
+ record ||= @record # TODO: Remove when relying on @record is removed
251
252
  associated = record.send(column.association.name)
252
253
 
253
254
  select_options = sorted_association_options_find(column.association, nil, record)
@@ -258,14 +259,15 @@ module ActiveScaffold
258
259
 
259
260
  html_options.merge!(column.options[:html_options] || {})
260
261
  options.merge!(column.options)
261
- html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]")
262
+ html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?('[]')
262
263
  active_scaffold_translate_select_options(options)
263
264
 
264
- html = if optgroup = options.delete(:optgroup)
265
- select(:record, method, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options)
266
- else
267
- collection_select(:record, method, select_options, :id, column.options[:label_method] || :to_label, options, html_options)
268
- end
265
+ html =
266
+ if (optgroup = options.delete(:optgroup))
267
+ select(:record, method, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options)
268
+ else
269
+ collection_select(:record, method, select_options, :id, column.options[:label_method] || :to_label, options, html_options)
270
+ end
269
271
  html << active_scaffold_refresh_link(column, html_options, record) if column.options[:refresh_link]
270
272
  html
271
273
  end
@@ -284,34 +286,35 @@ module ActiveScaffold
284
286
  end
285
287
 
286
288
  def active_scaffold_plural_association_options(column, record = nil)
287
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, call with record.", caller if record.nil? # TODO Remove when relying on @record is removed
288
- record ||= @record # TODO Remove when relying on @record is removed
289
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, call with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
290
+ record ||= @record # TODO: Remove when relying on @record is removed
289
291
  associated_options = record.send(column.association.name)
290
292
  [associated_options, associated_options | sorted_association_options_find(column.association, nil, record)]
291
293
  end
292
294
 
293
295
  def active_scaffold_input_plural_association(column, options)
294
296
  record = options.delete(:object)
295
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
296
- record ||= @record # TODO Remove when relying on @record is removed
297
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include :object in options with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
298
+ record ||= @record # TODO: Remove when relying on @record is removed
297
299
  associated_options, select_options = active_scaffold_plural_association_options(column, record)
298
-
299
- html = if select_options.empty?
300
- content_tag(:span, as_(:no_options), :class => "#{options[:class]} no-options", :id => options[:id])
301
- else
302
- active_scaffold_checkbox_list(column, select_options, associated_options.collect(&:id), options)
303
- end
300
+
301
+ html =
302
+ if select_options.empty?
303
+ content_tag(:span, as_(:no_options), :class => "#{options[:class]} no-options", :id => options[:id])
304
+ else
305
+ active_scaffold_checkbox_list(column, select_options, associated_options.collect(&:id), options)
306
+ end
304
307
  html << active_scaffold_refresh_link(column, options, record) if column.options[:refresh_link]
305
308
  html
306
309
  end
307
310
 
308
311
  def active_scaffold_checkbox_option(option, label_method, associated_ids, checkbox_options, li_options = {})
309
- content_tag(:li, li_options) do
312
+ content_tag(:li, li_options) do
310
313
  check_box_tag(checkbox_options[:name], option.id, associated_ids.include?(option.id), checkbox_options) <<
311
- content_tag(:label, option.send(label_method), :for => checkbox_options[:id])
314
+ content_tag(:label, option.send(label_method), :for => checkbox_options[:id])
312
315
  end
313
316
  end
314
-
317
+
315
318
  def active_scaffold_checkbox_list(column, select_options, associated_ids, options)
316
319
  label_method = column.options[:label_method] || :to_label
317
320
  html = hidden_field_tag("#{options[:name]}[]", '', :id => nil)
@@ -329,16 +332,16 @@ module ActiveScaffold
329
332
  value = text if value.nil?
330
333
  [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value]
331
334
  end
332
-
335
+
333
336
  def active_scaffold_enum_options(column, record = nil)
334
337
  column.options[:options]
335
338
  end
336
339
 
337
340
  def active_scaffold_input_enum(column, html_options)
338
341
  record = html_options.delete(:object)
339
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in html_options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
340
- record ||= @record # TODO Remove when relying on @record is removed
341
- options = { :selected => record.send(column.name), :object => record }
342
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include :object in html_options with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
343
+ record ||= @record # TODO: Remove when relying on @record is removed
344
+ options = {:selected => record.send(column.name), :object => record}
342
345
  options_for_select = active_scaffold_enum_options(column, record).collect do |text, value|
343
346
  active_scaffold_translated_option(column, text, value)
344
347
  end
@@ -361,16 +364,23 @@ module ActiveScaffold
361
364
  def active_scaffold_input_radio(column, html_options)
362
365
  record = html_options[:object]
363
366
  html_options.merge!(column.options[:html_options] || {})
364
- options = if column.association
365
- sorted_association_options_find(column.association, nil, record)
366
- else
367
- active_scaffold_enum_options(column, record)
368
- end
367
+ options =
368
+ if column.association
369
+ sorted_association_options_find(column.association, nil, record)
370
+ else
371
+ active_scaffold_enum_options(column, record)
372
+ end
369
373
  id_key = html_options[:"data-id"] ? :"data-id" : :id
370
- options.inject('') do |html, (text, value)|
371
- method = column.options[:label_method] || :to_label if column.association
372
- text, value = column.association ? [text.send(method), text.id] : active_scaffold_translated_option(column, text, value)
373
- checked = {:checked => html_options[:object].send(column.association.name).try(:id) == value} if column.association
374
+ label_method = column.options[:label_method] || :to_label if column.association
375
+
376
+ options.each_with_object('') do |(text, value), html|
377
+ if column.association
378
+ text, value = [text.send(label_method), text.id]
379
+ checked = {:checked => html_options[:object].send(column.association.name).try(:id) == value}
380
+ else
381
+ text, value = active_scaffold_translated_option(column, text, value)
382
+ end
383
+
374
384
  radio_options = html_options.merge(id_key => html_options[id_key] + '-' + value.to_s)
375
385
  radio_options.merge!(checked) if checked
376
386
  html << content_tag(:label, radio_button(:record, column.name, value, radio_options) + text)
@@ -389,7 +399,7 @@ module ActiveScaffold
389
399
  def active_scaffold_input_textarea(column, options)
390
400
  text_area(:record, column.name, options.merge(:cols => column.options[:cols], :rows => column.options[:rows], :size => column.options[:size]))
391
401
  end
392
-
402
+
393
403
  def active_scaffold_input_virtual(column, options)
394
404
  options = active_scaffold_input_text_options(options)
395
405
  text_field :record, column.name, options.merge(column.options)
@@ -436,8 +446,8 @@ module ActiveScaffold
436
446
 
437
447
  def active_scaffold_input_boolean(column, options)
438
448
  record = options.delete(:object)
439
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
440
- record ||= @record # TODO Remove when relying on @record is removed
449
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include :object in options with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
450
+ record ||= @record # TODO: Remove when relying on @record is removed
441
451
  select_options = []
442
452
  select_options << [as_(:_select_), nil] if !column.virtual? && column.column.null
443
453
  select_options << [as_(:true), true]
@@ -500,9 +510,9 @@ module ActiveScaffold
500
510
  def column_renders_as(column)
501
511
  if column.respond_to? :each
502
512
  return :subsection
503
- elsif column.active_record_class.locking_column.to_s == column.name.to_s or column.form_ui == :hidden
513
+ elsif column.active_record_class.locking_column.to_s == column.name.to_s || column.form_ui == :hidden
504
514
  return :hidden
505
- elsif column.association.nil? or column.form_ui or !active_scaffold_config_for(column.association.klass).actions.include?(:subform) or override_form_field?(column)
515
+ elsif column.association.nil? || column.form_ui || !active_scaffold_config_for(column.association.klass).actions.include?(:subform) || override_form_field?(column)
506
516
  return :field
507
517
  else
508
518
  return :subform
@@ -510,7 +520,7 @@ module ActiveScaffold
510
520
  end
511
521
 
512
522
  def column_scope(column, scope = nil, record = nil)
513
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, call with record.", caller if record.nil? # TODO Remove when relying on @record is removed
523
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, call with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
514
524
  if column.plural_association?
515
525
  "#{scope}[#{column.name}][#{record.id || generate_temporary_id(record)}]"
516
526
  else
@@ -520,9 +530,9 @@ module ActiveScaffold
520
530
 
521
531
  def active_scaffold_add_existing_input(options)
522
532
  record = options.delete(:object)
523
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
524
- record ||= @record # TODO Remove when relying on @record is removed
525
- if ActiveScaffold.js_framework == :prototype && controller.respond_to?(:record_select_config, true)
533
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include :object in options with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
534
+ record ||= @record # TODO: Remove when relying on @record is removed
535
+ if !ActiveScaffold.js_framework.nil? && controller.respond_to?(:record_select_config, true)
526
536
  remote_controller = active_scaffold_controller_for(record_select_config.model).controller_path
527
537
  options.merge!(:controller => remote_controller)
528
538
  options.merge!(active_scaffold_input_text_options)
@@ -548,51 +558,51 @@ module ActiveScaffold
548
558
  if column.numerical_constraints.nil?
549
559
  numerical_constraints = {}
550
560
  validators = column.active_record_class.validators.select do |v|
551
- v.is_a? ActiveModel::Validations::NumericalityValidator and v.attributes.include? column.name
561
+ v.is_a?(ActiveModel::Validations::NumericalityValidator) && v.attributes.include?(column.name)
552
562
  end
553
- equal_to = (v = validators.find{ |v| v.options[:equal_to] }) ? v.options[:equal_to] : nil
554
-
563
+ equal_to = (val = validators.find { |v| v.options[:equal_to] }) ? val.options[:equal_to] : nil
564
+
555
565
  # If there is equal_to constraint - use it (unless otherwise specified by user)
556
- if equal_to and not (options[:min] or options[:max])
566
+ if equal_to && !(options[:min] || options[:max])
557
567
  numerical_constraints[:min] = numerical_constraints[:max] = equal_to
558
568
  else # find minimum and maximum from validators
559
569
  # we can safely modify :min and :max by 1 for :greater_tnan or :less_than value only for integer values
560
570
  only_integer = column.column.type == :integer if column.column
561
- only_integer ||= !!validators.find{ |v| v.options[:only_integer] }
571
+ only_integer ||= validators.find { |v| v.options[:only_integer] }.present?
562
572
  margin = only_integer ? 1 : 0
563
-
573
+
564
574
  # Minimum
565
575
  unless options[:min]
566
- min = validators.map{ |v| v.options[:greater_than_or_equal] }.compact.max
567
- greater_than = validators.map{ |v| v.options[:greater_than] }.compact.max
568
- numerical_constraints[:min] = [min, (greater_than+margin if greater_than)].compact.max
576
+ min = validators.map { |v| v.options[:greater_than_or_equal] }.compact.max
577
+ greater_than = validators.map { |v| v.options[:greater_than] }.compact.max
578
+ numerical_constraints[:min] = [min, (greater_than + margin if greater_than)].compact.max
569
579
  end
570
-
580
+
571
581
  # Maximum
572
582
  unless options[:max]
573
- max = validators.map{ |v| v.options[:less_than_or_equal] }.compact.min
574
- less_than = validators.map{ |v| v.options[:less_than] }.compact.min
575
- numerical_constraints[:max] = [max, (less_than-margin if less_than)].compact.min
583
+ max = validators.map { |v| v.options[:less_than_or_equal] }.compact.min
584
+ less_than = validators.map { |v| v.options[:less_than] }.compact.min
585
+ numerical_constraints[:max] = [max, (less_than - margin if less_than)].compact.min
576
586
  end
577
-
587
+
578
588
  # Set step = 2 for column values restricted to be odd or even (but only if minimum is set)
579
589
  unless options[:step]
580
- only_odd_valid = validators.any?{ |v| v.options[:odd] }
581
- only_even_valid = validators.any?{ |v| v.options[:even] } unless only_odd_valid
590
+ only_odd_valid = validators.any? { |v| v.options[:odd] }
591
+ only_even_valid = validators.any? { |v| v.options[:even] } unless only_odd_valid
582
592
  if !only_integer
583
- numerical_constraints[:step] ||= "0.#{'0'*(column.column.scale-1)}1" if column.column && column.column.scale.to_i > 0
584
- elsif options[:min] and options[:min].respond_to? :even? and (only_odd_valid or only_even_valid)
593
+ numerical_constraints[:step] ||= "0.#{'0' * (column.column.scale - 1)}1" if column.column && column.column.scale.to_i > 0
594
+ elsif options[:min] && options[:min].respond_to?(:even?) && (only_odd_valid || only_even_valid)
585
595
  numerical_constraints[:step] = 2
586
- numerical_constraints[:min] += 1 if only_odd_valid and not options[:min].odd?
587
- numerical_constraints[:min] += 1 if only_even_valid and not options[:min].even?
596
+ numerical_constraints[:min] += 1 if only_odd_valid && !options[:min].odd?
597
+ numerical_constraints[:min] += 1 if only_even_valid && !options[:min].even?
588
598
  end
589
599
  numerical_constraints[:step] ||= 'any' unless only_integer
590
600
  end
591
601
  end
592
-
602
+
593
603
  column.numerical_constraints = numerical_constraints
594
604
  end
595
- return column.numerical_constraints.merge(options)
605
+ column.numerical_constraints.merge(options)
596
606
  end
597
607
  end
598
608
  end