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.
- checksums.yaml +4 -4
- data/CHANGELOG +12 -1
- data/README.md +8 -4
- data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
- data/app/assets/stylesheets/active_scaffold.scss +1 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
- data/app/assets/stylesheets/blue-theme.css +1 -1
- data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
- data/lib/active_scaffold.rb +16 -16
- data/lib/active_scaffold/actions/common_search.rb +13 -11
- data/lib/active_scaffold/actions/core.rb +85 -78
- data/lib/active_scaffold/actions/create.rb +29 -28
- data/lib/active_scaffold/actions/delete.rb +17 -17
- data/lib/active_scaffold/actions/field_search.rb +18 -19
- data/lib/active_scaffold/actions/list.rb +30 -22
- data/lib/active_scaffold/actions/mark.rb +1 -1
- data/lib/active_scaffold/actions/nested.rb +78 -65
- data/lib/active_scaffold/actions/search.rb +13 -10
- data/lib/active_scaffold/actions/show.rb +10 -6
- data/lib/active_scaffold/actions/subform.rb +1 -2
- data/lib/active_scaffold/actions/update.rb +39 -31
- data/lib/active_scaffold/active_record_permissions.rb +14 -15
- data/lib/active_scaffold/attribute_params.rb +42 -43
- data/lib/active_scaffold/bridges.rb +22 -12
- data/lib/active_scaffold/bridges/ancestry.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
- data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
- data/lib/active_scaffold/bridges/cancan.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
- data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
- data/lib/active_scaffold/bridges/chosen.rb +1 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
- data/lib/active_scaffold/bridges/country_helper.rb +1 -1
- data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
- data/lib/active_scaffold/bridges/date_picker.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
- data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
- data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/file_column.rb +5 -5
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
- data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
- data/lib/active_scaffold/bridges/paperclip.rb +5 -5
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
- data/lib/active_scaffold/bridges/record_select.rb +1 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
- data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
- data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
- data/lib/active_scaffold/config/base.rb +9 -10
- data/lib/active_scaffold/config/core.rb +24 -29
- data/lib/active_scaffold/config/create.rb +0 -1
- data/lib/active_scaffold/config/field_search.rb +8 -10
- data/lib/active_scaffold/config/form.rb +5 -5
- data/lib/active_scaffold/config/list.rb +21 -20
- data/lib/active_scaffold/config/mark.rb +3 -3
- data/lib/active_scaffold/config/nested.rb +11 -10
- data/lib/active_scaffold/config/search.rb +2 -3
- data/lib/active_scaffold/config/show.rb +1 -1
- data/lib/active_scaffold/config/update.rb +1 -2
- data/lib/active_scaffold/configurable.rb +9 -11
- data/lib/active_scaffold/constraints.rb +9 -8
- data/lib/active_scaffold/core.rb +72 -84
- data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
- data/lib/active_scaffold/data_structures/action_link.rb +43 -43
- data/lib/active_scaffold/data_structures/action_links.rb +17 -15
- data/lib/active_scaffold/data_structures/actions.rb +5 -5
- data/lib/active_scaffold/data_structures/bridge.rb +6 -3
- data/lib/active_scaffold/data_structures/column.rb +110 -89
- data/lib/active_scaffold/data_structures/columns.rb +3 -3
- data/lib/active_scaffold/data_structures/error_message.rb +4 -6
- data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
- data/lib/active_scaffold/data_structures/set.rb +7 -8
- data/lib/active_scaffold/data_structures/sorting.rb +38 -33
- data/lib/active_scaffold/delayed_setup.rb +5 -6
- data/lib/active_scaffold/engine.rb +4 -4
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
- data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
- data/lib/active_scaffold/extensions/localize.rb +1 -1
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
- data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
- data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
- data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
- data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
- data/lib/active_scaffold/finder.rb +90 -93
- data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
- data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
- data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
- data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
- data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
- data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
- data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
- data/lib/active_scaffold/marked_model.rb +10 -10
- data/lib/active_scaffold/paginator.rb +30 -34
- data/lib/active_scaffold/responds_to_parent.rb +27 -28
- data/lib/active_scaffold/tableless.rb +20 -15
- data/lib/active_scaffold/version.rb +1 -1
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
- data/shoulda_macros/macros.rb +27 -22
- data/test/bridges/bridge_test.rb +38 -29
- data/test/bridges/date_picker_test.rb +1 -1
- data/test/bridges/paper_trail_test.rb +17 -0
- data/test/bridges/paperclip_test.rb +3 -2
- data/test/bridges/tiny_mce_test.rb +5 -2
- data/test/company.rb +25 -30
- data/test/config/base_test.rb +1 -1
- data/test/config/core_test.rb +9 -9
- data/test/config/create_test.rb +14 -8
- data/test/config/delete_test.rb +4 -4
- data/test/config/field_search_test.rb +6 -6
- data/test/config/list_test.rb +16 -16
- data/test/config/nested_test.rb +4 -4
- data/test/config/search_test.rb +8 -8
- data/test/config/show_test.rb +6 -6
- data/test/config/subform_test.rb +1 -1
- data/test/config/update_test.rb +5 -5
- data/test/const_mocker.rb +4 -4
- data/test/data_structures/action_columns_test.rb +4 -5
- data/test/data_structures/action_link_test.rb +1 -0
- data/test/data_structures/action_links_test.rb +5 -5
- data/test/data_structures/column_test.rb +9 -9
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/error_message_test.rb +4 -5
- data/test/data_structures/set_test.rb +1 -2
- data/test/data_structures/sorting_test.rb +10 -10
- data/test/data_structures/validation_reflection_test.rb +8 -0
- data/test/extensions/routing_mapper_test.rb +2 -2
- data/test/helpers/list_column_helpers_test.rb +3 -2
- data/test/helpers/pagination_helpers_test.rb +5 -4
- data/test/helpers/search_column_helpers_test.rb +1 -1
- data/test/misc/active_record_permissions_test.rb +63 -50
- data/test/misc/attribute_params_test.rb +28 -26
- data/test/misc/calculation_test.rb +10 -3
- data/test/misc/configurable_test.rb +12 -13
- data/test/misc/constraints_test.rb +6 -6
- data/test/misc/convert_numbers_format_test.rb +7 -6
- data/test/misc/finder_test.rb +17 -12
- data/test/misc/lang_test.rb +3 -4
- data/test/misc/tableless_test.rb +2 -3
- data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
- data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
- data/test/mock_app/app/controllers/cars_controller.rb +1 -1
- data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
- data/test/mock_app/app/controllers/people_controller.rb +1 -1
- data/test/mock_app/app/models/file_model.rb +2 -2
- data/test/mock_app/app/models/person.rb +1 -1
- data/test/mock_app/config/application.rb +3 -3
- data/test/mock_app/config/boot.rb +1 -1
- data/test/mock_app/config/environment.rb +1 -0
- data/test/mock_app/config/environments/development.rb +0 -1
- data/test/mock_app/config/environments/production.rb +1 -1
- data/test/mock_app/db/schema.rb +14 -15
- data/test/model_stub.rb +13 -16
- data/test/run_all.rb +5 -7
- data/test/test_helper.rb +12 -9
- metadata +19 -3
@@ -4,50 +4,47 @@ module ActiveScaffold
|
|
4
4
|
module FileColumnHelpers
|
5
5
|
class << self
|
6
6
|
def file_column_fields(klass)
|
7
|
-
klass.instance_methods.select{|m| m.to_s =~ /_just_uploaded\?$/}.collect{|m| m[0..-16].to_sym }
|
7
|
+
klass.instance_methods.select { |m| m.to_s =~ /_just_uploaded\?$/ }.collect { |m| m[0..-16].to_sym }
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def generate_delete_helpers(klass)
|
11
|
-
file_column_fields(klass).each
|
11
|
+
file_column_fields(klass).each do |field|
|
12
12
|
klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.method_defined?(:"#{field}_with_delete=")
|
13
13
|
attr_reader :delete_#{field}
|
14
|
-
|
14
|
+
|
15
15
|
def delete_#{field}=(value)
|
16
16
|
value = (value=="true") if String===value
|
17
17
|
return unless value
|
18
|
-
|
18
|
+
|
19
19
|
# passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file!
|
20
20
|
self.#{field} = nil unless self.#{field}_just_uploaded?
|
21
21
|
end
|
22
22
|
EOF
|
23
|
-
|
23
|
+
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def klass_has_file_column_fields?(klass)
|
27
27
|
true unless file_column_fields(klass).empty?
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def file_column_fields
|
32
|
-
@file_column_fields||=FileColumnHelpers.file_column_fields(self)
|
32
|
+
@file_column_fields ||= FileColumnHelpers.file_column_fields(self)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def options_for_file_column_field(field)
|
36
|
-
|
36
|
+
allocate.send("#{field}_options")
|
37
37
|
end
|
38
|
-
|
39
|
-
def field_has_image_version?(field, version=
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
rescue
|
47
|
-
false
|
48
|
-
end
|
38
|
+
|
39
|
+
def field_has_image_version?(field, version = 'thumb')
|
40
|
+
options = options_for_file_column_field(field)
|
41
|
+
versions = options[:magick][:versions]
|
42
|
+
raise unless versions.stringify_keys[version]
|
43
|
+
true
|
44
|
+
rescue
|
45
|
+
false
|
49
46
|
end
|
50
|
-
|
47
|
+
|
51
48
|
def generate_delete_helpers
|
52
49
|
FileColumnHelpers.generate_delete_helpers(self)
|
53
50
|
end
|
@@ -4,32 +4,31 @@ module ActiveScaffold
|
|
4
4
|
module FormColumnHelpers
|
5
5
|
def active_scaffold_input_file_column(column, options)
|
6
6
|
record = options[:object]
|
7
|
-
ActiveSupport::Deprecation.warn
|
8
|
-
record ||= @record # TODO Remove when relying on @record is removed
|
9
|
-
if record.send(column.name)
|
7
|
+
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
|
8
|
+
record ||= @record # TODO: Remove when relying on @record is removed
|
9
|
+
if record.send(column.name)
|
10
10
|
# we already have a value? display the form for deletion.
|
11
11
|
case ActiveScaffold.js_framework
|
12
12
|
when :jquery
|
13
|
-
remove_file_js = "jQuery(this).prev().val('true'); jQuery(this).parent().hide().next().show(); return false;"
|
13
|
+
remove_file_js = "jQuery(this).prev().val('true'); jQuery(this).parent().hide().next().show(); return false;"
|
14
14
|
when :prototype
|
15
|
-
remove_file_js = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show(); return false;"
|
16
|
-
end
|
17
|
-
|
15
|
+
remove_file_js = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show(); return false;"
|
16
|
+
end
|
17
|
+
|
18
18
|
hidden_options = options.merge(:id => options[:id] + '_delete', :name => options[:name].sub("[#{column.name}]", "[delete_#{column.name}]"), :value => 'false')
|
19
19
|
custom_hidden_field_tag = hidden_field(:record, column.name, hidden_options)
|
20
20
|
|
21
21
|
content_tag(:div) do
|
22
22
|
content_tag(:div) do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
get_column_value(record, column) + " #{custom_hidden_field_tag} | ".html_safe <<
|
24
|
+
content_tag(:a, as_(:remove_file), :href => '#', :onclick => remove_file_js) <<
|
25
|
+
content_tag(:div, file_column_field('record', column.name, options), :style => 'display: none')
|
26
|
+
end
|
27
27
|
end
|
28
28
|
else
|
29
|
-
file_column_field(
|
30
|
-
end
|
29
|
+
file_column_field('record', column.name, options)
|
30
|
+
end
|
31
31
|
end
|
32
|
-
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -6,21 +6,20 @@ module ActiveScaffold
|
|
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
10
|
def active_scaffold_column_download_link(record, column, label = nil)
|
11
11
|
return nil if record.send(column.name).nil?
|
12
|
-
label||=as_(:download)
|
13
|
-
link_to(
|
12
|
+
label ||= as_(:download)
|
13
|
+
link_to(label, url_for_file_column(record, column.name.to_s), :popup => true)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def active_scaffold_column_thumbnail(record, column)
|
17
17
|
return nil if record.send(column.name).nil?
|
18
|
-
link_to(
|
19
|
-
image_tag(url_for_file_column(record, column.name.to_s,
|
20
|
-
url_for_file_column(record, column.name.to_s),
|
18
|
+
link_to(
|
19
|
+
image_tag(url_for_file_column(record, column.name.to_s, 'thumb'), :border => 0),
|
20
|
+
url_for_file_column(record, column.name.to_s),
|
21
21
|
:popup => true)
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
@@ -1,43 +1,39 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
2
|
|
3
3
|
class DeleteFileColumnTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
DeleteFileColumn.generate_delete_helpers(MockModel)
|
6
6
|
@model = MockModel.new
|
7
|
-
@model.band_image =
|
7
|
+
@model.band_image = 'coolio.jpg'
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def test__file_column_fields
|
11
11
|
assert_equal(1, @model.file_column_fields.length)
|
12
12
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
|
14
|
+
def test__delete_band_image__boolean__should_delete
|
15
|
+
@model.delete_band_image = true
|
16
16
|
assert_nil @model.band_image
|
17
17
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
def test__delete_band_image__string__should_delete
|
20
|
+
@model.delete_band_image = 'true'
|
21
21
|
assert_nil @model.band_image
|
22
22
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@model.delete_band_image = false
|
23
|
+
|
24
|
+
def test__delete_band_image__boolean_false__shouldnt_delete
|
25
|
+
@model.delete_band_image = false
|
27
26
|
assert_not_nil @model.band_image
|
28
27
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
|
29
|
+
def test__delete_band_image__string_false__shouldnt_delete
|
30
|
+
@model.delete_band_image = 'false'
|
32
31
|
assert_not_nil @model.band_image
|
33
32
|
end
|
34
|
-
|
35
|
-
|
33
|
+
|
36
34
|
def test__just_uploaded__shouldnt_delete
|
37
35
|
@model.band_image_just_uploaded = true
|
38
|
-
@model.delete_band_image =
|
36
|
+
@model.delete_band_image = 'true'
|
39
37
|
assert_not_nil(@model.band_image)
|
40
38
|
end
|
41
|
-
|
42
|
-
|
43
|
-
end
|
39
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class MockModel
|
2
2
|
attr_accessor :name
|
3
3
|
attr_accessor :bio
|
4
|
-
|
4
|
+
|
5
5
|
attr_accessor :band_image
|
6
6
|
attr_accessor :band_image_just_uploaded
|
7
|
-
def band_image_just_uploaded
|
8
|
-
|
9
|
-
end
|
7
|
+
def band_image_just_uploaded?
|
8
|
+
band_image_just_uploaded
|
9
|
+
end
|
10
|
+
end
|
@@ -1,15 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require
|
2
|
+
require 'rubygems'
|
3
3
|
require 'active_support'
|
4
4
|
|
5
|
-
|
5
|
+
%w(../lib/delete_file_column.rb mock_model.rb).each do |file|
|
6
6
|
require File.expand_path(File.join(File.dirname(__FILE__), file))
|
7
7
|
end
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def dbg
|
12
|
-
require 'ruby-debug'
|
13
|
-
Debugger.start
|
14
|
-
debugger
|
15
|
-
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class ActiveScaffold::Bridges::PaperTrail < ActiveScaffold::DataStructures::Bridge
|
2
2
|
def self.install
|
3
|
-
require File.join(File.dirname(__FILE__),
|
4
|
-
require File.join(File.dirname(__FILE__),
|
5
|
-
require File.join(File.dirname(__FILE__),
|
6
|
-
require File.join(File.dirname(__FILE__),
|
7
|
-
|
3
|
+
require File.join(File.dirname(__FILE__), 'paper_trail/paper_trail_bridge')
|
4
|
+
require File.join(File.dirname(__FILE__), 'paper_trail/actions')
|
5
|
+
require File.join(File.dirname(__FILE__), 'paper_trail/config')
|
6
|
+
require File.join(File.dirname(__FILE__), 'paper_trail/helper')
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.prepare
|
8
10
|
ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:deleted] = :get
|
9
11
|
end
|
10
12
|
end
|
@@ -4,10 +4,10 @@ module ActiveScaffold
|
|
4
4
|
module PaperTrailBridge
|
5
5
|
def initialize_with_paper_trail(model_id)
|
6
6
|
initialize_without_paper_trail(model_id)
|
7
|
-
return unless
|
8
|
-
|
7
|
+
return unless model < ::PaperTrail::Model::InstanceMethods
|
8
|
+
actions << :deleted_records
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.included(base)
|
12
12
|
base.alias_method_chain :initialize, :paper_trail
|
13
13
|
end
|
@@ -15,3 +15,4 @@ module ActiveScaffold
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::PaperTrail::PaperTrailBridge
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class ActiveScaffold::Bridges::Paperclip < ActiveScaffold::DataStructures::Bridge
|
2
2
|
def self.install
|
3
3
|
if ActiveScaffold::Config::Core.method_defined?(:initialize_with_paperclip)
|
4
|
-
raise
|
4
|
+
raise "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts"
|
5
5
|
end
|
6
|
-
require File.join(File.dirname(__FILE__),
|
7
|
-
require File.join(File.dirname(__FILE__),
|
8
|
-
require File.join(File.dirname(__FILE__),
|
9
|
-
require File.join(File.dirname(__FILE__),
|
6
|
+
require File.join(File.dirname(__FILE__), 'paperclip/form_ui')
|
7
|
+
require File.join(File.dirname(__FILE__), 'paperclip/list_ui')
|
8
|
+
require File.join(File.dirname(__FILE__), 'paperclip/paperclip_bridge_helpers')
|
9
|
+
require File.join(File.dirname(__FILE__), 'paperclip/paperclip_bridge')
|
10
10
|
ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Paperclip::PaperclipBridge
|
11
11
|
end
|
12
12
|
end
|
@@ -3,8 +3,8 @@ module ActiveScaffold
|
|
3
3
|
module FormColumnHelpers
|
4
4
|
def active_scaffold_input_paperclip(column, options)
|
5
5
|
record = options[:object]
|
6
|
-
ActiveSupport::Deprecation.warn
|
7
|
-
record ||= @record # TODO Remove when relying on @record is removed
|
6
|
+
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
|
7
|
+
record ||= @record # TODO: Remove when relying on @record is removed
|
8
8
|
options = active_scaffold_input_text_options(options.merge(column.options))
|
9
9
|
|
10
10
|
input = file_field(:record, column.name, options)
|
@@ -12,20 +12,21 @@ module ActiveScaffold
|
|
12
12
|
if paperclip.file?
|
13
13
|
case ActiveScaffold.js_framework
|
14
14
|
when :jquery
|
15
|
-
js_remove_file_code = "jQuery(this).prev().val('true'); jQuery(this).parent().hide().next().show(); return false;"
|
15
|
+
js_remove_file_code = "jQuery(this).prev().val('true'); jQuery(this).parent().hide().next().show(); return false;"
|
16
16
|
when :prototype
|
17
|
-
js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"
|
17
|
+
js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
object_name, method = options[:name].split(/\[(#{column.name})\]/)
|
21
21
|
method.sub!(/#{column.name}/, 'delete_\0')
|
22
22
|
|
23
23
|
content = active_scaffold_column_paperclip(record, column)
|
24
|
-
content_tag(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
content_tag(
|
25
|
+
:div,
|
26
|
+
content + ' | ' +
|
27
|
+
hidden_field(object_name, method, :value => 'false') +
|
28
|
+
content_tag(:a, as_(:remove_file), :href => '#', :onclick => js_remove_file_code)
|
29
|
+
) + content_tag(:div, input, :style => 'display: none')
|
29
30
|
else
|
30
31
|
input
|
31
32
|
end
|
@@ -4,11 +4,12 @@ module ActiveScaffold
|
|
4
4
|
def active_scaffold_column_paperclip(record, column)
|
5
5
|
paperclip = record.send("#{column.name}")
|
6
6
|
return nil unless paperclip.file?
|
7
|
-
content =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
content =
|
8
|
+
if paperclip.styles.include?(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style)
|
9
|
+
image_tag(paperclip.url(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style), :border => 0)
|
10
|
+
else
|
11
|
+
paperclip.original_filename
|
12
|
+
end
|
12
13
|
link_to(content, paperclip.url, :target => '_blank')
|
13
14
|
end
|
14
15
|
end
|
@@ -4,15 +4,15 @@ module ActiveScaffold
|
|
4
4
|
module PaperclipBridge
|
5
5
|
def initialize_with_paperclip(model_id)
|
6
6
|
initialize_without_paperclip(model_id)
|
7
|
-
return unless
|
7
|
+
return unless model.respond_to?(:attachment_definitions) && !model.attachment_definitions.nil?
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
update.multipart = true
|
10
|
+
create.multipart = true
|
11
11
|
|
12
|
-
|
12
|
+
model.attachment_definitions.keys.each do |field|
|
13
13
|
configure_paperclip_field(field.to_sym)
|
14
14
|
# define the "delete" helper for use with active scaffold, unless it's already defined
|
15
|
-
ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.generate_delete_helper(
|
15
|
+
ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.generate_delete_helper(model, field)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -21,13 +21,14 @@ module ActiveScaffold
|
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
|
+
|
24
25
|
def configure_paperclip_field(field)
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
columns << field
|
27
|
+
columns[field].form_ui ||= :paperclip
|
28
|
+
columns[field].params.add "delete_#{field}"
|
28
29
|
|
29
30
|
[:file_name, :content_type, :file_size, :updated_at].each do |f|
|
30
|
-
|
31
|
+
columns.exclude("#{field}_#{f}".to_sym)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class ActiveScaffold::Bridges::RecordSelect < ActiveScaffold::DataStructures::Bridge
|
2
2
|
def self.install
|
3
|
-
require File.join(File.dirname(__FILE__),
|
3
|
+
require File.join(File.dirname(__FILE__), 'record_select/helpers.rb')
|
4
4
|
end
|
5
5
|
def self.stylesheets
|
6
6
|
'record_select'
|
@@ -11,8 +11,8 @@ class ActiveScaffold::Bridges::RecordSelect
|
|
11
11
|
# requires RecordSelect plugin to be installed and configured.
|
12
12
|
def active_scaffold_input_record_select(column, options)
|
13
13
|
record = options.delete(:object)
|
14
|
-
ActiveSupport::Deprecation.warn
|
15
|
-
record ||= @record # TODO Remove when relying on @record is removed
|
14
|
+
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
|
15
|
+
record ||= @record # TODO: Remove when relying on @record is removed
|
16
16
|
if column.singular_association?
|
17
17
|
multiple = false
|
18
18
|
multiple = column.options[:html_options][:multiple] if column.options[:html_options] && column.options[:html_options][:multiple]
|
@@ -28,11 +28,12 @@ class ActiveScaffold::Bridges::RecordSelect
|
|
28
28
|
unless column.association
|
29
29
|
raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)."
|
30
30
|
end
|
31
|
-
klass =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
klass =
|
32
|
+
if column.polymorphic_association?
|
33
|
+
record.send(column.association.foreign_type).constantize rescue nil
|
34
|
+
else
|
35
|
+
column.association.klass
|
36
|
+
end
|
36
37
|
return content_tag :span, '', :class => options[:class] unless klass
|
37
38
|
|
38
39
|
remote_controller = active_scaffold_controller_for(klass).controller_path
|
@@ -40,23 +41,24 @@ class ActiveScaffold::Bridges::RecordSelect
|
|
40
41
|
# if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many)
|
41
42
|
# then only show records that have not been associated yet
|
42
43
|
if [:has_one, :has_many].include?(column.association.macro)
|
43
|
-
params.merge!(
|
44
|
+
params.merge!(column.association.foreign_key => '')
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
record_select_options = active_scaffold_input_text_options(options).merge(
|
47
48
|
:controller => remote_controller
|
48
49
|
)
|
49
50
|
record_select_options.merge!(column.options)
|
50
|
-
|
51
|
-
html =
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
|
52
|
+
html =
|
53
|
+
if multiple
|
54
|
+
record_multi_select_field(options[:name], value || [], record_select_options)
|
55
|
+
else
|
56
|
+
record_select_field(options[:name], value || klass.new, record_select_options)
|
57
|
+
end
|
56
58
|
html = self.class.field_error_proc.call(html, self) if record.errors[column.name].any?
|
57
59
|
html
|
58
60
|
end
|
59
|
-
|
61
|
+
|
60
62
|
def active_scaffold_record_select_autocomplete(record, column, options)
|
61
63
|
record_select_options = active_scaffold_input_text_options(options).merge(
|
62
64
|
:controller => active_scaffold_controller_for(record.class).controller_path
|
@@ -72,21 +74,19 @@ class ActiveScaffold::Bridges::RecordSelect
|
|
72
74
|
value = field_search_record_select_value(column)
|
73
75
|
active_scaffold_record_select(options[:object], column, options, value, column.options[:multiple])
|
74
76
|
end
|
75
|
-
|
77
|
+
|
76
78
|
def field_search_record_select_value(column)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
column.association.klass.find(value.to_i)
|
84
|
-
end
|
79
|
+
value = field_search_params[column.name]
|
80
|
+
unless value.blank?
|
81
|
+
if column.options[:multiple]
|
82
|
+
column.association.klass.find value.collect!(&:to_i)
|
83
|
+
else
|
84
|
+
column.association.klass.find(value.to_i)
|
85
85
|
end
|
86
|
-
rescue Exception => e
|
87
|
-
logger.error "#{e.class.name}: #{e.message} -- Sorry, we are not that smart yet. Attempted to restore search values to search fields :#{column.name} in #{controller.class}"
|
88
|
-
raise e
|
89
86
|
end
|
87
|
+
rescue StandardError => e
|
88
|
+
logger.error "#{e.class.name}: #{e.message} -- Sorry, we are not that smart yet. Attempted to restore search values to search fields :#{column.name} in #{controller.class}"
|
89
|
+
raise e
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|