Annotation of todotxt/Text-Todo-REST-API/example/htdocs/index.html, Revision 1.10
1.2 andrew 1: <html><head>
1.10 ! andrew 2: <!-- $AFresh1: index.html,v 1.9 2010/02/16 03:45:17 andrew Exp $ -->
1.7 andrew 3: <title>todo.txt - ajax client</title>
4: <link rel="stylesheet" href="todo.css">
1.9 andrew 5:
1.7 andrew 6: <script src="scriptaculous/lib/prototype.js"></script>
7: <script src="scriptaculous/src/scriptaculous.js?load=effects,controls"></script>
1.2 andrew 8: <script type='text/javascript'>
1.4 andrew 9:
1.9 andrew 10: var TODO = function () {
11: var base_url = '/~andrew/user-bin/todo.cgi',
1.10 ! andrew 12: editors = {},
! 13:
! 14: makeEntryEditor = function(id, list_url) {
! 15: var url = list_url + '/entry/' + id;
! 16:
! 17: if (!editors[id]) {
! 18: editors[id] = {
! 19: list_url: list_url,
! 20: editor: new Ajax.InPlaceEditor(
! 21: id, url + '.json', {
! 22: cols: 80,
! 23: rows: 1,
! 24: onComplete: updateEntry,
! 25: }
! 26: ),
! 27: };
! 28: }
! 29: },
! 30:
! 31: updateEntry = function(transport, element) {
! 32: var list_url = editors[element.id].list_url,
! 33: entry;
! 34:
! 35: if (transport && transport.responseJSON) {
! 36: entry = transport.responseJSON;
1.9 andrew 37:
1.10 ! andrew 38: element.update(entry.text);
! 39:
! 40: if (element.id !== entry.md5) {
! 41: if (editors[element.id]) {
! 42: editors[element.id].editor.dispose();
! 43: delete editors[element.id];
! 44: }
! 45:
! 46: element.id = entry.md5;
! 47:
! 48: makeEntryEditor(element.id, list_url);
! 49: }
! 50: }
! 51: },
! 52:
! 53: updateList = function (list_url, transport) {
1.9 andrew 54: var i,
55: todo = transport.responseJSON,
1.10 ! andrew 56: url = '';
1.9 andrew 57:
1.10 ! andrew 58: $("list").update();
1.9 andrew 59:
60: for (i=0; i <= todo.length; i++) {
61: $('list').insert({
1.10 ! andrew 62: bottom: new Element('div',
! 63: { id: todo[i].md5 }
! 64: ).update(todo[i].text)
! 65: }
! 66: );
1.9 andrew 67:
1.10 ! andrew 68: makeEntryEditor(todo[i].md5, list_url);
1.9 andrew 69: }
70: };
71:
72: return {
73: getFiles: function () {
74: $('files').update("Getting Files . . .");
75:
76: new Ajax.Updater('files', base_url, {
77: method: 'get',
78: });
79: },
80:
81: getTags: function (list) {
82: var url = base_url + '/' + list + '/tags';
83: $('tags').update("Getting Tags. . .");
84:
85: new Ajax.Request(url + '.json', {
86: method: 'get',
87: onSuccess: function (transport) {
88: var data = transport.responseJSON,
89: k,
90: html = '';
91: for (k in data) {
92: if (data.hasOwnProperty(k)) {
93: html += k + ": " + data[k] + "<br/>\n";
94: }
95: }
96: $("tags").innerHTML = html;
97: },
98: });
99: },
100:
101: getList: function (list) {
102: var url = base_url + '/' + list;
103: $('list').update("Getting List . . .");
104:
105: new Ajax.Request(url + '.json', {
1.10 ! andrew 106: method: 'get',
! 107: onSuccess: function (transport) { updateList(url, transport) },
1.9 andrew 108: });
109:
110: },
111: };
112: }();
1.7 andrew 113:
1.2 andrew 114: </script>
115: </head>
1.6 andrew 116:
1.9 andrew 117: <body onLoad="TODO.getList('todo');TODO.getTags('todo');TODO.getFiles()">
1.7 andrew 118: <h1>Files:</h1><div id='files'></div>
1.9 andrew 119: <h1>Tags:</h1> <div id='tags'></div>
1.7 andrew 120: <h1>List:</h1> <div id='list'></div>
1.1 andrew 121: </body></html>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>