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: { "/": 'home', "/home": 'home', "/login": 'signin', "/signin": 'signin', "/signup": 'signup', "/auth/usernameTaken": 'usernameTaken', "/auth/password": 'passwordReset', "/auth/forgotPassword": 'passwordForgot', "/profile": 'profile', "/profile/edit": 'editProfile', "/profile/:name": 'profile', "/about/:name/edit": 'editDocument', "/about/new": 'newDocument', "/layout": 'layoutPicker', "/layout/:name": 'layoutEditor', "/project": 'projectPicker', "/project/new": 'newProject', "/project/new/:layout": 'projectNewWithLayout', "/project/:name": 'projectViewer', "/project/:name/edit": 'projectEditor', "/project/:name/view": 'projectViewer', }, mobileRoutes: { "/": 'home', "/home": 'home', "/login": 'signin', "/signin": 'signin', "/signup": 'signup', "/auth/usernameTaken": 'usernameTaken', "/auth/password": 'passwordReset', "/auth/forgotPassword": 'passwordForgot', "/profile": 'profile', "/profile/edit": 'editProfile', "/profile/:name": 'profile', "/project/:name": '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() if (is_mobile) { // $(".topLinks").hide() // $(".share").hide() $('.projectItem').each(function(){ this.href = this.href.replace(/\/edit$/, "") }) } $("body").removeClass("loading") }, layoutEditor: function(e, name){ app.mode.builder = true app.launch() if (app.unsupported) return // this.builderView = app.controller = 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() if (app.unsupported) return layout = slugify(layout) window.history.pushState(null, document.title, "/project/new/" + layout) // this.editorView = app.controller = 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() if (app.unsupported) return this.editorView = app.controller = new EditorView() this.editorView.load(name) }, projectViewer: function(e, name){ app.mode.editor = true app.launch() if (app.unsupported) return this.readerView = app.controller = new ReaderView() this.readerView.load(name) }, 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() }, home: function(){ this.homeView = new HomeView () this.homeView.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 + "?", function(){ this.documentModal.destroy(name, function(){ AlertModal.alert("Document deleted!", function(){ window.location.href = "/about" }.bind(this)) }.bind(this)) }.bind(this)) // this.documentModal.destroy(name) }, })