couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r730038 - /couchdb/trunk/share/www/script/browse.js
Date Tue, 30 Dec 2008 03:08:08 GMT
Author: jchris
Date: Mon Dec 29 19:08:08 2008
New Revision: 730038

URL: http://svn.apache.org/viewvc?rev=730038&view=rev
Log:
Futon supports pretty slashes for design docs and attachment paths

Modified:
    couchdb/trunk/share/www/script/browse.js

Modified: couchdb/trunk/share/www/script/browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/browse.js?rev=730038&r1=730037&r2=730038&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/browse.js [utf-8] Mon Dec 29 19:08:08 2008
@@ -127,7 +127,7 @@
           },
           success: function(resp) {
             location.href = "document.html?" + encodeURIComponent(dbName) +
-                            "/" + encodeURIComponent(resp.id);
+                            "/" + encodeDocId(resp.id);
           }
         });
       }
@@ -325,7 +325,7 @@
                 callback();
                 page.isDirty = false;
                 location.href = "database.html?" + encodeURIComponent(dbName) +
-                  "/" + encodeURIComponent(doc._id) +
+                  "/" + encodeDocId(doc._id) +
                   "/" + encodeURIComponent(data.name);
               }
             });
@@ -370,7 +370,7 @@
     if (viewName && /^_design/.test(viewName)) {
       var docId = "_design/" + viewName.split("/")[1];
       $("#designdoc-link").attr("href", "document.html?" +
-        encodeURIComponent(dbName) + "/" + encodeURIComponent(docId)).text(docId);
+        encodeURIComponent(dbName) + "/" + encodeDocId(docId)).text(docId);
     } else {
       $("#designdoc-link").removeAttr("href").text("");
     }
@@ -446,7 +446,7 @@
         var key = row.key;
         if (row.id) {
           $("<td class='key'><a href='document.html?" + encodeURIComponent(db.name)
+
-            "/" + encodeURIComponent(row.id) + "'><strong></strong><br>"
+
+            "/" + encodeDocId(row.id) + "'><strong></strong><br>" +
             "<span class='docid'>ID:&nbsp;" + row.id + "</span></a></td>")
             .find("strong").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end()
             .appendTo(tr);
@@ -604,12 +604,12 @@
         if (currentIndex < revs.length - 1) {
           var prevRev = revs[currentIndex + 1].rev;
           $("#paging a.prev").attr("href", "?" + encodeURIComponent(dbName) +
-            "/" + encodeURIComponent(docId) + "@" + prevRev);
+            "/" + encodeDocId(docId) + "@" + prevRev);
         }
         if (currentIndex > 0) {
           var nextRev = revs[currentIndex - 1].rev;
           $("#paging a.next").attr("href", "?" + encodeURIComponent(dbName) +
-            "/" + encodeURIComponent(docId) + "@" + nextRev);
+            "/" + encodeDocId(docId) + "@" + nextRev);
         }
         $("#fields tbody.footer td span").text("Showing revision " +
           (revs.length - currentIndex) + " of " + revs.length);
@@ -627,7 +627,7 @@
               alert("The requested revision was not found. " +
                     "You will be redirected back to the latest revision.");
               location.href = "?" + encodeURIComponent(dbName) +
-                "/" + encodeURIComponent(docId);
+                "/" + encodeDocId(docId);
             },
             success: function(doc) {
               handleResult(doc, revs);
@@ -659,7 +659,7 @@
       success: function(resp) {
         page.isDirty = false;
         location.href = "?" + encodeURIComponent(dbName) +
-          "/" + encodeURIComponent(docId);
+          "/" + encodeDocId(docId);
       }
     });
   }
@@ -682,12 +682,12 @@
         var form = $("#upload-form");
         form.find("#progress").css("visibility", "visible");
         form.ajaxSubmit({
-          url: db.uri + encodeURIComponent(page.docId),
+          url: db.uri + encodeDocId(page.docId),
           success: function(resp) {
             form.find("#progress").css("visibility", "hidden");
             page.isDirty = false;
             location.href = "?" + encodeURIComponent(dbName) +
-              "/" + encodeURIComponent(docId);
+              "/" + encodeDocId(docId);
           }
         });
       }
@@ -874,8 +874,8 @@
   }
 
   function _renderAttachmentItem(name, attachment) {
-    var attachmentHref = db.uri + encodeURIComponent(docId) 
-      + "/" + encodeURIComponent(name);
+    var attachmentHref = db.uri + encodeDocId(docId) 
+      + "/" + encodeAttachment(name);
     var li = $("<li></li>");
     $("<a href='' title='Download file' target='_top'></a>").text(name)
       .attr("href", attachmentHref)
@@ -898,5 +898,25 @@
       return false;
     }).prependTo($("a", li));
   }
-
 }
+
+// Ideally these would be module-private. Maybe there's a helper they can go on.
+
+function encodeDocId(docid) {
+  var encoded, parts = docid.split('/');
+  if (parts[0] == '_design') {
+    parts.shift();
+    encoded = encodeURIComponent(parts.join('/'));
+    return '_design/'+encoded;
+  } else {
+    return encodeURIComponent(docid);
+  }
+};
+
+function encodeAttachment(name) {
+  var encoded = [], parts = name.split('/');
+  for (var i=0; i < parts.length; i++) {
+    encoded.push(encodeURIComponent(parts[i]));
+  };
+  return encoded.join('/');
+}
\ No newline at end of file



Mime
View raw message