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
@@ -2,49 +2,76 @@ module ActiveScaffold
2
2
  module Helpers
3
3
  # Helpers that assist with rendering of a human readable search statement
4
4
  module HumanConditionHelpers
5
-
6
5
  def active_scaffold_human_condition_for(column)
7
- value = field_search_params[column.name]
6
+ return if (value = field_search_params[column.name]).nil?
8
7
  search_ui = column.search_ui
9
8
  search_ui ||= column.column.type if column.column
10
9
  if override_human_condition_column?(column)
11
10
  send(override_human_condition_column(column), value, {})
12
- elsif search_ui and override_human_condition?(column.search_ui)
13
- send(override_human_condition(column.search_ui), column, value)
11
+ elsif search_ui && override_human_condition?(search_ui)
12
+ send(override_human_condition(search_ui), column, value)
14
13
  else
15
- case search_ui
16
- when :integer, :decimal, :float
17
- "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{format_number_value(controller.class.condition_value_for_numeric(column, value[:from]), column.options) if value[:from].present?} #{value[:opt] == 'BETWEEN' ? '- ' + format_number_value(controller.class.condition_value_for_numeric(column, value[:to]), column.options).to_s : ''}"
18
- when :string
19
- opt = ActiveScaffold::Finder::StringComparators.index(value[:opt]) || value[:opt]
20
- "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '- ' + value[:to].to_s : ''}"
21
- when :date, :time, :datetime, :timestamp
22
- conversion = column.column.type == :date ? :to_date : :to_time
23
- from = controller.condition_value_for_datetime(column, value[:from], conversion)
24
- to = controller.condition_value_for_datetime(column, value[:to], conversion)
25
- "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}"
26
- when :select, :multi_select, :record_select
27
- associated = value
28
- associated = [associated].compact unless associated.is_a? Array
29
- if column.association
30
- method = column.options[:label_method] || :to_label
31
- associated = column.association.klass.where(:id => associated.map(&:to_i)).collect(&method)
32
- elsif column.options[:options]
33
- associated = associated.collect do |value|
34
- text, val = column.options[:options].find {|text, val| (val.nil? ? text : val).to_s == value.to_s}
35
- value = active_scaffold_translated_option(column, text, val).first if text
36
- value
37
- end
38
- end
39
- as_(:association, :scope => :human_conditions, :column => column.active_record_class.human_attribute_name(column.name), :value => associated.join(', '))
40
- when :boolean, :checkbox
41
- label = ActiveScaffold::Core.column_type_cast(value, column.column) ? as_(:true) : as_(:false)
42
- as_(:boolean, :scope => :human_conditions, :column => column.active_record_class.human_attribute_name(column.name), :value => label)
43
- when :null
44
- "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value.to_sym)}"
14
+ logger.warn "undefined active_scaffold_human_condition method for search_ui #{search_ui} on column #{column.name}"
15
+ end
16
+ end
17
+
18
+ def format_human_condition(column, opt, from = nil, to = nil)
19
+ attribute = column.active_record_class.human_attribute_name(column.name)
20
+ "#{attribute} #{as_(opt).downcase} #{from} #{to}"
21
+ end
22
+
23
+ def active_scaffold_human_condition_integer(column, value)
24
+ from = format_number_value(controller.class.condition_value_for_numeric(column, value[:from]), column.options) if value[:from].present?
25
+ to = "- #{format_number_value(controller.class.condition_value_for_numeric(column, value[:to]), column.options)}" if value[:opt] == 'BETWEEN'
26
+ format_human_condition column, value[:opt].downcase, from, to
27
+ end
28
+ alias_method :active_scaffold_human_condition_decimal, :active_scaffold_human_condition_integer
29
+ alias_method :active_scaffold_human_condition_float, :active_scaffold_human_condition_integer
30
+
31
+ def active_scaffold_human_condition_string(column, value)
32
+ opt = ActiveScaffold::Finder::STRING_COMPARATORS.index(value[:opt]) || value[:opt]
33
+ to = "- #{value[:to]}" if opt == 'BETWEEN'
34
+ format_human_condition column, opt, "'#{value[:from]}'", to
35
+ end
36
+
37
+ def active_scaffold_human_condition_date(column, value)
38
+ conversion = column.column.type == :date ? :to_date : :to_time
39
+ from = I18n.l controller.condition_value_for_datetime(column, value[:from], conversion)
40
+ to = "- #{I18n.l controller.condition_value_for_datetime(column, value[:to], conversion)}" if value[:opt] == 'BETWEEN'
41
+ format_human_condition column, value[:opt], from, to
42
+ end
43
+ alias_method :active_scaffold_human_condition_time, :active_scaffold_human_condition_date
44
+ alias_method :active_scaffold_human_condition_datetime, :active_scaffold_human_condition_date
45
+ alias_method :active_scaffold_human_condition_timestamp, :active_scaffold_human_condition_date
46
+
47
+ def active_scaffold_human_condition_boolean(column, value)
48
+ attribute = column.active_record_class.human_attribute_name(column.name)
49
+ label = as_(ActiveScaffold::Core.column_type_cast(value, column.column) ? :true : :false)
50
+ as_(:boolean, :scope => :human_conditions, :column => attribute, :value => label)
51
+ end
52
+ alias_method :active_scaffold_human_condition_checkbox, :active_scaffold_human_condition_boolean
53
+
54
+ def active_scaffold_human_condition_null(column, value)
55
+ format_human_condition column, value.to_sym
56
+ end
57
+
58
+ def active_scaffold_human_condition_select(column, associated)
59
+ attribute = column.active_record_class.human_attribute_name(column.name)
60
+ associated = [associated].compact unless associated.is_a? Array
61
+ if column.association
62
+ method = column.options[:label_method] || :to_label
63
+ associated = column.association.klass.where(:id => associated.map(&:to_i)).map(&method)
64
+ elsif column.options[:options]
65
+ associated = associated.collect do |value|
66
+ text, val = column.options[:options].find { |text, val| (val.nil? ? text : val).to_s == value.to_s }
67
+ value = active_scaffold_translated_option(column, text, val).first if text
68
+ value
45
69
  end
