summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2009-07-22 09:03:40 +0000
committerChristopher Lenz <cmlenz@apache.org>2009-07-22 09:03:40 +0000
commitf6507e21f87f962c7e7731123450914aa12e227d (patch)
tree26b415f94a696d8bca9f1232ac6b058d3a6127fa /share
parentf4aa228848f8b465ae5ea3088ef02a04051feeac (diff)
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.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@796635 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share')
-rw-r--r--share/Makefile.am1
-rw-r--r--share/www/database.html8
-rw-r--r--share/www/dialog/_create_document.html31
-rw-r--r--share/www/document.html10
-rw-r--r--share/www/script/futon.browse.js98
-rw-r--r--share/www/script/jquery.couch.js18
-rw-r--r--share/www/script/jquery.editinline.js6
-rw-r--r--share/www/style/layout.css2
8 files changed, 90 insertions, 84 deletions
diff --git a/share/Makefile.am b/share/Makefile.am
index d1cdb457..16fe247d 100644
--- a/share/Makefile.am
+++ b/share/Makefile.am
@@ -34,7 +34,6 @@ EXTRA_DIST = $(JS_FILE_COMPONENTS) $(JS_FILE_COMPONENTS_LAST)
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 \
diff --git a/share/www/database.html b/share/www/database.html
index b94b1e93..9b22cf76 100644
--- a/share/www/database.html
+++ b/share/www/database.html
@@ -99,7 +99,7 @@ specific language governing permissions and limitations under the License.
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 @@ specific language governing permissions and limitations under the License.
</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">
diff --git a/share/www/dialog/_create_document.html b/share/www/dialog/_create_document.html
deleted file mode 100644
index f2f24a71..00000000
--- a/share/www/dialog/_create_document.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<!--
-
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use
-this file except in compliance with the License. You may obtain a copy of the
-License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software distributed
-under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-CONDITIONS OF ANY KIND, either express or implied. See the License for the
-specific language governing permissions and limitations under the License.
-
--->
-<form action="" method="post">
- <h2>Create New Document</h2>
- <fieldset>
- <p class="help">
- Please enter a unique ID of the document, or leave the field empty to get
- an auto-generated ID.
- </p>
- <table summary=""><tbody><tr>
- <th><label>Document ID:</label></th>
- <td><input type="text" name="docid" size="32"></td>
- </tr></table>
- </fieldset>
- <div class="buttons">
- <button type="submit">Create</button>
- <button type="button" class="cancel">Cancel</button>
- </div>
-</form>
diff --git a/share/www/document.html b/share/www/document.html
index c13c745c..f3dcf326 100644
--- a/share/www/document.html
+++ b/share/www/document.html
@@ -54,7 +54,11 @@ specific language governing permissions and limitations under the License.
$("#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 @@ specific language governing permissions and limitations under the License.
<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">
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js
index 538a747b..85e9a0ec 100644
--- a/share/www/script/futon.browse.js
+++ b/share/www/script/futon.browse.js
@@ -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)
diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js
index 1d83a91d..0b5d4eab 100644
--- a/share/www/script/jquery.couch.js
+++ b/share/www/script/jquery.couch.js
@@ -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();
}
});
diff --git a/share/www/script/jquery.editinline.js b/share/www/script/jquery.editinline.js
index e677b982..b48607d4 100644
--- a/share/www/script/jquery.editinline.js
+++ b/share/www/script/jquery.editinline.js
@@ -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 },
diff --git a/share/www/style/layout.css b/share/www/style/layout.css
index 473d62d8..ec49c7eb 100644
--- a/share/www/style/layout.css
+++ b/share/www/style/layout.css
@@ -211,7 +211,7 @@ ul.suggest-dropdown li.selected { cursor: pointer; background: Highlight;
#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; }