===================================================================
RCS file: /cvs/todotxt/Text-Todo-REST-API/example/htdocs/index.html,v
retrieving revision 1.9
retrieving revision 1.12
diff -u -r1.9 -r1.12
--- 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 06:25:31 1.12
@@ -1,5 +1,5 @@
-
+
todo.txt - ajax client
@@ -9,73 +9,162 @@
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 (!id) {
+ id = 'entry_' + entry.line;
+ }
+
+ 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(list, entry, element) {
+ if (!entry.id) {
+ entry.id = 'entry_' + entry.line;
+ }
+ var liId = 'li_' + entry.id;
+
+ 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, transport) {
- var i,
+ 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;
+
+ entryElement = new Element('li', {
+ id: 'li_' + todo[i].id,
+ value: todo[i].line
});
- url = base_url + '/' + list + '/entry/' + todo[i].md5;
+ element.insert(entryElement);
- new Ajax.InPlaceEditor(todo[i].md5, url + '.json', {
- cols: 80,
- loadTextURL: url + '.txt',
- //getText: function () {},
- });
+ 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
@@ -83,6 +172,6 @@
Files:
- Tags:
List:
+ Tags: