active_scaffold-sequel 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/app/assets/stylesheets/active_scaffold_images.css.scss +3 -6
  2. data/app/assets/stylesheets/active_scaffold_layout.css +1 -4
  3. data/frontends/default/views/_field_search.html.erb +1 -1
  4. data/frontends/default/views/_form_association.html.erb +1 -1
  5. data/frontends/default/views/_form_attribute.html.erb +1 -1
  6. data/frontends/default/views/_search.html.erb +1 -1
  7. data/lib/active_scaffold/actions/core.rb +20 -8
  8. data/lib/active_scaffold/actions/create.rb +11 -22
  9. data/lib/active_scaffold/actions/list.rb +3 -4
  10. data/lib/active_scaffold/actions/nested.rb +26 -15
  11. data/lib/active_scaffold/actions/update.rb +11 -18
  12. data/lib/active_scaffold/attribute_params.rb +6 -6
  13. data/lib/active_scaffold/config/nested.rb +0 -7
  14. data/lib/active_scaffold/data_structures/action_link.rb +1 -8
  15. data/lib/active_scaffold/data_structures/column.rb +8 -0
  16. data/lib/active_scaffold/data_structures/nested_info.rb +10 -62
  17. data/lib/active_scaffold/extensions/routing_mapper.rb +0 -7
  18. data/lib/active_scaffold/finder.rb +1 -1
  19. data/lib/active_scaffold/helpers/form_column_helpers.rb +3 -2
  20. data/lib/active_scaffold/helpers/list_column_helpers.rb +4 -3
  21. data/lib/active_scaffold/helpers/search_column_helpers.rb +2 -2
  22. data/lib/active_scaffold/helpers/view_helpers.rb +6 -8
  23. data/lib/active_scaffold/version.rb +1 -1
  24. data/lib/active_scaffold.rb +0 -8
  25. metadata +4 -24
  26. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +0 -39
  27. data/lib/active_scaffold/bridges/ancestry.rb +0 -5
  28. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +0 -48
  29. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +0 -57
  30. data/lib/active_scaffold/bridges/file_column/form_ui.rb +0 -34
  31. data/lib/active_scaffold/bridges/file_column/list_ui.rb +0 -26
  32. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +0 -43
  33. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +0 -9
  34. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +0 -15
  35. data/lib/active_scaffold/bridges/file_column.rb +0 -11
  36. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +0 -27
  37. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +0 -16
  38. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +0 -36
  39. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +0 -24
  40. data/lib/active_scaffold/bridges/paperclip.rb +0 -12
  41. data/lib/active_scaffold/bridges/record_select/helpers.rb +0 -86
  42. data/lib/active_scaffold/bridges/record_select.rb +0 -11
  43. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +0 -20
  44. data/lib/active_scaffold/bridges/semantic_attributes.rb +0 -5
  45. data/lib/active_scaffold/extensions/cache_association.rb +0 -16
@@ -267,7 +267,6 @@ module ActiveScaffold
267
267
 
268
268
  ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association?
269
269
  else
270
- actions = [:create, :update, :show]
271
270
  actions = controller.active_scaffold_config.actions
272
271
  column.actions_for_association_links.delete :new unless actions.include? :create
273
272
  column.actions_for_association_links.delete :edit unless actions.include? :update
@@ -276,13 +275,6 @@ module ActiveScaffold
276
275
  end
277
276
  end
278
277
  end
279
-
280
- def link_for_association_as_scope(scope, options = {})
281
- options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path
282
- options[:parameters] ||= {}
283
- options[:parameters].reverse_merge! :parent_scaffold => controller_path, :named_scope => scope
284
- ActiveScaffold::DataStructures::ActionLink.new('index', options)
285
- end
286
278
 
287
279
  def add_active_scaffold_path(path)
288
280
  @active_scaffold_paths = nil # Force active_scaffold_paths to rebuild
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: active_scaffold-sequel
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Many, see README
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-22 00:00:00 Z
13
+ date: 2012-03-02 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: shoulda
@@ -189,8 +189,6 @@ files:
189
189
  - lib/active_scaffold/active_record_permissions.rb
190
190
  - lib/active_scaffold/attribute_params.rb
191
191
  - lib/active_scaffold/bridges.rb
192
- - lib/active_scaffold/bridges/ancestry.rb
193
- - lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
194
192
  - lib/active_scaffold/bridges/calendar_date_select.rb
