summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2009-07-21 21:16:56 +0000
committerChristopher Lenz <cmlenz@apache.org>2009-07-21 21:16:56 +0000
commit4fa38ad4e4245f27776b4269634a98212bbae3e8 (patch)
tree15c354c16f33c31df257c7bff79f54249b47ab72 /share
parent1ddff48dbb8f18d3bde189477827164528a8d938 (diff)
Fix for compatibility of Futon with design documents that have slashes in the document ID or a view name. Closes COUCHDB-408 (again).
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@796541 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share')
-rw-r--r--share/www/script/futon.browse.js64
-rw-r--r--share/www/script/jquery.couch.js18
2 files changed, 41 insertions, 41 deletions
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js
index 6aeb14f3..e9a6ff98 100644
--- a/share/www/script/futon.browse.js
+++ b/share/www/script/futon.browse.js
@@ -97,7 +97,6 @@
var dbName = decodeURIComponent(urlParts.shift());
var viewName = (urlParts.length > 0) ? urlParts.join("/") : null;
if (viewName) {
- viewName = decodeURIComponent(viewName);
$.cookies.set(dbName + ".view", viewName);
} else {
viewName = $.cookies.get(dbName + ".view", "");
@@ -132,7 +131,7 @@
},
success: function(resp) {
location.href = "document.html?" + encodeURIComponent(dbName) +
- "/" + encodeDocId(resp.id);
+ "/" + $.couch.encodeDocId(resp.id);
}
});
}
@@ -206,7 +205,7 @@
$.cookies.get(db.name + ".map", templates[page.viewLanguage]),
$.cookies.get(db.name + ".reduce", "")
);
- $("#grouptruenotice").show();
+ $("#grouptruenotice").show();
}
page.populateLanguagesMenu();
if (this.isTempView) {
@@ -257,11 +256,11 @@
var optGroup = $(document.createElement("optgroup"))
.attr("label", doc._id.substr(8)).appendTo(select);
for (var name in doc.views) {
+ var path = $.couch.encodeDocId(doc._id) + "/_view/" +
+ encodeURIComponent(name);
var option = $(document.createElement("option"))
- .attr("value", encodeURIComponent(doc._id) + "/_view/" +
- encodeURIComponent(name)).text(name)
- .appendTo(optGroup);
- if (doc._id + "/_view/" + name == viewName) {
+ .attr("value", path).text(name).appendTo(optGroup);
+ if (path == viewName) {
option[0].selected = true;
}
}
@@ -282,9 +281,9 @@
this.revertViewChanges = function(callback) {
if (!page.storedViewCode) {
var viewNameParts = viewName.split("/");
- var designDocId = viewNameParts[1];
- var localViewName = viewNameParts[3];
- db.openDoc(["_design", designDocId].join("/"), {
+ var designDocId = decodeURIComponent(viewNameParts[1]);
+ var localViewName = decodeURIComponent(viewNameParts[3]);
+ db.openDoc("_design/" + designDocId, {
error: function(status, error, reason) {
if (status == 404) {
$.cookies.remove(dbName + ".view");
@@ -331,8 +330,8 @@
this.saveViewAs = function() {
if (viewName && /^_design/.test(viewName)) {
var viewNameParts = viewName.split("/");
- var designDocId = viewNameParts[1];
- var localViewName = viewNameParts[3];
+ var designDocId = decodeURIComponent(viewNameParts[1]);
+ var localViewName = decodeURIComponent(viewNameParts[3]);
} else {
var designDocId = "", localViewName = "";
}
@@ -406,7 +405,7 @@
callback();
page.isDirty = false;
location.href = "database.html?" + encodeURIComponent(dbName) +
- "/" + encodeDocId(doc._id) +
+ "/" + $.couch.encodeDocId(doc._id) +
"/_view/" + encodeURIComponent(data.name);
}
});
@@ -427,9 +426,9 @@
this.saveViewChanges = function() {
var viewNameParts = viewName.split("/");
- var designDocId = viewNameParts[1];
- var localViewName = viewNameParts[3];
- db.openDoc(["_design", designDocId].join("/"), {
+ var designDocId = decodeURIComponent(viewNameParts[1]);
+ var localViewName = decodeURIComponent(viewNameParts[3]);
+ db.openDoc("_design/" + designDocId, {
success: function(doc) {
var numViews = 0;
for (var viewName in (doc.views || {})) {
@@ -458,9 +457,9 @@
this.updateDesignDocLink = function() {
if (viewName && /^_design/.test(viewName)) {
- var docId = "_design/" + viewName.split("/")[1];
+ var docId = "_design/" + decodeURIComponent(viewName.split("/")[1]);
$("#designdoc-link").attr("href", "document.html?" +
- encodeURIComponent(dbName) + "/" + encodeDocId(docId)).text(docId);
+ encodeURIComponent(dbName) + "/" + $.couch.encodeDocId(docId)).text(docId);
} else {
$("#designdoc-link").removeAttr("href").text("");
}
@@ -469,7 +468,7 @@
this.jumpToDocument = function(docId) {
if (docId != "") {
location.href = 'document.html?' + encodeURIComponent(db.name)
- + "/" + encodeDocId(docId);
+ + "/" + $.couch.encodeDocId(docId);
}
}
@@ -559,7 +558,7 @@
}
if (row.id) {
$("<td class='key'><a href='document.html?" + encodeURIComponent(db.name) +
- "/" + encodeDocId(row.id) + "'><strong></strong><br>" +
+ "/" + $.couch.encodeDocId(row.id) + "'><strong></strong><br>" +
"<span class='docid'>ID:&nbsp;" + row.id + "</span></a></td>")
.find("strong").text(key).end()
.appendTo(tr);
@@ -738,12 +737,12 @@
if (currentIndex < revs.length - 1) {
var prevRev = revs[currentIndex + 1].rev;
$("#paging a.prev").attr("href", "?" + encodeURIComponent(dbName) +
- "/" + encodeDocId(docId) + "@" + prevRev);
+ "/" + $.couch.encodeDocId(docId) + "@" + prevRev);
}
if (currentIndex > 0) {
var nextRev = revs[currentIndex - 1].rev;
$("#paging a.next").attr("href", "?" + encodeURIComponent(dbName) +
- "/" + encodeDocId(docId) + "@" + nextRev);
+ "/" + $.couch.encodeDocId(docId) + "@" + nextRev);
}
$("#fields tbody.footer td span").text("Showing revision " +
(revs.length - currentIndex) + " of " + revs.length);
@@ -763,7 +762,7 @@
alert("The requested revision was not found. " +
"You will be redirected back to the latest revision.");
location.href = "?" + encodeURIComponent(dbName) +
- "/" + encodeDocId(docId);
+ "/" + $.couch.encodeDocId(docId);
},
success: function(doc) {
handleResult(doc, revs);
@@ -797,7 +796,7 @@
success: function(resp) {
page.isDirty = false;
location.href = "?" + encodeURIComponent(dbName) +
- "/" + encodeDocId(docId);
+ "/" + $.couch.encodeDocId(docId);
}
});
}
@@ -820,12 +819,12 @@
var form = $("#upload-form");
form.find("#progress").css("visibility", "visible");
form.ajaxSubmit({
- url: db.uri + encodeDocId(page.docId),
+ url: db.uri + $.couch.encodeDocId(page.docId),
success: function(resp) {
form.find("#progress").css("visibility", "hidden");
page.isDirty = false;
location.href = "?" + encodeURIComponent(dbName) +
- "/" + encodeDocId(docId);
+ "/" + $.couch.encodeDocId(docId);
}
});
}
@@ -968,7 +967,7 @@
}
function _renderAttachmentItem(name, attachment) {
- var attachmentHref = db.uri + encodeDocId(docId)
+ var attachmentHref = db.uri + $.couch.encodeDocId(docId)
+ "/" + encodeAttachment(name);
var li = $("<li></li>");
$("<a href='' title='Download file' target='_top'></a>").text(name)
@@ -1002,17 +1001,6 @@
});
- 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++) {
diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js
index 5d659843..1d83a91d 100644
--- a/share/www/script/jquery.couch.js
+++ b/share/www/script/jquery.couch.js
@@ -12,6 +12,16 @@
(function($) {
$.couch = $.couch || {};
+
+ function encodeDocId(docID) {
+ var parts = docID.split("/");
+ if (parts[0] == "_design") {
+ parts.shift();
+ return "_design/" + encodeURIComponent(parts.join('/'));
+ }
+ return encodeURIComponent(docID);
+ }
+
$.extend($.couch, {
activeTasks: function(options) {
ajax(
@@ -127,7 +137,7 @@
}
},
openDoc: function(docId, options, ajaxOptions) {
- ajax({url: this.uri + encodeURIComponent(docId) + encodeOptions(options)},
+ ajax({url: this.uri + encodeDocId(docId) + encodeOptions(options)},
options,
"The document could not be retrieved",
ajaxOptions
@@ -140,7 +150,7 @@
var uri = this.uri;
} else {
var method = "PUT";
- var uri = this.uri + encodeURIComponent(doc._id);
+ var uri = this.uri + encodeDocId(doc._id);
}
$.ajax({
type: method, url: uri + encodeOptions(options),
@@ -174,7 +184,7 @@
ajax({
type: "DELETE",
url: this.uri +
- encodeURIComponent(doc._id) +
+ encodeDocId(doc._id) +
encodeOptions({rev: doc._rev})
},
options,
@@ -213,6 +223,8 @@
};
},
+ encodeDocId: encodeDocId,
+
info: function(options) {
ajax(
{url: "/"},