summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/mail/compose.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-12 10:29:59 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-12 10:29:59 +0100
commit64c4a75529db6c2129fbcde2b1b63a44d4a45fb4 (patch)
treecc28046dcbd0bc62f54093c1bae03c375ccc04ae /public/assets/js/lib/views/mail/compose.js
parentaefc83f729ab3f3c35d9371ec972fb6885b13125 (diff)
replying to messages
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(/&nbsp;/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