You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by cm...@apache.org on 2008/04/14 13:50:58 UTC
svn commit: r647741 - in /incubator/couchdb/branches/futon-async/share/www:
browse/database.html browse/document.html script/browse.js
Author: cmlenz
Date: Mon Apr 14 04:50:56 2008
New Revision: 647741
URL: http://svn.apache.org/viewvc?rev=647741&view=rev
Log:
futon-async branch: now most parts async and working.
Modified:
incubator/couchdb/branches/futon-async/share/www/browse/database.html
incubator/couchdb/branches/futon-async/share/www/browse/document.html
incubator/couchdb/branches/futon-async/share/www/script/browse.js
Modified: incubator/couchdb/branches/futon-async/share/www/browse/database.html
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/browse/database.html?rev=647741&r1=647740&r2=647741&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/browse/database.html [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/browse/database.html [utf-8] Mon Apr 14 04:50:56 2008
@@ -67,7 +67,8 @@
$("#switch select").change(function() {
var viewName = $(this).val();
if (!viewName) $.cookies.remove(page.db.name + ".view");
- location.href = "?" + page.db.name + (viewName ? "/" + viewName : "");
+ location.href = "?" + encodeURIComponent(page.db.name) +
+ (viewName ? "/" + encodeURIComponent(viewName) : "");
});
$("#documents thead th.key").click(function() {
$(this).toggleClass("desc");
Modified: incubator/couchdb/branches/futon-async/share/www/browse/document.html
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/browse/document.html?rev=647741&r1=647740&r2=647741&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/browse/document.html [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/browse/document.html [utf-8] Mon Apr 14 04:50:56 2008
@@ -21,9 +21,9 @@
<script src="../script/json2.js"></script>
<script src="../script/jquery.js"></script>
<script src="../script/jquery.cookies.js"></script>
+ <script src="../script/jquery.couch.js"></script>
<script src="../script/jquery.dialog.js"></script>
<script src="../script/jquery.resizer.js"></script>
- <script src="../script/couch.js"></script>
<script src="../script/browse.js"></script>
<script src="../script/pprint.js"></script>
<script>
@@ -32,13 +32,14 @@
var dbLink = $("h1 a.dbname").get(0);
parent.updateNavigation(
location.pathname.replace(/document\.html/, "database.html"),
- location.search.split("/")[0]
+ encodeURIComponent(location.search.split("/")[0])
);
}
$(function() {
- $("h1 a.dbname").text(page.dbName).attr("href", "database.html?" + page.dbName);
- $("h1 strong").text(page.doc._id);
+ $("h1 a.dbname").text(page.dbName)
+ .attr("href", "database.html?" + encodeURIComponent(page.db.name));
+ $("h1 strong").text(page.docId);
page.updateFieldListing();
$("#toolbar button.save").click(page.saveDocument);
$("#toolbar button.add").click(page.addField);
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=647741&r1=647740&r2=647741&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 04:50:56 2008
@@ -42,7 +42,8 @@
success: function(dbs) {
$.each(dbs, function(idx, dbName) {
$("#databases tbody.content").append("<tr>" +
- "<th><a href='database.html?" + dbName + "'>" + dbName + "</a></th>" +
+ "<th><a href='database.html?" + encodeURIComponent(dbName) + "'>" +
+ dbName + "</a></th>" +
"<td class='size'></td><td class='count'></td>" +
"<td class='seq'></td></tr>");
$.couch.db(dbName).info({
@@ -70,7 +71,7 @@
*/
function CouchDatabasePage() {
var urlParts = location.search.substr(1).split("/");
- var dbName = urlParts.shift();
+ var dbName = decodeURIComponent(urlParts.shift());
var viewName = (urlParts.length > 0) ? urlParts.join("/") : null;
if (viewName) {
viewName = decodeURIComponent(viewName);
@@ -89,12 +90,13 @@
this.addDocument = function() {
$.showDialog("_create_document.html", {
submit: function(data, callback) {
- db.save(data.docid ? {_id: data.docid} : {}, {
+ db.saveDoc(data.docid ? {_id: data.docid} : {}, {
error: function(status, error, reason) {
callback({docid: reason});
},
success: function(resp) {
- location.href = "document.html?" + dbName + "/" + result.id;
+ location.href = "document.html?" + encodeURIComponent(dbName) +
+ "/" + encodeURIComponent(resp.id);
}
});
}
@@ -193,18 +195,25 @@
var designDocId = viewNameParts[1];
var localViewName = viewNameParts[2];
db.openDoc(["_design", designDocId].join("/"), {
+ error: function(status, error, reason) {
+ if (status == 404) {
+ $.cookies.remove(dbName + ".view");
+ location.reload();
+ }
+ },
success: function(resp) {
page.storedViewCode = resp.views[localViewName];
$("#viewcode textarea").val(page.storedViewCode);
+ $("#viewcode button.revert, #viewcode button.save").attr("disabled", "disabled");
if (callback) callback();
}
});
} else {
$("#viewcode textarea").val(page.storedViewCode);
page.isDirty = false;
+ $("#viewcode button.revert, #viewcode button.save").attr("disabled", "disabled");
if (callback) callback();
}
- $("#viewcode button.revert, #viewcode button.save").attr("disabled", "disabled");
}
this.saveViewAs = function() {
@@ -363,11 +372,11 @@
var row = resp.rows[i];
var tr = $("<tr></tr>");
var key = row.key;
- $("<td class='key'><a href='document.html?" + db.name + "/" + row.id + "'>" +
- "<em></em><br><span class='docid'>ID: " + row.id +
- "</span></a></td>").find("em").text(
- key !== null ? prettyPrintJSON(key, 0, "") : "null"
- ).end().appendTo(tr);
+ $("<td class='key'><a href='document.html?" + encodeURIComponent(db.name) +
+ "/" + encodeURIComponent(row.id) + "'><em></em><br>" +
+ "<span class='docid'>ID: " + row.id + "</span></a></td>")
+ .find("em").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end()
+ .appendTo(tr);
var value = row.value;
$("<td class='value'></td>").text(
value !== null ? prettyPrintJSON(value, 0, "") : "null"
@@ -405,7 +414,7 @@
} else {
$("#viewcode").show();
var currentViewCode = $("#viewcode textarea").val();
- if (currentViewCode != page.storedViewCode) {
+ if (page.isDirty) {
db.query(currentViewCode, options);
} else {
db.view(viewName.substr(8), options);
@@ -429,103 +438,121 @@
*/
function CouchDocumentPage() {
var urlParts = location.search.substr(1).split("/");
- var dbName = urlParts.shift();
+ var dbName = decodeURIComponent(urlParts.shift());
var idParts = urlParts.join("/").split("@", 2);
var docId = decodeURIComponent(idParts[0]);
var docRev = (idParts.length > 1) ? idParts[1] : null;
- var db = new CouchDB(dbName);
- var doc = db.open(docId, {revs_info: true});
- var revs = doc._revs_info;
- delete doc._revs_info;
- if (docRev != null) {
- try {
- doc = db.open(docId, {rev: docRev});
- } catch (e) {
- alert("The requested revision was not found. " +
- "You will be redirected back to the latest revision.");
- location.href = "?" + dbName + "/" + docId;
- return;
- }
- }
+ var db = $.couch.db(dbName);
this.dbName = dbName;
this.db = db;
- this.doc = doc;
+ this.docId = docId;
+ this.doc = null;
this.isDirty = false;
page = this;
this.addField = function() {
var fieldName = "unnamed";
var fieldIdx = 1;
- while (doc.hasOwnProperty(fieldName)) {
+ while (page.doc.hasOwnProperty(fieldName)) {
fieldName = "unnamed " + fieldIdx++;
}
- doc[fieldName] = null;
- var row = _addRowForField(fieldName);
+ page.doc[fieldName] = null;
+ var row = _addRowForField(page.doc, fieldName);
page.isDirty = true;
- _editKey(row.find("th"), fieldName);
+ _editKey(page.doc, row.find("th"), fieldName);
}
this.updateFieldListing = function() {
+ $(document.body).addClass("loading");
$("#fields tbody.content").empty();
- var propNames = [];
- for (var prop in doc) {
- if (!doc.hasOwnProperty(prop)) continue;
- propNames.push(prop);
- }
- // Order properties alphabetically, but put internal fields first
- propNames.sort(function(a, b) {
- var a0 = a.charAt(0), b0 = b.charAt(0);
- if (a0 == "_" && b0 != "_") {
- return -1;
- } else if (a0 != "_" && b0 == "_") {
- return 1;
- } else {
- return a < b ? -1 : a != b ? 1 : 0;
- }
- });
- for (var pi = 0; pi < propNames.length; pi++) {
- _addRowForField(propNames[pi]);
- }
- if (revs.length > 1) {
- var currentIndex = 0;
- for (var i = 0; i < revs.length; i++) {
- if (revs[i].rev == doc._rev) {
- currentIndex = i;
- break;
+
+ function handleResult(doc, revs) {
+ page.doc = doc;
+ var propNames = [];
+ for (var prop in doc) {
+ if (!doc.hasOwnProperty(prop)) continue;
+ propNames.push(prop);
+ }
+ // Order properties alphabetically, but put internal fields first
+ propNames.sort(function(a, b) {
+ var a0 = a.charAt(0), b0 = b.charAt(0);
+ if (a0 == "_" && b0 != "_") {
+ return -1;
+ } else if (a0 != "_" && b0 == "_") {
+ return 1;
+ } else {
+ return a < b ? -1 : a != b ? 1 : 0;
}
+ });
+ for (var pi = 0; pi < propNames.length; pi++) {
+ _addRowForField(doc, propNames[pi]);
}
- if (currentIndex < revs.length - 1) {
- var prevRev = revs[currentIndex + 1].rev;
- $("#paging a.prev").attr("href", "?" + dbName + "/" + docId + "@" + prevRev);
- }
- if (currentIndex > 0) {
- var nextRev = revs[currentIndex - 1].rev;
- $("#paging a.next").attr("href", "?" + dbName + "/" + docId + "@" + nextRev);
+ if (revs.length > 1) {
+ var currentIndex = 0;
+ for (var i = 0; i < revs.length; i++) {
+ if (revs[i].rev == doc._rev) {
+ currentIndex = i;
+ break;
+ }
+ }
+ if (currentIndex < revs.length - 1) {
+ var prevRev = revs[currentIndex + 1].rev;
+ $("#paging a.prev").attr("href", "?" + dbName + "/" + docId + "@" + prevRev);
+ }
+ if (currentIndex > 0) {
+ var nextRev = revs[currentIndex - 1].rev;
+ $("#paging a.next").attr("href", "?" + dbName + "/" + docId + "@" + nextRev);
+ }
+ $("#fields tbody.footer td span").text("Showing revision " +
+ (revs.length - currentIndex) + " of " + revs.length);
}
- $("#fields tbody.footer td span").text("Showing revision " +
- (revs.length - currentIndex) + " of " + revs.length);
+ $(document.body).removeClass("loading");
}
+
+ 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 = "?" + dbName + "/" + docId;
+ },
+ success: function(doc) {
+ handleResult(doc, revs);
+ }
+ });
+ } else {
+ handleResult(doc, revs);
+ }
+ }
+ });
}
this.deleteDocument = function() {
$.showDialog("_delete_document.html", {
- submit: function() {
- db.deleteDoc(doc);
- location.href = "database.html?" + dbName;
+ submit: function(data, callback) {
+ db.removeDoc(page.doc, {
+ success: function(resp) {
+ callback();
+ location.href = "database.html?" + dbName;
+ }
+ });
}
});
}
this.saveDocument = function() {
- try {
- db.save(doc);
- } catch (e) {
- alert(e.reason);
- return;
- }
- page.isDirty = false;
- location.href = "?" + dbName + "/" + docId;
+ $(document.body).addClass("loading");
+ db.saveDoc(page.doc, {
+ success: function(resp) {
+ page.isDirty = false;
+ location.href = "?" + dbName + "/" + docId;
+ }
+ });
}
window.onbeforeunload = function() {
@@ -535,26 +562,26 @@
}
}
- function _addRowForField(fieldName) {
+ function _addRowForField(doc, fieldName) {
var value = _renderValue(doc[fieldName]);
var row = $("<tr><th></th><td></td></tr>")
.find("th").append($("<b></b>").text(fieldName)).dblclick(function() {
- _editKey(this, $(this).text());
+ _editKey(doc, this, $(this).text());
}).end()
.find("td").append(value).dblclick(function() {
- _editValue(this, $(this).prev("th").text());
+ _editValue(doc, this, $(this).prev("th").text());
}).end()
.appendTo("#fields tbody.content");
if (fieldName != "_id" && fieldName != "_rev") {
row.find("th, td").attr("title", "Double click to edit");
- _initKey(row, fieldName);
+ _initKey(doc, row, fieldName);
_initValue(value);
}
$("#fields tbody tr").removeClass("odd").filter(":odd").addClass("odd");
return row;
}
- function _editKey(cell, fieldName) {
+ function _editKey(doc, cell, fieldName) {
if (fieldName == "_id" || fieldName == "_rev") return;
var th = $(cell);
th.empty();
@@ -577,13 +604,13 @@
delete doc[fieldName];
th.children().remove();
th.append($("<b></b>").text(newName));
- _initKey(th.parent("tr"), fieldName);
+ _initKey(doc, th.parent("tr"), fieldName);
page.isDirty = true;
}
function cancelChange() {
th.children().remove();
th.append($("<b></b>").text(fieldName));
- _initKey(th.parent("tr"), fieldName);
+ _initKey(doc, th.parent("tr"), fieldName);
}
$("<button type='button' class='apply'></button>").click(function() {
@@ -597,7 +624,7 @@
input.each(function() { this.focus(); this.select(); });
}
- function _editValue(cell, fieldName) {
+ function _editValue(doc, cell, fieldName) {
if (fieldName == "_id" || fieldName == "_rev") return;
var td = $(cell);
var value = doc[fieldName];
@@ -657,7 +684,7 @@
if (needsTextarea) input.resizable();
}
- function _initKey(row, fieldName) {
+ function _initKey(doc, row, fieldName) {
if (fieldName != "_id" && fieldName != "_rev") {
$("<button type='button' class='delete' title='Delete field'></button>").click(function() {
delete doc[fieldName];