Permalink
Browse files

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
  • Loading branch information...
1 parent fba2421 commit 7816420c63f8e03b497b420d190a38db7ed44b0c @dhh dhh committed Mar 13, 2005
Showing with 9 additions and 5 deletions.
  1. +9 −5 actionpack/lib/action_view/helpers/javascript_helper.rb
View
14 actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -58,19 +58,23 @@ def define_javascript_functions
/* 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() {
var url = arguments[0];
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 @@ def remote_function(options)
"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

0 comments on commit 7816420

Please sign in to comment.