couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r796635 - in /couchdb/trunk/share: Makefile.am www/database.html www/dialog/_create_document.html www/document.html www/script/futon.browse.js www/script/jquery.couch.js www/script/jquery.editinline.js www/style/layout.css
Date Wed, 22 Jul 2009 09:03:41 GMT
Author: cmlenz
Date: Wed Jul 22 09:03:40 2009
New Revision: 796635

URL: http://svn.apache.org/viewvc?rev=796635&view=rev
Log:
Change document creation in Futon so that it no longer prompts for a document ID, but simply
opens the document page for an empty (and unsaved) document, and allows you to modify the
ID.

Removed:
    couchdb/trunk/share/www/dialog/_create_document.html
Modified:
    couchdb/trunk/share/Makefile.am
    couchdb/trunk/share/www/database.html
    couchdb/trunk/share/www/document.html
    couchdb/trunk/share/www/script/futon.browse.js
    couchdb/trunk/share/www/script/jquery.couch.js
    couchdb/trunk/share/www/script/jquery.editinline.js
    couchdb/trunk/share/www/style/layout.css

Modified: couchdb/trunk/share/Makefile.am
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/Makefile.am?rev=796635&r1=796634&r2=796635&view=diff
==============================================================================
--- couchdb/trunk/share/Makefile.am (original)
+++ couchdb/trunk/share/Makefile.am Wed Jul 22 09:03:40 2009
@@ -34,7 +34,6 @@
 nobase_dist_localdata_DATA = \
     $(JS_FILE) \
     www/dialog/_compact_database.html \
-    www/dialog/_create_document.html \
     www/dialog/_create_database.html \
     www/dialog/_delete_database.html \
     www/dialog/_delete_document.html \

Modified: couchdb/trunk/share/www/database.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/database.html?rev=796635&r1=796634&r2=796635&view=diff
==============================================================================
--- couchdb/trunk/share/www/database.html [utf-8] (original)
+++ couchdb/trunk/share/www/database.html [utf-8] Wed Jul 22 09:03:40 2009
@@ -99,7 +99,7 @@
           page.updateDocumentListing();
           $.cookies.set(page.db.name + ".perpage", this.value);
         });
-        $("#toolbar button.add").click(page.addDocument);
+        $("#toolbar button.add").click(page.newDocument);
         $("#toolbar button.compact").click(page.compactDatabase);
         $("#toolbar button.delete").click(page.deleteDatabase);
 
@@ -145,9 +145,9 @@
         </label>
       </div>
       <ul id="toolbar">
-        <li><button class="add">Create Document …</button></li>
-        <li><button class="compact">Compact Database</button></li>
-        <li><button class="delete">Delete Database</button></li>
+        <li><button class="add">New Document</button></li>
+        <li><button class="compact">Compact Database…</button></li>
+        <li><button class="delete">Delete Database…</button></li>
       </ul>
 
       <div id="viewcode" class="collapsed" style="display: none">

Modified: couchdb/trunk/share/www/document.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/document.html?rev=796635&r1=796634&r2=796635&view=diff
==============================================================================
--- couchdb/trunk/share/www/document.html [utf-8] (original)
+++ couchdb/trunk/share/www/document.html [utf-8] Wed Jul 22 09:03:40 2009
@@ -54,7 +54,11 @@
         $("#toolbar button.save").click(page.saveDocument);
         $("#toolbar button.add").click(page.addField);
         $("#toolbar button.load").click(page.uploadAttachment);
-        $("#toolbar button.delete").click(page.deleteDocument);
+        if (page.isNew) {
+          $("#toolbar button.delete").hide();
+        } else {
+          $("#toolbar button.delete").click(page.deleteDocument);
+        }
       });
     </script>
   </head>
@@ -70,8 +74,8 @@
       <ul id="toolbar">
         <li><button class="save">Save Document</button></li>
         <li><button class="add">Add Field</button></li>
-        <li><button class="load">Upload Attachment</button></li>
-        <li><button class="delete">Delete Document</button></li>
+        <li><button class="load">Upload Attachment…</button></li>
+        <li><button class="delete">Delete Document…</button></li>
       </ul>
 
       <ul id="tabs">

