summaryrefslogtreecommitdiff
path: root/web-ui/app/js/mail_list_actions/ui/pagination_trigger.js
blob: 1ada36e7ee4606cf7919fbb70d58c3931ab47e85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
define(
  [
    'flight/lib/component',
    'views/templates',
    'page/events'
  ],

  function(defineComponent, templates, events) {
    'use strict';

    return defineComponent(paginationTrigger);

    function paginationTrigger() {
      this.defaultAttrs({
        previous: '#left-arrow',
        next: '#right-arrow',
        currentPage: "#current-page"
      });

      this.renderWithPageNumber = function(pageNumber) {
        this.$node.html(templates.mailActions.paginationTrigger({
          currentPage: pageNumber
        }));
        this.on(this.attr.previous, 'click', this.previousPage);
        this.on(this.attr.next, 'click', this.nextPage);
      };

      this.render = function() {
        this.renderWithPageNumber(1);
      };

      this.updatePageDisplay = function(event, data) {
        this.renderWithPageNumber(data.currentPage + 1);
      };

      this.previousPage = function(event) {
        this.trigger(document, events.ui.page.previous);
      };

      this.nextPage = function(event) {
        this.trigger(document, events.ui.page.next);
      };

      this.after('initialize', function () {
        this.render();
        this.on(document, events.ui.page.changed, this.updatePageDisplay);
      });
    }
  }
);