diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-06-09 11:26:04 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-06-09 11:26:04 -0400 |
| commit | e5dc46846ce9fb1c990d291ef852c0cad3f74957 (patch) | |
| tree | 16de7362bcdb8d87e41f22f452f6b8e427e98ff1 /public/assets/javascripts/ui/EditProfileModal.js | |
| parent | e8ba718205d41e75923264ef945178030b662c93 (diff) | |
editing profile
Diffstat (limited to 'public/assets/javascripts/ui/EditProfileModal.js')
| -rw-r--r-- | public/assets/javascripts/ui/EditProfileModal.js | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/public/assets/javascripts/ui/EditProfileModal.js b/public/assets/javascripts/ui/EditProfileModal.js index 5b79a31..6b89ad8 100644 --- a/public/assets/javascripts/ui/EditProfileModal.js +++ b/public/assets/javascripts/ui/EditProfileModal.js @@ -2,6 +2,7 @@ var EditProfileModal = ModalFormView.extend({ el: ".mediaDrawer.editProfile", action: "/api/profile", + method: "put", load: function(){ this.reset() @@ -12,13 +13,44 @@ var EditProfileModal = ModalFormView.extend({ this.$("[name='" + i + "']").val(data[i]) } + this.$("#profile_username").html(data.username) + + if (data.photo && data.photo.length) { + this.$("#load_avatar").attr("src", data.photo) + } + else { + this.$("#load_avatar").hide() + } + this.show() }, this)) }, + + validate: function(){ + var errors = [] + + var email = this.$("#profile_email").val() + var pw0 = this.$("#profile_old_password").val() + var pw1 = this.$("#profile_new_password").val() + var pw2 = this.$("#profile_new_password2").val() + + if (pw1.length) { + if (! pw0.length) { + errors.push("Please enter your old password.") + } + if (pw1 !== pw2) { + errors.push("New passwords don't match"); + } + } + if (email.length && email.indexOf("@") === -1) { + errors.push("Please enter a valid email address"); + } + + return errors + }, success: function(){ window.location.href = "/profile" } }) - |
