Annotation of todotxt/Text-Todo-REST-API/example/htdocs/lib/todo.js, Revision 1.1
1.1 ! andrew 1: var TODO = function () {
! 2: var base_url = '/~andrew/user-bin/todo.cgi',
! 3: editors = {},
! 4:
! 5: makeEntryEditor = function(list, entry) {
! 6: var url = base_url + '/' + list + '/entry/' + entry.line,
! 7: id = entry.id;
! 8:
! 9: if (!id) {
! 10: id = 'entry_' + entry.line;
! 11: }
! 12:
! 13: if (editors[id]) {
! 14: editors[id].dispose();
! 15: delete editors[id];
! 16: }
! 17:
! 18: editors[id] = new Ajax.InPlaceEditor( id, url + '.json', {
! 19: cols: 80,
! 20: rows: 1,
! 21: callback: function(form, value) {
! 22: entry.oldText = entry.text;
! 23: entry.text = value;
! 24: return entry;
! 25: },
! 26: onComplete: function (transport, element) {
! 27: if (transport && transport.responseJSON) {
! 28: updateEntry( list, transport.responseJSON, element);
! 29: }
! 30: }
! 31: }
! 32: );
! 33: },
! 34:
! 35: updateEntry = function(list, entry, element) {
! 36: if (!entry.id) {
! 37: entry.id = 'entry_' + entry.line;
! 38: }
! 39: var liId = 'li_' + entry.id;
! 40:
! 41: if (parseInt(entry.line) !== $(liId).value) {
! 42: for (k in editors) {
! 43: if (editors.hasOwnProperty(k)) {
! 44: editors[k].dispose();
! 45: delete editors[k];
! 46: }
! 47: }
! 48: return getList(list);
! 49: }
! 50:
! 51: $(liId).update(
! 52: new Element('span', { id: entry.id }). update(entry.text)
! 53: ).insert({
! 54: top: new Element('input', {
! 55: type: 'checkbox' ,
! 56: id: 'do_' + entry.line,
! 57: checked: entry.done,
! 58: disabled: true,
! 59: })
! 60: });
! 61:
! 62: makeEntryEditor(list, entry);
! 63: },
! 64:
! 65: updateList = function (list, transport) {
! 66: var i,
! 67: todo = transport.responseJSON,
! 68: element = new Element('ol'),
! 69: entryElement;
! 70:
! 71: $("list").update( element );
! 72:
! 73: for (i=0; i <= todo.length; i++) {
! 74: todo[i].id = 'entry_' + todo[i].line;
! 75:
! 76: entryElement = new Element('li', {
! 77: id: 'li_' + todo[i].id,
! 78: value: todo[i].line
! 79: });
! 80:
! 81: element.insert(entryElement);
! 82:
! 83: updateEntry(list, todo[i], entryElement);
! 84: }
! 85: },
! 86:
! 87: getFiles = function () {
! 88: $('files').update("Getting Files . . .");
! 89:
! 90: new Ajax.Updater('files', base_url, {
! 91: method: 'get',
! 92: });
! 93: },
! 94:
! 95: getTags = function (list) {
! 96: $('tags').update("Getting Tags. . .");
! 97:
! 98: var url = base_url + '/' + list + '/tags';
! 99:
! 100: new Ajax.Request(url + '.json', {
! 101: method: 'get',
! 102: onSuccess: function (transport) {
! 103: var k,
! 104: data = transport.responseJSON,
! 105: element = new Element('ul');
! 106:
! 107: $("tags").update(element);
! 108: for (k in data) {
! 109: if (data.hasOwnProperty(k)) {
! 110: element.insert(
! 111: new Element('li', {
! 112: id: 'tag_' + k,
! 113: }).update( k + ": " + data[k] )
! 114: );
! 115: getTag(list, k);
! 116: }
! 117: }
! 118: },
! 119: });
! 120: },
! 121:
! 122: getTag = function( list, tag ) {
! 123: new Ajax.Request(base_url + '/' + list + '/tags/' + tag + '.json', {
! 124: method: 'get',
! 125: onSuccess: function (transport) {
! 126: if (transport && transport.responseJSON) {
! 127: var i,
! 128: myTags = transport.responseJSON,
! 129: element = new Element('ul');
! 130:
! 131: if (myTags.length) {
! 132: $('tag_' + tag).insert(element);
! 133:
! 134: for (i=0; i<myTags.length; i++) {
! 135: element.insert( new Element('li').
! 136: update( myTags[i] ));
! 137: }
! 138: }
! 139: }
! 140: }
! 141: });
! 142: },
! 143:
! 144: getList = function (list) {
! 145: $('list').update("Getting List . . .");
! 146:
! 147: new Ajax.Request(base_url + '/' + list + '.json', {
! 148: method: 'get',
! 149: onSuccess: function (transport) { updateList(list, transport) },
! 150: });
! 151:
! 152: };
! 153:
! 154: return {
! 155: getList: getList,
! 156: getFiles: getFiles,
! 157: getTags: getTags,
! 158: };
! 159: }();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>