46
- end unless value.nil?
70
+ end
71
+ as_(:association, :scope => :human_conditions, :column => attribute, :value => associated.join(', '))
47
72
  end
73
+ alias_method :active_scaffold_human_condition_multi_select, :active_scaffold_human_condition_select
74
+ alias_method :active_scaffold_human_condition_record_select, :active_scaffold_human_condition_select
48
75
 
49
76
  # the naming convention for overriding form fields with helpers
50
77
  def override_human_condition_column(column)
@@ -3,11 +3,11 @@ module ActiveScaffold
3
3
  # A bunch of helper methods to produce the common view ids
4
4
  module IdHelpers
5
5
  def id_from_controller(controller)
6
- controller.to_s.gsub("/", "__").html_safe
6
+ controller.to_s.gsub('/', '__').html_safe
7
7
  end
8
8
 
9
9
  def controller_id(controller = (params[:eid] || nested_id || params[:parent_controller] || params[:controller]))
10
- controller_id ||= 'as_' + id_from_controller(controller)
10
+ 'as_' + id_from_controller(controller)
11
11
  end
12
12
 
13
13
  def nested_parent_id
@@ -50,7 +50,7 @@ module ActiveScaffold
50
50
  "#{controller_id}-search-input"
51
51
  end
52
52
 
53
- def action_link_id(link_action,link_id)
53
+ def action_link_id(link_action, link_id)
54
54
  "#{controller_id}-#{link_action}-#{link_id}-link"
55
55
  end
56
56
 
