===================================================================
RCS file: /cvs/todotxt/Text-Todo-REST-API/example/htdocs/index.html,v
retrieving revision 1.9
retrieving revision 1.11
diff -u -r1.9 -r1.11
--- 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/18 05:35:04 1.11
@@ -1,5 +1,5 @@
-
+
todo.txt - ajax client
@@ -9,73 +9,146 @@
var TODO = function () {
var base_url = '/~andrew/user-bin/todo.cgi',
+ editors = {},
+
+ makeEntryEditor = function(list, entry) {
+ var url = base_url + '/' + list + '/entry/' + entry.line,
+ id = entry.id;
+ if (editors[id]) {
+ editors[id].editor.dispose();
+ delete editors[id];
+ }
+
+ 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);
+ }
+ }
+ }
+ ),
+ };
+ },
+
+ updateEntry = function(entry, element) {
+ var list = editors[element.id].list;
+
+ element.update(entry.text);
+
+ if (parseInt(entry.line) !== element.value) {
+ for (k in editors) {
+ if (editors.hasOwnProperty(k)) {
+ editors[k].editor.dispose();
+ delete editors[k];
+ }
+ }
+ return getList(list);
+ }
+ },
+
updateList = function (list, transport) {
- var i,
+ var i,
todo = transport.responseJSON,
- url = '';
+ element = new Element('ol');
- $('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;
- url = base_url + '/' + list + '/entry/' + todo[i].md5;
+ element.insert( new Element('li', {
+ id: 'entry_' + todo[i].line,
+ value: todo[i].line
+ }).update(todo[i].text)
+ );
- new Ajax.InPlaceEditor(todo[i].md5, url + '.json', {
- cols: 80,
- loadTextURL: url + '.txt',
- //getText: function () {},
- });
+ makeEntryEditor(list, todo[i]);
}
- };
+ },
- 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
@@ -83,6 +156,6 @@
Files:
- Tags:
List:
+ Tags: