about summary refs log tree commit diff
path: root/uploader/templates/phenotypes/view-dataset.html
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/templates/phenotypes/view-dataset.html')
-rw-r--r--uploader/templates/phenotypes/view-dataset.html45
1 files changed, 44 insertions, 1 deletions
diff --git a/uploader/templates/phenotypes/view-dataset.html b/uploader/templates/phenotypes/view-dataset.html
index 10fd428..fa1044b 100644
--- a/uploader/templates/phenotypes/view-dataset.html
+++ b/uploader/templates/phenotypes/view-dataset.html
@@ -89,7 +89,12 @@
 {%block javascript%}
 <script type="text/javascript">
   $(function() {
+      var species_id = {{species.SpeciesId}};
+      var population_id = {{population.Id}};
+      var dataset_id = {{dataset.Id}};
+      var dataset_name = "{{dataset.Name}}";
       var data = {{phenotypes | tojson}};
+
       var dtPhenotypesList = buildDataTable(
           "#tbl-phenotypes-list",
           data,
@@ -143,7 +148,45 @@
                           {
                               text: "Bulk Edit (Download Data)",
                               action: (event, dt, node, config) => {
-                                  alert("Not implemented yet!");
+                                  var phenoids = [];
+                                  var selected = dt.rows({selected: true, page: "all"}).data();
+                                  for(var idx = 0; idx < selected.length; idx++) {
+                                      phenoids.push({
+                                          phenotype_id: selected[idx].Id,
+                                          xref_id: selected[idx].xref_id
+                                      });
+                                  }
+                                  if(phenoids.length == 0) {
+                                      alert("No record selected. Nothing to do!");
+                                      return false;
+                                  }
+                                  $.ajax(
+                                      (`/species/${species_id}/populations/` +
+                                       `${population_id}/phenotypes/datasets/` +
+                                       `${dataset_id}/download`),
+                                      {
+                                          method: "POST",
+                                          data: JSON.stringify(phenoids),
+                                          xhrFields: {
+                                              responseType: "blob"
+                                          },
+                                          success: (data, textStatus, jqXHR) => {
+                                              var link = document.createElement("a");
+                                              uri = window.URL.createObjectURL(data);
+                                              link.href = uri;
+                                              link.download = `${dataset_name}_data.tsv`;
+
+                                              document.body.appendChild(link);
+                                              link.click();
+                                              window.URL.revokeObjectURL(uri);
+                                              link.remove();
+                                          },
+                                          error: (jQXHR, textStatus, errorThrown) => {
+                                              console.log("Experienced an error: ", textStatus);
+                                              console.log("The ERROR: ", errorThrown);
+                                          },
+                                          contentType: "application/json"
+                                      });
                               },
                               className: "btn btn-info",
                               titleAttr: "Click to download data for editing."