summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/stream/index.js
blob: 1504554597cb38b773ab038a27baacf1684e0f67 (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
51
52
53
54
55
56
57
58
var StreamView = View.extend({
  action: "/api/stream/",

  initialize: function (opt) {
    // opt.parent = parent
    this.hootform = new HootForm({ parent: this });
    this.hootstream = new HootStream({ parent: this });
    this.hootfilters = new HootFilters({ parent: this });
  },

  load: function ({ ...target }) {
    $("body").addClass("index");
    this.target = target;
    console.log("target", target);
    $.get(this.action, target, this.populate.bind(this));
  },

  populate: function (data) {
    $("body").removeClass("loading");
    this.data = data;
    const { query } = data;
    const isHomePage = !(query.thread || query.username || query.keyword);
    this.hootform.toggle(isHomePage);
    this.hootfilters.load(data, this.target);
    this.hootstream.load(data, this.hootfilters.state);
    if (data.mail.count) {
      $(".alert")
        .show()
        .html(
          "<a href='/mail'>" +
            "You have " +
            data.mail.count +
            " new message" +
            courtesy_s(data.mail.count) +
            "!</a>"
        );
      if (is_mobile) {
        $("#content").prepend($(".alert"));
      }
    }
    $(".search_form input").focus();
  },

  onComment: function (comment) {
    this.data.hootbox.comments.push(comment);
    this.data.hootstream.comments.push(comment);
    this.populate(this.data);
  },

  onFilter: function (filters) {
    console.log("onfilter");
    this.hootstream.build(filters);
  },

  success: function () {
    window.location.href = "/index";
  },
});