@@ -92,7 +92,7 @@ module ActiveScaffold
92
92
  options[:id] ||= nested_parent_id if nested?
93
93
  clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-loading-indicator"
94
94
  end
95
-
95
+
96
96
  def sub_section_id(options = {})
97
97
  options[:id] ||= params[:id]
98
98
  options[:id] ||= nested_parent_id if nested?
@@ -104,7 +104,7 @@ module ActiveScaffold
104
104
  options[:id] ||= nested_parent_id if nested?
105
105
  clean_id "#{controller_id}-#{options[:id]}-#{options[:association]}-subform"
106
106
  end
107
-
107
+
108
108
  def sub_form_list_id(options = {})
109
109
  options[:id] ||= params[:id]
110
110
  options[:id] ||= nested_parent_id if nested?
@@ -121,7 +121,7 @@ module ActiveScaffold
121
121
  def action_iframe_id(options)
122
122
  "#{controller_id}-#{options[:action]}-#{options[:id]}-iframe"
123
123
  end
124
-
124
+
125
125
  def scope_id(scope)
126
126
  scope.gsub(/(\[|\])/, '_').gsub('__', '_').gsub(/_$/, '')
127
127
  end
@@ -4,59 +4,51 @@ module ActiveScaffold
4
4
  # Helpers that assist with the rendering of a List Column
5
5
  module ListColumnHelpers
6
6
  def get_column_value(record, column)
7
- begin
8
- method = get_column_method(record, column)
9
- value = send(method, record, column)
10
- value = ' '.html_safe if value.nil? or value.blank? # fix for IE 6
11
- return value
12
- rescue Exception => e
13
- logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}, record: #{record.inspect}"
14
- raise e
15
- end
7
+ method = get_column_method(record, column)
8
+ value = send(method, record, column)
9
+ value = ' '.html_safe if value.nil? || value.blank? # fix for IE 6
10
+ return value
11
+ rescue StandardError => e
12
+ logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}, record: #{record.inspect}"
13
+ raise e
16
14
  end
17
15
 
18
-
19
16
  def get_column_method(record, column)
20
17
  # check for an override helper
21
- method = column.list_method
22
- unless method
23
- method = if (method = column_override(column))
18
+ column.list_method ||= begin
19
+ if (method = column_override(column))
24
20
  # we only pass the record as the argument. we previously also passed the formatted_value,
25
21
  # but mike perham pointed out that prohibited the usage of overrides to improve on the
26
22
  # performance of our default formatting. see issue #138.
27
23
  method
28
24
  # second, check if the dev has specified a valid list_ui for this column
29
- elsif column.list_ui and (method = override_column_ui(column.list_ui))
25
+ elsif column.list_ui && (method = override_column_ui(column.list_ui))
30
26
  method
31
- elsif column.column and (method = override_column_ui(column.column.type))
27
+ elsif column.column && (method = override_column_ui(column.column.type))
32
28
  method
33
29
  else
34
30
  :format_column_value
35
31
  end
36
- column.list_method = method
37
32
  end
38
- method
39
33
  end
40
34
 
41
35
  # TODO: move empty_field_text and   logic in here?
42
36
  # TODO: we need to distinguish between the automatic links *we* create and the ones that the dev specified. some logic may not apply if the dev specified the link.
43
37
  def render_list_column(text, column, record)
44
- begin
45
- if column.link && !skip_action_link?(column.link, record)
46
- link = column.link
47
- associated = record.send(column.association.name) if column.association
48
- render_action_link(link, record, :link => text, :authorized => link.action.nil? || column_link_authorized?(link, column, record, associated))
49
- elsif inplace_edit?(record, column)
50
- active_scaffold_inplace_edit(record, column, {:formatted_column => text})
51
- elsif active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.wrap_tag
52
- content_tag active_scaffold_config.list.wrap_tag, text
53
- else
54
- text
55
- end
56
- rescue Exception => e
57
- logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}"
58
- raise e
38
+ if column.link && !skip_action_link?(column.link, record)
39
+ link = column.link
40
+ associated = record.send(column.association.name) if column.association
41
+ render_action_link(link, record, :link => text, :authorized => link.action.nil? || column_link_authorized?(link, column, record, associated))
42
+ elsif inplace_edit?(record, column)
43
+ active_scaffold_inplace_edit(record, column, :formatted_column => text)
44
+ elsif active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.wrap_tag
45
+ content_tag active_scaffold_config.list.wrap_tag, text
46
+ else
47
+ text
59
48
  end
