===================================================================
RCS file: /cvs/todotxt/Text-Todo-REST-API/example/htdocs/index.html,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- todotxt/Text-Todo-REST-API/example/htdocs/index.html 2010/02/18 05:35:04 1.11
+++ todotxt/Text-Todo-REST-API/example/htdocs/index.html 2010/02/18 06:25:31 1.12
@@ -1,5 +1,5 @@
-
+
todo.txt - ajax client
@@ -15,65 +15,81 @@
var url = base_url + '/' + list + '/entry/' + entry.line,
id = entry.id;
- if (editors[id]) {
- editors[id].editor.dispose();
- delete editors[id];
- }
+ if (!id) {
+ id = 'entry_' + entry.line;
+ }
- editors[id] = {
- list: list,
- editor: new Ajax.InPlaceEditor(
- id, url + '.json', {
- cols: 80,
- rows: 1,
- callback: function(form, value) {
- entry.oldText = entry.text;
- entry.text = value;
- return entry;
- },
- onComplete: function (transport, element) {
- if (transport && transport.responseJSON) {
- updateEntry(transport.responseJSON, element);
- }
+ if (editors[id]) {
+ editors[id].dispose();
+ delete editors[id];
+ }
+
+ editors[id] = new Ajax.InPlaceEditor( id, url + '.json', {
+ cols: 80,
+ rows: 1,
+ callback: function(form, value) {
+ entry.oldText = entry.text;
+ entry.text = value;
+ return entry;
+ },
+ onComplete: function (transport, element) {
+ if (transport && transport.responseJSON) {
+ updateEntry( list, transport.responseJSON, element);
}
}
- ),
- };
+ }
+ );
},
- updateEntry = function(entry, element) {
- var list = editors[element.id].list;
+ updateEntry = function(list, entry, element) {
+ if (!entry.id) {
+ entry.id = 'entry_' + entry.line;
+ }
+ var liId = 'li_' + entry.id;
- element.update(entry.text);
-
- if (parseInt(entry.line) !== element.value) {
+ if (parseInt(entry.line) !== $(liId).value) {
for (k in editors) {
if (editors.hasOwnProperty(k)) {
- editors[k].editor.dispose();
+ editors[k].dispose();
delete editors[k];
}
}
return getList(list);
}
+
+ $(liId).update(
+ new Element('span', { id: entry.id }). update(entry.text)
+ ).insert({
+ top: new Element('input', {
+ type: 'checkbox' ,
+ id: 'do_' + entry.line,
+ checked: entry.done,
+ disabled: true,
+ })
+ });
+
+ makeEntryEditor(list, entry);
},
updateList = function (list, transport) {
var i,
todo = transport.responseJSON,
- element = new Element('ol');
+ element = new Element('ol'),
+ entryElement;
$("list").update( element );
for (i=0; i <= todo.length; i++) {
todo[i].id = 'entry_' + todo[i].line;
- element.insert( new Element('li', {
- id: 'entry_' + todo[i].line,
- value: todo[i].line
- }).update(todo[i].text)
- );
+ entryElement = new Element('li', {
+ id: 'li_' + todo[i].id,
+ value: todo[i].line
+ });
- makeEntryEditor(list, todo[i]);
+ element.insert(entryElement);
+
+ updateEntry(list, todo[i], entryElement);
}
},