summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/mail/mailbox.js
blob: fb852529025e8ad2014d651d479780d256fdf0bf (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 MailboxView = View.extend({
  el: ".mailbox",
  
  events: {
  },
  
  action: "/api/mailbox/",
  
  initialize: function(){
    this.__super__.initialize.call(this)
    this.template = this.$(".template").html()
    this.boxTemplate = this.$(".boxTemplate").html()
  },
  
  load: function(name){
    $("h1").html(name)
    $.get(this.action + name, this.populate.bind(this))
  },
  
  populate: function(data){
    data.boxes.forEach(this.appendBox.bind(this))
    data.messages.forEach(this.appendMessage.bind(this))
  },
  
  parseBox: function(box){
    var t = this.boxTemplate
                .replace(/{{box}}/g, box.name)
                .replace(/{{count}}/g, box.count)
    return t
  },
  
  parseMessage: function(message){
    var datetime = verbose_date(message.date)
    var id = message.id

    var t = this.template
                .replace(/{{id}}/g, thread.id)
                .replace(/{{username}}/g, thread.username)
                .replace(/{{subject}}/g, thread.title)
                .replace(/{{date}}/g, datetime[0])
                .replace(/{{time}}/g, datetime[1])
                .replace(/{{date_class}}/g, carbon_date(thread.lastmodified) )
                .replace(/{{size}}/g, size[1] )
                .replace(/{{size_class}}/g, size[0] )
    return t
  },

  appendBox: function(box){
    var $row = $( this.parseBox(box) )
    this.$el.append($row)
  },

  appendMessage: function(message){
    var $row = $( this.parseMessage(message) )
    this.$el.append($row)
  },

})