PageRenderTime 66ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/netflix-request-paging/views/PaginationView.js

https://github.com/dgs700/backbone.paginator
JavaScript | 75 lines | 55 code | 20 blank | 0 comment | 0 complexity | f9fcc0e7bc233d8c94b0310e911ef6a1 MD5 | raw file
Possible License(s): MIT
  1. (function (views) {
  2. views.PaginatedView = Backbone.View.extend({
  3. events: {
  4. 'click a.servernext': 'nextResultPage',
  5. 'click a.serverprevious': 'previousResultPage',
  6. 'click a.orderUpdate': 'updateSortBy',
  7. 'click a.serverlast': 'gotoLast',
  8. 'click a.serverfirst': 'gotoFirst',
  9. 'click a.serverpage': 'gotoPage',
  10. 'click .serverhowmany a': 'changeCount'
  11. },
  12. tagName: 'aside',
  13. template: _.template($('#tmpServerPagination').html()),
  14. initialize: function () {
  15. this.collection.on('reset', this.render, this);
  16. this.collection.on('change', this.render, this);
  17. this.$el.appendTo('#pagination');
  18. },
  19. render: function () {
  20. var html = this.template(this.collection.info());
  21. this.$el.html(html);
  22. },
  23. updateSortBy: function (e) {
  24. e.preventDefault();
  25. var currentSort = $('#sortByField').val();
  26. this.collection.updateOrder(currentSort);
  27. },
  28. nextResultPage: function (e) {
  29. e.preventDefault();
  30. this.collection.requestNextPage();
  31. },
  32. previousResultPage: function (e) {
  33. e.preventDefault();
  34. this.collection.requestPreviousPage();
  35. },
  36. gotoFirst: function (e) {
  37. e.preventDefault();
  38. this.collection.goTo(this.collection.information.firstPage);
  39. },
  40. gotoLast: function (e) {
  41. e.preventDefault();
  42. this.collection.goTo(this.collection.information.lastPage);
  43. },
  44. gotoPage: function (e) {
  45. e.preventDefault();
  46. var page = $(e.target).text();
  47. this.collection.goTo(page);
  48. },
  49. changeCount: function (e) {
  50. e.preventDefault();
  51. var per = $(e.target).text();
  52. this.collection.howManyPer(per);
  53. }
  54. });
  55. })( app.views );