From 0c0a10746f1996c5ed09063cdd74fc5bdbd0c1fe Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 14 Mar 2005 15:12:31 +0000 Subject: Made async the default approach and add get_elements_by_class git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@903 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_view/helpers/javascript_helper.rb | 46 +++++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'actionpack/lib/action_view/helpers/javascript_helper.rb') diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 5d87c85647..6ce1d05e2c 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -25,22 +25,24 @@ module ActionView # link_to_remote "Delete this post", :update => "posts", :url => { :action => "destroy", :id => post.id } # link_to_remote(image_tag("refresh"), :update => "emails", :url => { :action => "list_emails" }) # - # Asynchronous requests may be made by specifying a callback function - # to invoke when the request finishes. + # By default, these remote requests are processed asynchronous during which various callbacks can be triggered (for progress indicators + # and the likes). # # Example: # link_to_remote word, # :url => { :action => "undo", :n => word_counter }, - # :before => "if(!prepareForUndo()) return false", # :complete => "undoRequestCompleted(request)" # # The complete list of callbacks that may be specified are: # - # * uninitialized - # * loading - # * loaded - # * interactive - # * complete + # * :uninitialized -- EXPLAIN ME! + # * :loading -- EXPLAIN ME! + # * :loaded -- EXPLAIN ME! + # * :interactive -- EXPLAIN ME! + # * :complete -- EXPLAIN ME! + # + # If you for some reason or another needs synchronous processing (that'll block the browser while the request is happening), you + # can specify options[:type] = :sync. def link_to_remote(name, options = {}, html_options = {}) link_to_function(name, remote_function(options), html_options) end @@ -54,6 +56,18 @@ module ActionView tag("form", options[:html], true) end + def remote_function(options) + function = options[:update] ? + "update_with_response('#{options[:update]}', '#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})" : + "xml_request('#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})" + + function = "#{options[:before]}; #{function}" if options[:before] + function = "#{function}; #{options[:after]}" if options[:after] + function = "if (#{options[:condition]}) { #{function}; }" if options[:condition] + + return function + end + def define_javascript_functions <<-EOF