Imagine the following situation - say you've got a set of documents which are all children of one container document. From within this parent container document you want to be able to quickly change the order in which the child documents appear. Sound familiar? It's a scenario I've come across a couple of times before and only now have I found a solution I'm happy with enough to share.
A Real-World Scenario
Let's use the example of a newsletter document. In this case the parent form is called something like newsletter and simply contains the title and date of the newsletter. Once saved we can add the child news item document to it. It's these news items that it would be nice to be able to sort as the author pleases.
In most cases news would be sorted by date/time. However with newsletter this is not always the case and so being able to adjust the order is a must in most cases. Whether or not you need to compile newsletters there's bound to be a scenario where the following technique would come in handy.
How to Sort Documents
The idea for the technique came to me both out of a necessity to develop it and from the inspiration I took from a demo of the Yahoo! UI Library, where they have a cross-browser sortable list.
Support
ass
Coding
Flesh-out the following items:
Notes:
Turned off conflicts in child form.
Mention inclusion of hidden text field in each LI element for use when no Ajax (although not in Safari, where order of fields is not reflected after re-sort)
Demo
Available here
Downloads
Most up to date database is Version 0.5
Version 0.5 fixes a problem in all previous versions described in this blog entry and also up
grades to Prototype 1.5 and Scriptaculous 1.7.
Version 0.1 uses the Yahoo! UI Library instead of Script.aculo.us and does NO T use Ajax. Horses for courses.
Taking It Further
Rep conflicts are a problem. How about having the Ajax call check the last-mod dates. Or with XML
Summary
Put summary here
Is using Ajax a good idea?
Copyright © 2000 - 2024 Jake Howlett of Rockall Design ltd. This article was printed from codestore.net