diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-02 11:25:21 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-02 11:25:21 +0000 |
commit | 50f0a736242e65408c06b62b0fbd68e2ea349c23 (patch) | |
tree | 6e65bb01cde1e63a2c84a55ffc41372d07e99610 /actionpack | |
parent | c2060719d358d60cb4f4204a6c79abebf6ff9b90 (diff) | |
download | rails-50f0a736242e65408c06b62b0fbd68e2ea349c23.tar.gz rails-50f0a736242e65408c06b62b0fbd68e2ea349c23.tar.bz2 rails-50f0a736242e65408c06b62b0fbd68e2ea349c23.zip |
Added JavascriptHelper#draggable_element and JavascriptHelper#drop_receiving_element to facilitate easy dragging and dropping through the script.aculo.us libraries #1578 [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1606 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/auto_complete.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/javascript_helper.rb | 57 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/controls.js | 2 |
4 files changed, 53 insertions, 10 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 6fbe896fd6..382215da8a 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added JavascriptHelper#draggable_element and JavascriptHelper#drop_receiving_element to facilitate easy dragging and dropping through the script.aculo.us libraries #1578 [Thomas Fuchs] + * Added that UrlHelper#mail_to will now also encode the default link title #749 [f.svehla@gmail.com] * Removed the default option of wrap=virtual on FormHelper#text_area to ensure XHTML compatibility #1300 [thomas@columbus.rr.com] diff --git a/actionpack/lib/action_controller/auto_complete.rb b/actionpack/lib/action_controller/auto_complete.rb index 685bb63ff9..ef2a57bdf0 100644 --- a/actionpack/lib/action_controller/auto_complete.rb +++ b/actionpack/lib/action_controller/auto_complete.rb @@ -29,7 +29,7 @@ module ActionController def auto_complete_for(object, method, options = {}) define_method("auto_complete_for_#{object}_#{method}") do find_options = { - :conditions => [ "LOWER(#{method}) LIKE ?", '%' + request.raw_post.downcase + '%' ], + :conditions => [ "LOWER(#{method}) LIKE ?", '%' + params[object][method] + '%' ], :order => "#{method} ASC", :limit => 10 }.merge!(options) diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index c6c5c58abf..5b7d739d4f 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -18,7 +18,8 @@ module ActionView unless const_defined? :CALLBACKS CALLBACKS = [:uninitialized, :loading, :loaded, :interactive, :complete, :failure].push((100..599).to_a).flatten - AJAX_OPTIONS = [ :url, :asynchronous, :method, :insertion, :form, :with, :update ].concat(CALLBACKS) + AJAX_OPTIONS = [ :before, :after, :condition, :url, :asynchronous, :method, + :insertion, :position, :form, :with, :update, :script ].concat(CALLBACKS) JAVASCRIPT_PATH = File.join(File.dirname(__FILE__), 'javascripts') end @@ -276,8 +277,7 @@ module ActionView # Defaults to field_id + '_auto_complete' # <tt>:with</tt>:: A JavaScript expression specifying the # parameters for the XMLHttpRequest. This defaults - # to 'value', which in the evaluated context - # refers to the new field value. + # to 'fieldname=value'. # <tt>:indicator</tt>:: Specifies the DOM ID of an elment which will be # displayed while autocomplete is running. def auto_complete_field(field_id, options = {}) @@ -287,8 +287,8 @@ module ActionView function << "'#{url_for(options[:url])}'" js_options = {} - js_options[:callback] = "function(element, value) { return #{options[:with]} }" if options[:with] - js_options[:indicator] = "'#{options[:indicator]}'" if options[:indicator] + js_options[:callback] = "function(element, value) { return #{options[:with]} }" if options[:with] + js_options[:indicator] = "'#{options[:indicator]}'" if options[:indicator] function << (', ' + options_for_javascript(js_options) + ')') javascript_tag(function) @@ -334,10 +334,19 @@ module ActionView # :url => { :action => "reload" }, # :complete => visual_effect(:highlight, "posts", :duration => 0.5 ) # + # If no element_id is given, it assumes "element" which should be a local + # variable in the generated JavaScript execution context. This can be used + # for example with drop_receiving_element: + # + # <%= drop_receving_element (...), :loading => visual_effect(:fade) %> + # + # This would fade the element that was dropped on the drop receiving element. + # # You can change the behaviour with various options, see # http://script.aculo.us for more documentation. - def visual_effect(name, element_id, js_options = {}) - "new Effect.#{name.to_s.capitalize}('#{element_id}',#{options_for_javascript(js_options)});" + def visual_effect(name, element_id = false, js_options = {}) + element = element_id ? "'#{element_id}'" : "element" + "new Effect.#{name.to_s.capitalize}(#{element},#{options_for_javascript(js_options)});" end # Makes the element with the DOM ID specified by +element_id+ sortable @@ -361,6 +370,38 @@ module ActionView javascript_tag("Sortable.create('#{element_id}', #{options_for_javascript(options)})") end + + # Makes the element with the DOM ID specified by +element_id+ draggable. + # + # Example: + # <%= draggable_element("my_image", :revert => true) + # + # You can change the behaviour with various options, see + # http://script.aculo.us for more documentation. + def draggable_element(element_id, options = {}) + javascript_tag("new Draggable('#{element_id}', #{options_for_javascript(options)})") + end + + # Makes the element with the DOM ID specified by +element_id+ receive + # dropped draggable elements (created by draggable_element). + # and make an AJAX call By default, the action called gets the DOM ID of the + # element as parameter. + # + # Example: + # <%= drop_receiving_element("my_cart", :url => { :controller => "cart", :action => "add" }) %> + # + # You can change the behaviour with various options, see + # http://script.aculo.us for more documentation. + def drop_receiving_element(element_id, options = {}) + options[:with] ||= "'id=' + encodeURIComponent(element.id)" + options[:onDrop] ||= "function(element){" + remote_function(options) + "}" + options.delete_if { |key, value| AJAX_OPTIONS.include?(key) } + + options[:accept] = "'#{options[:accept]}'" if options[:accept] + options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass] + + javascript_tag("Droppables.add('#{element_id}', #{options_for_javascript(options)})") + end # Escape carrier returns and single and double quotes for JavaScript segments. def escape_javascript(javascript) @@ -384,7 +425,7 @@ module ActionView js_options['asynchronous'] = options[:type] != :synchronous js_options['method'] = method_option_to_s(options[:method]) if options[:method] js_options['insertion'] = "Insertion.#{options[:position].to_s.camelize}" if options[:position] - js_options['evalScripts'] = options[:script] == true if options[:script] + js_options['evalScripts'] = options[:script].nil? || options[:script] if options[:form] js_options['parameters'] = 'Form.serialize(this)' diff --git a/actionpack/lib/action_view/helpers/javascripts/controls.js b/actionpack/lib/action_view/helpers/javascripts/controls.js index f4be26b289..e68820d834 100644 --- a/actionpack/lib/action_view/helpers/javascripts/controls.js +++ b/actionpack/lib/action_view/helpers/javascripts/controls.js @@ -116,7 +116,7 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({ this.startIndicator(); this.options.parameters = this.options.callback ? this.options.callback(this.element, Form.Element.getValue(this.element)) : - Form.Element.getValue(this.element); + Form.Element.serialize(this.element); new Ajax.Request(this.url, this.options); } else { this.active = false; |