summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/mail/compose.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/views/mail/compose.js')
-rw-r--r--public/assets/js/lib/views/mail/compose.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/public/assets/js/lib/views/mail/compose.js b/public/assets/js/lib/views/mail/compose.js
index b3e302e..1da4ceb 100644
--- a/public/assets/js/lib/views/mail/compose.js
+++ b/public/assets/js/lib/views/mail/compose.js
@@ -13,6 +13,24 @@ var ComposeView = FormView.extend({
},
load: function(username){
+ var id = parseInt(username)
+ if (! isNaN(id)) {
+ $.get('/api/message/' + id, function(data){
+ var message = data.message
+ var date = verbose_date(message.date)
+ var tmpl = $("#reply-template").html()
+ .replace(/{{username}}/, message.sender)
+ .replace(/{{date}}/, date[0])
+ .replace(/{{time}}/, date[1])
+ .replace(/ /g, " ")
+ console.log(tmpl)
+ this.$("[name=username]").val(message.sender)
+ this.$("[name=subject]").val(message.subject)
+ this.$("[name=body]").val(sanitize(tmpl + message.body))
+ $("body").removeClass('loading')
+ }.bind(this))
+ return
+ }
this.$("[name=username]").val(sanitize(username))
$("body").removeClass('loading')
},
@@ -20,17 +38,17 @@ var ComposeView = FormView.extend({
validate: function(){
var errors = []
var username = $("[name=username]").val()
- var message = $("[name=message]").val()
+ var body = $("[name=body]").val()
if (! username || ! username.length) {
errors.push("Please enter who this message is going to.")
}
- if (! message || ! message.length) {
- errors.push("Please enter your message.")
+ if (! body || ! body.length) {
+ errors.push("Please enter your body.")
}
return errors.length ? errors : null
},
success: function(){
- window.location.reload()
+ window.location.href = "/mail/outbox"
}
}) \ No newline at end of file