summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/SiteRouter.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/ui/SiteRouter.js')
-rw-r--r--public/assets/javascripts/ui/SiteRouter.js133
1 files changed, 133 insertions, 0 deletions
diff --git a/public/assets/javascripts/ui/SiteRouter.js b/public/assets/javascripts/ui/SiteRouter.js
new file mode 100644
index 0000000..c02b19c
--- /dev/null
+++ b/public/assets/javascripts/ui/SiteRouter.js
@@ -0,0 +1,133 @@
+
+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',
+ },
+
+ routes: {
+ "/login": 'signin',
+ "/signup": 'signup',
+ "/project/new": 'newProject',
+ "/profile": 'profile',
+ "/profile/edit": 'editProfile',
+ "/about/:name/edit": 'editDocument',
+ "/about/new": 'newDocument',
+ "/editor": 'launchEditor',
+ "/builder": 'launchBuilder',
+ },
+
+ initialize: function(){
+ this.signUpModal = new SignUpModal()
+ this.signInModal = new SignInModal()
+ this.newProjectModal = new NewProjectModal()
+ 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()
+ },
+
+ 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.newProjectModal.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)
+ },
+
+})
+