From 41c1c2a3835dd3d2bcf2552f05f8fce1f28d0025 Mon Sep 17 00:00:00 2001 From: Jim Allman Date: Wed, 12 Oct 2016 12:42:47 -0400 Subject: [PATCH 1/2] Coerce all new-taxon source DOIs to URL form. This replaces the prior fixes in peyotl. Addresses https://github.com/OpenTreeOfLife/peyotl/issues/155. --- curator/static/js/study-editor.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/curator/static/js/study-editor.js b/curator/static/js/study-editor.js index a5ef7baea..68eb87279 100644 --- a/curator/static/js/study-editor.js +++ b/curator/static/js/study-editor.js @@ -7773,6 +7773,9 @@ function formatDataDepositDOIAsURL() { */ function DOItoURL( doi ) { /* Return the DOI provided (if any) in URL form */ + if (!doi) { // null, undefined, or empty string + return ""; + } if (urlPattern.test(doi) === true) { // It's already in the form of a URL, return unchanged return doi; @@ -9596,12 +9599,30 @@ function disableRankDivider(option, item) { function updateActiveTaxonSources() { // trigger validation, updates to next/previous buttons + coerceTaxonSourceDOIsToURLs(); currentTaxonCandidate.valueHasMutated(); updateTaxonSourceDetails(); updateTaxonSourceTypeOptions(); taxonCondidateIsValid(currentTaxonCandidate()); } +function coerceTaxonSourceDOIsToURLs() { + var activeSources = getActiveTaxonSources(currentTaxonCandidate()); + $.each(activeSources(), function(i, source) { + switch( source.type ) { + case undefined: + case '': + case 'The taxon is described in this study': + case 'Other': + break; + default: + // its value should be a valid URL (convert simple DOIs) + source.value = DOItoURL( source.value ); + break; + } + }); +} + function updateTaxonSourceDetails( ) { var activeSources = getActiveTaxonSources(currentTaxonCandidate()); $.each(activeSources(), function(i, source) { From 7e564cf309ebc930e01855a28dc637a5c2c852c8 Mon Sep 17 00:00:00 2001 From: Jim Allman Date: Wed, 12 Oct 2016 13:03:23 -0400 Subject: [PATCH 2/2] Update observable array after DOI coercion! --- curator/static/js/study-editor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/curator/static/js/study-editor.js b/curator/static/js/study-editor.js index 68eb87279..68726da00 100644 --- a/curator/static/js/study-editor.js +++ b/curator/static/js/study-editor.js @@ -9618,6 +9618,7 @@ function coerceTaxonSourceDOIsToURLs() { default: // its value should be a valid URL (convert simple DOIs) source.value = DOItoURL( source.value ); + activeSources.replace(source, source); break; } });