couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r699023 - /incubator/couchdb/trunk/share/www/script/browse.js
Date Thu, 25 Sep 2008 17:13:53 GMT
Author: jchris
Date: Thu Sep 25 10:13:53 2008
New Revision: 699023

URL: http://svn.apache.org/viewvc?rev=699023&view=rev
Log:
Futon pagination no longer uses negative counts.

Modified:
    incubator/couchdb/trunk/share/www/script/browse.js

Modified: incubator/couchdb/trunk/share/www/script/browse.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/browse.js?rev=699023&r1=699022&r2=699023&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/browse.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/browse.js [utf-8] Thu Sep 25 10:13:53 2008
@@ -386,10 +386,11 @@
       options.group = true;
     }
     if ($("#documents thead th.key").is(".desc")) {
-      options.descending = true;
+      if (typeof options.descending == 'undefined') options.descending = true;
+      var descend = true;
       $.cookies.set(dbName + ".desc", "1");
     } else {
-      if (options.descending !== undefined) delete options.descending;
+      var descend = false;
       $.cookies.remove(dbName + ".desc");
     }
     $("#paging a").unbind();
@@ -400,27 +401,37 @@
       if (resp.offset === undefined) {
         resp.offset = 0;
       }
-      if (resp.rows !== null && resp.offset > 0) {
+      var decending_reverse = ((options.descending && !descend) || (descend &&
(options.descending === false)));
+      if (decending_reverse && resp.rows) {
+        resp.rows = resp.rows.reverse();
+      }
+      if (resp.rows !== null && (decending_reverse ? 
+        (resp.total_rows - resp.offset > options.count) :
+        (resp.offset > 0))) {
         $("#paging a.prev").attr("href", "#" + (resp.offset - options.count)).click(function()
{
           var firstDoc = resp.rows[0];
           page.updateDocumentListing({
             startkey: firstDoc.key !== undefined ? firstDoc.key : null,
             startkey_docid: firstDoc.id,
             skip: 1,
-            count: -options.count
+            descending: !descend,
+            count: options.count
           });
           return false;
         });
       } else {
         $("#paging a.prev").removeAttr("href");
       }
-      if (resp.rows !== null && resp.total_rows - resp.offset > options.count)
{
+      if (resp.rows !== null && (decending_reverse ? 
+        (resp.offset - resp.total_rows < options.count) : 
+        (resp.total_rows - resp.offset > options.count))) {
         $("#paging a.next").attr("href", "#" + (resp.offset + options.count)).click(function()
{
           var lastDoc = resp.rows[resp.rows.length - 1];
           page.updateDocumentListing({
             startkey: lastDoc.key !== undefined ? lastDoc.key : null,
             startkey_docid: lastDoc.id,
             skip: 1,
+            descending: descend,
             count: options.count
           });
           return false;
@@ -455,8 +466,13 @@
       var firstNum = 1;
       var lastNum = totalNum = resp.rows.length;
       if (resp.total_rows != null) {
-        firstNum = Math.min(resp.total_rows, resp.offset + 1);
-        lastNum = firstNum + resp.rows.length - 1;
+        if (decending_reverse) {
+          lastNum = Math.min(resp.total_rows, resp.total_rows - resp.offset);
+          firstNum = lastNum - resp.rows.length + 1;          
+        } else {
+          firstNum = Math.min(resp.total_rows, resp.offset + 1);
+          lastNum = firstNum + resp.rows.length - 1;
+        }
         totalNum = resp.total_rows;
         $("#paging").show();
       } else {



Mime
View raw message