1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
var ProfileView = View.extend({
el: "#profile",
events: {
},
action: "/api/user/",
initialize: function(opt){
this.template = this.$(".template").html()
},
load: function(username){
$.get(this.action + username, this.populate.bind(this))
},
populate: function(user){
$("body").removeClass('loading')
var $table = this.$("table")
var username = sanitize(user.username)
var is_own_profile = (username === auth.user.username)
if (is_own_profile) {
$(".edit_profile a").attr("href", "/profile/" + username + "/edit")
} else {
$(".edit_profile").hide()
}
this.$("img").attr("src", profile_image(username))
var fields = [
["username", "Username"],
["realname", "Real Name"],
["location", "Location"],
["phone", "Phone"],
].map(pair => {
var key = pair[0], label = pair[1]
if (! user[key]) return;
return [label, sanitize(user[key])]
})
if (user.email) {
fields.push([
'Email',
'<a href="mailto:' + sanitize(user.email) + '">' + sanitize(user.email) + '</a>'
])
}
if (user.twitter) {
if (user.twitter.match(/^http/)) {
var partz = user.twitter.split('/')
if (partz.length > 2) {
var handle = sanitize(partz[3])
fields.push([
'Twitter',
'<a href="https://twitter.com/' + handle + '">@' + handle + '</a>'
])
}
} else {
var handle = sanitize(user.twitter)
fields.push([
'Twitter',
'<a href="https://twitter.com/' + handle + '">@' + handle + '</a>'
])
}
}
if (user.website) {
var website = sanitize(user.website)
fields.push([
'Website',
'<a href="' + sanitize(website) + '">' + sanitize(website) + '</a>'
])
}
fields = fields.concat([
["firstseen", "First Seen"],
["lastseen", "Last Seen"],
].map((pair) => {
var key = pair[0], label = pair[1]
if (! user[key]) return;
var date = verbose_date(user[key])
return [label, date[0] + ' <small>' + date[1] + '</small>']
}))
fields.push([
' ',
'<a href="/mail/compose/' + username + '">send ' + username + ' a message</a>'
])
var rows = fields.filter(pair => !!pair).map(pair => {
var t = this.template.replace(/{{label}}/, pair[0])
.replace(/{{value}}/, pair[1])
return t
})
$table.append(rows.join(""))
},
})
|