From ce73133c4e982db99f218bf930d82eb991ce81e3 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 11 Dec 2017 11:17:55 +0100 Subject: profile --- public/assets/js/lib/views/profile/profile.js | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 public/assets/js/lib/views/profile/profile.js (limited to 'public/assets/js/lib/views/profile/profile.js') diff --git a/public/assets/js/lib/views/profile/profile.js b/public/assets/js/lib/views/profile/profile.js new file mode 100644 index 0000000..2180532 --- /dev/null +++ b/public/assets/js/lib/views/profile/profile.js @@ -0,0 +1,37 @@ +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") + this.$("img").attr("src", "/data/profile/" + sanitize(user.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) + }) + }, + +}) -- cgit v1.2.3-70-g09d2