var SiteRouter = Router.extend({ el: "body", events: { "click [data-role='show-signup-modal']": 'signup', "click [data-role='show-signin-modal']": 'signin', "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='delete-document-modal']": 'destroyDocument', "click [data-role='show-layouts-modal']": 'showLayoutsModal', }, routes: { "/login": 'signin', "/signup": 'signup', "/project/new": 'newProject', "/profile": 'profile', "/profile/edit": 'editProfile', "/about/:name/edit": 'editDocument', "/about/new": 'newDocument', "/editor": 'launchEditor', "/builder": 'showLayoutsModal', "/builder/new": 'launchBuilder', "/builder/:name": 'launchBuilder', }, initialize: function(){ this.signUpModal = new SignUpModal() this.signInModal = new SignInModal() this.layoutsModal = new LayoutsModal() this.editProjectModal = new EditProjectModal() this.editProfileModal = new EditProfileModal() this.documentModal = new DocumentModal() this.confirmModal = new ConfirmModal() this.alertModal = new AlertModal() this.route() $("body").removeClass("loading") }, launchBuilder: function(){ app.mode.builder = true app.launch() this.builderView = new BuilderView() this.builderView.load() }, showLayoutsModal: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/builder") this.layoutsModal.load("builder") }, launchEditor: function(){ app.mode.editor = true app.launch() this.editorView = new EditorView() this.editorView.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() }, newProject: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/project/new") this.layoutsModal.load() }, editProject: function(e){ e && e.preventDefault() window.history.pushState(null, document.title, "/project/edit") this.editProjectModal.load() }, profile: function(e){ var classes = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen']; $(".bio").addClass(choice(classes)); }, 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 this.confirmModal.confirm("Are you sure you want to delete " + name + "?", $.proxy(function(){ this.documentModal.destroy(name, $.proxy(function(){ this.alertModal.alert("Document deleted!", $.proxy(function(){ window.location.href = "/about" }, this)) }, this)) }, this)) // this.documentModal.destroy(name) }, })