aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-13 15:47:06 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-13 15:47:06 +0000
commit7816420c63f8e03b497b420d190a38db7ed44b0c (patch)
tree33f2236d733753ff90b62e8a9d15969421e265ac
parentfba2421c79a74bf91743080ebe2b32866b157aa4 (diff)
downloadrails-7816420c63f8e03b497b420d190a38db7ed44b0c.tar.gz
rails-7816420c63f8e03b497b420d190a38db7ed44b0c.tar.bz2
rails-7816420c63f8e03b497b420d190a38db7ed44b0c.zip
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
-rw-r--r--actionpack/lib/action_view/helpers/javascript_helper.rb14
1 files 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