diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-12-14 06:48:53 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-12-14 06:48:53 +0100 |
| commit | f9a0743696c5e21d81ae0e215e36358788e708df (patch) | |
| tree | 07bc648b9b4f16999caa669ed5faf40f92d0345f /public/assets/js | |
| parent | 54b4af27409fba0032faf4c8bed825ce2bc71cce (diff) | |
profile form
Diffstat (limited to 'public/assets/js')
| -rw-r--r-- | public/assets/js/lib/router.js | 8 | ||||
| -rw-r--r-- | public/assets/js/lib/views/details/comments.js | 3 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/hootbox.js | 3 | ||||
| -rw-r--r-- | public/assets/js/lib/views/profile/profile.js | 8 | ||||
| -rw-r--r-- | public/assets/js/lib/views/profile/profile_edit.js | 50 | ||||
| -rw-r--r-- | public/assets/js/util/format.js | 3 |
6 files changed, 71 insertions, 4 deletions
diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js index 7b0fbb6..c16e58e 100644 --- a/public/assets/js/lib/router.js +++ b/public/assets/js/lib/router.js @@ -23,10 +23,11 @@ var SiteRouter = Router.extend({ "/comment/:id/edit": 'editComment', "/profile": 'profile', "/profile/:username": 'profile', + "/profile/:username/edit": 'editProfile', }, initialize: function(){ - $("#logout").click(() => this.logout()) + $(".logout").click(() => this.logout()) }, index: function(keyword){ @@ -82,6 +83,11 @@ var SiteRouter = Router.extend({ app.view.load(username || auth.user.username) }, + editProfile: function(username){ + app.view = new ProfileForm () + app.view.load(username || auth.user.username) + }, + compose: function(username){ app.view = new ComposeView () app.view.load(username) diff --git a/public/assets/js/lib/views/details/comments.js b/public/assets/js/lib/views/details/comments.js index 4c217a4..0c2cdcc 100644 --- a/public/assets/js/lib/views/details/comments.js +++ b/public/assets/js/lib/views/details/comments.js @@ -27,7 +27,8 @@ var CommentsView = FormView.extend({ parse: function(comment){ if (! comment.comment.length) return $('') var datetime = verbose_date(comment.date, true) - var t = this.template.replace(/{{username}}/g, comment.username) + var t = this.template.replace(/{{image}}/g, profile_image(comment.username)) + .replace(/{{username}}/g, comment.username) .replace(/{{id}}/g, comment.id) .replace(/{{comment}}/g, tidy_urls(comment.comment)) .replace(/{{date}}/g, datetime[0]) diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js index 6be9596..85fd51e 100644 --- a/public/assets/js/lib/views/index/hootbox.js +++ b/public/assets/js/lib/views/index/hootbox.js @@ -23,7 +23,8 @@ var HootBox = FormView.extend({ }, parse: function(comment){ - var t = this.template.replace(/{{username}}/g, comment.username) + var t = this.template.replace(/{{username}}/g, profile_image(comment.username)) + .replace(/{{username}}/g, comment.username) .replace(/{{comment}}/g, tidy_urls(comment.comment, true)) return t }, diff --git a/public/assets/js/lib/views/profile/profile.js b/public/assets/js/lib/views/profile/profile.js index d8bc535..1b3e496 100644 --- a/public/assets/js/lib/views/profile/profile.js +++ b/public/assets/js/lib/views/profile/profile.js @@ -19,7 +19,13 @@ var ProfileView = View.extend({ $("body").removeClass('loading') var $table = this.$("table") var username = sanitize(user.username) - this.$("img").attr("src", "/data/profile/" + username + ".jpg") + 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 realname phone location".split(" ").map((key) => { if (! user[key]) return; var t = this.template.replace(/{{key}}/, sanitize(key)) diff --git a/public/assets/js/lib/views/profile/profile_edit.js b/public/assets/js/lib/views/profile/profile_edit.js new file mode 100644 index 0000000..a6ff211 --- /dev/null +++ b/public/assets/js/lib/views/profile/profile_edit.js @@ -0,0 +1,50 @@ +var ProfileForm = FormView.extend({ + + el: "#profile_form", + + events: { + "change #profile-pic": 'changeProfilePic', + }, + + action: "/api/user", + method: "POST", + + initialize: function(){ + this.__super__.initialize.call(this) + this.template = this.$(".template").html() + }, + + load: function(username){ + console.log('hi') + this.action = "/api/user/" + username; + "realname location email phone website fb twitter".split(" ").forEach((field) => { + this.$('[name=' + field + ']').val( sanitize(auth.user[field]) ) + }) + if (! auth.user.pic) { + $("#profile-pic-embed").hide() + } else { + $("#profile-pic-embed").attr("src", sanitize(auth.user.pic)) + } + $("body").removeClass('loading') + }, + + changeProfilePic: function(){ + // $("#profile-pic-embed").show().attr("src", sanitize(auth.user.pic)) + }, + + validate: function(){ + var errors = [] + var title = this.$("[name=title]").val() + if (! title || ! title.length) { + errors.push("Please title your post.") + } + return errors.length ? errors : null + }, + + success: function(data){ + if (data.error) { + return alert(data.error) + } + window.location.href = "/details/" + data.id + } +})
\ No newline at end of file diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js index fcc1df0..7dee404 100644 --- a/public/assets/js/util/format.js +++ b/public/assets/js/util/format.js @@ -217,6 +217,9 @@ function make_link(file){ } return file.filename } +function profile_image(username){ + return "//s3.amazonaws.com/i.asdf.us/bucky/data/profile/" + username + ".jpg" +} function make_thumb(file){ if (file.storage) { return "//s3.amazonaws.com/" + file.storage + "/bucky/data/" + file.thread + "/" + encodeURIComponent(file.filename) |