Modified: couchdb/trunk/share/www/script/futon.browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.browse.js?rev=796635&r1=796634&r2=796635&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.browse.js [utf-8] Wed Jul 22 09:03:40 2009
@@ -122,20 +122,8 @@
         ruby: "{|doc|\n  emit(nil, doc);\n}"
       }
 
-      this.addDocument = function() {
-        $.showDialog("dialog/_create_document.html", {
-          submit: function(data, callback) {
-            db.saveDoc(data.docid ? {_id: data.docid} : {}, {
-              error: function(status, error, reason) {
-                callback({docid: reason});
-              },
-              success: function(resp) {
-                location.href = "document.html?" + encodeURIComponent(dbName) +
-                                "/" + $.couch.encodeDocId(resp.id);
-              }
-            });
-          }
-        });
+      this.newDocument = function() {
+        location.href = "document.html?" + encodeURIComponent(db.name);
       }
 
       this.compactDatabase = function() {
@@ -655,16 +643,23 @@
     CouchDocumentPage: function() {
       var urlParts = location.search.substr(1).split("/");
       var dbName = decodeURIComponent(urlParts.shift());
-      var idParts = urlParts.join("/").split("@", 2);
-      var docId = decodeURIComponent(idParts[0]);
-      var docRev = (idParts.length > 1) ? idParts[1] : null;
+      if (urlParts.length) {
+        var idParts = urlParts.join("/").split("@", 2);
+        var docId = decodeURIComponent(idParts[0]);
+        var docRev = (idParts.length > 1) ? idParts[1] : null;
+        this.isNew = false;
+      } else {
+        var docId = $.couch.newUUID();
+        var docRev = null;
+        this.isNew = true;
+      }
       var db = $.couch.db(dbName);
 
       this.dbName = dbName;
       this.db = db;
       this.docId = docId;
       this.doc = null;
-      this.isDirty = false;
+      this.isDirty = this.isNew;
       page = this;
 
       this.activateTabularView = function() {
@@ -752,27 +747,32 @@
           }
         }
 
-        db.openDoc(docId, {revs_info: true,
-          success: function(doc) {
-            var revs = doc._revs_info || [];
-            delete doc._revs_info;
-            if (docRev != null) {
-              db.openDoc(docId, {rev: docRev,
-                error: function(status, error, reason) {
-                  alert("The requested revision was not found. " +
-                        "You will be redirected back to the latest revision.");
-                  location.href = "?" + encodeURIComponent(dbName) +
-                    "/" + $.couch.encodeDocId(docId);
-                },
-                success: function(doc) {
-                  handleResult(doc, revs);
-                }
-              });
-            } else {
-              handleResult(doc, revs);
+        if (!page.isNew) {
+          db.openDoc(docId, {revs_info: true,
+            success: function(doc) {
+              var revs = doc._revs_info || [];
+              delete doc._revs_info;
+              if (docRev != null) {
+                db.openDoc(docId, {rev: docRev,
+                  error: function(status, error, reason) {
+                    alert("The requested revision was not found. You will " +
+                          "be redirected back to the latest revision.");
+                    location.href = "?" + encodeURIComponent(dbName) +
+                      "/" + $.couch.encodeDocId(docId);
+                  },
+                  success: function(doc) {
+                    handleResult(doc, revs);
+                  }
+                });
+              } else {
+                handleResult(doc, revs);
+              }
             }
-          }
-        });
+          });
+        } else {
+          handleResult({_id: docId}, []);
+          $("#fields tbody td").dblclick();
+        }
       }
 
       this.deleteDocument = function() {
@@ -796,7 +796,7 @@
           success: function(resp) {
             page.isDirty = false;
             location.href = "?" + encodeURIComponent(dbName) +
-              "/" + $.couch.encodeDocId(docId);
+              "/" + $.couch.encodeDocId(page.docId);
           }
         });
       }
@@ -824,7 +824,7 @@
                 form.find("#progress").css("visibility", "hidden");
                 page.isDirty = false;
                 location.href = "?" + encodeURIComponent(dbName) +
-                  "/" + $.couch.encodeDocId(docId);
+                  "/" + $.couch.encodeDocId(page.docId);
               }
             });
           }
