summaryrefslogtreecommitdiff
path: root/static/new_form.html
diff options
context:
space:
mode:
Diffstat (limited to 'static/new_form.html')
-rw-r--r--static/new_form.html74
1 files changed, 74 insertions, 0 deletions
diff --git a/static/new_form.html b/static/new_form.html
new file mode 100644
index 0000000..7022d5a
--- /dev/null
+++ b/static/new_form.html
@@ -0,0 +1,74 @@
+<html>
+ <head>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ </head>
+ <body>
+ <nav></nav>
+ <div class="main">
+
+ <div>
+ <label for="type">Type:</label>
+ <select name="type" onchange="update_select()">
+ <option value="multiple_select">multiple_select</option>
+ <option value="number">number</option>
+ <option value="range">range</option>
+ <option value="textarea">textarea</option>
+ <option value="text">text</option>
+ </select>
+ </div>
+
+ <div>
+ <label for="prompt">prompt</label>
+ <input name="prompt" type="text"></input>
+ </div>
+ <div>
+ <label for="prompt_id">prompt_id</label>
+ <input name="prompt_id" type="text"></input>
+ </div>
+
+ <div class="range">
+ <div>
+ <label for="min">min</label>
+ <input name="min" type="text"></input>
+ </div>
+ <div>
+ <label for="max">max</label>
+ <input name="max" type="text"></input>
+ </div>
+ </div>
+
+ <div><button onclick="on_submit()">Submit</button></div>
+ <script>
+ async function enqueue_data(path, payload, do_alert=false, timestamp=true){
+ if(timestamp){
+ payload["timestamp"] = Date.now()
+ }
+ await fetch(path, {method: "POST", body: JSON.stringify(payload)})
+ if(do_alert){
+ alert("saved!")
+ }
+ }
+ function update_select(){
+ let v = document.querySelectorAll("select")[0].value
+ document.querySelectorAll(".range").forEach(el => {
+ el.style.display = v == "range" ? "block" : "none"
+ })
+ }
+ function on_submit(){
+ let payload = {
+ "type": document.querySelectorAll("select")[0].value,
+ }
+ document.querySelectorAll("input").forEach(el => {
+ if(el.value.length > 0){
+ payload[el.name] = el.value
+ }
+ })
+ enqueue_data("/submit_new_form", payload, do_alert=true, timestamp=false)
+ }
+ window.onload = function(){
+ update_select()
+ }
+ </script>
+ </div>
+ </body>
+</html>