diff --git a/assets/js/editor.js b/assets/js/editor.js index ee1de98..cdf287b 100644 --- a/assets/js/editor.js +++ b/assets/js/editor.js @@ -82,59 +82,69 @@ function startCreateElement(event) { document.getElementById("resetButton").style = "display: none;"; document.getElementById("buttons").style = "display: block;"; - document.getElementById("resourcetype").addEventListener("change", function () { - var selectedType = document.getElementById("resourcetype").value; - - if (selectedType == "MarkerElement") { - createMarkerElement(event, thetaStart); - } else if (selectedType == "ImageElement") { - createImageElement(event, thetaStart); - } else if (selectedType == "TeleportElement") { - createTeleportElement(event, thetaStart); - } - }); + document + .getElementById("resourcetype") + .addEventListener("change", function () { + var selectedType = document.getElementById("resourcetype").value; + createElementPropertiesForm(selectedType, event, thetaStart); + }); } -function createMarkerElement(event, thetaStart) { - var elementProperties = document.getElementById("elementProperties"); - elementProperties.innerHTML = ` -
- - -
-
- - -
- `; -} +function createElementPropertiesForm(elementType, event, thetaStart) { + const elementProperties = document.getElementById("elementProperties"); + let inputFields = ""; -function createImageElement(event, thetaStart) { - var elementProperties = document.getElementById("elementProperties"); - elementProperties.innerHTML = ` -
- - -
-
- - -
- `; -} + switch (elementType) { + case "MarkerElement": + case "ImageElement": + case "TeleportElement": + inputFields = ` +
+ + +
`; + if (elementType !== "MarkerElement") { + inputFields += ` +
+ + +
`; + } + if (elementType === "TeleportElement") { + inputFields += ` + -function createTeleportElement(event, thetaStart) { - var elementProperties = document.getElementById("elementProperties"); - elementProperties.innerHTML = ` -
- - -
-
-
- `; -} +
+ +
+
+ +
+
+ +
+
+ +
+
+
+ + `; + } + break; + default: + // Handle unknown element type + } + elementProperties.innerHTML = inputFields; +} function startModifyElement(event) { // Make the element draggable for positioning @@ -170,39 +180,16 @@ function startModifyElement(event) { "csrftoken" )}"> - - -
- -
-
- -
-
- -
-
- -
-
-
- - -
- - -
- +
`; + createElementPropertiesForm( + element_data.obj.resourcetype, + event, + element_data.obj.thetaStart + ); + var scene_data_request = getScene(scene.getAttribute("id")); scene_data_request.then((scene_data) => { var category_data_request = getCategory(scene_data.obj.category);