Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Belgian Biodiversity Platform
astapor
Commits
c7c8680f
Commit
c7c8680f
authored
Jun 16, 2017
by
Nicolas Noé
Browse files
Scientific names: USe of GBIF API when editing.
parent
216d45ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
website/specimens/templates/admin/specimens/specimen/change_form.html
0 → 100644
View file @
c7c8680f
{% extends "admin/change_form.html" %}
{% load static %}
{% block admin_change_form_document_ready %}
{{ block.super }}
<script
type=
"text/javascript"
>
var
$
=
django
.
jQuery
;
$
(
function
()
{
var
conf
=
{
'
container_selector
'
:
$
(
'
.field-scientific_name div:first-child
'
),
'
sn_value_selector
'
:
$
(
"
#id_scientific_name
"
),
'
icon_success
'
:
'
{% static "admin/img/icon-yes.svg" %}
'
,
'
icon_warning
'
:
'
{% static "admin/img/icon-alert.svg" %}
'
,
'
icon_error
'
:
'
{% static "admin/img/icon-no.svg" %}
'
};
var
exactMatchAction
=
function
(
r
){
var
res
=
'
<img src="
'
+
conf
.
icon_success
+
'
" />
'
;
res
+=
'
Ok, exact species name found at GBIF
'
;
res
+=
'
with a confidence score of <strong>
'
+
r
.
confidence
+
'
</strong>
'
;
return
res
;
};
var
fuzzyMatchAction
=
function
(
r
){
var
res
=
'
<img src="
'
+
conf
.
icon_warning
+
'
" />
'
;
res
+=
'
Fuzzy match at GBIF
'
;
res
+=
'
(
'
+
'
<strong><i>
'
+
r
.
canonicalName
+
'
</i></strong>
'
+
'
confidence:
'
+
r
.
confidence
+
'
)
'
;
console
.
log
(
r
)
return
res
;
};
var
higherrankAction
=
function
(
r
){
var
res
=
'
<img src="
'
+
conf
.
icon_warning
+
'
" />
'
;
res
+=
'
Higher taxon found at GBIF
'
;
res
+=
'
(
'
+
r
.
rank
+
'
:
'
+
r
.
canonicalName
+
'
)
'
;
return
res
;
};
var
noneAction
=
function
(
r
){
var
res
=
'
<img src="
'
+
conf
.
icon_error
+
'
" />
'
;
res
+=
'
:( Species unknown at GBIF
'
;
return
res
;
};
var
GBIFSpeciesMatch
=
function
(){
$
(
'
#results
'
).
empty
();
var
params
=
{
rank
:
'
species
'
,
name
:
conf
.
sn_value_selector
.
val
()
};
$
.
getJSON
(
'
http://api.gbif.org/v1/species/match
'
,
params
,
function
(
r
)
{
var
res
;
switch
(
r
.
matchType
)
{
case
"
EXACT
"
:
res
=
exactMatchAction
(
r
);
break
;
case
"
FUZZY
"
:
res
=
fuzzyMatchAction
(
r
);
break
;
case
"
HIGHERRANK
"
:
res
=
higherrankAction
(
r
);
break
;
case
"
NONE
"
:
res
=
noneAction
(
r
);
break
;
}
$
(
'
#results
'
).
html
(
res
);
})
};
conf
.
container_selector
.
append
(
'
<div id="results"></div>
'
);
// Call on page load...
GBIFSpeciesMatch
();
// ... And when value change
conf
.
sn_value_selector
.
on
(
'
input
'
,
GBIFSpeciesMatch
);
});
</script>
{% endblock %}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment