diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-09-07 14:04:18 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-09-07 14:04:18 -0400 |
| commit | ebac7f79d32c524de750adc3bcf1cc539625d552 (patch) | |
| tree | 0967200ce631c16a54121d36a3e472eb08ad049c /public/assets/js/lib/views/mail/mailbox.js | |
| parent | aa9718404cba9cf1c872b7cedded31d68d3beb54 (diff) | |
split up partials and stub in mailbox frontend
Diffstat (limited to 'public/assets/js/lib/views/mail/mailbox.js')
| -rw-r--r-- | public/assets/js/lib/views/mail/mailbox.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/mail/mailbox.js b/public/assets/js/lib/views/mail/mailbox.js new file mode 100644 index 0000000..fe16980 --- /dev/null +++ b/public/assets/js/lib/views/mail/mailbox.js @@ -0,0 +1,58 @@ +var Mailbox = 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) + }, + +}) |
