From 2807ccc69a54805e3914bcc21716f9bafbebef39 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 10 Sep 2007 00:53:13 +0000 Subject: Moved ActionController::Macros::InPlaceEditing into the in_place_editor plugin on the official Rails svn (closes #9513) [lifofifo] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7442 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 + actionpack/lib/action_controller.rb | 2 - .../action_controller/macros/in_place_editing.rb | 33 --------- .../helpers/java_script_macros_helper.rb | 78 +--------------------- .../template/java_script_macros_helper_test.rb | 44 ------------ 5 files changed, 3 insertions(+), 156 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index dd5de62a67..99482b8090 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Moved ActionController::Macros::InPlaceEditing into the in_place_editor plugin on the official Rails svn #9513 [lifofifo] + * Removed deprecated form of calling xml_http_request/xhr without the first argument being the http verb [DHH] * Removed deprecated methods [DHH]: diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 5f67d3ebcc..10c8591b51 100755 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -55,7 +55,6 @@ require 'action_controller/http_authentication' require 'action_controller/components' require 'action_controller/record_identifier' require 'action_controller/macros/auto_complete' -require 'action_controller/macros/in_place_editing' require 'action_view' ActionController::Base.template_class = ActionView::Base @@ -77,5 +76,4 @@ ActionController::Base.class_eval do include ActionController::Components include ActionController::RecordIdentifier include ActionController::Macros::AutoComplete - include ActionController::Macros::InPlaceEditing end diff --git a/actionpack/lib/action_controller/macros/in_place_editing.rb b/actionpack/lib/action_controller/macros/in_place_editing.rb index d04f1ce1de..e69de29bb2 100644 --- a/actionpack/lib/action_controller/macros/in_place_editing.rb +++ b/actionpack/lib/action_controller/macros/in_place_editing.rb @@ -1,33 +0,0 @@ -module ActionController - module Macros - module InPlaceEditing #:nodoc: - def self.included(base) #:nodoc: - base.extend(ClassMethods) - end - - # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships. - # - # Example: - # - # # Controller - # class BlogController < ApplicationController - # in_place_edit_for :post, :title - # end - # - # # View - # <%= in_place_editor_field :post, 'title' %> - # - # For help on defining an in place editor in the browser, - # see ActionView::Helpers::JavaScriptHelper. - module ClassMethods - def in_place_edit_for(object, attribute, options = {}) - define_method("set_#{object}_#{attribute}") do - @item = object.to_s.camelize.constantize.find(params[:id]) - @item.update_attribute(attribute, params[:value]) - render :text => @item.send(attribute) - end - end - end - end - end -end 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 d346f0367c..2109478909 100644 --- a/actionpack/lib/action_view/helpers/java_script_macros_helper.rb +++ b/actionpack/lib/action_view/helpers/java_script_macros_helper.rb @@ -6,83 +6,7 @@ module ActionView # larger units. These macros also rely on counterparts in the controller that provide them with their backing. The in-place # editing relies on ActionController::Base.in_place_edit_for and the autocompletion relies on # ActionController::Base.auto_complete_for. - module JavaScriptMacrosHelper - # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships. - # - # Makes an HTML element specified by the DOM ID +field_id+ become an in-place - # editor of a property. - # - # A form is automatically created and displayed when the user clicks the element, - # something like this: - #
- # - # - # 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 - # the reponse. The element will automatically be updated with the changed value - # (as returned from the server). - # - # Required +options+ are: - # :url:: Specifies the url where the updated value should - # be sent after the user presses "ok". - # - # 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 while the data is being loaded from the server (default: "Loading...") - # :saving_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 - # :script:: Instructs the in-place editor to evaluate the remote JavaScript response (default: false) - # :click_to_edit_text::The text shown during mouseover the editable text (default: "Click to edit") - def in_place_editor(field_id, options = {}) - function = "new Ajax.InPlaceEditor(" - function << "'#{field_id}', " - function << "'#{url_for(options[:url])}'" - - 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['savingText'] = %('#{options[:saving_text]}') if options[:saving_text] - js_options['rows'] = options[:rows] if options[:rows] - 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['evalScripts'] = options[:script] if options[:script] - js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with] - js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text] - function << (', ' + options_for_javascript(js_options)) unless js_options.empty? - - function << ')' - - javascript_tag(function) - end - - # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships. - # - # Renders the value of the specified object and method with in-place editing capabilities. - # - # See the RDoc on ActionController::InPlaceEditing to learn more about this. - def in_place_editor_field(object, method, tag_options = {}, in_place_editor_options = {}) - tag = ::ActionView::Helpers::InstanceTag.new(object, method, self) - tag_options = {:tag => "span", :id => "#{object}_#{method}_#{tag.object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!(tag_options) - in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id }) - tag.to_content_tag(tag_options.delete(:tag), tag_options) + - in_place_editor(tag_options[:id], in_place_editor_options) - end - + module JavaScriptMacrosHelper # DEPRECATION WARNING: This method will become a separate plugin when Rails 2.0 ships. # # Adds AJAX autocomplete functionality to the text input field with the diff --git a/actionpack/test/template/java_script_macros_helper_test.rb b/actionpack/test/template/java_script_macros_helper_test.rb index 961f12cf32..bba851e9a6 100644 --- a/actionpack/test/template/java_script_macros_helper_test.rb +++ b/actionpack/test/template/java_script_macros_helper_test.rb @@ -64,48 +64,4 @@ class JavaScriptMacrosHelperTest < Test::Unit::TestCase 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 - - def test_in_place_editor_eval_scripts - assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value', {evalScripts:true})", - in_place_editor( 'id-goes-here', - :url => { :action => "action_to_set_value" }, - :script => true ) - end - end -- cgit v1.2.3