===================================================================
RCS file: /cvs/todotxt/Text-Todo-REST-API/example/htdocs/index.html,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- 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 05:35:04 1.11
@@ -1,5 +1,5 @@
-
+
todo.txt - ajax client
@@ -9,106 +9,146 @@
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 (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(transport, element) {
- var list_url = editors[element.id].list_url,
- entry;
+ updateEntry = function(entry, element) {
+ var list = editors[element.id].list;
- if (transport && transport.responseJSON) {
- entry = transport.responseJSON;
+ element.update(entry.text);
- element.update(entry.text);
-
- if (element.id !== entry.md5) {
- if (editors[element.id]) {
- editors[element.id].editor.dispose();
- delete editors[element.id];
+ if (parseInt(entry.line) !== element.value) {
+ for (k in editors) {
+ if (editors.hasOwnProperty(k)) {
+ editors[k].editor.dispose();
+ delete editors[k];
}
-
- element.id = entry.md5;
-
- makeEntryEditor(element.id, list_url);
}
+ return getList(list);
}
},
- updateList = function (list_url, transport) {
- var i,
+ updateList = function (list, transport) {
+ 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;
+
+ element.insert( new Element('li', {
+ id: 'entry_' + todo[i].line,
+ value: todo[i].line
+ }).update(todo[i].text)
);
- makeEntryEditor(todo[i].md5, list_url);
+ 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
@@ -116,6 +156,6 @@
Files:
- Tags:
List:
+ Tags: