couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [33/50] git commit: updated refs/heads/route-events to c33e390
Date Thu, 09 May 2013 14:01:30 GMT
Generalized pagination


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/4c695622
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/4c695622
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/4c695622

Branch: refs/heads/route-events
Commit: 4c695622dced266950cd522e5ff601e932a44022
Parents: be90939
Author: Russell Branca <chewbranca@gmail.com>
Authored: Thu Apr 4 17:15:12 2013 -0700
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Thu May 9 09:59:57 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/modules/databases/views.js        |   18 ++++++++----
 src/fauxton/app/modules/fauxton/base.js           |   22 ++++++++++++++++
 src/fauxton/app/templates/databases/list.html     |   18 +------------
 src/fauxton/app/templates/fauxton/pagination.html |   17 ++++++++++++
 4 files changed, 52 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/4c695622/src/fauxton/app/modules/databases/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/databases/views.js b/src/fauxton/app/modules/databases/views.js
index afaee07..26e902e 100644
--- a/src/fauxton/app/modules/databases/views.js
+++ b/src/fauxton/app/modules/databases/views.js
@@ -13,10 +13,11 @@
 define([
   "app",
 
+  "modules/fauxton/base",
   "api"
 ],
 
-function(app, FauxtonAPI) {
+function(app, Fauxton, FauxtonAPI) {
   var Views = {};
 
   Views.Item = FauxtonAPI.View.extend({
@@ -47,11 +48,7 @@ function(app, FauxtonAPI) {
 
     serialize: function() {
       return {
-        databases: this.collection,
-        page: this.page,
-        perPage: this.perPage,
-        totalDbs: this.collection.length,
-        totalPages: Math.ceil(this.collection.length / this.perPage)
+        databases: this.collection
       };
     },
 
@@ -80,6 +77,15 @@ function(app, FauxtonAPI) {
           model: database
         }));
       }, this);
+
+      this.insertView("#database-pagination", new Fauxton.Pagination({
+        page: this.page,
+        perPage: this.perPage,
+        total: this.collection.length,
+        urlFun: function(page) {
+          return "#/_all_dbs?page=" + page;
+        }
+      }));
     },
 
     afterRender: function() {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4c695622/src/fauxton/app/modules/fauxton/base.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/fauxton/base.js b/src/fauxton/app/modules/fauxton/base.js
index 382c852..8ddbb17 100644
--- a/src/fauxton/app/modules/fauxton/base.js
+++ b/src/fauxton/app/modules/fauxton/base.js
@@ -148,5 +148,27 @@ function(app, Backbone) {
     }
   });
 
+  Fauxton.Pagination = Backbone.View.extend({
+    template: "templates/fauxton/pagination",
+
+    initialize: function(options) {
+      this.page = options.page;
+      this.perPage = options.perPage;
+      this.total = options.total;
+      this.totalPages = Math.ceil(this.total / this.perPage);
+      this.urlFun = options.urlFun;
+    },
+
+    serialize: function() {
+      return {
+        page: this.page,
+        perPage: this.perPage,
+        total: this.total,
+        totalPages: this.totalPages,
+        urlFun: this.urlFun
+      };
+    }
+  });
+
   return Fauxton;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4c695622/src/fauxton/app/templates/databases/list.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/databases/list.html b/src/fauxton/app/templates/databases/list.html
index a2e70f1..808c950 100644
--- a/src/fauxton/app/templates/databases/list.html
+++ b/src/fauxton/app/templates/databases/list.html
@@ -27,20 +27,4 @@ the License.
   <tbody>
   </tbody>
 </table>
-<div class="pagination pagination-centered">
-  <ul>
-    <% if (page > 1) { %>
-      <li><a href="#/_all_dbs?page=<%= page - 1 %>">&laquo;</a></li>
-    <% } else { %>
-      <li class="disabled"><a href="#/_all_dbs?page=<%= page %>">&laquo;</a></li>
-    <% } %>
-    <% _.each(_.range(1, totalPages+1), function(i) { %>
-      <li <% if (page == i) { %>class="active"<% } %>><a href="#/_all_dbs?page=<%=
i %>"><%= i %></a></li>
-    <% }) %>
-    <% if (page < totalPages) { %>
-      <li><a href="#/_all_dbs?page=<%= page + 1 %>">&raquo;</a></li>
-    <% } else { %>
-      <li class="disabled"><a href="#/_all_dbs?page=<%= page %>">&raquo;</a></li>
-    <% } %>
-  </ul>
-</div>
+<div id="database-pagination"></div>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4c695622/src/fauxton/app/templates/fauxton/pagination.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/fauxton/pagination.html b/src/fauxton/app/templates/fauxton/pagination.html
new file mode 100644
index 0000000..161593b
--- /dev/null
+++ b/src/fauxton/app/templates/fauxton/pagination.html
@@ -0,0 +1,17 @@
+<div class="pagination pagination-centered">
+  <ul>
+    <% if (page > 1) { %>
+      <li><a href="<%= urlFun(page-1) %>">&laquo;</a></li>
+    <% } else { %>
+      <li class="disabled"><a href="<%= urlFun(page) %>">&laquo;</a></li>
+    <% } %>
+    <% _.each(_.range(1, totalPages+1), function(i) { %>
+      <li <% if (page == i) { %>class="active"<% } %>><a href="<%=
urlFun(i) %>"><%= i %></a></li>
+    <% }) %>
+    <% if (page < totalPages) { %>
+      <li><a href="<%= urlFun(page+1) %>">&raquo;</a></li>
+    <% } else { %>
+      <li class="disabled"><a href="<%= urlFun(page) %>">&raquo;</a></li>
+    <% } %>
+  </ul>
+</div>


Mime
View raw message