Skip to content

Commit

Permalink
Checklist Add taxon bugfix
Browse files Browse the repository at this point in the history
see #1602. This fix ties the add taxon feature to a taxonomy.tid (instead of the sciname value returned by the autocomplete.
  • Loading branch information
GregoryPost committed Aug 7, 2024
1 parent 3148dc6 commit c5ff7a7
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 162 deletions.
4 changes: 3 additions & 1 deletion checklists/checklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ function changeImageSource(elem){
f.submit();
}
</script>
<script type="text/javascript" src="../js/symb/checklists.checklist.js?ver=4"></script>
<?php include($SERVER_ROOT.'/js/symb/checklists.checklist.js');
// <script type="text/javascript" src="../js/symb/checklists.checklist.js?ver=4"></script>
?>
<style>
<?php
if($printMode){
Expand Down
1 change: 1 addition & 0 deletions classes/APITaxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function getTaxon($sciname){
while($r = $rs->fetch_object()){
$retArr[$r->tid]['sciname'] = $r->sciname;
$retArr[$r->tid]['author'] = $r->author;
$retArr[$r->tid]['tid'] = $r->tid;
}
$rs->free();
if(count($retArr) > 1){
Expand Down
2 changes: 2 additions & 0 deletions content/lang/checklists/checklist.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
$LANG['IMAGE_SRC'] = 'Image source';
$LANG['ALL_IMG'] = 'all images';
$LANG['LINKED_IMG'] = 'linked voucher images only';
$LANG['SELECT_TAXON'] = 'Please select a taxon from the list';
$LANG['NAME_BLANK'] = 'Scientific name field is blank';

//from dynamicchecklist.php
$LANG['ERROR_GEN_CHECK'] = 'ERROR generating checklist';
Expand Down
2 changes: 2 additions & 0 deletions content/lang/checklists/checklist.es.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
$LANG['IMAGE_SRC'] = 'Fuente de la imagen';
$LANG['ALL_IMG'] = 'todas las imágenes';
$LANG['LINKED_IMG'] = 'sólo imágenes de vales vinculadas';
$LANG['SELECT_TAXON'] = 'Por favor seleccione un taxón de la lista';
$LANG['NAME_BLANK'] = 'El campo de nombre científico está vacío';

//from dynamicchecklist.php
$LANG['ERROR_GEN_CHECK'] = 'ERROR al generar lista';
Expand Down
2 changes: 2 additions & 0 deletions content/lang/checklists/checklist.fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
$LANG['IMAGE_SRC'] = 'Source de l\'image';
$LANG['ALL_IMG'] = 'toutes les images';
$LANG['LINKED_IMG'] = 'images de bons liés uniquement';
$LANG['SELECT_TAXON'] = 'Veuillez sélectionner un taxon dans la liste';
$LANG['NAME_BLANK'] = 'Le champ du nom scientifique est vide';

//from dynamicchecklist.php
$LANG['ERROR_GEN_CHECK'] = 'ERREUR lors de la génération de la liste';
Expand Down
320 changes: 159 additions & 161 deletions js/symb/checklists.checklist.js
Original file line number Diff line number Diff line change
@@ -1,174 +1,172 @@
$(document).ready(function() {
//Filter autocomplete
$("#taxonfilter").autocomplete({
source: function( request, response ) {
$.getJSON( "rpc/searchsuggest.php", { term: request.term, clid: clid, deep: 1 }, response );
}
},
{ minLength: 3 });

//Species add form
$("#speciestoadd").autocomplete({
source: function( request, response ) {
$.getJSON( "rpc/speciessuggest.php", { term: request.term }, response );
}
},{
minLength: 4,
autoFocus: true
});

if(document.cookie.indexOf("editspp") > -1){
$(".editspp").show();
document.getElementById("editsppon").style.display = "inline";
}
if(taxaCount == 0) $(".editspp").show();
});

function toggleVoucherDiv(tid) {
toggle("voucdiv-" + tid);
toggle("morevouch-" + tid);
toggle("lessvouch-" + tid);
//anchorObj.style.display = "none";
return false;
}

function toggleSppEditControls() {
if (document.cookie.indexOf("editspp") > -1) {
document.cookie = "editspp=;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
document.getElementById("editsppon").style.display = "none";
$(".editspp").hide();
} else {
document.cookie = "editspp=1";
document.getElementById("editsppon").style.display = "inline";
$(".editspp").show();
}
}

function toggle(target) {
$("." + target).toggle();
$("#" + target).toggle();
}

function openIndividualPopup(occid) {
var indUrl = "../collections/individual/index.php?occid=" + occid;
openPopup(indUrl, "indwindow");
return false;
}

function openPopup(urlStr, windowName) {
newWindow = window.open(
urlStr,
windowName,
"scrollbars=1,toolbar=0,resizable=1,width=1000,height=800,left=400,top=40"
);
if (newWindow.opener == null) newWindow.opener = self;
return false;
}

function showImagesChecked(f) {
if (f.showimages.checked) {
document.getElementById("wordicondiv").style.display = "none";
f.showsynonyms.checked = false;
document.getElementById("showsynonymsdiv").style.display = "none";
f.showvouchers.checked = false;
document.getElementById("showvouchersdiv").style.display = "none";
f.showauthors.checked = false;
document.getElementById("showauthorsdiv").style.display = "none";
} else {
document.getElementById("wordicondiv").style.display = "block";
document.getElementById("showsynonymsdiv").style.display = "block";
document.getElementById("showvouchersdiv").style.display = "block";
document.getElementById("showauthorsdiv").style.display = "block";
}
}
<script type="text/javascript">
$(document).ready(function() {
//Filter autocomplete
$("#taxonfilter").autocomplete({
source: function( request, response ) {
$.getJSON( "rpc/searchsuggest.php", { term: request.term, clid: clid, deep: 1 }, response );
}
},
{ minLength: 3 });

function validateAddSpecies(f) {
var sciName = f.speciestoadd.value;
if (sciName == "") {
alert("Enter the scientific name of species you wish to add");
return false;
} else {
$.ajax({
type: "POST",
url: "../rpc/gettaxon.php",
dataType: "json",
data: { sciname: sciName },
}).done(function (taxaObj) {
//alert(JSON.stringify(taxaObj));
//alert(Object.keys(taxaObj).length)
var retCnt = Object.keys(taxaObj).length;
if (retCnt == 0) {
alert(
"ERROR: Scientific name does not exist in database. Did you spell it correctly? If so, contact your data administrator to add this species to the Taxonomic Thesaurus."
);
} else {
if (retCnt == 1) {
f.tid.value = Object.keys(taxaObj)[0];
f.submit();
} else {
f.tid.value = Object.keys(taxaObj)[0];
f.submit();
//alert(Object.keys(taxaObj)[0]);
//alert(Object.keys(taxaObj)[1]);
//Species add form
$("#speciestoadd").autocomplete({
source: function( request, response ) {
$.getJSON( "rpc/speciessuggest.php", { term: request.term }, response );
}
},{
minLength: 4,
autoFocus: true,
select: function( event, ui ) {
if(ui.item){
$( "#speciestoadd" ).val(ui.item.value);
$( "#tid" ).val(ui.item.id);
}
},
change: function( event, ui ) {
if(ui.item === null) {
$( "#tid" ).val("");
if($( "#speciestoadd" ).val() != ""){
alert('<?= $LANG['SELECT_TAXON'] ?>');
$("#speciestoadd").focus();
}
}
}
});

if(document.cookie.indexOf("editspp") > -1){
$(".editspp").show();
document.getElementById("editsppon").style.display = "inline";
}
if(taxaCount == 0) $(".editspp").show();
});

function toggleVoucherDiv(tid) {
toggle("voucdiv-" + tid);
toggle("morevouch-" + tid);
toggle("lessvouch-" + tid);
//anchorObj.style.display = "none";
return false;
}
}

function changeOptionFormAction(action, target) {
document.optionform.action = action;
document.optionform.target = target;
}

//Misc functions
Array.prototype.unique = function () {
var a = [];
var l = this.length;
for (var i = 0; i < l; i++) {
for (var j = i + 1; j < l; j++) {
if (this[i] === this[j]) j = ++i;

function toggleSppEditControls() {
if (document.cookie.indexOf("editspp") > -1) {
document.cookie = "editspp=;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
document.getElementById("editsppon").style.display = "none";
$(".editspp").hide();
} else {
document.cookie = "editspp=1";
document.getElementById("editsppon").style.display = "inline";
$(".editspp").show();
}
a.push(this[i]);
}
return a;
};

//Game menu
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
function toggle(target) {
$("." + target).toggle();
$("#" + target).toggle();
}

function openIndividualPopup(occid) {
var indUrl = "../collections/individual/index.php?occid=" + occid;
openPopup(indUrl, "indwindow");
return false;
}

function openPopup(urlStr, windowName) {
newWindow = window.open(
urlStr,
windowName,
"scrollbars=1,toolbar=0,resizable=1,width=1000,height=800,left=400,top=40"
);
if (newWindow.opener == null) newWindow.opener = self;
return false;
}

function showImagesChecked(f) {
if (f.showimages.checked) {
document.getElementById("wordicondiv").style.display = "none";
f.showsynonyms.checked = false;
document.getElementById("showsynonymsdiv").style.display = "none";
f.showvouchers.checked = false;
document.getElementById("showvouchersdiv").style.display = "none";
f.showauthors.checked = false;
document.getElementById("showauthorsdiv").style.display = "none";
} else {
document.getElementById("wordicondiv").style.display = "block";
document.getElementById("showsynonymsdiv").style.display = "block";
document.getElementById("showvouchersdiv").style.display = "block";
document.getElementById("showauthorsdiv").style.display = "block";
}
}

function validateAddSpecies(f) {
//var sciName = f.speciestoadd.value;
//var tid = f.tid.value;
if(f.speciestoadd.value !== "" && f.tid.value !== ""){
f.submit();
}
else if (f.speciestoadd.value == "") {
alert("<?= $LANG['NAME_BLANK'] ?>");
}
else {
alert('<?= $LANG['SELECT_TAXON'] ?>');
}
f.speciestoadd.focus();
return false;
}

function changeOptionFormAction(action, target) {
document.optionform.action = action;
document.optionform.target = target;
}

//Misc functions
Array.prototype.unique = function () {
var a = [];
var l = this.length;
for (var i = 0; i < l; i++) {
for (var j = i + 1; j < l; j++) {
if (this[i] === this[j]) j = ++i;
}
a.push(this[i]);
}
return a;
};

//Game menu
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

// open hidden layer
function mopen(id) {
// cancel close timer
mcancelclosetime();

// close old layer
if (ddmenuitem) ddmenuitem.style.visibility = "hidden";

// get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = "visible";
}
// close showed layer
function mclose() {
if (ddmenuitem) ddmenuitem.style.visibility = "hidden";
}

// go close timer
function mclosetime() {
closetimer = window.setTimeout(mclose, timeout);
}

// open hidden layer
function mopen(id) {
// cancel close timer
mcancelclosetime();

// close old layer
if (ddmenuitem) ddmenuitem.style.visibility = "hidden";

// get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = "visible";
}
// close showed layer
function mclose() {
if (ddmenuitem) ddmenuitem.style.visibility = "hidden";
}

// go close timer
function mclosetime() {
closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
if (closetimer) {
window.clearTimeout(closetimer);
closetimer = null;
function mcancelclosetime() {
if (closetimer) {
window.clearTimeout(closetimer);
closetimer = null;
}
}
}

// close layer when click-out
document.onclick = mclose;
// close layer when click-out
document.onclick = mclose;
</script>

0 comments on commit c5ff7a7

Please sign in to comment.