@@ -899,7 +899,7 @@
       }
 
       function _initValue(doc, row, fieldName) {
-        if (fieldName == "_id" || fieldName == "_rev") {
+        if ((fieldName == "_id" && !page.isNew) || fieldName == "_rev") {
           return;
         }
 
@@ -920,8 +920,13 @@
             }
           },
           accept: function(newValue) {
-            doc[row.data("name")] = JSON.parse(newValue);
+            var fieldName = row.data("name");
+            doc[fieldName] = JSON.parse(newValue);
             page.isDirty = true;
+            if (fieldName == "_id") {
+              page.docId = page.doc._id = doc[fieldName];
+              $("h1 strong").text(page.docId);
+            }
           },
           populate: function(value) {
             return $.futon.formatJSON(doc[row.data("name")]);
@@ -929,7 +934,12 @@
           validate: function(value) {
             $("div.error", this).remove();
             try {
-              JSON.parse(value);
+              var parsed = JSON.parse(value);
+              if (row.data("name") == "_id" && typeof(parsed) != "string") {
+                $("<div class='error'>The document ID must be a string.</div>")
+                  .appendTo(this);
+                return false;
+              }
               return true;
             } catch (err) {
               var msg = err.message;
@@ -977,7 +987,7 @@
       }
 
       function _renderAttachmentItem(name, attachment) {
-        var attachmentHref = db.uri + $.couch.encodeDocId(docId)
+        var attachmentHref = db.uri + $.couch.encodeDocId(page.docId)
           + "/" + encodeAttachment(name);
         var li = $("<li></li>");
         $("<a href='' title='Download file' target='_top'></a>").text(name)

Modified: couchdb/trunk/share/www/script/jquery.couch.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.couch.js?rev=796635&r1=796634&r2=796635&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.couch.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/jquery.couch.js [utf-8] Wed Jul 22 09:03:40 2009
@@ -22,6 +22,8 @@
     return encodeURIComponent(docID);
   }
 
+  uuidCache = [];
+
   $.extend($.couch, {
     activeTasks: function(options) {
       ajax(
@@ -242,6 +244,22 @@
         options,
         "Replication failed"
       );
+    },
+
+    newUUID: function(cacheNum) {
+      if (cacheNum === undefined) {
+        cacheNum = 1;
+      }
+      if (!uuidCache.length) {
+        ajax({url: "/_uuids", data: {count: cacheNum}, async: false}, {
+            success: function(resp) {
+              uuidCache = resp.uuids
+            }
+          },
+          "Failed to retrieve UUID batch."
+        );
+      }
+      return uuidCache.shift();
     }
 
   });

Modified: couchdb/trunk/share/www/script/jquery.editinline.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.editinline.js?rev=796635&r1=796634&r2=796635&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.editinline.js (original)
+++ couchdb/trunk/share/www/script/jquery.editinline.js Wed Jul 22 09:03:40 2009
@@ -42,6 +42,11 @@
           }
         }
       });
+    if (options.acceptOnBlur) {
+      input.blur(function() {
+        return applyChange();
+      });
+    }
 
     function applyChange(keyCode) {
       var newText = input.val();
@@ -86,6 +91,7 @@
       acceptLabel: "",
       cancelLabel: "",
       toolTip: "Double click to edit",
+      acceptOnBlur: true,
 
       // callbacks
       begin: function() { return true },

Modified: couchdb/trunk/share/www/style/layout.css
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/style/layout.css?rev=796635&r1=796634&r2=796635&view=diff
==============================================================================
--- couchdb/trunk/share/www/style/layout.css (original)
+++ couchdb/trunk/share/www/style/layout.css Wed Jul 22 09:03:40 2009
@@ -211,7 +211,7 @@
 #toolbar li { display: inline; }
 #toolbar button { background: transparent 2px 2px no-repeat; border: none;
   color: #666; margin: 0; padding: 2px 1em 2px 22px; cursor: pointer;
-  font-size: 95%; font-weight: bold; line-height: 16px;
+  font-size: 95%; line-height: 16px;
 }
 #toolbar button:hover { background-position: 2px -30px; color: #000; }
 #toolbar button:active { background-position: 2px -62px; color: #000; }



Mime
View raw message