From b0ab3271996d542e718e8e3fc910053d60cf81f6 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 23 Jun 2014 15:27:02 -0400 Subject: standalone viewer --- public/assets/javascripts/ui/SiteRouter.js | 169 -------------------- public/assets/javascripts/ui/_router.js | 175 +++++++++++++++++++++ .../assets/javascripts/ui/editor/EditorToolbar.js | 38 ++++- public/assets/javascripts/ui/reader/ReaderView.js | 28 ++++ 4 files changed, 235 insertions(+), 175 deletions(-) delete mode 100644 public/assets/javascripts/ui/SiteRouter.js create mode 100644 public/assets/javascripts/ui/_router.js create mode 100644 public/assets/javascripts/ui/reader/ReaderView.js (limited to 'public/assets/javascripts/ui') diff --git a/public/assets/javascripts/ui/SiteRouter.js b/public/assets/javascripts/ui/SiteRouter.js deleted file mode 100644 index 3a6b589..0000000 --- a/public/assets/javascripts/ui/SiteRouter.js +++ /dev/null @@ -1,169 +0,0 @@ - -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() - - 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) - }, - -}) - 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) + }, + +}) + diff --git a/public/assets/javascripts/ui/editor/EditorToolbar.js b/public/assets/javascripts/ui/editor/EditorToolbar.js index c3589db..210ef6c 100644 --- a/public/assets/javascripts/ui/editor/EditorToolbar.js +++ b/public/assets/javascripts/ui/editor/EditorToolbar.js @@ -29,21 +29,46 @@ var EditorToolbar = View.extend({ openMediaViewer: function(){ this.parent.mediaViewer.show() this.parent.mediaUpload.show() + this.resetMode() }, - resizeMedia: function(e){ - var state = editor.permissions.toggle("resize") + resetMode: function(){ + this.resizeMedia(false) + this.destroyMedia(false) + }, + + resetControls: function(){ + this.parent.wallpaperPicker.hide() + this.parent.lightControl.hide() + }, + + resizeMedia: function(e, state){ + if (! state && typeof e == "boolean") { + state = e + editor.permissions.assign("resize", state) + } + else { + state = editor.permissions.toggle("resize") + } + ! state && editor.permissions.assign("move", true) $(".inuse").removeClass("inuse") - $(e.currentTarget).toggleClass("inuse", state) + $("[data-role='resize-media']").toggleClass("inuse", state) if (state) { Scenery.resize.hide() } }, - destroyMedia: function(e){ - var state = editor.permissions.toggle("destroy") + destroyMedia: function(e, state){ + if (! state && typeof e == "boolean") { + state = e + editor.permissions.assign("destroy", state) + } + else { + state = editor.permissions.toggle("destroy") + } + ! state && editor.permissions.assign("move", true) $(".inuse").removeClass("inuse") - $(e.currentTarget).toggleClass("inuse", state) + $("[data-role='destroy-media']").toggleClass("inuse", state) $("body").toggleClass("destroyActive", state) }, @@ -62,6 +87,7 @@ var EditorToolbar = View.extend({ var editor = new function(){ this.permissions = new Permissions({ + 'move': true, 'resize': false, 'destroy': false, }) diff --git a/public/assets/javascripts/ui/reader/ReaderView.js b/public/assets/javascripts/ui/reader/ReaderView.js new file mode 100644 index 0000000..001d097 --- /dev/null +++ b/public/assets/javascripts/ui/reader/ReaderView.js @@ -0,0 +1,28 @@ + +var ReaderView = View.extend({ + el: "#readerView", + + projectAction: "/api/projects/", + + events: { + }, + + initialize: function(){ + }, + + load: function(name){ + name = sanitize(name) + $.get(this.projectAction + name, $.proxy(this.ready, this)) + }, + + ready: function(data){ + $("#map").hide() + + data.rooms && Rooms.deserialize(data.rooms) + data.media && Scenery.deserialize(data.media) + data.startPosition && scene.camera.move(data.startPosition) + + editor.permissions.clear() + } + +}) -- cgit v1.2.3-70-g09d2