Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added various InPlaceEditor options, #3746, #3891, #3896, #3906

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3626 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 523d54b56d612a791f16468ae3776ac12fd71bb7 1 parent 7a2ce50
Thomas Fuchs madrobby authored
2  actionpack/CHANGELOG
View
@@ -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]
20 actionpack/lib/action_view/helpers/java_script_macros_helper.rb
View
@@ -12,11 +12,11 @@ module JavaScriptMacrosHelper
#
# 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 JavaScriptMacrosHelper
#
# 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 @@ 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?
38 actionpack/test/template/java_script_macros_helper_test.rb
View
@@ -53,4 +53,42 @@ def test_text_field_with_auto_complete
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
Please sign in to comment.
Something went wrong with that request. Please try again.