var SiteRouter = Router.extend({ el: "body", events: { "click [data-role='show-signup-modal']": 'signup', "click [data-role='show-signin-modal']": 'signin', "click [data-role='forgot-password']": 'passwordForgot', "click [data-role='new-project-modal']": 'newProject', "click [data-role='edit-project-modal']": 'editProject', "click [data-role='edit-profile-modal']": 'editProfile', "click [data-role='new-document-modal']": 'newDocument', "click [data-role='edit-document-modal']": 'editDocument', "click [data-role='destroy-document-modal']": 'destroyDocument', "click [data-role='show-layouts-modal']": 'layoutPicker', "click [data-role='show-projects-modal']": 'projectPicker', }, routes: { "/login": 'signin', "/signup": 'signup', "/auth/usernameTaken": 'usernameTaken', "/auth/password": 'passwordReset', "/auth/forgotPassword": 'passwordForgot', "/profile": 'profile', "/profile/edit": 'editProfile', "/about/:name/edit": 'editDocument', "/about/new": 'newDocument', "/layout": 'layoutPicker', "/layout/:name": 'layoutEditor', "/project": 'projectPicker', "/project/new": 'newProject', "/project/new/:layout": 'projectNewWithLayout', "/project/:name": 'project', "/project/:name/view": 'projectViewer', }, initialize: function(){ this.signUpModal = new SignUpModal() this.signInModal = new SignInModal() this.layoutsModal = new LayoutsModal() this.projectsModal = new ProjectsModal() this.newProjectModal = new NewProjectModal() this.editProjectModal = new EditProjectModal() this.editProfileModal = new EditProfileModal() this.passwordForgotModal = new PasswordForgot() this.documentModal = new DocumentModal() this.profileView = new ProfileView() this.route() $("body").removeClass("loading") }, layoutEditor: function(e, name){ app.mode.builder = true app.launch() this.builderView = new BuilderView() this.builderView.load(name) }, layoutPicker: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/layout") this.layoutsModal.load() }, projectPicker: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/project") this.projectsModal.load() }, newProject: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/project/new") this.newProjectModal.load() }, projectNewWithLayout: function(e, layout){ e && e.preventDefault() app.mode.editor = true app.launch() layout = slugify(layout) window.history.pushState(null, document.title, "/project/new/" + layout) this.editorView = new EditorView() this.editorView.loadLayout(layout) }, project: function(e, name){ if ($(".aboutRoom").length) { this.projectViewer(e, name) } else { this.projectEditor(e, name) } }, projectEditor: function(e, name){ app.mode.editor = true app.launch() this.editorView = new EditorView() this.editorView.load(name) }, projectViewer: function(e, name){ app.mode.editor = true app.launch() this.readerView = new ReaderView() this.readerView.load(name) }, /* editProject: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/project/edit") this.editProjectModal.load() }, */ signup: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/signup") this.signUpModal.load() }, signin: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/login") this.signInModal.load() }, usernameTaken: function(e){ this.usernameTakenModal = new UsernameTaken () this.usernameTakenModal.load() }, passwordForgot: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/auth/forgotPassword") this.passwordForgotModal.load() }, passwordReset: function(e){ this.passwordResetModal = new PasswordReset () this.passwordResetModal.load() }, profile: function(e){ this.profileView.load() }, editProfile: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/profile/edit") this.editProfileModal.load() }, newDocument: function(e){ e && e.preventDefault() var name = e ? $(e.currentTarget).data("name") : "new" window.history.pushState(null, document.title, "/about/new") this.documentModal.load(name, true) }, editDocument: function(e, name){ e && e.preventDefault() var name = e ? $(e.currentTarget).data("name") : name window.history.pushState(null, document.title, "/about/" + name + "/edit") this.documentModal.load(name, false) }, destroyDocument: function(e, name){ e && e.preventDefault() var name = e ? $(e.currentTarget).data("name") : name confirmModal.confirm("Are you sure you want to delete " + name + "?", $.proxy(function(){ this.documentModal.destroy(name, $.proxy(function(){ AlertModal.alert("Document deleted!", $.proxy(function(){ window.location.href = "/about" }, this)) }, this)) }, this)) // this.documentModal.destroy(name) }, })