From c87220a67f5c5a69be0e6ff41b3bc2a2ba113b35 Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Sun, 25 May 2008 18:10:48 +0000 Subject: Nicer display of attachments in Futon. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@660007 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/browse.js | 88 +++++++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 25 deletions(-) (limited to 'share/www/script') diff --git a/share/www/script/browse.js b/share/www/script/browse.js index ebf3916f..4491246b 100644 --- a/share/www/script/browse.js +++ b/share/www/script/browse.js @@ -40,10 +40,10 @@ function CouchIndexPage() { $(document.body).addClass("loading"); $.couch.allDbs({ success: function(dbs) { - if(dbs.length == 0) { + if (dbs.length == 0) { $(document.body).removeClass("loading"); } - + $.each(dbs, function(idx, dbName) { $("#databases tbody.content").append("" + "" + @@ -505,6 +505,19 @@ function CouchDocumentPage() { _editKey(page.doc, row.find("th"), fieldName); } + var _sortFields = function(a, b) { + var a0 = a.charAt(0), b0 = b.charAt(0); + if (a0 == "_" && b0 != "_") { + return -1; + } else if (a0 != "_" && b0 == "_") { + return 1; + } else if (a == "_attachments" || b == "_attachments") { + return a0 == "_attachments" ? 1 : -1; + } else { + return a < b ? -1 : a != b ? 1 : 0; + } + } + this.updateFieldListing = function() { $(document.body).addClass("loading"); $("#fields tbody.content").empty(); @@ -517,16 +530,7 @@ function CouchDocumentPage() { propNames.push(prop); } // Order properties alphabetically, but put internal fields first - propNames.sort(function(a, b) { - var a0 = a.charAt(0), b0 = b.charAt(0); - if (a0 == "_" && b0 != "_") { - return -1; - } else if (a0 != "_" && b0 == "_") { - return 1; - } else { - return a < b ? -1 : a != b ? 1 : 0; - } - }); + propNames.sort(_sortFields); for (var pi = 0; pi < propNames.length; pi++) { _addRowForField(doc, propNames[pi]); } @@ -609,20 +613,27 @@ function CouchDocumentPage() { } function _addRowForField(doc, fieldName) { - var value = _renderValue(doc[fieldName]); - var row = $("") - .find("th").append($("").text(fieldName)).dblclick(function() { - _editKey(doc, this, $(this).text()); - }).end() - .find("td").append(value).dblclick(function() { - _editValue(doc, this, $(this).prev("th").text()); - }).end() - .appendTo("#fields tbody.content"); - if (fieldName != "_id" && fieldName != "_rev") { - row.find("th, td").attr("title", "Double click to edit"); - _initKey(doc, row, fieldName); - _initValue(value); + var row = $("").find("th").append($("").text(fieldName)).end(); + if (fieldName == "_attachments") { + row + .find("td").append(_renderAttachmentList(doc[fieldName])); + } else { + var value = _renderValue(doc[fieldName]); + row + .find("th b").dblclick(function() { + _editKey(doc, this, $(this).text()); + }).end() + .find("td").append(value).dblclick(function() { + _editValue(doc, this, $(this).prev("th").text()); + }).end() + + if (fieldName != "_id" && fieldName != "_rev") { + row.find("th, td").attr("title", "Double click to edit"); + _initKey(doc, row, fieldName); + _initValue(value); + } } + row.appendTo("#fields tbody.content"); $("#fields tbody tr").removeClass("odd").filter(":odd").addClass("odd"); return row; } @@ -766,4 +777,31 @@ function CouchDocumentPage() { } } + function _renderAttachmentList(attachments) { + var ul = $("").addClass("attachments"); + $.each(attachments, function(idx, attachment) { + _renderAttachmentItem(idx, attachment).appendTo(ul); + }); + return ul; + } + + function _renderAttachmentItem(name, attachment) { + var li = $("
  • "); + $("
    ").text(name) + .attr("href", db.uri + encodeURIComponent(docId) + "/" + encodeURIComponent(name)) + .wrapInner("").appendTo(li); + $("()").text("" + prettyPrintSize(attachment.length) + + ", " + attachment["content-type"]).addClass("info").appendTo(li); + _initAttachmentItem(name, attachment, li); + return li; + } + + function _initAttachmentItem(name, attachment, li) { + $("").click(function() { + delete page.doc._attachments[name]; + li.remove(); + page.isDirty = true; + }).prependTo($("a", li)); + } + } -- cgit v1.2.3