couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r647725 - in /incubator/couchdb/branches/futon-async/share/www/script: browse.js jquery.couch.js
Date Mon, 14 Apr 2008 10:25:29 GMT
Author: cmlenz
Date: Mon Apr 14 03:25:24 2008
New Revision: 647725

URL: http://svn.apache.org/viewvc?rev=647725&view=rev
Log:
futon-async branch: made the save-view-as dialog async.

Modified:
    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/script/browse.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/script/browse.js?rev=647725&r1=647724&r2=647725&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 03:25:24
2008
@@ -24,7 +24,7 @@
           return;
         }
         $.couch.db(data.name).create({
-          error: function(id, reason) { callback({name: reason}) },
+          error: function(status, id, reason) { callback({name: reason}) },
           success: function(resp) {
             if (window !== parent) parent.setTimeout("updateDatabaseList()", 500);
             window.open("database.html?" + data.name, "content");
@@ -90,7 +90,7 @@
     $.showDialog("_create_document.html", {
       submit: function(data, callback) {
         db.save(data.docid ? {_id: data.docid} : {}, {
-          error: function(error, reason) {
+          error: function(status, error, reason) {
             callback({docid: reason});
           },
           success: function(resp) {
@@ -105,9 +105,6 @@
     $.showDialog("_compact_database.html", {
       submit: function(data, callback) {
         db.compact({
-          error: function(error, reason) {
-            alert(reason);
-          },
           success: function(resp) {
             callback();
           }
@@ -199,13 +196,13 @@
         success: function(resp) {
           page.storedViewCode = resp.views[localViewName];
           $("#viewcode textarea").val(page.storedViewCode);
-          callback();
+          if (callback) callback();
         }
       });
     } else {
       $("#viewcode textarea").val(page.storedViewCode);
       page.isDirty = false;
-      callback();
+      if (callback) callback();
     }
     $("#viewcode button.revert, #viewcode button.save").attr("disabled", "disabled");
   }
@@ -221,49 +218,66 @@
     $.showDialog("_save_view_as.html", {
       load: function(elem) {
         $("#input_docid", elem).val(designDocId).suggest(function(text, callback) {
-          var matches = [];
-          var docs = db.allDocs({
+          db.allDocs({
             count: 10, startkey: "_design/" + text,
-            endkey: "_design/" + text + "ZZZZ"
+            endkey: "_design/" + text + "ZZZZ",
+            success: function(docs) {
+              var matches = [];
+              for (var i = 0; i < docs.rows.length; i++) {
+                matches[i] = docs.rows[i].id.substr(8);
+              }
+              callback(matches);
+            }
           });
-          for (var i = 0; i < docs.rows.length; i++) {
-            matches[i] = docs.rows[i].id.substr(8);
-          }
-          callback(matches);
         });
         $("#input_name", elem).val(localViewName).suggest(function(text, callback) {
-          var matches = [];
-          try {
-            var doc = db.open("_design/" + $("#input_docid").val());
-          } catch (err) {
-            return;
-          }
-          if (!doc || !doc.views) return;
-          for (var viewName in doc.views) {
-            if (!doc.views.hasOwnProperty(viewName) || !viewName.match("^" + text)) {
-              continue;
+          db.openDoc("_design/" + $("#input_docid").val(), {
+            error: function() {}, // ignore
+            success: function(doc) {
+              var matches = [];
+              if (!doc.views) return;
+              for (var viewName in doc.views) {
+                if (!doc.views.hasOwnProperty(viewName) || !viewName.match("^" + text)) {
+                  continue;
+                }
+                matches.push(viewName);
+              }
+              callback(matches);
             }
-            matches.push(viewName);
-          }
-          callback(matches);
+          });
         });
       },
-      submit: function(data) {
+      submit: function(data, callback) {
         if (!data.docid || !data.name) {
           var errors = {};
           if (!data.docid) errors.docid = "Please enter a document ID";
           if (!data.name) errors.name = "Please enter a view name";
-          return errors;
+          callback(errors);
+        } else {
+          var viewCode = $("#viewcode textarea").val();
+          var docId = ["_design", data.docid].join("/");
+          function save(doc) {
+            if (!doc) doc = {_id: docId, language: "text/javascript"};
+            if (doc.views === undefined) doc.views = {};
+            doc.views[data.name] = viewCode;
+            db.saveDoc(doc, {
+              success: function(resp) {
+                callback();
+                page.isDirty = false;
+                location.href = "database.html?" + dbName + "/" + doc._id + "/" + data.name;
+              }
+            });
+          }
+          db.openDoc(docId, {
+            error: function(status, error, reason) {
+              if (status == 404) save(null);
+              else alert(reason);
+            },
+            success: function(doc) {
+              save(doc);
+            }
+          });
         }
-        var viewCode = $("#viewcode textarea").val();
-        var docId = ["_design", data.docid].join("/");
-        var designDoc = db.open(docId);
-        if (!designDoc) designDoc = {_id: docId, language: "text/javascript"};
-        if (designDoc.views === undefined) designDoc.views = {};
-        designDoc.views[data.name] = viewCode;
-        db.save(designDoc);
-        page.isDirty = false;
-        location.href = "database.html?" + dbName + "/" + designDoc._id + "/" + data.name;
       }
     });
   }
@@ -272,13 +286,16 @@
     var viewNameParts = viewName.split("/");
     var designDocId = viewNameParts[1];
     var localViewName = viewNameParts[2];
-    var designDoc = db.open(["_design", designDocId].join("/"));
-    var viewCode = $("#viewcode textarea").val();
-    designDoc.views[localViewName] = viewCode;
-    db.saveDoc(designDoc, {
-      success: function(resp) {
-        page.isDirty = false;
-        $("#viewcode button.revert, #viewcode button.save").attr("disabled", "disabled");
+    db.openDoc(["_design", designDocId].join("/"), {
+      success: function(doc) {
+        doc.views[localViewName] = $("#viewcode textarea").val();
+        db.saveDoc(doc, {
+          success: function(resp) {
+            page.isDirty = false;
+            $("#viewcode button.revert, #viewcode button.save")
+              .attr("disabled", "disabled");
+          }
+        });
       }
     });
   }

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=647725&r1=647724&r2=647725&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 03:25:24 2008
@@ -22,7 +22,7 @@
           if (req.status == 200 && options.success) {
             options.success(resp);
           } else if (options.error) {
-            options.error(resp.error, resp.reason);
+            options.error(req.status, resp.error, resp.reason);
           } else {
             alert(resp.reason);
           }
@@ -43,7 +43,7 @@
               if (req.status == 202 && options.success) {
                 options.success(resp);
               } else if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -58,7 +58,7 @@
               if (req.status == 201 && options.success) {
                 options.success(resp);
               } else if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -73,7 +73,7 @@
               if (req.status == 202 && options.success) {
                 options.success(resp);
               } else if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -88,7 +88,7 @@
               if (req.status == 200 && options.success) {
                 options.success(resp);
               } else  if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -104,7 +104,7 @@
               if (req.status == 200 && options.success) {
                 options.success(resp);
               } else if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -121,7 +121,7 @@
               if (req.status == 200 && options.success) {
                 options.success(resp);
               } else if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -147,7 +147,7 @@
               if (req.status == 201 && options.success) {
                 options.success(resp);
               } else if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -164,7 +164,7 @@
               if (req.status == 202 && options.success) {
                 options.success(resp);
               } else if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -182,7 +182,7 @@
               if (req.status == 200 && options.success) {
                 options.success(resp);
               } else if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -198,7 +198,7 @@
               if (req.status == 200 && options.success) {
                 options.success(resp);
               } else if (options.error) {
-                options.error(resp.error, resp.reason);
+                options.error(req.status, resp.error, resp.reason);
               } else {
                 alert(resp.reason);
               }
@@ -216,7 +216,7 @@
           if (req.status == 200 && options.success) {
             options.success(resp);
           } else if (options.error) {
-            options.error(resp.error, resp.reason);
+            options.error(req.status, resp.error, resp.reason);
           } else {
             alert(resp.reason);
           }



Mime
View raw message