Merge pull request #390 from kielni/pager-widget

update what changing from/to inputs does
This commit is contained in:
Rufus Pollock
2014-02-07 10:57:43 +00:00
2 changed files with 48 additions and 13 deletions

View File

@@ -30,11 +30,16 @@ my.Pager = Backbone.View.extend({
},
onFormSubmit: function(e) {
e.preventDefault();
var newFrom = parseInt(this.$el.find('input[name="from"]').val());
newFrom = Math.min(this.model.recordCount, Math.max(newFrom, 1))-1;
var newSize = parseInt(this.$el.find('input[name="to"]').val()) - newFrom;
newSize = Math.min(Math.max(newSize, 1), this.model.recordCount);
this.model.queryState.set({size: newSize, from: newFrom});
// filter is 0-based; form is 1-based
var formFrom = parseInt(this.$el.find('input[name="from"]').val())-1;
var formTo = parseInt(this.$el.find('input[name="to"]').val())-1;
var maxRecord = this.model.recordCount-1;
if (this.model.queryState.get('from') != formFrom) { // changed from; update from
this.model.queryState.set({from: Math.min(maxRecord, Math.max(formFrom, 0))});
} else if (this.model.queryState.get('to') != formTo) { // change to; update size
var to = Math.min(maxRecord, Math.max(formTo, 0));
this.model.queryState.set({size: Math.min(maxRecord+1, Math.max(to-formFrom+1, 1))});
}
},
onPaginationUpdate: function(e) {
e.preventDefault();
@@ -44,10 +49,10 @@ my.Pager = Backbone.View.extend({
var size = this.model.queryState.get('size');
var updateQuery = false;
if ($el.parent().hasClass('prev')) {
newFrom = Math.max(currFrom - Math.max(0, size), 1)-1;
newFrom = Math.max(currFrom - Math.max(0, size), 0);
updateQuery = newFrom != currFrom;
} else {
newFrom = Math.max(currFrom + size, 1);
newFrom = Math.max(currFrom + size, 0);
updateQuery = (newFrom < this.model.recordCount);
}
if (updateQuery) {