From 3255308650e1d3496870b2df963bc1c440ce87ca Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Tue, 30 Dec 2008 03:08:08 +0000 Subject: Futon supports pretty slashes for design docs and attachment paths git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@730038 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/browse.js | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'share') diff --git a/share/www/script/browse.js b/share/www/script/browse.js index 1417a96b..ed6b7882 100644 --- a/share/www/script/browse.js +++ b/share/www/script/browse.js @@ -127,7 +127,7 @@ function CouchDatabasePage() { }, success: function(resp) { location.href = "document.html?" + encodeURIComponent(dbName) + - "/" + encodeURIComponent(resp.id); + "/" + encodeDocId(resp.id); } }); } @@ -325,7 +325,7 @@ function CouchDatabasePage() { callback(); page.isDirty = false; location.href = "database.html?" + encodeURIComponent(dbName) + - "/" + encodeURIComponent(doc._id) + + "/" + encodeDocId(doc._id) + "/" + encodeURIComponent(data.name); } }); @@ -370,7 +370,7 @@ function CouchDatabasePage() { 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 @@ function CouchDatabasePage() { var key = row.key; if (row.id) { $("
" + + "/" + encodeDocId(row.id) + "'>
" + "ID: " + row.id + "
") .find("strong").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end() .appendTo(tr); @@ -604,12 +604,12 @@ function CouchDocumentPage() { 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 @@ function CouchDocumentPage() { 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 @@ function CouchDocumentPage() { success: function(resp) { page.isDirty = false; location.href = "?" + encodeURIComponent(dbName) + - "/" + encodeURIComponent(docId); + "/" + encodeDocId(docId); } }); } @@ -682,12 +682,12 @@ function CouchDocumentPage() { 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 CouchDocumentPage() { } function _renderAttachmentItem(name, attachment) { - var attachmentHref = db.uri + encodeURIComponent(docId) - + "/" + encodeURIComponent(name); + var attachmentHref = db.uri + encodeDocId(docId) + + "/" + encodeAttachment(name); var li = $("
  • "); $("").text(name) .attr("href", attachmentHref) @@ -898,5 +898,25 @@ function CouchDocumentPage() { 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 -- cgit v1.2.3