Skip to content
This repository
Browse code

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 authored February 21, 2006
2  actionpack/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Added various InPlaceEditor options, #3746, #3891, #3896, #3906 [Bill Burcham, ruairi, sl33p3r]
  4
+
3 5
 * 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]
4 6
 
5 7
 * Update script.aculo.us to V1.5.2 [Thomas Fuchs]
20  actionpack/lib/action_view/helpers/java_script_macros_helper.rb
@@ -12,11 +12,11 @@ module JavaScriptMacrosHelper
12 12
       #
13 13
       # A form is automatically created and displayed when the user clicks the element,
14 14
       # something like this:
15  
-      # <form id="myElement-in-place-edit-form" target="specified url">
16  
-      #   <input name="value" text="The content of myElement"/>
17  
-      #   <input type="submit" value="ok"/>
18  
-      #   <a onclick="javascript to cancel the editing">cancel</a>
19  
-      # </form>
  15
+      #   <form id="myElement-in-place-edit-form" target="specified url">
  16
+      #     <input name="value" text="The content of myElement"/>
  17
+      #     <input type="submit" value="ok"/>
  18
+      #     <a onclick="javascript to cancel the editing">cancel</a>
  19
+      #   </form>
20 20
       # 
21 21
       # The form is serialized and sent to the server using an AJAX call, the action on
22 22
       # the server should process the value and return the updated value in the body of
@@ -29,9 +29,13 @@ module JavaScriptMacrosHelper
29 29
       # 
30 30
       # Addtional +options+ are:
31 31
       # <tt>:rows</tt>::              Number of rows (more than 1 will use a TEXTAREA)
  32
+      # <tt>:cols</tt>::              Number of characters the text input should span (works for both INPUT and TEXTAREA)
  33
+      # <tt>:size</tt>::              Synonym for :cols when using a single line text input.
32 34
       # <tt>:cancel_text</tt>::       The text on the cancel link. (default: "cancel")
33 35
       # <tt>:save_text</tt>::         The text on the save link. (default: "ok")
  36
+      # <tt>:loading_text</tt>::      The text to display when submitting to the server (default: "Saving...")
34 37
       # <tt>:external_control</tt>::  The id of an external control used to enter edit mode.
  38
+      # <tt>:load_text_url</tt>::     URL where initial value of editor (content) is retrieved.
35 39
       # <tt>:options</tt>::           Pass through options to the AJAX call (see prototype's Ajax.Updater)
36 40
       # <tt>:with</tt>::              JavaScript snippet that should return what is to be sent
37 41
       #                               in the AJAX call, +form+ is an implicit parameter
@@ -43,8 +47,12 @@ def in_place_editor(field_id, options = {})
43 47
         js_options = {}
44 48
         js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text]
45 49
         js_options['okText'] = %('#{options[:save_text]}') if options[:save_text]
  50
+        js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text]
46 51
         js_options['rows'] = options[:rows] if options[:rows]
47  
-        js_options['externalControl'] = options[:external_control] if options[:external_control]
  52
+        js_options['cols'] = options[:cols] if options[:cols]
  53
+        js_options['size'] = options[:size] if options[:size]
  54
+        js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control]
  55
+        js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url]        
48 56
         js_options['ajaxOptions'] = options[:options] if options[:options]
49 57
         js_options['callback']   = "function(form) { return #{options[:with]} }" if options[:with]
50 58
         function << (', ' + options_for_javascript(js_options)) unless js_options.empty?
38  actionpack/test/template/java_script_macros_helper_test.rb
@@ -53,4 +53,42 @@ def test_text_field_with_auto_complete
53 53
     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>),
54 54
       text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
55 55
   end
  56
+  
  57
+  def test_in_place_editor_external_control
  58
+      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>),
  59
+        in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :external_control => 'blah'})
  60
+  end
  61
+  
  62
+  def test_in_place_editor_size
  63
+      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>),
  64
+        in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :size => 4})
  65
+  end
  66
+  
  67
+  def test_in_place_editor_cols_no_rows
  68
+      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>),
  69
+        in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :cols => 4})
  70
+  end
  71
+  
  72
+  def test_in_place_editor_cols_with_rows
  73
+      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>),
  74
+        in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :rows => 5, :cols => 40})
  75
+  end
  76
+
  77
+  def test_inplace_editor_loading_text
  78
+      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>),
  79
+        in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :loading_text => 'Why are we waiting?'})
  80
+  end
  81
+  
  82
+  def test_in_place_editor_url
  83
+    assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value')",
  84
+    in_place_editor( 'id-goes-here', :url => { :action => "action_to_set_value" })    
  85
+  end
  86
+  
  87
+  def test_in_place_editor_load_text_url
  88
+    assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value', {loadTextURL:'http://www.example.com/action_to_get_value'})",
  89
+    in_place_editor( 'id-goes-here', 
  90
+      :url => { :action => "action_to_set_value" }, 
  91
+      :load_text_url => { :action => "action_to_get_value" })
  92
+  end
  93
+  
56 94
 end

0 notes on commit 523d54b

Please sign in to comment.
Something went wrong with that request. Please try again.