diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-06-09 16:14:49 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-06-09 16:14:49 -0400 |
| commit | 1165ef5440e643252635aeea73a14cba0bb2e461 (patch) | |
| tree | 6563f5314c774ee3ac9216e8375b38037b2eddcb /public/assets/javascripts/ui/Router.js | |
| parent | b1974b9c2fe6ee1f35b3e34895f134d906299cec (diff) | |
documentation system
Diffstat (limited to 'public/assets/javascripts/ui/Router.js')
| -rw-r--r-- | public/assets/javascripts/ui/Router.js | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/public/assets/javascripts/ui/Router.js b/public/assets/javascripts/ui/Router.js index a518e27..fea3698 100644 --- a/public/assets/javascripts/ui/Router.js +++ b/public/assets/javascripts/ui/Router.js @@ -8,14 +8,18 @@ var Router = View.extend({ "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', }, routes: { - "/login": 'signin', - "/signup": 'signup', - "/project/new": 'newProject', - "/profile/edit": 'editProfile', - "/app": 'launch', + "/login": 'signin', + "/signup": 'signup', + "/project/new": 'newProject', + "/profile/edit": 'editProfile', + "/about/:name/edit": 'editDocument', + "/about/new": 'newDocument', + "/app": 'launch', }, initialize: function(){ @@ -24,13 +28,29 @@ var Router = View.extend({ this.newProjectModal = new NewProjectModal() this.editProjectModal = new EditProjectModal() this.editProfileModal = new EditProfileModal() + this.documentModal = new DocumentModal() this.originalPath = window.location.pathname + var path = window.location.pathname.split("/") + console.log(path) for (var route in this.routes) { - if (window.location.pathname.indexOf(route) === 0) { - this[this.routes[route]]() - break; + var routePath = route.split("/") + if (routePath[1] == path[1]) { + if (routePath[2] && routePath[2].indexOf(":") !== -1 && path[2] && (path[3] === routePath[3]) ) { + console.log("GOT :") + console.log(routePath) + this[this.routes[route]](null, path[2]) + break; + } + else if (routePath[2] == path[2]) { + this[this.routes[route]](null) + break; + } + else if (! routePath[2] && (! path[2].length || ! path[2])) { + this[this.routes[route]](null) + break; + } } } @@ -73,5 +93,22 @@ var Router = View.extend({ 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) + }, + }) |
