Wednesday, October 12th, 2005

Autosave and Undo

Category: Dojo, Editorial

Cristian Vidmar wrote a brief posting on taking care of users with autosave.

He talks about how to implement this in iframe and XHR:

  • The AJAX way. Start a timer on the BODY load. At every iteration get the value property of the editing textarea and fire it through an XmlHttpRequest to a server-side saveDraft API method.
  • The degraded way. Include an invisible IFRAME in your editor’s page. Have it load a page that has a timered form post. Include a JS function that at loading stage of the iframe’s page fills a hidden INPUT with the value property of the editing textarea. When the timered form posts, use the target server script to save the draft.

I wonder if a toolkit such as Dojo could give us a nice clean Undo framework, as well as Autosave so we can simply define the hooks.

Posted by Dion Almaer at 3:52 pm
1 Comment

+++--
3.5 rating from 8 votes

1 Comment »

Comments feed

Assuming you design your Ajax client app with the MVC pattern, undo operations ought be relatively straightforward. The key would be cloning your model objects.

Cloning in JavaScript is pretty easy (walk the object hierarchy, duplicating objects and properties as you go). The only tricky bit is dealing with circular references.

Once you have cloning, you can keep a queue of the previous states of your model, and each undo/redo operations would move you up and down in the queue. Using MVC, redraw your view based on the current model state.

With MVC, the only logic you really need is the cloning logic and a queue of model states. Without MVC, undo/redo is going to be very ugly, and I doubt any amount of framework code will make it workable.

Comment by Paul Strack — October 12, 2005

Leave a comment

You must be logged in to post a comment.