Ticket #9513: remove_in_place_editing.patch
| File remove_in_place_editing.patch, 10.8 kB (added by lifofifo, 10 months ago) |
|---|
-
actionpack/test/template/java_script_macros_helper_test.rb
old new 64 64 text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true) 65 65 end 66 66 67 def test_in_place_editor_external_control68 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>),69 in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :external_control => 'blah'})70 end71 72 def test_in_place_editor_size73 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>),74 in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :size => 4})75 end76 77 def test_in_place_editor_cols_no_rows78 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>),79 in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :cols => 4})80 end81 82 def test_in_place_editor_cols_with_rows83 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>),84 in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :rows => 5, :cols => 40})85 end86 87 def test_inplace_editor_loading_text88 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>),89 in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :loading_text => 'Why are we waiting?'})90 end91 92 def test_in_place_editor_url93 assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value')",94 in_place_editor( 'id-goes-here', :url => { :action => "action_to_set_value" })95 end96 97 def test_in_place_editor_load_text_url98 assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value', {loadTextURL:'http://www.example.com/action_to_get_value'})",99 in_place_editor( 'id-goes-here',100 :url => { :action => "action_to_set_value" },101 :load_text_url => { :action => "action_to_get_value" })102 end103 104 def test_in_place_editor_eval_scripts105 assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value', {evalScripts:true})",106 in_place_editor( 'id-goes-here',107 :url => { :action => "action_to_set_value" },108 :script => true )109 end110 111 67 end -
actionpack/lib/action_controller/macros/in_place_editing.rb
old new 1 module ActionController2 module Macros3 module InPlaceEditing #:nodoc:4 def self.included(base) #:nodoc:5 base.extend(ClassMethods)6 end7 8 # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships.9 #10 # Example:11 #12 # # Controller13 # class BlogController < ApplicationController14 # in_place_edit_for :post, :title15 # end16 #17 # # View18 # <%= in_place_editor_field :post, 'title' %>19 #20 # For help on defining an in place editor in the browser,21 # see ActionView::Helpers::JavaScriptHelper.22 module ClassMethods23 def in_place_edit_for(object, attribute, options = {})24 define_method("set_#{object}_#{attribute}") do25 @item = object.to_s.camelize.constantize.find(params[:id])26 @item.update_attribute(attribute, params[:value])27 render :text => @item.send(attribute)28 end29 end30 end31 end32 end33 end -
actionpack/lib/action_controller.rb
old new 55 55 require 'action_controller/components' 56 56 require 'action_controller/record_identifier' 57 57 require 'action_controller/macros/auto_complete' 58 require 'action_controller/macros/in_place_editing'59 58 60 59 require 'action_view' 61 60 ActionController::Base.template_class = ActionView::Base … … 77 76 include ActionController::Components 78 77 include ActionController::RecordIdentifier 79 78 include ActionController::Macros::AutoComplete 80 include ActionController::Macros::InPlaceEditing81 79 end -
actionpack/lib/action_view/helpers/java_script_macros_helper.rb
old new 6 6 # larger units. These macros also rely on counterparts in the controller that provide them with their backing. The in-place 7 7 # editing relies on ActionController::Base.in_place_edit_for and the autocompletion relies on 8 8 # ActionController::Base.auto_complete_for. 9 module JavaScriptMacrosHelper 9 module JavaScriptMacrosHelper 10 10 # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships. 11 11 # 12 # Makes an HTML element specified by the DOM ID +field_id+ become an in-place13 # editor of a property.14 #15 # A form is automatically created and displayed when the user clicks the element,16 # something like this:17 # <form id="myElement-in-place-edit-form" target="specified url">18 # <input name="value" text="The content of myElement"/>19 # <input type="submit" value="ok"/>20 # <a onclick="javascript to cancel the editing">cancel</a>21 # </form>22 #23 # The form is serialized and sent to the server using an AJAX call, the action on24 # the server should process the value and return the updated value in the body of25 # the reponse. The element will automatically be updated with the changed value26 # (as returned from the server).27 #28 # Required +options+ are:29 # <tt>:url</tt>:: Specifies the url where the updated value should30 # be sent after the user presses "ok".31 #32 # Addtional +options+ are:33 # <tt>:rows</tt>:: Number of rows (more than 1 will use a TEXTAREA)34 # <tt>:cols</tt>:: Number of characters the text input should span (works for both INPUT and TEXTAREA)35 # <tt>:size</tt>:: Synonym for :cols when using a single line text input.36 # <tt>:cancel_text</tt>:: The text on the cancel link. (default: "cancel")37 # <tt>:save_text</tt>:: The text on the save link. (default: "ok")38 # <tt>:loading_text</tt>:: The text to display while the data is being loaded from the server (default: "Loading...")39 # <tt>:saving_text</tt>:: The text to display when submitting to the server (default: "Saving...")40 # <tt>:external_control</tt>:: The id of an external control used to enter edit mode.41 # <tt>:load_text_url</tt>:: URL where initial value of editor (content) is retrieved.42 # <tt>:options</tt>:: Pass through options to the AJAX call (see prototype's Ajax.Updater)43 # <tt>:with</tt>:: JavaScript snippet that should return what is to be sent44 # in the AJAX call, +form+ is an implicit parameter45 # <tt>:script</tt>:: Instructs the in-place editor to evaluate the remote JavaScript response (default: false)46 # <tt>:click_to_edit_text</tt>::The text shown during mouseover the editable text (default: "Click to edit")47 def in_place_editor(field_id, options = {})48 function = "new Ajax.InPlaceEditor("49 function << "'#{field_id}', "50 function << "'#{url_for(options[:url])}'"51 52 js_options = {}53 js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text]54 js_options['okText'] = %('#{options[:save_text]}') if options[:save_text]55 js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text]56 js_options['savingText'] = %('#{options[:saving_text]}') if options[:saving_text]57 js_options['rows'] = options[:rows] if options[:rows]58 js_options['cols'] = options[:cols] if options[:cols]59 js_options['size'] = options[:size] if options[:size]60 js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control]61 js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url]62 js_options['ajaxOptions'] = options[:options] if options[:options]63 js_options['evalScripts'] = options[:script] if options[:script]64 js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with]65 js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text]66 function << (', ' + options_for_javascript(js_options)) unless js_options.empty?67 68 function << ')'69 70 javascript_tag(function)71 end72 73 # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships.74 #75 # Renders the value of the specified object and method with in-place editing capabilities.76 #77 # See the RDoc on ActionController::InPlaceEditing to learn more about this.78 def in_place_editor_field(object, method, tag_options = {}, in_place_editor_options = {})79 tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)80 tag_options = {:tag => "span", :id => "#{object}_#{method}_#{tag.object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!(tag_options)81 in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id })82 tag.to_content_tag(tag_options.delete(:tag), tag_options) +83 in_place_editor(tag_options[:id], in_place_editor_options)84 end85 86 # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships.87 #88 12 # Adds AJAX autocomplete functionality to the text input field with the 89 13 # DOM ID specified by +field_id+. 90 14 #