Yoji SHIDARA
null+****@clear*****
Tue Sep 25 16:40:32 JST 2012
Yoji SHIDARA 2012-09-25 16:40:32 +0900 (Tue, 25 Sep 2012) New Revision: ecea4eac27ecdfe46764491445674f6a7acf6c4b https://github.com/groonga/gcs/commit/ecea4eac27ecdfe46764491445674f6a7acf6c4b Log: Implement pagination Modified files: public/js/gcs.js views/index.jade Modified: public/js/gcs.js (+29 -1) =================================================================== --- public/js/gcs.js 2012-09-25 15:58:44 +0900 (4082296) +++ public/js/gcs.js 2012-09-25 16:40:32 +0900 (e8ed36e) @@ -92,7 +92,29 @@ App.SearchController = Ember.ArrayController.extend({ self.set('data', data); } }); - } + }, + nextPageAvailable: function() { + return this.get('start') + this.get('perPage') < this.get('numHits'); + }.property('start', 'perPage', 'numHits'), + nextPage: function() { + console.log("nextPage"); + var newStart = this.get('start') + this.get('perPage'); + if (newStart < this.get('numHits')) { + this.set('start', newStart); + this.executeSearch(); + } + }, + previousPageAvailable: function() { + return this.get('start') > 0; + }.property('start'), + previousPage: function() { + var newStart = this.get('start') - this.get('perPage'); + if (newStart < 0) { + newStart = 0; + } + this.set('start', newStart); + this.executeSearch(); + }, }); App.SearchView = Ember.View.extend({ @@ -122,6 +144,12 @@ App.Router = Ember.Router.extend({ route: 'search', connectOutlets: function(router) { router.get('applicationController').connectOutlet('search'); + }, + nextPage: function(router) { + router.get('searchController').nextPage(); + }, + previousPage: function(router) { + router.get('searchController').previousPage(); } }) }) Modified: views/index.jade (+16 -0) =================================================================== --- views/index.jade 2012-09-25 15:58:44 +0900 (3601586) +++ views/index.jade 2012-09-25 16:40:32 +0900 (c06eb7f) @@ -51,6 +51,22 @@ html {{#if resultsAvailable}} //- DOM structure of this table seems to be broken. The issue https://github.com/wycats/handlebars.js/issues/184 may be related with this. + ul.pager + {{#if previousPageAvailable}} + li.previous + <a class="previous" {{action previousPage}}>← Previous</a> + {{else}} + li.previous.disabled + a ← Previous + {{/if}} + {{#if nextPageAvailable}} + li.next + <a class="next" {{action nextPage}}>Next →</a> + {{else}} + li.next.disabled + a Next → + {{/if}} + table.table.table-bordered tbody {{#each controller}} -------------- next part -------------- HTML����������������������������... Descargar