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) 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)) .replace(/{{value}}/, sanitize(user[key])) $table.append(t) }) var fields = "firstseen lastseen".split(" ").map((key) => { if (! user[key]) return; var date = verbose_date(user[key]) var t = this.template.replace(/{{key}}/, sanitize(key)) .replace(/{{value}}/, date[0] + ' ' + date[1] + '') $table.append(t) }) var t = this.template.replace(/{{key}}/, " ") .replace(/{{value}}/, 'send ' + username + ' a message') $table.append(t) }, })