===================================================================
RCS file: /cvs/todotxt/Text-Todo-REST-API/example/htdocs/index.html,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- todotxt/Text-Todo-REST-API/example/htdocs/index.html 2010/02/16 03:45:17 1.9
+++ todotxt/Text-Todo-REST-API/example/htdocs/index.html 2010/02/17 02:16:28 1.10
@@ -1,5 +1,5 @@
-
+
todo.txt - ajax client
@@ -9,28 +9,63 @@
var TODO = function () {
var base_url = '/~andrew/user-bin/todo.cgi',
+ editors = {},
+
+ makeEntryEditor = function(id, list_url) {
+ var url = list_url + '/entry/' + id;
- updateList = function (list, transport) {
+ if (!editors[id]) {
+ editors[id] = {
+ list_url: list_url,
+ editor: new Ajax.InPlaceEditor(
+ id, url + '.json', {
+ cols: 80,
+ rows: 1,
+ onComplete: updateEntry,
+ }
+ ),
+ };
+ }
+ },
+
+ updateEntry = function(transport, element) {
+ var list_url = editors[element.id].list_url,
+ entry;
+
+ if (transport && transport.responseJSON) {
+ entry = transport.responseJSON;
+
+ element.update(entry.text);
+
+ if (element.id !== entry.md5) {
+ if (editors[element.id]) {
+ editors[element.id].editor.dispose();
+ delete editors[element.id];
+ }
+
+ element.id = entry.md5;
+
+ makeEntryEditor(element.id, list_url);
+ }
+ }
+ },
+
+ updateList = function (list_url, transport) {
var i,
todo = transport.responseJSON,
- url = '';
+ url = '';
- $('list').update('');
+ $("list").update();
for (i=0; i <= todo.length; i++) {
$('list').insert({
- bottom: new Element('div', {
- id: todo[i].md5,
- }).update(todo[i].text),
- });
+ bottom: new Element('div',
+ { id: todo[i].md5 }
+ ).update(todo[i].text)
+ }
+ );
- url = base_url + '/' + list + '/entry/' + todo[i].md5;
-
- new Ajax.InPlaceEditor(todo[i].md5, url + '.json', {
- cols: 80,
- loadTextURL: url + '.txt',
- //getText: function () {},
- });
+ makeEntryEditor(todo[i].md5, list_url);
}
};
@@ -68,10 +103,8 @@
$('list').update("Getting List . . .");
new Ajax.Request(url + '.json', {
- method: 'get',
- onSuccess: function (transport) {
- updateList(list, transport)
- },
+ method: 'get',
+ onSuccess: function (transport) { updateList(url, transport) },
});
},