PageRenderTime 40ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/public/js/views/misc/pagination.js

https://github.com/bozz/cashflow
JavaScript | 78 lines | 58 code | 15 blank | 5 comment | 2 complexity | 66d113956ae64ee5e650ebd821a2711d MD5 | raw file
  1. define(function(require) {
  2. var Backbone = require('backbone');
  3. var tpl = require('text!/templates/misc/pagination.jst.ejs');
  4. var PaginationView = Backbone.View.extend({
  5. tagName: 'ul',
  6. template: _.template(tpl),
  7. events: {
  8. 'click a.servernext': 'nextResultPage',
  9. 'click a.serverprevious': 'previousResultPage',
  10. 'click a.page': 'gotoPage'
  11. // 'click a.orderUpdate': 'updateSortBy',
  12. // 'click a.serverlast': 'gotoLast',
  13. // 'click a.serverfirst': 'gotoFirst',
  14. },
  15. initialize: function (options) {
  16. this.parentView = options.parentView;
  17. // this.collection.on('reset', this.render, this);
  18. // this.collection.on('change', this.render, this);
  19. },
  20. render: function () {
  21. var html = this.template(this.collection.info());
  22. $('div.pagination', this.parentView.el).html(this.$el.html(html));
  23. this.delegateEvents();
  24. return this;
  25. },
  26. updateSortBy: function (e) {
  27. e.preventDefault();
  28. var currentSort = $('#sortByField').val();
  29. this.collection.updateOrder(currentSort);
  30. },
  31. nextResultPage: function (e) {
  32. e.preventDefault();
  33. if(this.collection.currentPage < this.collection.totalPages) {
  34. this.collection.requestNextPage();
  35. }
  36. },
  37. previousResultPage: function (e) {
  38. e.preventDefault();
  39. if(this.collection.currentPage > 1) {
  40. this.collection.requestPreviousPage();
  41. }
  42. },
  43. gotoFirst: function (e) {
  44. e.preventDefault();
  45. this.collection.goTo(this.collection.information.firstPage);
  46. },
  47. gotoLast: function (e) {
  48. e.preventDefault();
  49. this.collection.goTo(this.collection.information.lastPage);
  50. },
  51. gotoPage: function (e) {
  52. e.preventDefault();
  53. var page = $(e.target).text();
  54. this.collection.goTo(page);
  55. },
  56. changeCount: function (e) {
  57. e.preventDefault();
  58. var per = $(e.target).text();
  59. this.collection.howManyPer(per);
  60. }
  61. });
  62. return PaginationView;
  63. });