diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-06-10 12:00:24 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-06-10 12:00:24 -0400 |
| commit | 9fb0fe9b7ef614d2248b00ea2b964205f3453f41 (patch) | |
| tree | 953fd956e1c6b3d641226d7ac36cc749ced92504 /public/assets/javascripts/ui/site | |
| parent | 3f8e4223cc57bc3fd461881e3d6e9eb331bf4dc5 (diff) | |
split up builder functionality
Diffstat (limited to 'public/assets/javascripts/ui/site')
| -rw-r--r-- | public/assets/javascripts/ui/site/DocumentModal.js | 49 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/site/EditProfileModal.js | 56 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/site/EditProjectModal.js | 49 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/site/NewProjectModal.js | 17 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/site/SignInModal.js | 12 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/site/SignUpModal.js | 37 |
6 files changed, 220 insertions, 0 deletions
diff --git a/public/assets/javascripts/ui/site/DocumentModal.js b/public/assets/javascripts/ui/site/DocumentModal.js new file mode 100644 index 0000000..6f16169 --- /dev/null +++ b/public/assets/javascripts/ui/site/DocumentModal.js @@ -0,0 +1,49 @@ + +var DocumentModal = ModalFormView.extend({ + el: ".mediaDrawer.editDocument", + createAction: "/api/docs/new", + updateAction: "/api/docs/edit", + destroyAction: "/api/docs/destroy", + + load: function(name, isNew){ + this.reset() + + if (isNew || name === "new") { + name = sanitize(name) + if (name !== "new") { + this.$("[name='new_name']").val( name.replace(/\s+/g,"-") ) + this.$("[name='displayName']").val( capitalize(name.replace(/-/g," ")) ) + } + this.action = this.createAction + return this.show() + } + + this.action = this.updateAction + + $.get("/api/docs", { name: name }, $.proxy(function(data){ + if (data.isNew) { + this.action = this.createAction + } + + for (var i in data) { + this.$("[name='" + i + "']").val(data[i]) + } + this.$("[name='new_name']").val(name) + + this.show() + }, this)) + }, + + success: function(res){ + window.location.pathname = "/about/" + res.name + }, + + destroy: function(name, cb){ + $.ajax({ + type: "delete", + url: this.destroyAction, + data: { name: name, _csrf: $("[name=_csrf]").val() } + }).complete(cb || function(){}) + }, + +}) diff --git a/public/assets/javascripts/ui/site/EditProfileModal.js b/public/assets/javascripts/ui/site/EditProfileModal.js new file mode 100644 index 0000000..6b89ad8 --- /dev/null +++ b/public/assets/javascripts/ui/site/EditProfileModal.js @@ -0,0 +1,56 @@ + +var EditProfileModal = ModalFormView.extend({ + el: ".mediaDrawer.editProfile", + action: "/api/profile", + method: "put", + + load: function(){ + this.reset() + $.get("/api/profile", $.proxy(function(data){ + console.log(data) + + for (var i in data) { + 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/site/EditProjectModal.js b/public/assets/javascripts/ui/site/EditProjectModal.js new file mode 100644 index 0000000..356d8b7 --- /dev/null +++ b/public/assets/javascripts/ui/site/EditProjectModal.js @@ -0,0 +1,49 @@ + +var EditProjectModal = ModalView.extend({ + el: ".mediaDrawer.editProject", + 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)); + } + +}) + diff --git a/public/assets/javascripts/ui/site/NewProjectModal.js b/public/assets/javascripts/ui/site/NewProjectModal.js new file mode 100644 index 0000000..cf2044f --- /dev/null +++ b/public/assets/javascripts/ui/site/NewProjectModal.js @@ -0,0 +1,17 @@ + + +var NewProjectModal = ModalFormView.extend({ + el: ".mediaDrawer.newProject", + action: "/project/new", + + load: function(){ + this.reset() + this.show() + }, + + success: function(){ + // + } + +}) + diff --git a/public/assets/javascripts/ui/site/SignInModal.js b/public/assets/javascripts/ui/site/SignInModal.js new file mode 100644 index 0000000..4c91b54 --- /dev/null +++ b/public/assets/javascripts/ui/site/SignInModal.js @@ -0,0 +1,12 @@ + + +var SignInModal = ModalFormView.extend({ + el: ".mediaDrawer.signin", + action: "/auth/signin", + + success: function(res){ + window.location.href = "/profile" + } + +}) + diff --git a/public/assets/javascripts/ui/site/SignUpModal.js b/public/assets/javascripts/ui/site/SignUpModal.js new file mode 100644 index 0000000..5c651ee --- /dev/null +++ b/public/assets/javascripts/ui/site/SignUpModal.js @@ -0,0 +1,37 @@ +var SignUpModal = ModalFormView.extend({ + el: ".mediaDrawer.signup", + action: "/auth/signup", + + validate: function(){ + var errors = [] + + var username = this.$("#usernameInput").val() + var email = this.$("#emailInput").val() + var pw1 = this.$("#passwordInput1").val() + var pw2 = this.$("#passwordInput2").val() + + if (! username.length) { + errors.push("Please enter a username"); + } + if (! pw1.length) { + errors.push("Please enter a password"); + } + if (! email.length) { + errors.push("Please enter an email address"); + } + else if (email.indexOf("@") === -1) { + errors.push("Please enter a valid email address"); + } + if (pw1 !== pw2) { + errors.push("Passwords don't match"); + } + + return errors + }, + + success: function(res){ + window.location.href = "/profile" + } + +}) + |
