summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/_router.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-06-23 15:27:02 -0400
committerJules Laplace <jules@okfoc.us>2014-06-23 15:27:02 -0400
commitb0ab3271996d542e718e8e3fc910053d60cf81f6 (patch)
treefb147d83a108c4945b6bb42850e62aa78ead5226 /public/assets/javascripts/ui/_router.js
parentb9dacb35ff90c6f666121742cf03f30ea4d2129d (diff)
standalone viewer
Diffstat (limited to 'public/assets/javascripts/ui/_router.js')
-rw-r--r--public/assets/javascripts/ui/_router.js175
1 files changed, 175 insertions, 0 deletions
diff --git a/public/assets/javascripts/ui/_router.js b/public/assets/javascripts/ui/_router.js
new file mode 100644
index 0000000..6d41d5b
--- /dev/null
+++ b/public/assets/javascripts/ui/_router.js
@@ -0,0 +1,175 @@
+
+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='destroy-document-modal']": 'destroyDocument',
+ "click [data-role='show-layouts-modal']": 'layoutPicker',
+ "click [data-role='show-projects-modal']": 'projectPicker',
+ },
+
+ routes: {
+ "/login": 'signin',
+ "/signup": 'signup',
+ "/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": 'projectEditor',
+ },
+
+ 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.documentModal = new DocumentModal()
+
+ 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)
+ },
+
+ projectEditor: function(e, name){
+ app.mode.editor = true
+ app.launch()
+
+ if ($(".aboutRoom").length) {
+ this.readerView = new ReaderView()
+ this.readerView.load(name)
+ }
+ else {
+ this.editorView = new EditorView()
+ this.editorView.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()
+ },
+
+ 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
+
+ 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)
+ },
+
+})
+