diff options
Diffstat (limited to 'public/assets/javascripts/ui/EditProfileModal.js')
| -rw-r--r-- | public/assets/javascripts/ui/EditProfileModal.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/public/assets/javascripts/ui/EditProfileModal.js b/public/assets/javascripts/ui/EditProfileModal.js new file mode 100644 index 0000000..de8a8be --- /dev/null +++ b/public/assets/javascripts/ui/EditProfileModal.js @@ -0,0 +1,49 @@ + +var EditProfileModal = ModalView.extend({ + el: ".mediaDrawer.editProfile", + action: "/project/edit", + + 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() + }, + + submit: function(e){ + e.preventDefault() + + this.$errors.hide(); + this.$errorList.empty() + + var fields = this.$form.serializeArray() + + var request = $.post(this.action, $.param(fields)); + request.done($.proxy(function (response) { + if (response.error) { + this.$errors.show(); + for (var key in response.error.errors) { + this.$errorList.append('<div>' + response.error.errors[key].message + '</div>'); + } + return + } + else { + window.location.href = "/profile" + } + }, this)); + } + +}) + |
