From caa299bfb081630fa2a35e175b5b35af2bb7d06d Mon Sep 17 00:00:00 2001 From: lukas Date: Thu, 23 Jan 2025 14:28:27 +0100 Subject: [PATCH] add default option --- sample_prep_protocol.html | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/sample_prep_protocol.html b/sample_prep_protocol.html index 55d521f..6ecc946 100644 --- a/sample_prep_protocol.html +++ b/sample_prep_protocol.html @@ -74,6 +74,17 @@ +
+
+ +
+
+ + +
+
@@ -98,6 +109,9 @@ function add(event){ + event.preventDefault(); + + let prep_protocol = { "name" : document.getElementById("name").value, "Sample_Size" : document.getElementById("Sample_Size").value, @@ -108,16 +122,30 @@ let transaction = db.transaction(["prep_protocol"], "readwrite"); let objectStore = transaction.objectStore("prep_protocol"); let add_request = objectStore.add(prep_protocol); // (3) - - transaction.oncomplete = (event) => { + let id_of_setup = 0; + add_request.onsuccess = (event) => { console.log("All done!"); + id_of_setup = event.target.result; + if (document.getElementById("Default").checked){ + let my_default = {"id" : 1, "prep_setup" : id_of_setup}; + let next_transaction = db.transaction(["defaults"], "readwrite"); + let next_objectStore = next_transaction.objectStore("defaults"); + let add_next_request = next_objectStore.put(my_default); + transaction.oncomplete = () => { + console.log("All done!"); + }; + transaction.onerror = () => { + console.log("something went wrong"); + // Don't forget to handle errors! + }; + } }; transaction.onerror = (event) => { console.log("something went wrong"); // Don't forget to handle errors! }; - event.preventDefault(); - } + + };