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 | |
| parent | e8ba718205d41e75923264ef945178030b662c93 (diff) | |
editing profile
Diffstat (limited to 'public/assets/javascripts/ui')
| -rw-r--r-- | public/assets/javascripts/ui/EditProfileModal.js | 34 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/ModalFormView.js | 70 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/ModalView.js | 28 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/Router.js (renamed from public/assets/javascripts/ui/MasterView.js) | 2 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/SignUpModal.js | 2 |
5 files changed, 34 insertions, 102 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" } }) - diff --git a/public/assets/javascripts/ui/ModalFormView.js b/public/assets/javascripts/ui/ModalFormView.js deleted file mode 100644 index 608b8c1..0000000 --- a/public/assets/javascripts/ui/ModalFormView.js +++ /dev/null @@ -1,70 +0,0 @@ - -var ModalFormView = ModalView.extend({ - - events: { - "submit form": "submit" - }, - - initialize: function(){ - this.$form = this.$("form") - this.$errors = this.$(".errors") - this.$errorList = this.$(".errorList") - }, - - reset: function(){ - this.$("input").not("[type='submit']").not("[type='hidden']").val("") - }, - - load: function(){ - this.reset() - this.show() - }, - - showErrors: function(errors){ - if (errors && errors.length) { - this.$errors.show(); - for (var i in errors) { - this.$errorList.append('<div>' + errors[i] + '</div>'); - } - } - }, - - submit: function(e){ - e.preventDefault() - - this.$errors.hide(); - this.$errorList.empty(); - - if (this.validate) { - var errors = this.validate() - if (errors && errors.length) { - this.showErrors(errors) - return - } - } - - var fields = this.$form.serializeArray() - fields.forEach(function(pair){ - if (pair.name == "password" && pair.value.length > 0) { - pair.value = SHA1.hex('lol$' + pair.value + '$vvalls') - } - }) - - var request = $.post(this.action, $.param(fields)); - request.done($.proxy(function (response) { - if (response.error) { - this.$errors.show(); - var errors = [] - for (var key in response.error.errors) { - errors.push(response.error.errors[key].message); - } - this.showErrors(errors) - return - } - else { - this.success && this.success(response) - } - }, this)); - } - -}) diff --git a/public/assets/javascripts/ui/ModalView.js b/public/assets/javascripts/ui/ModalView.js deleted file mode 100644 index 80ce8d0..0000000 --- a/public/assets/javascripts/ui/ModalView.js +++ /dev/null @@ -1,28 +0,0 @@ - -var ModalView = View.extend({ - events: { - "click .close": 'close', - }, - - show: function(){ - $(".mediaDrawer").removeClass("active"); - this.$el.addClass("active"); - $("body").addClass("noOverflow"); - }, - - hide: function(){ - // $(".mediaDrawer, .room1").removeClass("active editing"); - this.$el.removeClass("active"); - $("body").removeClass("noOverflow"); - }, - - close: function(){ - if (window.isModalView) { - window.location.pathname = "/" - } - else { - history.pushState(null, document.title, app.master.originalPath) - this.hide() - } - } -}) diff --git a/public/assets/javascripts/ui/MasterView.js b/public/assets/javascripts/ui/Router.js index 5aca4e0..a518e27 100644 --- a/public/assets/javascripts/ui/MasterView.js +++ b/public/assets/javascripts/ui/Router.js @@ -1,5 +1,5 @@ -var MasterView = View.extend({ +var Router = View.extend({ el: "body", events: { diff --git a/public/assets/javascripts/ui/SignUpModal.js b/public/assets/javascripts/ui/SignUpModal.js index 95b5837..5c651ee 100644 --- a/public/assets/javascripts/ui/SignUpModal.js +++ b/public/assets/javascripts/ui/SignUpModal.js @@ -1,5 +1,3 @@ - - var SignUpModal = ModalFormView.extend({ el: ".mediaDrawer.signup", action: "/auth/signup", |
