aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/java_script_macros_helper.rb20
-rw-r--r--actionpack/test/template/java_script_macros_helper_test.rb38
3 files changed, 54 insertions, 6 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 3336572189..f010044e7c 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 5641d55bc8..4237909f1d 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 ActionView
#
# A form is automatically created and displayed when the user clicks the element,
# something like this:
- # <form id="myElement-in-place-edit-form" target="specified url">
- # <input name="value" text="The content of myElement"/>
- # <input type="submit" value="ok"/>
- # <a onclick="javascript to cancel the editing">cancel</a>
- # </form>
+ # <form id="myElement-in-place-edit-form" target="specified url">
+ # <input name="value" text="The content of myElement"/>
+ # <input type="submit" value="ok"/>
+ # <a onclick="javascript to cancel the editing">cancel</a>
+ # </form>
#
# 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 ActionView
#
# Addtional +options+ are:
# <tt>:rows</tt>:: Number of rows (more than 1 will use a TEXTAREA)
+ # <tt>:cols</tt>:: Number of characters the text input should span (works for both INPUT and TEXTAREA)
+ # <tt>:size</tt>:: Synonym for :cols when using a single line text input.
# <tt>:cancel_text</tt>:: The text on the cancel link. (default: "cancel")
# <tt>:save_text</tt>:: The text on the save link. (default: "ok")
+ # <tt>:loading_text</tt>:: The text to display when submitting to the server (default: "Saving...")
# <tt>:external_control</tt>:: The id of an external control used to enter edit mode.
+ # <tt>:load_text_url</tt>:: URL where initial value of editor (content) is retrieved.
# <tt>:options</tt>:: Pass through options to the AJAX call (see prototype's Ajax.Updater)
# <tt>:with</tt>:: JavaScript snippet that should return what is to be sent
# in the AJAX call, +form+ is an implicit parameter
@@ -43,8 +47,12 @@ module ActionView
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 ae3069ccb5..1a18c00e72 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 @@ class JavaScriptMacrosHelperTest < Test::Unit::TestCase
assert_dom_equal %(<input id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">\n//<![CDATA[\nvar message_recipient_auto_completer = new Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})\n//]]>\n</script>),
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
end
+
+ def test_in_place_editor_external_control
+ assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {externalControl:'blah'})\n//]]>\n</script>),
+ in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :external_control => 'blah'})
+ end
+
+ def test_in_place_editor_size
+ assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {size:4})\n//]]>\n</script>),
+ in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :size => 4})
+ end
+
+ def test_in_place_editor_cols_no_rows
+ assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {cols:4})\n//]]>\n</script>),
+ in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :cols => 4})
+ end
+
+ def test_in_place_editor_cols_with_rows
+ assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {cols:40, rows:5})\n//]]>\n</script>),
+ in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :rows => 5, :cols => 40})
+ end
+
+ def test_inplace_editor_loading_text
+ assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {loadingText:'Why are we waiting?'})\n//]]>\n</script>),
+ 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