www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit ce6e37d92bafde9abbc3f1f97141152e55a8df86
parent e072a3967b78cf8f909a957a3d8aed59eeb9979e
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Thu,  8 Aug 2024 17:17:44 -0700

Move floorplan's make_input function to etc

Diffstat:
Mfiles/floorplans/main.js | 24++----------------------
Mfiles/lib/etc.js | 28++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/files/floorplans/main.js b/files/floorplans/main.js @@ -139,11 +139,11 @@ function editable_floorplan_func(element, data) { let c = floorplan_info_class(editables[i]) let e = parent.querySelector("." + c) // .getElementsByClassName() if (e) { - input = make_input(editables[i], { value: e.textContent }) + input = etc.create_input(editables[i], { value: e.textContent }) input.setAttribute("class", c) e.replaceWith(input) } else { - input = make_input(editables[i]) + input = etc.create_input(editables[i]) input.setAttribute("class", c) if (prev) { prev.after(input) @@ -167,26 +167,6 @@ function floorplan_info_name(classname) { return classname.substring(3) } -function make_input(name, options) { - if (!name) { - throw new Error("No name provided") - } - if (!options) { - options = {} - } - - let input = document.createElement("input") - input.name = name - input.placeholder = name - if (options["type"]) { - input.type = options["type"] - } - if (options["value"]) { - input.value = options["value"] - } - return input -} - function delete_floorplan_func(item, floorplan) { return function() { api.fetch("DELETE", "floorplans/" + etc.url_literal(floorplan.user) + "/" + etc.url_literal(floorplan.name)) diff --git a/files/lib/etc.js b/files/lib/etc.js @@ -83,3 +83,31 @@ export function handle_wrap(func, on) { export function url_literal(text) { return encodeURIComponent(text) } + +export function require_id(id) { + let e = document.getElementById(id) + if (!e) { + throw new Error("'#" + id + "' is required to exist, but doesn't") + } + return e +} + +export function create_input(name, options) { + if (!name) { + throw new Error("No name provided") + } + if (!options) { + options = {} + } + + let input = document.createElement("input") + input.name = name + input.placeholder = name + if (options["type"]) { + input.type = options["type"] + } + if (options["value"]) { + input.value = options["value"] + } + return input +}