var ProfileView = View.extend({ el: "#profile", events: { }, action: "/api/profile/", initialize: function(opt){ this.template = this.$(".template").html() this.comments = new CommentsView ({ parent: this }) this.files = new FilesView ({ parent: this }) this.gallery = new GalleryView ({ parent: this }) this.threadbox = new ThreadBox ({ parent: this }) }, load: function(username){ $.get(this.action + username, this.loadProfile.bind(this)) }, loadProfile: function(data){ const { user, threads, topThreads, files, comments } = data this.populate(user) // this.populateComments(topComments) // this.comments.load(data.comments, data.thread) this.gallery.load(files) this.files.load(files) this.files.resort("date_desc") this.threadbox.load({ threads, user, sort: 'date' }) }, populate: function(user){ $("body").removeClass('loading') var $table = this.$("table.profile_meta") var username = sanitizeHTML(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, sanitizeHTML(user[key])] }) if (user.email) { fields.push([ 'Email', '' + sanitizeHTML(user.email) + '' ]) } if (user.twitter) { if (user.twitter.match(/^http/)) { var partz = user.twitter.split('/') if (partz.length > 2) { var handle = sanitizeHTML(partz[3]) fields.push([ 'Twitter', '@' + handle + '' ]) } } else { var handle = sanitizeHTML(user.twitter) fields.push([ 'Twitter', '@' + handle + '' ]) } } if (user.website) { var website = sanitizeHTML(user.website) fields.push([ 'Website', '' + sanitizeHTML(website) + '' ]) } 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] + ' ' + date[1] + ''] })) fields.push([ ' ', 'send ' + username + ' a message' ]) 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("")) }, })