In-Place Editing (without Ajax.InPlaceEditor()!)
Now that each terminal Scalar
has
a DIV
section with a unique id
, we can do something with that id
. Our users need to double-click on a DIV
, edit its contents in a little editor, and
submit the contents to the server, which will emend this page's YAML file.
To do all that, the server needs to know which page we have, and which
node we clicked.
Our users need to edit YAML nodes as raw text, not as raw YAML markup. Our users don't want to worry about all the quotes, escapes, and line breaks that delimit YAML text. Engineers like that stuff more than civilians. If we can provide a system to in-place edit those nodes, our "Onsite Customers" can edit their contents for us.
Curiously, despite the fact that Rails provides wrappers for
Script.aculo.us's mighty Ajax.InPlaceEditor()
, we can't use them.
Adjusting them to work without a Model would be more difficult than
installing a simpler Script.aculo.us system, Ajax.Updater()
.
To get some Script.aculo.us JavaScript modules, add this line to our
index.rhtml
:
<%= javascript_include_tag(:defaults) %>
The ondblclick
event needs to
call Ajax.Updater()
, so our next test
queries this out of the DIV
, and looks
at its contents:
def test_ondblclick yaml_to_xhtml(get_omap) hammy_id = 'node:test_hammy_squirrel:script' assert_xpath "//div[ @id = '#{hammy_id}' ]" do |div| assert_equal hammy_id, div.attributes['id'] ondblclick = div.attributes['ondblclick'] puts ondblclick assert_match /new Ajax.Updater\("#{hammy_id}"/, ...
Get Test Driven Ajax (on Rails) now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.