Module: InPlaceMacrosHelper
- Included in:
- InPlaceEditingTest
- Defined in:
- lib/six-updater-web/vendor/plugins/in_place_editing/lib/in_place_macros_helper.rb
Instance Method Summary collapse
-
#in_place_editor(field_id, options = {}) ⇒ Object
Makes an HTML element specified by the DOM ID
field_id
become an in-place editor of a property. -
#in_place_editor_field(object, method, tag_options = {}, in_place_editor_options = {}) ⇒ Object
Renders the value of the specified object and method with in-place editing capabilities.
Instance Method Details
#in_place_editor(field_id, options = {}) ⇒ Object
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:
<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 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”)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/six-updater-web/vendor/plugins/in_place_editing/lib/in_place_macros_helper.rb', line 38 def in_place_editor(field_id, = {}) function = "new Ajax.InPlaceEditor(" function << "'#{field_id}', " function << "'#{url_for([:url])}'" = {} if protect_against_forgery? [:with] ||= "Form.serialize(form)" [:with] += " + '&authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')" end ['cancelText'] = %('#{[:cancel_text]}') if [:cancel_text] ['okText'] = %('#{[:save_text]}') if [:save_text] ['loadingText'] = %('#{[:loading_text]}') if [:loading_text] ['savingText'] = %('#{[:saving_text]}') if [:saving_text] ['rows'] = [:rows] if [:rows] ['cols'] = [:cols] if [:cols] ['size'] = [:size] if [:size] ['externalControl'] = "'#{[:external_control]}'" if [:external_control] ['loadTextURL'] = "'#{url_for([:load_text_url])}'" if [:load_text_url] ['ajaxOptions'] = [:options] if [:options] ['htmlResponse'] = ![:script] if [:script] ['callback'] = "function(form) { return #{[:with]} }" if [:with] ['clickToEditText'] = %('#{[:click_to_edit_text]}') if [:click_to_edit_text] ['textBetweenControls'] = %('#{[:text_between_controls]}') if [:text_between_controls] function << (', ' + ()) unless .empty? function << ')' javascript_tag(function).force_encoding("utf-8") # TODO: Only on Ruby 1.9! end |
#in_place_editor_field(object, method, tag_options = {}, in_place_editor_options = {}) ⇒ Object
Renders the value of the specified object and method with in-place editing capabilities.
72 73 74 75 76 77 78 79 80 |
# File 'lib/six-updater-web/vendor/plugins/in_place_editing/lib/in_place_macros_helper.rb', line 72 def in_place_editor_field(object, method, = {}, = {}) instance_tag = ::ActionView::Helpers::InstanceTag.new(object, method, self) = {:tag => "span", :id => "#{object}_#{method}_#{instance_tag.object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!() [:url] = [:url] || url_for({ :action => "set_#{object}_#{method}", :id => instance_tag.object.id }) tag = content_tag(.delete(:tag), h(instance_tag.value(instance_tag.object)),) return (tag + in_place_editor([:id], )).force_encoding("utf-8") # TODO: Only on Ruby 1.9! end |