AJAX error handling fix, Prototype event handling #1589 [Thomas Fuchs]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1617 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 da4b15fe
......@@ -164,17 +164,19 @@ def submit_to_remote(name, value, options = {})
def remote_function(options) #:nodoc: for now
javascript_options = options_for_ajax(options)
update = []
update = ''
if options[:update] and options[:update].is_a?Hash
update = []
update << "success:'#{options[:update][:success]}'" if options[:update][:success]
update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
update = '{' + update.join(',') + '}'
elsif options[:update]
update << "success:'#{options[:update]}'"
update << "'#{options[:update]}'"
end
function = update.empty? ?
"new Ajax.Request(" :
"new Ajax.Updater({#{update.join(',')}}, "
"new Ajax.Updater(#{update}, "
function << "'#{url_for(options[:url])}'"
function << ", #{javascript_options})"
......
......@@ -265,7 +265,8 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({
initialize: function(container, url, options) {
this.containers = {
success: container.success ? $(container.success) : $(container),
failure: container.failure ? $(container.failure) : $(container)
failure: container.failure ? $(container.failure) :
(container.success ? null : $(container))
}
this.setOptions(options);
......@@ -836,7 +837,7 @@ Object.extend(Event, {
KEY_DELETE: 46,
element: function(event) {
return event.srcElement || event.currentTarget;
return event.target || event.srcElement;
},
isLeftClick: function(event) {
......
......@@ -41,17 +41,23 @@ def test_link_to_remote
end
def test_periodically_call_remote
assert_equal %(<script>new PeriodicalExecuter(function() {new Ajax.Updater({success:'schremser_bier'}, 'http://www.example.com/mehr_bier', {evalScripts:true, asynchronous:true})}, 10)</script>),
assert_equal %(<script>new PeriodicalExecuter(function() {new Ajax.Updater('schremser_bier', 'http://www.example.com/mehr_bier', {evalScripts:true, asynchronous:true})}, 10)</script>),
periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })
end
def test_form_remote_tag
assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast })
assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast })
assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_water'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
form_remote_tag(:update => { :failure => "glass_of_water" }, :url => { :action => :fast })
assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
form_remote_tag(:update => { :success => 'glass_of_beer', :failure => "glass_of_water" }, :url => { :action => :fast })
end
def test_submit_to_remote
assert_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater({success:'empty_bottle'}, 'http://www.example.com/', {parameters:Form.serialize(this.form), evalScripts:true, asynchronous:true}); return false;\" type=\"button\" value=\"1000000\" />),
assert_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {parameters:Form.serialize(this.form), evalScripts:true, asynchronous:true}); return false;\" type=\"button\" value=\"1000000\" />),
submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle")
end
......@@ -110,7 +116,7 @@ def test_drop_receiving_element
drop_receiving_element('droptarget1')
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Request('http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}, accept:'products'})</script>),
drop_receiving_element('droptarget1', :accept => 'products')
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Updater({success:'infobox'}, 'http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}, accept:'products'})</script>),
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}, accept:'products'})</script>),
drop_receiving_element('droptarget1', :accept => 'products', :update => 'infobox')
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册