=================================================================== RCS file: /cvs/todotxt/Text-Todo-REST-API/example/htdocs/index.html,v retrieving revision 1.10 retrieving revision 1.12 diff -u -r1.10 -r1.12 --- todotxt/Text-Todo-REST-API/example/htdocs/index.html 2010/02/17 02:16:28 1.10 +++ 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 @@ -9,106 +9,162 @@ var TODO = function () { var base_url = '/~andrew/user-bin/todo.cgi', - editors = {}, + editors = {}, - makeEntryEditor = function(id, list_url) { - var url = list_url + '/entry/' + id; + makeEntryEditor = function(list, entry) { + var url = base_url + '/' + list + '/entry/' + entry.line, + id = entry.id; - if (!editors[id]) { - editors[id] = { - list_url: list_url, - editor: new Ajax.InPlaceEditor( - id, url + '.json', { - cols: 80, - rows: 1, - onComplete: updateEntry, - } - ), - }; + if (!id) { + id = 'entry_' + entry.line; } - }, - updateEntry = function(transport, element) { - var list_url = editors[element.id].list_url, - entry; + if (editors[id]) { + editors[id].dispose(); + delete editors[id]; + } - 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]; + 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); + } } + } + ); + }, - element.id = entry.md5; + updateEntry = function(list, entry, element) { + if (!entry.id) { + entry.id = 'entry_' + entry.line; + } + var liId = 'li_' + entry.id; - makeEntryEditor(element.id, list_url); + if (parseInt(entry.line) !== $(liId).value) { + for (k in editors) { + if (editors.hasOwnProperty(k)) { + 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_url, transport) { - var i, + updateList = function (list, transport) { + var i, todo = transport.responseJSON, - url = ''; + element = new Element('ol'), + entryElement; - $("list").update(); + $("list").update( element ); for (i=0; i <= todo.length; i++) { - $('list').insert({ - bottom: new Element('div', - { id: todo[i].md5 } - ).update(todo[i].text) - } - ); + todo[i].id = 'entry_' + todo[i].line; - makeEntryEditor(todo[i].md5, list_url); + entryElement = new Element('li', { + id: 'li_' + todo[i].id, + value: todo[i].line + }); + + element.insert(entryElement); + + updateEntry(list, todo[i], entryElement); } - }; + }, - return { - getFiles: function () { - $('files').update("Getting Files . . ."); + getFiles = function () { + $('files').update("Getting Files . . ."); - new Ajax.Updater('files', base_url, { - method: 'get', - }); - }, + new Ajax.Updater('files', base_url, { + method: 'get', + }); + }, - getTags: function (list) { - var url = base_url + '/' + list + '/tags'; - $('tags').update("Getting Tags. . ."); + getTags = function (list) { + $('tags').update("Getting Tags. . ."); - new Ajax.Request(url + '.json', { - method: 'get', - onSuccess: function (transport) { - var data = transport.responseJSON, - k, - html = ''; - for (k in data) { - if (data.hasOwnProperty(k)) { - html += k + ": " + data[k] + "
\n"; + var url = base_url + '/' + list + '/tags'; + + new Ajax.Request(url + '.json', { + method: 'get', + onSuccess: function (transport) { + var k, + data = transport.responseJSON, + element = new Element('ul'); + + $("tags").update(element); + for (k in data) { + if (data.hasOwnProperty(k)) { + element.insert( + new Element('li', { + id: 'tag_' + k, + }).update( k + ": " + data[k] ) + ); + getTag(list, k); + } + } + }, + }); + }, + + getTag = function( list, tag ) { + new Ajax.Request(base_url + '/' + list + '/tags/' + tag + '.json', { + method: 'get', + onSuccess: function (transport) { + if (transport && transport.responseJSON) { + var i, + myTags = transport.responseJSON, + element = new Element('ul'); + + if (myTags.length) { + $('tag_' + tag).insert(element); + + for (i=0; i @@ -116,6 +172,6 @@

Files:

-

Tags:

List:

+

Tags: