aboutsummaryrefslogtreecommitdiff
path: root/uploader
diff options
context:
space:
mode:
Diffstat (limited to 'uploader')
-rw-r--r--uploader/templates/phenotypes/add-phenotypes-base.html117
1 files changed, 67 insertions, 50 deletions
diff --git a/uploader/templates/phenotypes/add-phenotypes-base.html b/uploader/templates/phenotypes/add-phenotypes-base.html
index 7ad1e09..c0dd35d 100644
--- a/uploader/templates/phenotypes/add-phenotypes-base.html
+++ b/uploader/templates/phenotypes/add-phenotypes-base.html
@@ -58,6 +58,9 @@
<button id="btn-search-pubmed-id" class="btn btn-info">Search</button>
</span>
</div>
+ <span id="search-pubmed-id-error"
+ class="form-text text-muted text-danger hidden">
+ </span><br />
<span class="form-text text-muted">
Enter your publication's PubMed ID above and click "Search" to search
for some (or all) of the publication details requested below.
@@ -226,7 +229,6 @@
};
var update_publication_details = (details) => {
- console.log("Updating with the following details:", details);
Object.entries(details).forEach((entry) => {;
switch(entry[0]) {
case "authors":
@@ -245,41 +247,7 @@
});
};
- var freds_variable = undefined;
- $("#btn-search-pubmed-id").on("click", (event) => {
- event.preventDefault();
- var search_button = event.target;
- var pubmed_id = $("#txt-pubmed-id").val().trim();
- remove_class($("#txt-pubmed-id").parent(), "has-error");
- if(pubmed_id == "") {
- add_class($("#txt-pubmed-id").parent(), "has-error");
- return false;
- }
-
- var flag_pub_details = false;
- var flag_pub_abstract = false;
- var enable_button = () => {
- search_button.disabled = !(flag_pub_details && flag_pub_abstract);
- };
- search_button.disabled = true;
- // Fetch publication details
- $.ajax("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi",
- {
- "method": "GET",
- "data": {"db": "pubmed", "id": pubmed_id, "format": "json"},
- "success": (data, textStatus, jqXHR) => {
- // process and update publication details
- update_publication_details(extract_details(
- pubmed_id, data.result));
- },
- "error": (jqXHR, textStatus, errorThrown) => {},
- "complete": () => {
- flag_pub_details = true;
- enable_button();
- },
- "dataType": "json"
- });
- // Fetch the abstract
+ var fetch_publication_abstract = (pubmed_id, pub_details) => {
$.ajax("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi",
{
"method": "GET",
@@ -290,25 +258,74 @@
"retmode": "xml"
},
"success": (data, textStatus, jqXHR) => {
- // process and update the abstract...
- freds_variable = data;
- console.log("ABSTRACT DETAILS:", data);
update_publication_details({
- "abstract": Array.from(data
- .getElementsByTagName(
- "Abstract")[0]
- .children)
- .map((elt) => {return elt.textContent.trim();})
- .join("\r\n")
- });
+ ...pub_details,
+ ...{
+ "abstract": Array.from(data
+ .getElementsByTagName(
+ "Abstract")[0]
+ .children)
+ .map((elt) => {return elt.textContent.trim();})
+ .join("\r\n")
+ }});
},
"error": (jqXHR, textStatus, errorThrown) => {},
- "complete": (jqXHR, textStatus) => {
- flag_pub_abstract = true;
- enable_button();
- },
+ "complete": (jqXHR, textStatus) => {},
"dataType": "xml"
});
+ };
+
+ var fetch_publication_details = (pubmed_id, complete_thunks) => {
+ error_display = $("#search-pubmed-id-error");
+ error_display.text("");
+ add_class(error_display, "hidden");
+ $.ajax("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi",
+ {
+ "method": "GET",
+ "data": {"db": "pubmed", "id": pubmed_id, "format": "json"},
+ "success": (data, textStatus, jqXHR) => {
+ // process and update publication details
+ hasError = (
+ Object.hasOwn(data, "error") ||
+ Object.hasOwn(data.result[pubmed_id], "error"));
+ if(hasError) {
+ error_display.text(
+ "There was an error fetching a publication with " +
+ "the given PubMed ID! The error received " +
+ "was: '" + (
+ data.error ||
+ data.result[pubmed_id].error) +
+ "'. Please check ID you provided and try " +
+ "again.");
+ remove_class(error_display, "hidden");
+ } else {
+ fetch_publication_abstract(
+ pubmed_id,
+ extract_details(pubmed_id, data.result));
+ }
+ },
+ "error": (jqXHR, textStatus, errorThrown) => {},
+ "complete": () => {
+ complete_thunks.forEach((thunk) => {thunk()});
+ },
+ "dataType": "json"
+ });
+ };
+
+ $("#btn-search-pubmed-id").on("click", (event) => {
+ event.preventDefault();
+ var search_button = event.target;
+ var pubmed_id = $("#txt-pubmed-id").val().trim();
+ remove_class($("#txt-pubmed-id").parent(), "has-error");
+ if(pubmed_id == "") {
+ add_class($("#txt-pubmed-id").parent(), "has-error");
+ return false;
+ }
+
+ search_button.disabled = true;
+ // Fetch publication details
+ fetch_publication_details(pubmed_id,
+ [() => {search_button.disabled = false;}]);
return false;
});
</script>