summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/details/index.js
blob: 0a40dbc61beb40bb0899807593696544f5e5acc9 (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
var DetailsView = View.extend({

  events: {
  },
  
  action: "/api/thread/",
  keywordAction: "/api/keyword/",
  
  
  initialize: function(opt){
    this.comments = new CommentsView ({ parent: this })
    this.files = new FilesView ({ parent: this })
    this.gallery = new GalleryView ({ parent: this })
    this.form = new CommentForm ({ parent: this })
    this.threadbox = new ThreadBox ({ parent: this })
  },
  
  load: function(id){
    id = id.replace(/\D/g, "")
    $.get(this.action + id, this.populate.bind(this))
  },
  
  populate: function(data){
    var thread = data.thread
    $("h1").html(thread.title)
    $(".subtitle").show().html(metadata(thread))
    this.form.load(data.thread)
    this.comments.load(data.comments)
    this.files.load(data.files)
    this.gallery.load(data.files)
    if (data.thread.keyword) {
      $.get(this.keywordAction + data.thread.keyword, this.populateKeyword.bind(this))
    }
  },
  
  populateKeyword: function(data){
    this.threadbox.load(data)
  },
  
  success: function(){
    window.location.href = "/index"
  },

})

var metadataTemplate = $(".metadata_template").html()
function metadata(thread){
  var datetime = verbose_date(thread.createdate, true)
  var age = get_age(thread.lastmodified, true)
  var t = metadataTemplate
              .replace(/{{ username }}/g, thread.username)
              .replace(/{{ date }}/g, datetime[0])
              .replace(/{{ time }}/g, datetime[1])
              .replace(/{{ active }}/g, age + " ago")
              .replace(/{{ views }}/g, thread.viewed + " view" + courtesy_s(thread.viewed))
  return t
}