49
+ rescue StandardError => e
50
+ logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}"
51
+ raise e
60
52
  end
61
53
 
62
54
  # There are two basic ways to clean a column's value: h() and sanitize(). The latter is useful
@@ -114,7 +106,7 @@ module ActiveScaffold
114
106
  value ||= record.send(column.name) unless record.nil?
115
107
  if column.association.nil?
116
108
  if column.form_ui == :select && column.options[:options]
117
- text, val = column.options[:options].find {|text, val| (val.nil? ? text : val).to_s == value.to_s}
109
+ text, val = column.options[:options].find { |text, val| (val.nil? ? text : val).to_s == value.to_s }
118
110
  value = active_scaffold_translated_option(column, text, val).first if text
119
111
  end
120
112
  if value.is_a? Numeric
@@ -147,43 +139,51 @@ module ActiveScaffold
147
139
  clean_column_value(value)
148
140
  end
149
141
 
142
+ def format_collection_association_value(value, column, label_method, size)
143
+ if column.associated_limit.nil?
144
+ firsts = value.collect(&label_method)
145
+ elsif column.associated_limit == 0
146
+ size if column.associated_number?
147
+ else
148
+ firsts = value.first(column.associated_limit)
149
+ firsts.collect!(&label_method)
150
+ firsts << '…' if value.size > column.associated_limit
151
+ text = firsts.join(h(active_scaffold_config.list.association_join_text)).html_safe
152
+ text << " (#{size})" if column.associated_number? && column.associated_limit && value.size > column.associated_limit
153
+ text
154
+ end
155
+ end
156
+
157
+ def format_singular_association_value(value, column, label_method)
158
+ if column.polymorphic_association?
159
+ "#{value.class.model_name.human}: #{value.send(label_method)}"
160
+ else
161
+ value.send(label_method)
162
+ end
163
+ end
164
+
150
165
  def format_association_value(value, column, size)
151
166
  method = column.options[:label_method] || :to_label
152
- value = if column.association.collection?
153
- if column.associated_limit.nil?
154
- firsts = value.collect(&method)
155
- else
156
- firsts = value.first(column.associated_limit)
157
- firsts.collect!(&method)
158
- firsts[column.associated_limit] = '…' if value.size > column.associated_limit
167
+ value =
168
+ if column.association.collection?
169
+ format_collection_association_value(value, column, method, size)
170
+ elsif value
171
+ format_singular_association_value(value, column, method)
159
172
  end
160
- if column.associated_limit == 0
161
- size if column.associated_number?
162
- else
163
- joined_associated = firsts.join(h(active_scaffold_config.list.association_join_text)).html_safe
164
- joined_associated << " (#{size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit
165
- joined_associated
166
- end
167
- elsif value
168
- if column.polymorphic_association?
169
- "#{value.class.model_name.human}: #{value.send(method)}"
170
- else
171
- value.send(method)
172
- end
173
- end
174
173
  format_value value
175
174
  end
176
175
 
177
176
  def format_value(column_value, options = {})
