/examples/netflix-client-paging/views/PaginationView.js
JavaScript | 86 lines | 69 code | 17 blank | 0 comment | 0 complexity | b9f8902e4b22b181d73ede8351f022f0 MD5 | raw file
Possible License(s): MIT
- (function (views) {
- views.PaginationView = Backbone.View.extend({
- events: {
- 'click a.first': 'gotoFirst',
- 'click a.prev': 'gotoPrev',
- 'click a.next': 'gotoNext',
- 'click a.last': 'gotoLast',
- 'click a.page': 'gotoPage',
- 'click .howmany a': 'changeCount',
- 'click a.sortAsc': 'sortByAscending',
- 'click a.sortDsc': 'sortByDescending'
- },
- tagName: 'aside',
- pagingTemplate: _.template($('#tmpClientPagination').html()),
- initialize: function () {
- this.collection.on('reset', this.render, this);
- this.collection.on('change', this.render, this);
- this.$el.appendTo('#pagination');
- },
- render: function () {
- var html = this.pagingTemplate(this.collection.info());
- this.$el.html(html);
- },
- gotoFirst: function (e) {
- e.preventDefault();
- this.collection.goTo(1);
- },
- gotoPrev: function (e) {
- e.preventDefault();
- this.collection.previousPage();
- },
- gotoNext: function (e) {
- e.preventDefault();
- this.collection.nextPage();
- },
- gotoLast: function (e) {
- e.preventDefault();
- this.collection.goTo(this.collection.information.lastPage);
- },
- gotoPage: function (e) {
- e.preventDefault();
- var page = $(e.target).text();
- this.collection.goTo(page);
- },
- changeCount: function (e) {
- e.preventDefault();
- var per = $(e.target).text();
- this.collection.howManyPer(per);
- },
- sortByAscending: function (e) {
- e.preventDefault();
- var currentSort = this.getSortOption();
- this.collection.pager(currentSort, 'asc');
- this.preserveSortOption(currentSort);
- },
- getSortOption: function () {
- return $('#sortByOption').val();
- },
- preserveSortOption: function (option) {
- $('#sortByOption').val(option);
- },
- sortByDescending: function (e) {
- e.preventDefault();
- var currentSort = this.getSortOption();
- this.collection.pager(currentSort, 'desc');
- this.preserveSortOption(currentSort);
- }
- });
- })( app.views );