From 7816420c63f8e03b497b420d190a38db7ed44b0c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 13 Mar 2005 15:47:06 +0000 Subject: Added :condition option to abort an update if some condition isnt there git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@894 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/javascript_helper.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 0818d2e827..83538490ee 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -58,7 +58,11 @@ module ActionView /* XMLHttpRequest Methods */ function update_with_response() { - o(arguments[0]).innerHTML = xml_request(arguments[1], arguments[2]); + var container = o(arguments[0]); + var url = arguments[1]; + var parameters = arguments[2]; + + container.innerHTML = xml_request(url, parameters); } function xml_request() { @@ -66,11 +70,11 @@ module ActionView var parameters = arguments[1]; var async = arguments[2]; var type = parameters ? "POST" : "GET"; - + req = xml_http_request_object(); req.open(type, url, async); req.send(parameters); - + return req.responseText; } @@ -174,8 +178,8 @@ module ActionView "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 = [ options[:before], function, options[:before] ].join("; ") + function = "if (#{options[:condition]}) { #{function}; }" if options[:condition] return function end -- cgit v1.2.3