178
- value = if column_empty?(column_value)
179
- empty_field_text
180
- elsif column_value.is_a?(Time) || column_value.is_a?(Date)
181
- l(column_value, :format => options[:format] || :default)
182
- elsif [FalseClass, TrueClass].include?(column_value.class)
183
- as_(column_value.to_s.to_sym)
184
- else
185
- column_value.to_s
186
- end
177
+ value =
178
+ if column_empty?(column_value)
179
+ empty_field_text
180
+ elsif column_value.is_a?(Time) || column_value.is_a?(Date)
181
+ l(column_value, :format => options[:format] || :default)
182
+ elsif [FalseClass, TrueClass].include?(column_value.class)
183
+ as_(column_value.to_s.to_sym)
184
+ else
185
+ column_value.to_s
186
+ end
187
187
  clean_column_value(value)
188
188
  end
189
189
 
@@ -204,19 +204,18 @@ module ActiveScaffold
204
204
  # ==========
205
205
 
206
206
  def inplace_edit?(record, column)
207
- if column.inplace_edit
208
- editable = controller.send(:update_authorized?, record) if controller.respond_to?(:update_authorized?, true)
209
- editable ||= record.authorized_for?(:crud_type => :update, :column => column.name)
210
- end
207
+ return unless column.inplace_edit
208
+ editable = controller.send(:update_authorized?, record) if controller.respond_to?(:update_authorized?, true)
209
+ editable || record.authorized_for?(:crud_type => :update, :column => column.name)
211
210
  end
212
211
 
213
212
  def inplace_edit_cloning?(column)
214
- column.inplace_edit != :ajax and (override_form_field?(column) or column.form_ui or (column.column and override_input?(column.column.type)))
213
+ column.inplace_edit != :ajax && (override_form_field?(column) || column.form_ui || (column.column && override_input?(column.column.type)))
215
214
  end
216
215
 
217
216
  def active_scaffold_inplace_edit_tag_options(record, column)
218
217
  id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s}
219
- tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field",
218
+ tag_options = {:id => element_cell_id(id_options), :class => 'in_place_editor_field',
220
219
  :title => as_(:click_to_edit), :data => {:ie_id => record.to_param}}
221
220
  tag_options[:data][:ie_update] = column.inplace_edit if column.inplace_edit != true
222
221
  tag_options
@@ -225,32 +224,31 @@ module ActiveScaffold
225
224
  def active_scaffold_inplace_edit(record, column, options = {})
226
225
  formatted_column = options[:formatted_column] || format_column_value(record, column)
227
226
  content_tag(:span, as_(:inplace_edit_handle), :class => 'handle') <<
228
- content_tag(:span, formatted_column, active_scaffold_inplace_edit_tag_options(record, column))
227
+ content_tag(:span, formatted_column, active_scaffold_inplace_edit_tag_options(record, column))
229
228
  end
230
229
 
231
230
  def inplace_edit_control(column)
232
- if inplace_edit?(active_scaffold_config.model, column) and inplace_edit_cloning?(column)
233
- old_record, @record = @record, new_model # TODO remove when relying on @record is removed
234
- column = column.clone
235
- column.options = column.options.clone
236
- column.form_ui = :select if (column.association && column.form_ui.nil?)
237
- options = active_scaffold_input_options(column).merge(:object => new_model)
238
- options[:class] = "#{options[:class]} inplace_field"
239
- options[:"data-id"] = options[:id]
240
- options[:id] = nil
241
- content_tag(:div, active_scaffold_input_for(column, nil, options), :style => "display:none;", :class => inplace_edit_control_css_class).tap do
242
- @record = old_record # TODO remove when relying on @record is removed
243
- end
231
+ return unless inplace_edit?(active_scaffold_config.model, column) && inplace_edit_cloning?(column)
232
+ old_record, @record = @record, active_scaffold_config.model.new # TODO: remove when relying on @record is removed
233
+ column = column.clone
234
+ column.options = column.options.clone
235
+ column.form_ui = :select if column.association && column.form_ui.nil?
236
+ options = active_scaffold_input_options(column).merge(:object => active_scaffold_config.model.new)
237
+ options[:class] = "#{options[:class]} inplace_field"
238
+ options[:"data-id"] = options[:id]
239
+ options[:id] = nil
240
+ content_tag(:div, active_scaffold_input_for(column, nil, options), :style => 'display:none;', :class => inplace_edit_control_css_class).tap do
241
+ @record = old_record # TODO: remove when relying on @record is removed
244
242
  end
