couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r648031 - in /incubator/couchdb/branches/futon-async/share/www: replicator.html script/browse.js script/jquery.couch.js
Date Mon, 14 Apr 2008 22:09:01 GMT
Author: cmlenz
Date: Mon Apr 14 15:08:54 2008
New Revision: 648031

URL: http://svn.apache.org/viewvc?rev=648031&view=rev
Log:
futon-async branch: made the replicator async.

Modified:
    incubator/couchdb/branches/futon-async/share/www/replicator.html
    incubator/couchdb/branches/futon-async/share/www/script/browse.js
    incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js

Modified: incubator/couchdb/branches/futon-async/share/www/replicator.html
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/replicator.html?rev=648031&r1=648030&r2=648031&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/replicator.html [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/replicator.html [utf-8] Mon Apr 14 15:08:54
2008
@@ -20,7 +20,7 @@
     <link rel="stylesheet" href="style/layout.css" type="text/css">
     <script src="script/json2.js"></script>
     <script src="script/jquery.js"></script>
-    <script src="script/couch.js"></script>
+    <script src="script/jquery.couch.js"></script>
     <script src="script/pprint.js"></script>
     <script>
       $(document).ready(function() {
@@ -39,12 +39,17 @@
           });
         });
 
-        var allDbs = CouchDB.allDbs();
-        $("fieldset select").each(function() {
-          for (var i = 0; i < allDbs.length; i++) {
-            $("<option></option>").text(allDbs[i]).appendTo(this);
+        
+        $.couch.allDbs({
+          success: function(dbs) {
+            $("fieldset select").each(function() {
+              var select = this;
+              $.each(dbs, function(idx, dbName) {
+                $("<option></option>").text(dbName).appendTo(select);
+              });
+              select.selectedIndex = 0;
+            });
           }
-          this.selectedIndex = 0;
         });
 
         $("button#swap").click(function() {
@@ -73,24 +78,23 @@
           $("#records tbody.content").empty();
           var source = $("#from_local")[0].checked ? $("#from_name").val() : $("#from_url").val();
           var target = $("#to_local")[0].checked ? $("#to_name").val() : $("#to_url").val();
-          try {
-            var results = CouchDB.replicate(source, target);
-          } catch (e) {
-            alert(e.reason);
-            return;
-          }
-          for (var i = 0; i < results.history.length; i++) {
-            var record = results.history[i];
-            $("<tr><th></th><td class='seq'></td>" +
-              "<td class='read'></td><td class='copied'></td></tr>")
-              .find("th").text(record.start_time).end()
-              .find("td.seq").text(record.start_last_seq + "–" + record.end_last_seq).end()
-              .find("td.read").text(record.docs_read + " (" + record.read_errors + " errors)").end()
-              .find("td.copied").text(record.docs_copied + " (" + record.copy_errors + "
errors)").end()
-              .appendTo("#records tbody.content");
-          }
-          $("#records tbody tr").removeClass("odd").filter(":odd").addClass("odd");
-          $("#records tbody.footer td").text("Replication session " + results.session_id);
+          $(document.body).addClass("loading");
+          $.couch.replicate(source, target, {
+            success: function(resp) {
+              $.each(resp.history, function(idx, record) {
+                $("<tr><th></th><td class='seq'></td>" +
+                  "<td class='read'></td><td class='copied'></td></tr>")
+                  .find("th").text(record.start_time).end()
+                  .find("td.seq").text(record.start_last_seq + "–" + record.end_last_seq).end()
+                  .find("td.read").text(record.docs_read + " (" + record.read_errors + "
errors)").end()
+                  .find("td.copied").text(record.docs_copied + " (" + record.copy_errors
+ " errors)").end()
+                  .appendTo("#records tbody.content");
+              });
+              $("#records tbody tr").removeClass("odd").filter(":odd").addClass("odd");
+              $("#records tbody.footer td").text("Replication session " + resp.session_id);
+              $(document.body).removeClass("loading");
+            }
+          });
         });
       });
     </script>

Modified: incubator/couchdb/branches/futon-async/share/www/script/browse.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/script/browse.js?rev=648031&r1=648030&r2=648031&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/script/browse.js [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/script/browse.js [utf-8] Mon Apr 14 15:08:54
2008
@@ -526,7 +526,8 @@
             error: function(status, error, reason) {
               alert("The requested revision was not found. " +
                     "You will be redirected back to the latest revision.");
-              location.href = "?" + dbName + "/" + docId;
+              location.href = "?" + encodeURIComponent(dbName) +
+                "/" + encodeURIComponent(docId);
             },
             success: function(doc) {
               handleResult(doc, revs);
@@ -680,10 +681,10 @@
       _initValue(value);
     }
 
-    $("<button type='button' class='apply'></button>").click(function() {
+    $("<button type='button' class='apply' title='Apply change'></button>").click(function()
{
       applyChange();
     }).appendTo(tools);
-    $("<button type='button' class='cancel'></button>").click(function() {
+    $("<button type='button' class='cancel' title='Revert change'></button>").click(function()
{
       cancelChange();
     }).appendTo(tools);
     tools.appendTo(td);

Modified: incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js?rev=648031&r1=648030&r2=648031&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js [utf-8] Mon Apr
14 15:08:54 2008
@@ -225,6 +225,24 @@
           }
         }
       });
+    },
+
+    replicate: function(source, target, options) {
+      $.ajax({
+        type: "POST", url: "/_replicate", dataType: "json",
+        data: JSON.stringify({source: source, target: target}),
+        contentType: "application/json",
+        complete: function(req) {
+          var resp = $.httpData(req, "json");
+          if (req.status == 200 && options.success) {
+            options.success(resp);
+          } else if (options.error) {
+            options.error(req.status, resp.error, resp.reason);
+          } else {
+            alert("Replication failed: " + resp.reason);
+          }
+        }
+      });
     }
 
   });



Mime
View raw message