Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
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
  • Loading branch information
cmlenz committed Jul 22, 2009
1 parent a5cfd1d commit b1e56054b0a30e044ed2e2dff5e9729c1e4c66cb
Showing 7 changed files with 90 additions and 83 deletions.
@@ -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 @@ <h1>
</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">

This file was deleted.

@@ -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 @@ <h1>
<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">
@@ -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,16 +920,26 @@
}
},
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")]);
},
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)
@@ -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();
}

});
@@ -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 },
@@ -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; }

0 comments on commit b1e5605

Please sign in to comment.