195
193
  - lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb
196
194
  - lib/active_scaffold/bridges/cancan.rb
@@ -210,24 +208,7 @@ files:
210
208
  - lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb
211
209
  - lib/active_scaffold/bridges/dragonfly/form_ui.rb
212
210
  - lib/active_scaffold/bridges/dragonfly/list_ui.rb
213
- - lib/active_scaffold/bridges/file_column.rb
214
- - lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb
215
- - lib/active_scaffold/bridges/file_column/file_column_helpers.rb
216
- - lib/active_scaffold/bridges/file_column/form_ui.rb
217
- - lib/active_scaffold/bridges/file_column/list_ui.rb
218
- - lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb
219
- - lib/active_scaffold/bridges/file_column/test/mock_model.rb
220
- - lib/active_scaffold/bridges/file_column/test/test_helper.rb
221
- - lib/active_scaffold/bridges/paperclip.rb
222
- - lib/active_scaffold/bridges/paperclip/form_ui.rb
223
- - lib/active_scaffold/bridges/paperclip/list_ui.rb
224
- - lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb
225
- - lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb
226
- - lib/active_scaffold/bridges/record_select.rb
227
- - lib/active_scaffold/bridges/record_select/helpers.rb
228
211
  - lib/active_scaffold/bridges/shared/date_bridge.rb
229
- - lib/active_scaffold/bridges/semantic_attributes.rb
230
- - lib/active_scaffold/bridges/semantic_attributes/column.rb
231
212
  - lib/active_scaffold/bridges/tiny_mce.rb
232
213
  - lib/active_scaffold/bridges/tiny_mce/helpers.rb
233
214
  - lib/active_scaffold/config/base.rb
@@ -262,14 +243,13 @@ files:
262
243
  - lib/active_scaffold/extensions/active_record_offset.rb
263
244
  - lib/active_scaffold/extensions/to_label.rb
264
245
  - lib/active_scaffold/extensions/array.rb
265
- - lib/active_scaffold/extensions/cache_association.rb
246
+ - lib/active_scaffold/extensions/paginator_extensions.rb
266
247
  - lib/active_scaffold/extensions/localize.rb
267
248
  - lib/active_scaffold/extensions/name_option_for_datetime.rb
268
249
  - lib/active_scaffold/extensions/nil_id_in_url_params.rb
269
- - lib/active_scaffold/extensions/paginator_extensions.rb
270
250
  - lib/active_scaffold/extensions/unsaved_associated.rb
271
- - lib/active_scaffold/extensions/routing_mapper.rb
272
251
  - lib/active_scaffold/extensions/unsaved_record.rb
252
+ - lib/active_scaffold/extensions/routing_mapper.rb
273
253
  - lib/active_scaffold/extensions/usa_state.rb
274
254
  - lib/active_scaffold/finder.rb
275
255
  - lib/active_scaffold/helpers/association_helpers.rb
