couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r660007 - in /incubator/couchdb/trunk/share/www: script/browse.js style/layout.css
Date Sun, 25 May 2008 18:10:49 GMT
Author: cmlenz
Date: Sun May 25 11:10:48 2008
New Revision: 660007

URL: http://svn.apache.org/viewvc?rev=660007&view=rev
Log:
Nicer display of attachments in Futon.

Modified:
    incubator/couchdb/trunk/share/www/script/browse.js
    incubator/couchdb/trunk/share/www/style/layout.css

Modified: incubator/couchdb/trunk/share/www/script/browse.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/browse.js?rev=660007&r1=660006&r2=660007&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/browse.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/browse.js [utf-8] Sun May 25 11:10:48 2008
@@ -40,10 +40,10 @@
     $(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("<tr>" + 
             "<th><a href='database.html?" + encodeURIComponent(dbName) + "'>"
+
@@ -505,6 +505,19 @@
     _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 @@
         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 _addRowForField(doc, fieldName) {
-    var value = _renderValue(doc[fieldName]);
-    var row = $("<tr><th></th><td></td></tr>")
-      .find("th").append($("<b></b>").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 = $("<tr><th></th><td></td></tr>").find("th").append($("<b></b>").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 _renderAttachmentList(attachments) {
+    var ul = $("<ul></ul>").addClass("attachments");
+    $.each(attachments, function(idx, attachment) {
+      _renderAttachmentItem(idx, attachment).appendTo(ul);
+    });
+    return ul;
+  }
+
+  function _renderAttachmentItem(name, attachment) {
+    var li = $("<li></li>");
+    $("<a href='' title='Download file' target='_top'></a>").text(name)
+      .attr("href", db.uri + encodeURIComponent(docId) + "/" + encodeURIComponent(name))
+      .wrapInner("<tt></tt>").appendTo(li);
+    $("<span>()</span>").text("" + prettyPrintSize(attachment.length) + 
+      ", " + attachment["content-type"]).addClass("info").appendTo(li);
+    _initAttachmentItem(name, attachment, li);
+    return li;
+  }
+
+  function _initAttachmentItem(name, attachment, li) {
+    $("<button type='button' class='delete' title='Delete attachment'></button>").click(function()
{
+      delete page.doc._attachments[name];
+      li.remove();
+      page.isDirty = true;
+    }).prependTo($("a", li));
+  }
+
 }

Modified: incubator/couchdb/trunk/share/www/style/layout.css
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/style/layout.css?rev=660007&r1=660006&r2=660007&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/style/layout.css (original)
+++ incubator/couchdb/trunk/share/www/style/layout.css Sun May 25 11:10:48 2008
@@ -380,6 +380,28 @@
 }
 #fields tbody.content div.error { color: #d33; }
 
+#fields tbody.content td ul.attachments { list-style: none; margin: 0;
+  padding: 0;
+}
+#fields tbody.content td ul.attachments li {
+  margin-bottom: .3em; min-height: 20px; padding-left: 20px;
+}
+#fields tbody.content td ul.attachments tt { font-size: 95%; }
+#fields tbody.content td ul.attachments li span.info { color: #666;
+  display: block; font-size: 95%;
+}
+#fields tbody.content td ul.attachments li button {
+  background: transparent no-repeat; border: none; cursor: pointer;
+  float: left; margin: 0 2px 0 -20px; padding: 0; width: 15px; height: 15px;
+  vertical-align: middle;
+}
+#fields tbody.content td ul.attachments li button:hover {
+  background-position: -15px 0;
+}
+#fields tbody.content td ul.attachments li button.delete {
+  background-image: url(../image/delete-mini.gif);
+}
+
 /* Test suite */
 
 #tests { table-layout: fixed; }



Mime
View raw message