summaryrefslogtreecommitdiff
path: root/share/www/script
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2008-08-29 15:25:19 +0000
committerChristopher Lenz <cmlenz@apache.org>2008-08-29 15:25:19 +0000
commit0cfe2b724df9173a25514b1617da50a23e8e6475 (patch)
treea9913e566902602c9622a9901885cb623868b5e8 /share/www/script
parentfbc8c2adc71267824c5ad0b72200a018fb2044e5 (diff)
Provide pagination for the database index page in Futon.
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@690297 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script')
-rw-r--r--share/www/script/browse.js35
1 files changed, 31 insertions, 4 deletions
diff --git a/share/www/script/browse.js b/share/www/script/browse.js
index 8291d914..298b8cbf 100644
--- a/share/www/script/browse.js
+++ b/share/www/script/browse.js
@@ -36,15 +36,22 @@ function CouchIndexPage() {
return false;
}
- this.updateDatabaseListing = function() {
+ this.updateDatabaseListing = function(offset) {
+ offset |= 0;
$(document.body).addClass("loading");
+ var maxPerPage = parseInt($("#perpage").val(), 10);
+
$.couch.allDbs({
success: function(dbs) {
+ $("#paging a").unbind();
+ $("#databases tbody.content").empty();
+
if (dbs.length == 0) {
$(document.body).removeClass("loading");
}
+ var dbsOnPage = dbs.slice(offset, offset + maxPerPage);
- $.each(dbs, function(idx, dbName) {
+ $.each(dbsOnPage, function(idx, dbName) {
$("#databases tbody.content").append("<tr>" +
"<th><a href='database.html?" + encodeURIComponent(dbName) + "'>" +
dbName + "</a></th>" +
@@ -56,14 +63,34 @@ function CouchIndexPage() {
.find("td.size").text(prettyPrintSize(info.disk_size)).end()
.find("td.count").text(info.doc_count).end()
.find("td.seq").text(info.update_seq);
- if (idx == dbs.length - 1) {
+ if (idx == dbsOnPage.length - 1) {
$(document.body).removeClass("loading");
}
}
});
});
$("#databases tbody tr:odd").addClass("odd");
- $("#databases tbody.footer tr td").text(dbs.length + " database(s)");
+
+ if (offset > 0) {
+ $("#paging a.prev").attr("href", "#" + (offset - maxPerPage)).click(function() {
+ page.updateDatabaseListing(offset - maxPerPage);
+ });
+ } else {
+ $("#paging a.prev").removeAttr("href");
+ }
+ if (offset + maxPerPage < dbs.length) {
+ $("#paging a.next").attr("href", "#" + (offset + maxPerPage)).click(function() {
+ page.updateDatabaseListing(offset + maxPerPage);
+ });
+ } else {
+ $("#paging a.next").removeAttr("href");
+ }
+
+ var firstNum = offset + 1;
+ var lastNum = firstNum + dbsOnPage.length - 1;
+ $("#databases tbody.footer tr td span").text(
+ "Showing " + firstNum + "-" + lastNum + " of " + dbs.length +
+ " databases");
}
});
}