@@ -1,39 +0,0 @@
1
- ActiveScaffold::Config::Core.class_eval do
2
- def initialize_with_ancestry(model_id)
3
- initialize_without_ancestry(model_id)
4
-
5
- return unless self.model.respond_to? :ancestry_column
6
-
7
- self.columns << :parent_id
8
- self.columns[:parent_id].form_ui = :ancestry
9
- update.columns.exclude :ancestry
10
- create.columns.exclude :ancestry, :parent_id
11
- list.columns.exclude :ancestry, :parent_id
12
- end
13
-
14
- alias_method_chain :initialize, :ancestry
15
- end
16
-
17
- module ActiveScaffold::Bridges
18
- class Ancestry
19
- module FormColumnHelpers
20
- def active_scaffold_input_ancestry(column, options)
21
- select_options = []
22
- select_control_options = {:selected => @record.parent_id}
23
- select_control_options[:include_blank] = as_(:_select_) if @record.parent_id.nil?
24
- traverse_ancestry = proc do|key, value|
25
- unless key == @record
26
- select_options << ["#{'__' * key.depth}#{key.to_label}", key.id]
27
- value.each(&traverse_ancestry) if value.is_a?(Hash) && !value.empty?
28
- end
29
- end
30
- @record.class.arrange.each(&traverse_ancestry)
31
- select(:record, :ancestry, select_options, select_control_options, options)
32
- end
33
- end
34
- end
35
- end
36
-
37
- ActionView::Base.class_eval do
38
- include ActiveScaffold::Bridges::Ancestry::FormColumnHelpers
39
- end
@@ -1,5 +0,0 @@
1
- class ActiveScaffold::Bridges::Ancestry < ActiveScaffold::DataStructures::Bridge
2
- def self.install
3
- require File.join(File.dirname(__FILE__), "ancestry/ancestry_bridge.rb")
4
- end
5
- end
@@ -1,48 +0,0 @@
1
- ActiveScaffold::DataStructures::Column.class_eval do
2
- attr_accessor :file_column_display
3
- end
4
-
5
- module ActiveScaffold::Config
6
- class Core < Base
7
- attr_accessor :file_column_fields
8
- def initialize_with_file_column(model_id)
9
- initialize_without_file_column(model_id)
10
-
11
- return unless ActiveScaffold::Bridges::FileColumn::FileColumnHelpers.klass_has_file_column_fields?(self.model)
12
-
13
- self.model.send :extend, ActiveScaffold::Bridges::FileColumn::FileColumnHelpers
14
-
15
- # include the "delete" helpers for use with active scaffold, unless they are already included
16
- self.model.generate_delete_helpers
17
-
18
- # switch on multipart
19
- self.update.multipart = true
20
- self.create.multipart = true
21
-
22
- self.model.file_column_fields.each{ |field|
23
- configure_file_column_field(field)
24
- }
25
- end
26
-
27
- alias_method_chain :initialize, :file_column unless self.instance_methods.include?("initialize_without_file_column")
28
-
29
- def configure_file_column_field(field)
30
- # set list_ui first because it gets its default value from form_ui
31
- self.columns[field].list_ui ||= self.model.field_has_image_version?(field, "thumb") ? :thumbnail : :download_link_with_filename
32
- self.columns[field].form_ui ||= :file_column
33
-
34
- # these 2 parameters are necessary helper attributes for the file column that must be allowed to be set to the model by active scaffold.
35
- self.columns[field].params.add "#{field}_temp", "delete_#{field}"
36
-
37
- # set null to false so active_scaffold wont set it to null
38
- # delete_file_column will take care of deleting a file or not.
39
- #
40
- # XXX what a strange hack
41
- #self.model.columns_hash[field.to_s].instance_variable_set("@null", false)
42
-
43
- rescue
44
- false
45
- end
46
-
47
- end
48
- end
@@ -1,57 +0,0 @@
1
- module ActiveScaffold
2
- module Bridges
3
- class FileColumn
4
- module FileColumnHelpers
5
- class << self
6
- def file_column_fields(klass)
7
- klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym }
8
- end
9
-
10
- def generate_delete_helpers(klass)
11
- file_column_fields(klass).each { |field|
12
- klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=")
13
- attr_reader :delete_#{field}
14
-
15
- def delete_#{field}=(value)
16
- value = (value=="true") if String===value
17
- return unless value
18
-
19
- # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file!
20
- self.#{field} = nil unless self.#{field}_just_uploaded?
21
- end
22
- EOF
23
- }
24
- end
25
-
26
- def klass_has_file_column_fields?(klass)
27
- true unless file_column_fields(klass).empty?
28
- end
29
- end
30
-
31
- def file_column_fields
32
- @file_column_fields||=FileColumnHelpers.file_column_fields(self)
33
- end
34
-
35
- def options_for_file_column_field(field)
36
- self.allocate.send("#{field}_options")
37
- end
38
-
39
- def field_has_image_version?(field, version="thumb")
40
- begin
41
- # the only way to get to the options of a particular field is to use the instance method
42
- options = options_for_file_column_field(field)
43
- versions = options[:magick][:versions]
44
- raise unless versions.stringify_keys[version]
45
- true
46
- rescue
47
- false
48
- end
49
- end
50
-
51
- def generate_delete_helpers
52
- FileColumnHelpers.generate_delete_helpers(self)
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,34 +0,0 @@
1
- module ActiveScaffold
2
- module Helpers
3
- # Helpers that assist with the rendering of a Form Column
4
- module FormColumnHelpers
5
- def active_scaffold_input_file_column(column, options)
6
- if @record.send(column.name)
7
- # we already have a value? display the form for deletion.
8
- if ActiveScaffold.js_framework == :jquery
9
- remove_file_js = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;";
10
- else
11
- remove_file_js = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show(); return false;";
12
- end
13
-
14
- hidden_options = options.dup
15
- hidden_options[:id] += '_delete'
16
- hidden_options[:name].sub!("[#{column.name}]", "[delete_#{column.name}]")
17
- hidden_options[:value] = 'false'
18
- custom_hidden_field_tag = hidden_field(:record, column.name, hidden_options)
19
-
20
- content_tag(:div) do
21
- content_tag(:div) do
22
- content = get_column_value(@record, column) + " #{custom_hidden_field_tag} | ".html_safe
23
- content += content_tag(:a, as_(:remove_file), {:href => '#', :onclick => remove_file_js})
24
- content += content_tag(:div, file_column_field("record", column.name, options), :style => "display: none")
25
- end
26
- end
27
- else
28
- file_column_field("record", column.name, options)
29
- end
30
- end
31
-
32
- end
33
- end
34
- end
@@ -1,26 +0,0 @@
1
- module ActiveScaffold
2
- module Helpers
3
- # Helpers that assist with the rendering of a List Column
4
- module ListColumnHelpers
5
- def active_scaffold_column_download_link_with_filename(column, record)
6
- return nil if record.send(column.name).nil?
7
- active_scaffold_column_download_link(column, record, File.basename(record.send(column.name)))
8
- end
9
-
10
- def active_scaffold_column_download_link(column, record, label = nil)
11
- return nil if record.send(column.name).nil?
12
- label||=as_(:download)
13
- link_to( label, url_for_file_column(record, column.name.to_s), :popup => true)
14
- end
15
-
16
- def active_scaffold_column_thumbnail(column, record)
17
- return nil if record.send(column.name).nil?
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
- :popup => true)
22
- end
23
-
24
- end
25
- end
26
- end
@@ -1,43 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "../test_helper.rb")
2
-
3
- class DeleteFileColumnTest < Test::Unit::TestCase
4
- def setup
5
- DeleteFileColumn.generate_delete_helpers(MockModel)
6
- @model = MockModel.new
7
- @model.band_image = "coolio.jpg"
8
- end
9
-
10
- def test__file_column_fields
11
- assert_equal(1, @model.file_column_fields.length)
12
- end
13
-
14
- def test__delete_band_image__boolean__should_delete
15
- @model.delete_band_image = true
16
- assert_nil @model.band_image
17
- end
18
-
19
- def test__delete_band_image__string__should_delete
20
- @model.delete_band_image = "true"
21
- assert_nil @model.band_image
22
- end
23
-
24
-
25
- def test__delete_band_image__boolean_false__shouldnt_delete
26
- @model.delete_band_image = false
27
- assert_not_nil @model.band_image
28
- end
29
-
30
- def test__delete_band_image__string_false__shouldnt_delete
31
- @model.delete_band_image = "false"
32
- assert_not_nil @model.band_image
33
- end
34
-
35
-
36
- def test__just_uploaded__shouldnt_delete
37
- @model.band_image_just_uploaded = true
38
- @model.delete_band_image = "true"
39
- assert_not_nil(@model.band_image)
40
- end
41
-
42
-
43
- end
@@ -1,9 +0,0 @@
1
- class MockModel
2
- attr_accessor :name
3
- attr_accessor :bio
4
-
5
- attr_accessor :band_image
6
- attr_accessor :band_image_just_uploaded
7
- def band_image_just_uploaded?; self.band_image_just_uploaded ? true : false; end
8
-
9
- end
@@ -1,15 +0,0 @@
1
- require 'test/unit'
2
- require "rubygems"
3
- require 'active_support'
4
-
5
- for file in ["../lib/delete_file_column.rb", "mock_model.rb"]
6
- require File.expand_path(File.join(File.dirname(__FILE__), file))
7
- end
8
-
9
-
10
-
11
- def dbg
12
- require 'ruby-debug'
13
- Debugger.start
14
- debugger
15
- end
@@ -1,11 +0,0 @@
1
- class ActiveScaffold::Bridges::FileColumn < ActiveScaffold::DataStructures::Bridge
2
- def self.install
3
- if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column")
4
- raise RuntimeError, "We've detected that you have active_scaffold_file_column_bridge installed. This plugin has been moved to core. Please remove active_scaffold_file_column_bridge to prevent any conflicts"
5
- end
6
- require File.join(File.dirname(__FILE__), "file_column/as_file_column_bridge")
7
- require File.join(File.dirname(__FILE__), "file_column/form_ui")
8
- require File.join(File.dirname(__FILE__), "file_column/list_ui")
9
- require File.join(File.dirname(__FILE__), "file_column/file_column_helpers")
10
- end
11
- end
@@ -1,27 +0,0 @@
1
- module ActiveScaffold
2
- module Helpers
3
- module FormColumnHelpers
4
- def active_scaffold_input_paperclip(column, options)
5
- options = active_scaffold_input_text_options(options)
6
- input = file_field(:record, column.name, options)
7
- paperclip = @record.send("#{column.name}")
8
- if paperclip.file?
9
- if ActiveScaffold.js_framework == :jquery
10
- js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;";
11
- else
12
- js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;";
13
- end
14
-
15
- content = active_scaffold_column_paperclip(column, @record)
16
- content_tag(:div,
17
- content + " | " +
18
- hidden_field(:record, "delete_#{column.name}", :value => "false") +
19
- content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code})
20
- ) + content_tag(:div, input, :style => "display: none")
21
- else
22
- input
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,16 +0,0 @@
1
- module ActiveScaffold
2
- module Helpers
3
- module ListColumnHelpers
4
- def active_scaffold_column_paperclip(column, record)
5
- paperclip = record.send("#{column.name}")
6
- return nil unless paperclip.file?
7
- content = if paperclip.styles.include?(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style)
8
- image_tag(paperclip.url(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style), :border => 0)
9
- else
10
- paperclip.original_filename
11
- end
12
- link_to(content, paperclip.url, {'data-popup' => true, :target => '_blank'})
13
- end
14
- end
15
- end
16
- end
@@ -1,36 +0,0 @@
1
- module ActiveScaffold
2
- module Bridges
3
- class Paperclip
4
- module PaperclipBridge
5
- def initialize_with_paperclip(model_id)
6
- initialize_without_paperclip(model_id)
7
- return unless self.model.respond_to?(:attachment_definitions) && !self.model.attachment_definitions.nil?
8
-
9
- self.update.multipart = true
10
- self.create.multipart = true
11
-
12
- self.model.attachment_definitions.keys.each do |field|
13
- configure_paperclip_field(field.to_sym)
14
- # define the "delete" helper for use with active scaffold, unless it's already defined
15
- ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.generate_delete_helper(self.model, field)
16
- end
17
- end
18
-
19
- def self.included(base)
20
- base.alias_method_chain :initialize, :paperclip
21
- end
22
-
23
- private
24
- def configure_paperclip_field(field)
25
- self.columns << field
26
- self.columns[field].form_ui ||= :paperclip
27
- self.columns[field].params.add "delete_#{field}"
28
-
29
- [:file_name, :content_type, :file_size, :updated_at].each do |f|
30
- self.columns.exclude("#{field}_#{f}".to_sym)
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,24 +0,0 @@
1
- module ActiveScaffold
2
- module Bridges
3
- class Paperclip
4
- module PaperclipBridgeHelpers
5
- mattr_accessor :thumbnail_style
6
- self.thumbnail_style = :thumbnail
7
-
8
- def self.generate_delete_helper(klass, field)
9
- klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=")
10
- attr_reader :delete_#{field}
11
-
12
- def delete_#{field}=(value)
13
- value = (value == "true") if String === value
14
- return unless value
15
-
16
- # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file!
17
- self.#{field} = nil unless self.#{field}.dirty?
18
- end
19
- EOF
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,12 +0,0 @@
1
- class ActiveScaffold::Bridges::Paperclip < ActiveScaffold::DataStructures::Bridge
2
- def self.install
3
- if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip")
4
- raise RuntimeError, "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
- end
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
- ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Paperclip::PaperclipBridge
11
- end
12
- end
@@ -1,86 +0,0 @@
1
- class ActiveScaffold::Bridges::RecordSelect
2
- module Helpers
3
- def self.included(base)
4
- base.class_eval do
5
- include FormColumnHelpers
6
- include SearchColumnHelpers
7
- end
8
- end
9
-
10
- module FormColumnHelpers
11
- # requires RecordSelect plugin to be installed and configured.
12
- def active_scaffold_input_record_select(column, options)
13
- if column.singular_association?
14
- multiple = false
15
- multiple = column.options[:html_options][:multiple] if column.options[:html_options] && column.options[:html_options][:multiple]
16
- active_scaffold_record_select(column, options, @record.send(column.name), multiple)
17
- elsif column.plural_association?
18
- active_scaffold_record_select(column, options, @record.send(column.name), true)
19
- else
20
- active_scaffold_record_select_autocomplete(column, options)
21
- end
22
- end
23
-
24
- def active_scaffold_record_select(column, options, value, multiple)
25
- unless column.association
26
- 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)."
27
- end
28
- remote_controller = active_scaffold_controller_for(column.association.associated_class).controller_path
29
-
30
- # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many)
31
- # then only show records that have not been associated yet
32
- if [:has_one, :has_many].include?(column.association.macro)
33
- params.merge!({column.association.primary_key_name => ''})
34
- end
35
-
36
- record_select_options = active_scaffold_input_text_options(options).merge(
37
- :controller => remote_controller
38
- )
39
- record_select_options.merge!(column.options)
40
-
41
- html = if multiple
42
- record_multi_select_field(options[:name], value || [], record_select_options)
43
- else
44
- record_select_field(options[:name], value || column.association.associated_class.new, record_select_options)
45
- end
46
- html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any?
47
- html
48
- end
49
-
50
- def active_scaffold_record_select_autocomplete(column, options)
51
- record_select_options = active_scaffold_input_text_options(options).merge(
52
- :controller => active_scaffold_controller_for(@record.class).controller_path
53
- )
54
- html = record_select_autocomplete(options[:name], @record, record_select_options)
55
- html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any?
56
- html
57
- end
58
- end
59
-
60
- module SearchColumnHelpers
61
- def active_scaffold_search_record_select(column, options)
62
- value = field_search_record_select_value(column)
63
- active_scaffold_record_select(column, options, value, column.options[:multiple])
64
- end
65
-
66
- def field_search_record_select_value(column)
67
- begin
68
- value = field_search_params[column.name]
69
- unless value.blank?
70
- klass = column.association.associated_class
71
- if column.options[:multiple]
72
- klass.filter(klass.primary_key => value.collect!(&:to_i))
73
- else
74
- klass[value.to_i]
75
- end
76
- end
77
- rescue Exception => e
78
- logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}"
79
- raise e
80
- end
81
- end
82
- end
83
- end
84
- end
85
-
86
- ActionView::Base.class_eval { include ActiveScaffold::Bridges::RecordSelect::Helpers }
@@ -1,11 +0,0 @@
1
- class ActiveScaffold::Bridges::RecordSelect < ActiveScaffold::DataStructures::Bridge
2
- def self.install
3
- require File.join(File.dirname(__FILE__), "record_select/helpers.rb")
4
- end
5
- def self.stylesheets
6
- 'record_select'
7
- end
8
- def self.javascripts
9
- 'record_select'
10
- end
11
- end
@@ -1,20 +0,0 @@
1
- class ActiveScaffold::Bridges::SemanticAttributes
2
- module Column
3
- def self.included(base)
4
- base.class_eval { alias_method_chain :initialize, :semantic_attributes }
5
- end
6
-
7
- def initialize_with_semantic_attributes(name, active_record_class)
8
- initialize_without_semantic_attributes(name, active_record_class)
9
- self.required = !active_record_class.semantic_attributes[self.name].predicates.find {|p| p.allow_empty? == false }.nil?
10
- active_record_class.semantic_attributes[self.name].predicates.find do |p|
11
- sem_type = p.class.to_s.split('::')[1].underscore.to_sym
12
- next if [:required, :association].include?(sem_type)
13
- @form_ui = sem_type
14
- end
15
- end
16
- end
17
- end
18
- ActiveScaffold::DataStructures::Column.class_eval do
19
- include ActiveScaffold::Bridges::SemanticAttributes::Column
20
- end
@@ -1,5 +0,0 @@
1
- class ActiveScaffold::Bridges::SemanticAttributes < ActiveScaffold::DataStructures::Bridge
2
- def self.install
3
- require File.join(File.dirname(__FILE__), "semantic_attributes/column.rb")
4
- end
5
- end
@@ -1,16 +0,0 @@
1
- module ActiveRecord
2
- class Relation
3
- def target=(records)
4
- @loaded = true
5
- @records = records
6
- @records
7
- end
8
- end
9
- end
10
- module ActiveRecord
11
- module Associations
12
- class CollectionProxy
13
- delegate :target=, :to => :@association
14
- end
15
- end
16
- end