commit acbf1bc5bb607513d8b4a75a24c28a0f10446518
parent bd46aa0e96e435780324fded80f6242e1a6d724f
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Wed, 9 Oct 2024 20:29:43 -0700
Allow accessing demo mode in editor
When the floorplan id 'flp_demo' is used, demo mode is used.
Diffstat:
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js
@@ -33,26 +33,36 @@ let State = {
const escapeEvent = new Event("escape")
function init() {
- etc.authorize()
- etc.bar()
-
// Just to get stuff out of the way for now
let debug = (new URLSearchParams(new URL(document.URL).search)).get("debug") != undefined
- let floorplan = (new URLSearchParams(new URL(document.URL).search)).get("id")
- if (!floorplan) {
+ let floorplan_id = (new URLSearchParams(new URL(document.URL).search)).get("id")
+ if (!floorplan_id) {
document.location.href = "/floorplans"
+ return
}
+ let floorplan
+ if (floorplan_id !== "flp_demo") {
+ etc.authorize()
+ floorplan = { user: localStorage.getItem("username"), name: floorplan }
+ }
+
+ etc.bar()
+
let h1 = document.querySelector("h1")
let suffix = h1.appendChild(document.createTextNode(""))
- api.fetch("GET", `floorplans/:user/${floorplan}`)
- .then(function(metadata) {
- h1.textContent = metadata.name
- })
- .catch(function(err) {
- document.location.href = "/floorplans"
- })
+ if (!floorplan) {
+ h1.textContent = "Demo"
+ } else {
+ api.fetch("GET", `floorplans/:user/${floorplan}`)
+ .then(function(metadata) {
+ h1.textContent = metadata.name
+ })
+ .catch(function(err) {
+ document.location.href = "/floorplans"
+ })
+ }
let draw = SVG()
.addTo("#editor")
@@ -64,8 +74,7 @@ function init() {
zoomFactor: .5
})
- let editor = new lib.FloorplanEditor(draw,
- { user: localStorage.getItem("username"), name: floorplan },
+ let editor = new lib.FloorplanEditor(draw, floorplan,
{ backend: {
callbacks: {
pull: function() {