Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8299: fix_confirmation_for_drop_receiving_element.diff

File fix_confirmation_for_drop_receiving_element.diff, 2.1 kB (added by thechrisoshow, 9 months ago)

This patch file ensures that the :confirm option works without having to supply extra quotes on the drop_receiving_element helper

  • actionpack/test/template/scriptaculous_helper_test.rb

    old new  
    8888      drop_receiving_element("droptarget1", :accept => 'products', :update => 'infobox') 
    8989    assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>), 
    9090      drop_receiving_element("droptarget1", :accept => ['tshirts','mugs'], :update => 'infobox') 
     91    assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add("droptarget1", {hoverclass:'dropready', onDrop:function(element){if (confirm('Are you sure?')) { new Ajax.Request('http://www.example.com/update_drop', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)}); }}})\n//]]>\n</script>), 
     92    drop_receiving_element('droptarget1', :hoverclass=>'dropready', :url=>{:action=>'update_drop'}, :confirm => 'Are you sure?') 
     93     
    9194  end 
    92  
    9395  def protect_against_forgery? 
    9496    false 
    9597  end 
  • actionpack/lib/action_view/helpers/scriptaculous_helper.rb

    old new  
    192192        options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]     
    193193        options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass] 
    194194         
     195        # Confirmation happens during the onDrop callback, so it can be removed from the options 
     196        options.delete(:confirm) if options[:confirm] 
     197         
    195198        %(Droppables.add(#{element_id.to_json}, #{options_for_javascript(options)});) 
    196199      end 
    197200    end