You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by cm...@apache.org on 2009/07/21 23:16:56 UTC

svn commit: r796541 - in /couchdb/trunk/share/www/script: futon.browse.js jquery.couch.js

Author: cmlenz
Date: Tue Jul 21 21:16:56 2009
New Revision: 796541

URL: http://svn.apache.org/viewvc?rev=796541&view=rev
Log:
Fix for compatibility of Futon with design documents that have slashes in the document ID or a view name. Closes COUCHDB-408 (again).

Modified:
    couchdb/trunk/share/www/script/futon.browse.js
    couchdb/trunk/share/www/script/jquery.couch.js

Modified: couchdb/trunk/share/www/script/futon.browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.browse.js?rev=796541&r1=796540&r2=796541&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.browse.js [utf-8] Tue Jul 21 21:16:56 2009
@@ -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++) {

Modified: couchdb/trunk/share/www/script/jquery.couch.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.couch.js?rev=796541&r1=796540&r2=796541&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.couch.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/jquery.couch.js [utf-8] Tue Jul 21 21:16:56 2009
@@ -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: "/"},