From 7a3a54ec40fac9071a513487602957f8418f163e Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 8 Jul 2022 07:32:58 +0300 Subject: Select the platform (GeneChipId) first --- qc_app/static/js/select_platform.js | 59 +++++++++++++++++++++++++++++++++++++ qc_app/static/js/utils.js | 10 +++++++ 2 files changed, 69 insertions(+) create mode 100644 qc_app/static/js/select_platform.js create mode 100644 qc_app/static/js/utils.js (limited to 'qc_app/static') 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); +} -- cgit v1.2.3