summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-09-07 14:56:27 -0400
committerJules Laplace <jules@okfoc.us>2015-09-07 14:56:27 -0400
commita7104749040bc425d1170901c6e7d8d5a8045fb3 (patch)
tree336b267593c4fed8afb7fb38b16f5f3cfb4034bf
parent9957952d2761b1d2b216a9310339e28f25df9f6c (diff)
list mailboxes
-rw-r--r--lib/bucky.js1
-rw-r--r--lib/router.js1
-rw-r--r--public/assets/js/lib/views/mail/boxlist.js26
-rw-r--r--public/assets/js/lib/views/mail/mailbox.js16
-rw-r--r--views/pages/mailbox.ejs2
-rw-r--r--views/partials/scripts.ejs1
6 files changed, 32 insertions, 15 deletions
diff --git a/lib/bucky.js b/lib/bucky.js
index db1672c..c003103 100644
--- a/lib/bucky.js
+++ b/lib/bucky.js
@@ -1,4 +1,5 @@
var db = require('./db')
+var util = require('./util')
var _ = require('lodash')
var bucky = module.exports = {
diff --git a/lib/router.js b/lib/router.js
index 5d3dcb5..806c6db 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -2,6 +2,7 @@ var auth = require('./auth')
var middleware = require('./middleware')
var fortune = require('./fortune')
var bucky = require('./bucky')
+var util = require('./util')
module.exports = function(app){
app.all('*', middleware.ensureLocals)
diff --git a/public/assets/js/lib/views/mail/boxlist.js b/public/assets/js/lib/views/mail/boxlist.js
new file mode 100644
index 0000000..68494ac
--- /dev/null
+++ b/public/assets/js/lib/views/mail/boxlist.js
@@ -0,0 +1,26 @@
+var BoxList = View.extend({
+ el: "#boxes",
+
+ initialize: function(){
+ this.__super__.initialize.call(this)
+ this.template = this.$(".template").html()
+ this.$table = this.$("table")
+ },
+
+ load: function(data){
+ data.forEach(this.appendBox.bind(this))
+ },
+
+ appendBox: function(box){
+ var $row = $( this.parseBox(box) )
+ this.$table.append($row)
+ },
+
+ parseBox: function(box){
+ var t = this.template
+ .replace(/{{box}}/g, box.mbox.split(".")[1])
+ .replace(/{{count}}/g, box.count)
+ return t
+ },
+
+}) \ No newline at end of file
diff --git a/public/assets/js/lib/views/mail/mailbox.js b/public/assets/js/lib/views/mail/mailbox.js
index 315a713..ac66c4c 100644
--- a/public/assets/js/lib/views/mail/mailbox.js
+++ b/public/assets/js/lib/views/mail/mailbox.js
@@ -9,7 +9,7 @@ var MailboxView = View.extend({
initialize: function(){
this.__super__.initialize.call(this)
this.template = this.$(".template").html()
- this.boxTemplate = this.$(".boxTemplate").html()
+ this.boxlist = new BoxList ()
},
load: function(name){
@@ -19,17 +19,10 @@ var MailboxView = View.extend({
},
populate: function(data){
- data.boxes.forEach(this.appendBox.bind(this))
+ this.boxlist.load(data.boxes)
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
@@ -46,11 +39,6 @@ var MailboxView = View.extend({
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)
diff --git a/views/pages/mailbox.ejs b/views/pages/mailbox.ejs
index d97755a..62cf718 100644
--- a/views/pages/mailbox.ejs
+++ b/views/pages/mailbox.ejs
@@ -13,7 +13,7 @@
<td>msgs</td>
</tr>
</table>
- <script type="text/html" class="boxTemplate">
+ <script type="text/html" class="template">
<tr>
<td><a href="/mail/{{box}}">{{box}}</a></td>
<td>{{count}}</td>
diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs
index d0f5908..0a5c4d6 100644
--- a/views/partials/scripts.ejs
+++ b/views/partials/scripts.ejs
@@ -28,5 +28,6 @@
<script src="/assets/js/lib/views/mail/mailbox.js"></script>
<script src="/assets/js/lib/views/mail/message.js"></script>
<script src="/assets/js/lib/views/mail/compose.js"></script>
+<script src="/assets/js/lib/views/mail/boxlist.js"></script>
<script src="/assets/js/index.js"></script>