Comparing version 0.2.3 to 0.2.4
@@ -993,13 +993,11 @@ // Generated by CoffeeScript 1.4.0 | ||
function PaginatedCollection() { | ||
return PaginatedCollection.__super__.constructor.apply(this, arguments); | ||
} | ||
PaginatedCollection.prototype.initialize = function(options) { | ||
function PaginatedCollection(models, options) { | ||
if (options == null) { | ||
options = {}; | ||
} | ||
this.page = options.page || 1; | ||
return this.perPage || (this.perPage = 10); | ||
}; | ||
this.query = options.query || {}; | ||
this.query.page = Number(this.query.page) || 1; | ||
this.query.perPage = Number(this.query.perPage) || this.perPage || 10; | ||
PaginatedCollection.__super__.constructor.apply(this, arguments); | ||
} | ||
@@ -1013,7 +1011,6 @@ PaginatedCollection.prototype.parse = function(resp) { | ||
PaginatedCollection.prototype.queryParams = function() { | ||
return highbrow.querystring.stringify({ | ||
page: this.page, | ||
perPage: this.perPage | ||
}); | ||
PaginatedCollection.prototype.queryParams = function(page) { | ||
return highbrow.querystring.stringify(page ? _.extend(this.query, { | ||
page: page | ||
}) : this.query); | ||
}; | ||
@@ -1027,24 +1024,31 @@ | ||
PaginatedCollection.prototype.pageInfo = function() { | ||
var info, max; | ||
var info, max, page, perPage; | ||
page = this.query.page; | ||
perPage = this.query.perPage; | ||
info = { | ||
total: this.total, | ||
page: this.page, | ||
perPage: this.perPage, | ||
page: page, | ||
perPage: perPage, | ||
prev: false, | ||
next: false | ||
next: false, | ||
prevUrl: '#', | ||
nextUrl: '#' | ||
}; | ||
info.pages = Math.ceil(this.total / this.perPage); | ||
max = Math.min(this.total, this.page * this.perPage); | ||
if (this.total === this.pages * this.perPage) { | ||
max = this.total; | ||
} | ||
info.range = [(this.page - 1) * this.perPage + 1, max]; | ||
info.pages = Math.ceil(this.total / perPage); | ||
max = Math.min(this.total, page * perPage); | ||
info.range = [(page - 1) * perPage + 1, max]; | ||
info.start = info.range[0]; | ||
info.end = info.range[1]; | ||
if (this.page > 1) { | ||
info.prev = this.page - 1; | ||
if (page > 1) { | ||
info.prev = page - 1; | ||
} | ||
if (this.page < info.pages) { | ||
info.next = this.page + 1; | ||
if (info.prev) { | ||
info.prevUrl = '?' + this.queryParams(info.prev); | ||
} | ||
if (page < info.pages) { | ||
info.next = page + 1; | ||
} | ||
if (info.next) { | ||
info.nextUrl = '?' + this.queryParams(info.next); | ||
} | ||
return info; | ||
@@ -1057,3 +1061,3 @@ }; | ||
} | ||
this.page += 1; | ||
this.query.page += 1; | ||
return this.fetch(); | ||
@@ -1066,3 +1070,3 @@ }; | ||
} | ||
this.page -= 1; | ||
this.query.page -= 1; | ||
return this.fetch(); | ||
@@ -1069,0 +1073,0 @@ }; |
@@ -1002,13 +1002,11 @@ /* | ||
function PaginatedCollection() { | ||
return PaginatedCollection.__super__.constructor.apply(this, arguments); | ||
} | ||
PaginatedCollection.prototype.initialize = function(options) { | ||
function PaginatedCollection(models, options) { | ||
if (options == null) { | ||
options = {}; | ||
} | ||
this.page = options.page || 1; | ||
return this.perPage || (this.perPage = 10); | ||
}; | ||
this.query = options.query || {}; | ||
this.query.page = Number(this.query.page) || 1; | ||
this.query.perPage = Number(this.query.perPage) || this.perPage || 10; | ||
PaginatedCollection.__super__.constructor.apply(this, arguments); | ||
} | ||
@@ -1022,7 +1020,6 @@ PaginatedCollection.prototype.parse = function(resp) { | ||
PaginatedCollection.prototype.queryParams = function() { | ||
return highbrow.querystring.stringify({ | ||
page: this.page, | ||
perPage: this.perPage | ||
}); | ||
PaginatedCollection.prototype.queryParams = function(page) { | ||
return highbrow.querystring.stringify(page ? _.extend(this.query, { | ||
page: page | ||
}) : this.query); | ||
}; | ||
@@ -1036,24 +1033,31 @@ | ||
PaginatedCollection.prototype.pageInfo = function() { | ||
var info, max; | ||
var info, max, page, perPage; | ||
page = this.query.page; | ||
perPage = this.query.perPage; | ||
info = { | ||
total: this.total, | ||
page: this.page, | ||
perPage: this.perPage, | ||
page: page, | ||
perPage: perPage, | ||
prev: false, | ||
next: false | ||
next: false, | ||
prevUrl: '#', | ||
nextUrl: '#' | ||
}; | ||
info.pages = Math.ceil(this.total / this.perPage); | ||
max = Math.min(this.total, this.page * this.perPage); | ||
if (this.total === this.pages * this.perPage) { | ||
max = this.total; | ||
} | ||
info.range = [(this.page - 1) * this.perPage + 1, max]; | ||
info.pages = Math.ceil(this.total / perPage); | ||
max = Math.min(this.total, page * perPage); | ||
info.range = [(page - 1) * perPage + 1, max]; | ||
info.start = info.range[0]; | ||
info.end = info.range[1]; | ||
if (this.page > 1) { | ||
info.prev = this.page - 1; | ||
if (page > 1) { | ||
info.prev = page - 1; | ||
} | ||
if (this.page < info.pages) { | ||
info.next = this.page + 1; | ||
if (info.prev) { | ||
info.prevUrl = '?' + this.queryParams(info.prev); | ||
} | ||
if (page < info.pages) { | ||
info.next = page + 1; | ||
} | ||
if (info.next) { | ||
info.nextUrl = '?' + this.queryParams(info.next); | ||
} | ||
return info; | ||
@@ -1066,3 +1070,3 @@ }; | ||
} | ||
this.page += 1; | ||
this.query.page += 1; | ||
return this.fetch(); | ||
@@ -1075,3 +1079,3 @@ }; | ||
} | ||
this.page -= 1; | ||
this.query.page -= 1; | ||
return this.fetch(); | ||
@@ -1078,0 +1082,0 @@ }; |
@@ -1003,13 +1003,11 @@ /* | ||
function PaginatedCollection() { | ||
return PaginatedCollection.__super__.constructor.apply(this, arguments); | ||
} | ||
PaginatedCollection.prototype.initialize = function(options) { | ||
function PaginatedCollection(models, options) { | ||
if (options == null) { | ||
options = {}; | ||
} | ||
this.page = options.page || 1; | ||
return this.perPage || (this.perPage = 10); | ||
}; | ||
this.query = options.query || {}; | ||
this.query.page = Number(this.query.page) || 1; | ||
this.query.perPage = Number(this.query.perPage) || this.perPage || 10; | ||
PaginatedCollection.__super__.constructor.apply(this, arguments); | ||
} | ||
@@ -1023,7 +1021,6 @@ PaginatedCollection.prototype.parse = function(resp) { | ||
PaginatedCollection.prototype.queryParams = function() { | ||
return highbrow.querystring.stringify({ | ||
page: this.page, | ||
perPage: this.perPage | ||
}); | ||
PaginatedCollection.prototype.queryParams = function(page) { | ||
return highbrow.querystring.stringify(page ? _.extend(this.query, { | ||
page: page | ||
}) : this.query); | ||
}; | ||
@@ -1037,24 +1034,31 @@ | ||
PaginatedCollection.prototype.pageInfo = function() { | ||
var info, max; | ||
var info, max, page, perPage; | ||
page = this.query.page; | ||
perPage = this.query.perPage; | ||
info = { | ||
total: this.total, | ||
page: this.page, | ||
perPage: this.perPage, | ||
page: page, | ||
perPage: perPage, | ||
prev: false, | ||
next: false | ||
next: false, | ||
prevUrl: '#', | ||
nextUrl: '#' | ||
}; | ||
info.pages = Math.ceil(this.total / this.perPage); | ||
max = Math.min(this.total, this.page * this.perPage); | ||
if (this.total === this.pages * this.perPage) { | ||
max = this.total; | ||
} | ||
info.range = [(this.page - 1) * this.perPage + 1, max]; | ||
info.pages = Math.ceil(this.total / perPage); | ||
max = Math.min(this.total, page * perPage); | ||
info.range = [(page - 1) * perPage + 1, max]; | ||
info.start = info.range[0]; | ||
info.end = info.range[1]; | ||
if (this.page > 1) { | ||
info.prev = this.page - 1; | ||
if (page > 1) { | ||
info.prev = page - 1; | ||
} | ||
if (this.page < info.pages) { | ||
info.next = this.page + 1; | ||
if (info.prev) { | ||
info.prevUrl = '?' + this.queryParams(info.prev); | ||
} | ||
if (page < info.pages) { | ||
info.next = page + 1; | ||
} | ||
if (info.next) { | ||
info.nextUrl = '?' + this.queryParams(info.next); | ||
} | ||
return info; | ||
@@ -1067,3 +1071,3 @@ }; | ||
} | ||
this.page += 1; | ||
this.query.page += 1; | ||
return this.fetch(); | ||
@@ -1076,3 +1080,3 @@ }; | ||
} | ||
this.page -= 1; | ||
this.query.page -= 1; | ||
return this.fetch(); | ||
@@ -1079,0 +1083,0 @@ }; |
{ "name": "highbrow" | ||
, "version": "0.2.3" | ||
, "version": "0.2.4" | ||
, "description": "A Backbone Base Framework" | ||
@@ -4,0 +4,0 @@ , "main": "lib/highbrow.js" |
Sorry, the diff of this file is not supported yet
324225
5512