245
243
  end
246
244
 
247
245
  def inplace_edit_control_css_class
248
- "as_inplace_pattern"
246
+ 'as_inplace_pattern'
249
247
  end
250
248
 
251
249
  def inplace_edit_data(column)
252
250
  data = {}
253
- data[:ie_url] = url_for(params_for(:action => "update_column", :column => column.name, :id => '__id__'))
251
+ data[:ie_url] = url_for(params_for(:action => 'update_column', :column => column.name, :id => '__id__'))
254
252
  data[:ie_cancel_text] = column.options[:cancel_text] || as_(:cancel)
255
253
  data[:ie_loading_text] = column.options[:loading_text] || as_(:loading)
256
254
  data[:ie_save_text] = column.options[:save_text] || as_(:update)
@@ -275,22 +273,22 @@ module ActiveScaffold
275
273
 
276
274
  def all_marked?
277
275
  if active_scaffold_config.mark.mark_all_mode == :page
278
- all_marked = @page.items.detect { |record| !marked_records.include?(record.id) }.nil?
276
+ @page.items.detect { |record| !marked_records.include?(record.id) }.nil?
279
277
  else
280
- all_marked = (marked_records.length >= @page.pager.count.to_i)
278
+ marked_records.length >= @page.pager.count.to_i
281
279
  end
282
280
  end
283
281
 
284
282
  def mark_column_heading
285
283
  tag_options = {
286
284
  :id => "#{controller_id}_mark_heading",
287
- :class => "mark_heading in_place_editor_field",
285
+ :class => 'mark_heading in_place_editor_field'
288
286
  }
289
287
  content_tag(:span, check_box_tag("#{controller_id}_mark_heading_span_input", '1', all_marked?), tag_options)
290
288
  end
291
289
 
292
290
  def column_heading_attributes(column, sorting, sort_direction)
293
- tag_options = {:id => active_scaffold_column_header_id(column), :class => column_heading_class(column, sorting), :title => strip_tags(column.description).presence}
291
+ {:id => active_scaffold_column_header_id(column), :class => column_heading_class(column, sorting), :title => strip_tags(column.description).presence}
294
292
  end
295
293
 
296
294
  def render_column_heading(column, sorting, sort_direction)
@@ -306,16 +304,15 @@ module ActiveScaffold
306
304
  content_tag(:th, column_heading_value(column, sorting, sort_direction) + inplace_edit_control(column), tag_options)
307
305
  end
308
306
 
309
-
310
307
  def column_heading_value(column, sorting, sort_direction)
311
308
  if column.name == :as_marked
312
309
  mark_column_heading
313
310
  elsif column.sortable?
314
- options = {:id => nil, :class => "as_sort",
311
+ options = {:id => nil, :class => 'as_sort',
315
312
  'data-page-history' => controller_id,
316
313
  :remote => true, :method => :get}
317
314
  url_options = params_for(:action => :index, :page => 1,
318
- :sort => column.name, :sort_direction => sort_direction)
315
+ :sort => column.name, :sort_direction => sort_direction)
319
316
  unless active_scaffold_config.store_user_settings
320
317
  url_options.merge!(:search => search_params) if search_params.present?
321
318
  end
@@ -324,12 +321,10 @@ module ActiveScaffold
324
321
  content_tag(:p, column_heading_label(column))
325
322
  end
326
323
  end
327
-
324
+
328
325
  def column_heading_label(column)
329
326
  column.label
330
327
  end
331
-
332
328
  end
333
329
  end
334
330
  end
335
-