From 2186ed83dd693ce3c70381f017bfd9ef0b47d1b7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 6 Jul 2005 08:32:04 +0000 Subject: [PATCH] Make new AJAX helpers aware of more of their options #1622 [Thomas Fuchs] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1729 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../action_view/helpers/javascript_helper.rb | 17 ++++++++++++++++- actionpack/test/template/javascript_helper.rb | 12 ++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 6ed84059e1..2a1b72396a 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -441,6 +441,16 @@ module ActionView options[:onUpdate] ||= "function(){" + remote_function(options) + "}" options.delete_if { |key, value| AJAX_OPTIONS.include?(key) } + [:tag, :overlap, :constraint].each do |option| + options[option] = "'#{options[option]}'" if options[option] + end + + if options[:containment] and options[:containment].kind_of?(Array) + options[:containment] = "['#{options[:containment].join('\',\'')}']" + elsif options[:containment] + options[:containment] = "'#{options[:containment]}'" if options[:containment] + end + javascript_tag("Sortable.create('#{element_id}', #{options_for_javascript(options)})") end @@ -470,7 +480,12 @@ module ActionView options[:onDrop] ||= "function(element){" + remote_function(options) + "}" options.delete_if { |key, value| AJAX_OPTIONS.include?(key) } - options[:accept] = "'#{options[:accept]}'" if options[:accept] + if options[:accept] and options[:accept].kind_of?(Array) + options[:accept] = "['#{options[:accept].join('\',\'')}']" + elsif options[:accept] + options[:accept] = "'#{options[:accept]}'" if options[:accept] + end + options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass] javascript_tag("Droppables.add('#{element_id}', #{options_for_javascript(options)})") diff --git a/actionpack/test/template/javascript_helper.rb b/actionpack/test/template/javascript_helper.rb index 8ce94a9d9b..d94c22c484 100644 --- a/actionpack/test/template/javascript_helper.rb +++ b/actionpack/test/template/javascript_helper.rb @@ -103,6 +103,12 @@ class JavaScriptHelperTest < Test::Unit::TestCase def test_sortable_element assert_equal %(), sortable_element("mylist", :url => { :action => "order" }) + assert_equal %(), + sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" }) + assert_equal %(), + sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" }) + assert_equal %(), + sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" }) end def test_draggable_element @@ -115,10 +121,12 @@ class JavaScriptHelperTest < Test::Unit::TestCase def test_drop_receiving_element assert_equal %(), drop_receiving_element('droptarget1') - assert_equal %(), + assert_equal %(), drop_receiving_element('droptarget1', :accept => 'products') - assert_equal %(), + assert_equal %(), drop_receiving_element('droptarget1', :accept => 'products', :update => 'infobox') + assert_equal %(), + drop_receiving_element('droptarget1', :accept => ['tshirts','mugs'], :update => 'infobox') end def test_update_element_function