about summary refs log tree commit diff
path: root/qc_app/static
diff options
context:
space:
mode:
Diffstat (limited to 'qc_app/static')
-rw-r--r--qc_app/static/js/select_platform.js59
-rw-r--r--qc_app/static/js/utils.js10
2 files changed, 69 insertions, 0 deletions
diff --git a/qc_app/static/js/select_platform.js b/qc_app/static/js/select_platform.js
new file mode 100644
index 0000000..d7541fa
--- /dev/null
+++ b/qc_app/static/js/select_platform.js
@@ -0,0 +1,59 @@
+function radio_column(chip) {
+    col = document.createElement("td");
+    radio = document.createElement("input");
+    radio.setAttribute("type", "radio");
+    radio.setAttribute("name", "genechipid");
+    radio.setAttribute("value", chip["GeneChipId"]);
+    radio.setAttribute("required", "required");
+    col.appendChild(radio);
+    return col;
+}
+
+function setup_genechips(genechip_data) {
+    columns = ["GeneChipName", "Name", "GeoPlatform", "GO_tree_value"]
+    submit_button = document.querySelector(
+	"#select-platform-form input[type='submit']");
+    elt = document.getElementById(
+	"genechips-table").getElementsByTagName("tbody")[0];
+    remove_children(elt);
+    if((genechip_data === undefined) || genechip_data.length === 0) {
+	row = document.createElement("tr");
+	col = document.createElement("td");
+	col.setAttribute("colspan", "5");
+	text = document.createTextNode("No chips found for selected species");
+	col.appendChild(text);
+	row.appendChild(col);
+	elt.appendChild(row);
+	submit_button.setAttribute("disabled", true);
+	return false;
+    }
+
+    submit_button.removeAttribute("disabled")
+    genechip_data.forEach(chip => {
+	row = document.createElement("tr");
+	row.appendChild(radio_column(chip));
+	columns.forEach(column => {
+	    col = document.createElement("td");
+	    content = document.createTextNode(chip[column]);
+	    col.appendChild(content);
+	    row.appendChild(col);
+	});
+	elt.appendChild(row);
+    });
+}
+
+function genechips() {
+    return JSON.parse(
+	document.getElementById("select-platform-form").getAttribute(
+	    "data-genechips"));
+}
+
+function update_genechips(event) {
+    genec = genechips();
+
+    species_elt = document.getElementById("species");
+
+    if(event.target == species_elt) {
+	setup_genechips(genec[species_elt.value.toLowerCase()]);
+    }
+}
diff --git a/qc_app/static/js/utils.js b/qc_app/static/js/utils.js
new file mode 100644
index 0000000..045dd47
--- /dev/null
+++ b/qc_app/static/js/utils.js
@@ -0,0 +1,10 @@
+function remove_children(element) {
+    Array.from(element.children).forEach(child => {
+	element.removeChild(child);
+    });
+}
+
+function trigger_change_event(element) {
+    evt = new Event("change");
+    element.dispatchEvent(evt);
+}