summaryrefslogtreecommitdiff
path: root/public/assets/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js')
-rw-r--r--public/assets/js/lib/router.js38
-rw-r--r--public/assets/js/lib/views/mail/compose.js35
-rw-r--r--public/assets/js/lib/views/profile/profile.js11
3 files changed, 64 insertions, 20 deletions
diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js
index 03c7bc8..1419e81 100644
--- a/public/assets/js/lib/router.js
+++ b/public/assets/js/lib/router.js
@@ -3,23 +3,24 @@ var SiteRouter = Router.extend({
el: "body",
routes: {
- "/": 'login',
- "/index/:keyword": 'index',
- "/index": 'index',
- "/login": 'login',
- "/signup": 'signup',
- "/details/:id": 'details',
- "/details/:id/settings": 'threadSettings',
- "/post": 'post',
- "/post/:keyword": 'post',
- "/search": 'search',
- "/mail": 'mailbox',
- "/mail/:mailbox": 'mailbox',
- "/mail/compose": 'compose',
- "/message/:id": 'message',
- "/comment/:id/edit": 'editComment',
- "/profile": 'profile',
- "/profile/:username": 'profile',
+ "/": 'login',
+ "/index/:keyword": 'index',
+ "/index": 'index',
+ "/login": 'login',
+ "/signup": 'signup',
+ "/details/:id": 'details',
+ "/details/:id/settings": 'threadSettings',
+ "/post": 'post',
+ "/post/:keyword": 'post',
+ "/search": 'search',
+ "/mail": 'mailbox',
+ "/mail/:mailbox": 'mailbox',
+ "/mail/compose": 'compose',
+ "/mail/compose/:username": 'compose',
+ "/message/:id": 'message',
+ "/comment/:id/edit": 'editComment',
+ "/profile": 'profile',
+ "/profile/:username": 'profile',
},
initialize: function(){
@@ -73,8 +74,9 @@ var SiteRouter = Router.extend({
app.view.load(username || auth.user.username)
},
- compose: function(){
+ compose: function(username){
app.view = new ComposeView ()
+ app.view.load(username)
},
search: function(){
diff --git a/public/assets/js/lib/views/mail/compose.js b/public/assets/js/lib/views/mail/compose.js
index 49f29f4..2c76b3f 100644
--- a/public/assets/js/lib/views/mail/compose.js
+++ b/public/assets/js/lib/views/mail/compose.js
@@ -1,3 +1,36 @@
var ComposeView = FormView.extend({
+
+ el: "#compose",
+
+ events: {
+ },
+
+ action: "",
+
+ initialize: function(){
+ this.__super__.initialize.call(this)
+ this.template = this.$(".template").html()
+ },
+
+ load: function(username){
+ this.$("[name=username]").val(sanitize(username))
+ $("body").removeClass('loading')
+ },
+
+ validate: function(){
+ var errors = []
+ var username = $("[name=username]").val()
+ var message = $("[name=message]").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.")
+ }
+ return errors.length ? errors : null
+ },
-})
+ success: function(){
+ window.location.reload()
+ }
+}) \ No newline at end of file
diff --git a/public/assets/js/lib/views/profile/profile.js b/public/assets/js/lib/views/profile/profile.js
index 2180532..34c8fba 100644
--- a/public/assets/js/lib/views/profile/profile.js
+++ b/public/assets/js/lib/views/profile/profile.js
@@ -18,7 +18,8 @@ var ProfileView = View.extend({
populate: function(user){
$("body").removeClass('loading')
var $table = this.$("table")
- this.$("img").attr("src", "/data/profile/" + sanitize(user.username) + ".jpg")
+ var username = sanitize(user.username)
+ this.$("img").attr("src", "/data/profile/" + username + ".jpg")
var fields = "username realname phone location".split(" ").map((key) => {
if (! user[key]) return;
var t = this.template.replace(/{{key}}/, sanitize(key))
@@ -32,6 +33,14 @@ var ProfileView = View.extend({
.replace(/{{value}}/, date[0] + ' <small>' + date[1] + '</small>')
$table.append(t)
})
+
+ var fields = "message".split(" ").map((key) => {
+ if (! user[key]) return;
+ var t = this.template.replace(/{{key}}/, "&nbsp;")
+ .replace(/{{value}}/, '<a href="/mail/compose/' + username + '">send ' + username + ' a message</a>')
+ $table.append(t)
+ })
+
},
})