diff --git a/src/js/widgets/list_of_things/paginated_view.js b/src/js/widgets/list_of_things/paginated_view.js index 8bd5e3e84..5f0c27839 100644 --- a/src/js/widgets/list_of_things/paginated_view.js +++ b/src/js/widgets/list_of_things/paginated_view.js @@ -136,7 +136,7 @@ function ( 'click .toggle-make-space': 'toggleMakeSpace', 'click a.page-control': 'changePageWithButton', 'keyup input.page-control': 'tabOrEnterChangePageWithInput', - 'click .per-page': 'changePerPage' + 'change #per-page-select': 'changePerPage' }, toggleHighlights: function () { @@ -232,9 +232,8 @@ function ( changePerPage: function (e) { e.preventDefault(); - var val = parseInt($(e.target).text().trim()); - if (val === this.model.get('perPage')) return; - this.trigger('pagination:changePerPage', val); + var val = parseInt(e.currentTarget ? e.currentTarget.value : 25); + val !== this.model.get('perPage') && this.trigger('pagination:changePerPage', val); } }); diff --git a/src/js/widgets/list_of_things/templates/pagination-partial.html b/src/js/widgets/list_of_things/templates/pagination-partial.html index 0785a57ac..0980282d2 100644 --- a/src/js/widgets/list_of_things/templates/pagination-partial.html +++ b/src/js/widgets/list_of_things/templates/pagination-partial.html @@ -12,12 +12,18 @@
{{#if pageData}} - Per Page: - 25 - 50 - 100 - 200 - 500 +
+ +
+ +
+
{{/if}}
diff --git a/test/mocha/js/widgets/list_of_things_widget.spec.js b/test/mocha/js/widgets/list_of_things_widget.spec.js index 95991abf8..035dcf7b1 100644 --- a/test/mocha/js/widgets/list_of_things_widget.spec.js +++ b/test/mocha/js/widgets/list_of_things_widget.spec.js @@ -30,10 +30,10 @@ define(['marionette', ) { describe("ListOfThings (list_of_things_widget.spec.js)", function () { - + // on slower machines 20000 default is not enough this.timeout(40000); - + beforeEach(function () { this.sb = sinon.sandbox.create(); }) @@ -237,7 +237,7 @@ define(['marionette', // give command to display first 20 docs; since responses are coming in // batches of 10; the collection will automatically ask twice minsub.publish(minsub.DISPLAY_DOCUMENTS, new ApiQuery({'q': 'bibcode:bar'})); - expect($w.find("label").length).to.equal(50); + expect($w.find("label").length).to.equal(51); expect($(".s-checkbox-col").text().replace(/\s+/g, " ")).to.eql(" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 ") // click on next page // this should trigger new request @@ -305,7 +305,7 @@ define(['marionette', // model should update, and reset page back to 0 expect(widget.model.get("perPage")).to.eql(50); - expect($(".per-page--active").text().trim()).to.eql("50"); + expect($("#per-page-select>option:selected").text().trim()).to.eql("50"); expect($("input.page-control").val()).to.eql("1"); @@ -316,10 +316,10 @@ define(['marionette', widget.trigger("pagination:changePerPage", 50); expect(widget.model.get("perPage")).to.eql(50); - + expect(JSON.stringify(widget.model.toJSON())).to.eql('{"mainResults":false,"showAbstract":"closed","showHighlights":false,"pagination":true,"start":0,"perPage":50,"numFound":100,"currentQuery":{"q":["foo:bar"]},"pageData":{"perPage":50,"totalPages":2,"currentPage":1,"previousPossible":false,"nextPossible":true},"page":0,"showRange":[0,49],"query":false,"loading":false}'); - expect($(".per-page--active").text().trim()).to.eql("50"); + expect($("#per-page-select>option:selected").text().trim()).to.eql("50"); expect($("input.page-control").val()).to.eql("1"); expect($(".page-control.previous-page").parent().hasClass("disabled")).to.be.true; @@ -382,7 +382,7 @@ define(['marionette', widget.updatePagination({ page : 2 , perPage : 25}); - expect($(".per-page--active").text().trim()).to.eql("25"); + expect($("#per-page-select>option:selected").text().trim()).to.eql("25"); expect($("input.page-control").val()).to.eql("3"); expect($(".page-control.previous-page").parent().hasClass("disabled")).to.be.false; @@ -400,7 +400,7 @@ define(['marionette', expect($(".page-control.previous-page").parent().hasClass("disabled")).to.be.false; expect($(".page-control.next-page").parent().hasClass("disabled")).to.be.true; - expect($(".per-page--active").text().trim()).to.eql("25"); + expect($("#per-page-select>option:selected").text().trim()).to.eql("25"); expect($("input.page-control").val()).to.eql("4"); diff --git a/test/mocha/js/widgets/lot_derivates.spec.js b/test/mocha/js/widgets/lot_derivates.spec.js index 48ff4b60a..db8090d5c 100644 --- a/test/mocha/js/widgets/lot_derivates.spec.js +++ b/test/mocha/js/widgets/lot_derivates.spec.js @@ -110,7 +110,7 @@ define([ //$('#test').append($w); minsub.publish(minsub.DISPLAY_DOCUMENTS, new ApiQuery({'q': 'bibcode:bar'})); - expect($w.find("label").length).to.equal(25); + expect($w.find("label").length).to.equal(26); expect($w.find("a:first").attr("href")).to.eql('#search/q=citations(bibcode%3Abar)&sort=date%20desc'); @@ -129,7 +129,7 @@ define([ expect(query.url()).to.eql('fl=title%2Cbibcode%2Cauthor%2Ckeyword%2Cpub%2Caff%2Cvolume%2Cyear%2C%5Bcitations%5D%2Cproperty%2Cpubdate%2Cabstract%2Cesources%2Cdata&q=references(bibcode%3Abar)&rows=25&sort=first_author%20asc&start=0'); minsub.publish(minsub.DISPLAY_DOCUMENTS, new ApiQuery({'q': 'bibcode:bar'})); - expect($w.find("label").length).to.equal(25); + expect($w.find("label").length).to.equal(26); expect($w.find(".s-list-description").text()).to.eql("Papers referenced by"); @@ -156,7 +156,7 @@ define([ expect(query.url()).to.eql( 'fl=title%2Cbibcode%2Cauthor%2Ckeyword%2Cpub%2Caff%2Cvolume%2Cyear%2C%5Bcitations%5D%2Cproperty%2Cpubdate%2Cabstract%2Cesources%2Cdata&q=trending(bibcode%3Abar)-bibcode%3Abar&rows=25&sort=date%20desc&start=0'); minsub.publish(minsub.DISPLAY_DOCUMENTS, new ApiQuery({'q': 'bibcode:bar'})); - expect($w.find("label").length).to.equal(25); + expect($w.find("label").length).to.equal(26); expect($w.find(".s-list-description").text()).to.eql("Papers also read by those who read"); @@ -182,7 +182,7 @@ define([ var $w = widget.render().$el; minsub.publish(minsub.DISPLAY_DOCUMENTS, new ApiQuery({'q': 'bibcode:bar'})); - expect($w.find("label").length).to.equal(25); + expect($w.find("label").length).to.equal(26); expect($w.find(".s-list-description").text()).to.eql("Papers in the same volume as");