361 lines
9.8 KiB
PHP
Raw Normal View History

2023-01-24 19:02:00 +01:00
<h2>Browse bibliography</h2>
<p>To filter bibliography based on certain criteria, please set one or more options below as needed. To display filtered results based on selected criteria, press the "Filter results" buttons.</p>
<form id="browsing">
<div class="container w1000">
<div class="browseFields full">
<div class="line nomargin"><label>Bibliographic type: </label>
<select id="pubType" name="pubType"><option>Please wait, loading data...</option></select>
</div>
</div>
<div class="browseFields left">
<div class="line">
<label>Affilitation 1:</label>
<select id="affiliation1" name="affiliation1"><option>Please wait, loading data...</option></select>
</div>
<div class="line">
<label>&nbsp;</label>
<input type="checkbox" id="affil1auth1" name="affil1auth1" value="1"><label for="affil1auth1">Limit affiliation 1 to 1<sup>st</sup> author</label>
</div>
</div>
<div class="browseFields right">
<div class="line">
<label>Affilitation 2:</label>
<select id="affiliation2" name="affiliation2"><option>Please wait, loading data...</option></select>
</div>
<div class="line">
<label>&nbsp;</label>
<input type="checkbox" id="affil2auth2" name="affil2auth2" value="1"><label for="affil2auth2">Limit affiliation 2 to 2<sup>nd</sup> author</label>
</div>
</div>
<div class="browseFields left">
<div class="line">
<label>Author:</label>
<input type="text" id="author" name="author">
</div>
</div>
<div class="browseFields right">
<div class="line">
<label>Journal:</label>
<input type="text" id="journal" name="journal">
</div>
</div>
<div class="browseFields left">
<div class="line">
<label>ESS round used:</label>
<select id="round" name="round"><option>Please wait, loading data...</option></select>
</div>
</div>
<div class="browseFields right">
<div class="line">
<label>Journal field:</label>
<select id="journalField" name="jField"><option>Please wait, loading data...</option></select>
</div>
</div>
<div class="browseFields left">
<div class="line">
<label>Title (or part of it):</label>
<input type="text" id="title_words" name="title_words">
</div>
</div>
<?php $de = 1; include ('topic-item-module.php'); ?>
<div class="browseFields full">
<input type="button" value="SHOW RESULTS" onClick="getResults();">
</div>
</div>
</form>
<div id="toth2">
<h2>Number of records in the database: <span id="numHitsTOT">loading...</span></h2>
<p>Please use the form above to browse them. If you want to display all (published) records, just hit the "SHOW RESULTS" button.</p>
</div>
<div id="results" style="display: none;">
<h2>Results (n=<span id="numHits">loading...</span>)</h2>
<form id="spreadsheet" action="parts/spreadsheet.php" method="post" target="_blank">
<input type="hidden" name="formdata" id="formdata">
<input type="submit" value="Download this bibliography in a spreadheet format">
</form>
<ul id="resultsList">
Please wait, loading data...
</ul>
</div>
<script type="text/javascript">
var numResults = 0;
var toLoad = 0;
$(document).ready(function () {
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'total_records_published'
}
})
.done (function (msg) {
if (msg == '') {
console.log('No response received from API!');
}
else {
// if everything is OK
if (msg['status'] == "200") {
$('#numHitsTOT').html(msg['data']);
}
else {
console.log(msg);
}
}
listCountries();
})
.fail (function() {
console.log('No response received from API!');
});
});
function listCountries() {
// retrieve data via web
// A: countries
// ADD TEXT THAT SOMETHING IS HAPPENING
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'list_countries'
}
})
.done (function (msg) {
if (msg == '') {
console.log('No response received from API!');
}
else {
$('#affiliation1').html('<option value="0">Any</option>');
$('#affiliation2').html('<option value="0">Any</option>');
// if everything is OK
if (msg['status'] == "200") {
msg['data'].forEach(function (item) {
$('#affiliation1').html( $('#affiliation1').html() + '<option value="' + item['id'] + '">' + item['name'] + '</option>');
$('#affiliation2').html( $('#affiliation2').html() + '<option value="' + item['id'] + '">' + item['name'] + '</option>');
});
console.log(msg);
toLoad++;
getTopicData();
getRoundData();
getPubTypes();
}
else {
console.log(msg);
}
}
})
.fail (function() {
console.log('No response received from API!');
});
}
function getPubTypes () {
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'list_pubType'
}
})
.done (function (msg) {
if (msg == '') {
console.log('No response received from API!');
}
else {
$('#pubType').html('<option value="0">Any</option>');
// if everything is OK
if (msg['status'] == "200") {
msg['data'].forEach(function (item) {
$('#pubType').html( $('#pubType').html() + '<option value="' + item['id'] + '">' + item['name'] + '</option>');
});
console.log(msg);
toLoad++;
getRoundData();
}
else {
console.log(msg);
}
}
})
.fail (function() {
console.log('No response received from API!');
});
}
function getRoundData() {
// next is ess round
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'list_rounds'
}
})
.done (function (msg) {
if (msg == '') {
console.log('No response received from API!');
}
else {
console.log(msg);
$('#round').html('<option value="0">Any</option>');
// if everything is OK
if (msg['status'] == "200") {
msg['data'].forEach(function (item) {
$('#round').html( $('#round').html() + '<option value="' + item['id'] + '">' + item['name'] + '</option>');
});
console.log(msg);
toLoad++;
getjFieldData();
}
else {
console.log(msg);
}
}
})
.fail (function() {
console.log('No response received from API!');
});
}
function getjFieldData() {
// next is ess round
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'list_journalField'
}
})
.done (function (msg) {
if (msg == '') {
console.log('No response received from API!');
}
else {
console.log(msg);
$('#journalField').html('<option value="0">Any</option>');
// if everything is OK
if (msg['status'] == "200") {
msg['data'].forEach(function (item) {
$('#journalField').html( $('#journalField').html() + '<option value="' + item['id'] + '">' + item['name'] + '</option>');
});
console.log(msg);
toLoad++;
// getResults(); NOT AUTO!
}
else {
console.log(msg);
}
}
})
.fail (function() {
console.log('No response received from API!');
});
}
function getResults() {
if (toLoad < 6) return;
var all_citations = '';
var data = $('#browsing').serializeArray();
$('#formdata').val(JSON.stringify(data));
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'browse',
d: data
}
})
.done (function (msg) {
$('#toth2').hide();
$('#results').show();
if (msg == '') {
console.log('No response received from API!');
}
else {
// if everything is OK
if (msg['status'] == "200") {
console.log('Looks OK...');
results = msg['data'];
$('#numHits').html(msg['data'].length);
if (msg['data'].length == 0) {
$('#resultsList').html('No results found.');
}
else {
msg['data'].forEach(function (item) {
if (item['citation']!='') {
all_citations += '<li>' + item['citation'] + '</li>';
}
});
$('#resultsList').html(all_citations);
}
}
else {
console.log(msg);
}
}
})
.fail (function(jqXHR, textStatus, errorThrown) {
console.log('Failure ' + jqXHR.stringify + textStatus + errorThrown);
});
}
</script>