diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 33365721893c21131e14f5836b15582a9c22e622..f010044e7c7baab1c51a2ea78d6fd5203482c2a8 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added various InPlaceEditor options, #3746, #3891, #3896, #3906 [Bill Burcham, ruairi, sl33p3r] + * Added :count option to pagination that'll make it possible for the ActiveRecord::Base.count call to using something else than * for the count. Especially important for count queries using DISTINCT #3839 [skaes] * Update script.aculo.us to V1.5.2 [Thomas Fuchs] diff --git a/actionpack/lib/action_view/helpers/java_script_macros_helper.rb b/actionpack/lib/action_view/helpers/java_script_macros_helper.rb index 5641d55bc8e03424a82976787775cce6a722425b..4237909f1da6428c270a03d070b3c736b750c617 100644 --- a/actionpack/lib/action_view/helpers/java_script_macros_helper.rb +++ b/actionpack/lib/action_view/helpers/java_script_macros_helper.rb @@ -12,11 +12,11 @@ module JavaScriptMacrosHelper # # A form is automatically created and displayed when the user clicks the element, # something like this: - #
- # - # - # cancel - #
+ #
+ # + # + # cancel + #
# # The form is serialized and sent to the server using an AJAX call, the action on # the server should process the value and return the updated value in the body of @@ -29,9 +29,13 @@ module JavaScriptMacrosHelper # # Addtional +options+ are: # :rows:: Number of rows (more than 1 will use a TEXTAREA) + # :cols:: Number of characters the text input should span (works for both INPUT and TEXTAREA) + # :size:: Synonym for :cols when using a single line text input. # :cancel_text:: The text on the cancel link. (default: "cancel") # :save_text:: The text on the save link. (default: "ok") + # :loading_text:: The text to display when submitting to the server (default: "Saving...") # :external_control:: The id of an external control used to enter edit mode. + # :load_text_url:: URL where initial value of editor (content) is retrieved. # :options:: Pass through options to the AJAX call (see prototype's Ajax.Updater) # :with:: JavaScript snippet that should return what is to be sent # in the AJAX call, +form+ is an implicit parameter @@ -43,8 +47,12 @@ def in_place_editor(field_id, options = {}) js_options = {} js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text] js_options['okText'] = %('#{options[:save_text]}') if options[:save_text] + js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text] js_options['rows'] = options[:rows] if options[:rows] - js_options['externalControl'] = options[:external_control] if options[:external_control] + js_options['cols'] = options[:cols] if options[:cols] + js_options['size'] = options[:size] if options[:size] + js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control] + js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url] js_options['ajaxOptions'] = options[:options] if options[:options] js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with] function << (', ' + options_for_javascript(js_options)) unless js_options.empty? diff --git a/actionpack/test/template/java_script_macros_helper_test.rb b/actionpack/test/template/java_script_macros_helper_test.rb index ae3069ccb57b2d7b45a540605689704ec6d465f8..1a18c00e726e4d140f61d210c75f33ab0e990126 100644 --- a/actionpack/test/template/java_script_macros_helper_test.rb +++ b/actionpack/test/template/java_script_macros_helper_test.rb @@ -53,4 +53,42 @@ def test_text_field_with_auto_complete assert_dom_equal %(
), text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true) end + + def test_in_place_editor_external_control + assert_dom_equal %(), + in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :external_control => 'blah'}) + end + + def test_in_place_editor_size + assert_dom_equal %(), + in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :size => 4}) + end + + def test_in_place_editor_cols_no_rows + assert_dom_equal %(), + in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :cols => 4}) + end + + def test_in_place_editor_cols_with_rows + assert_dom_equal %(), + in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :rows => 5, :cols => 40}) + end + + def test_inplace_editor_loading_text + assert_dom_equal %(), + in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :loading_text => 'Why are we waiting?'}) + end + + def test_in_place_editor_url + assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value')", + in_place_editor( 'id-goes-here', :url => { :action => "action_to_set_value" }) + end + + def test_in_place_editor_load_text_url + assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value', {loadTextURL:'http://www.example.com/action_to_get_value'})", + in_place_editor( 'id-goes-here', + :url => { :action => "action_to_set_value" }, + :load_text_url => { :action => "action_to_get_value" }) + end + end