459 lines
16 KiB
PHP
Raw Permalink Normal View History

2023-01-24 19:02:00 +01:00
<h2>Insert bibliographic record</h2>
<p></p>
<form id="insert" action="/do_insert" method="post">
<div class="container w1000">
<div class="browseFields full">
<div class="line">
<label>Enter DOI:</label>
<input type="text" name="doi" id="doi"><input type="button" onClick="checkDOI();" value="&#8635;">
</div>
</div>
</div>
<div class="container w1000" id="data" style="display: none;">
<h2>Publication details</h2>
<p>Please review all values returned from DOI and fix all missing / wrong data.</p>
<div class="browseFields full">
<div class="line">
<label>Publication title:</label>
<input type="text" id="title" name="title" style="width: 750px;">
</div>
</div>
<div class="browseFields full">
<div class="line">
<label>Publication language:</label>
<select id="language" name="language"><option>Please wait, loading data...</option></select>
</div>
<div class="line" id="lang_add" style="display: none;">
<label>Add a new language:</label>
<input type="text" id="newLang" name="newLang" style="width: 750px;">
</div>
</div>
<div class="browseFields left" id="cnt_addauth">
<div class="line">
<input type="button" value="Add another author" onClick="addAuthorFields(_cnt_authors); _cnt_authors++;">
</div>
</div>
<div class="browseFields right">
<div class="line">
<input type="button" value="Remove last author" onClick="_cnt_authors--; $('#auth' + _cnt_authors).remove();">
</div>
</div>
<div class="browseFields full">
<div class="line">
<label>Abstract:</label>
<textarea id="abstract_orig" name="abstract_orig" style="width: 750px; height: 250px"></textarea>
</div>
</div>
<div class="browseFields full">
<p>English abstract is applicable for non-English publications.</p>
</div>
<div class="browseFields full">
<div class="line">
<label title="Applicable for non-English texts">English abstract:</label>
<textarea id="abstract_eng" name="abstract_eng" style="width: 750px; height: 250px;"></textarea>
</div>
</div>
<div class="browseFields left nomargin">
<div class="line">
<label>Bibliographic type:</label>
<select id="pubType" name="pubType"><option>Please wait, loading data...</option></select>
</div>
</div>
<div class="browseFields right nomargin" id="cntyear">
<div class="line">
<label>Year:</label>
<select id="year" name="year">
<option value="0">Please select year</option>
<?php for ($year = 1500; $year<=date('Y'); $year++) {echo '<option value="' .$year .'">' .$year .'</option>';}?>
</select>
</div>
</div>
<?php $de = 0; include ('topic-item-module.php');?>
<div class="line"><label>ESS rounds used:</label>
<div class="columns2 w800 ml200 mb50" id="cnt_ess_round">
Loading data, please wait...
</div>
<div class="line"><label></label>
<div class="w800 ml200 mb50">
<input type="button" value="Add article" id="submit">
</div>
</div>
</form>
<script type="text/javascript">
var countries = '<option value="0">Please select country</option>';
var languages = '';
var _cnt_authors = 1;
function checkDOI() {
_cnt_authors = 1;
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'doi',
doi: $('#doi').val()
}
})
.done (function (msg) {
if (msg == '') {
console.log('No response received from API!');
}
else {
// if everything is OK
if (msg['status'] == "200") {
console.log(msg);
$('#title').val(msg['data']['title']);
$('#year').val(msg['data']['year']);
// journal article
if (msg['data']['journal']) {
$('#pubType option').each(function(){
if($(this).text() == 'Journal Article'){
$(this).prop('selected', true).trigger('change');
}
});
addJournalFields();
if (msg['data']['journal']) $('#journalName').val(msg['data']['journal']);
if (msg['data']['publisher']) $('#publisher').val(msg['data']['publisher']);
if (msg['data']['volume']) $('#volume').val(msg['data']['volume']);
if (msg['data']['number']) $('#issue').val(msg['data']['number']);
if (msg['data']['pages'])
{
var pages = msg['data']['pages'];
pages = pages.split('--');
if (pages[0]) $('#fromPage').val(pages[0]);
if (pages[1]) $('#toPage').val(pages[1]);
}
}
else if (msg['data']['booktitle']) {
$('#pubType option').each(function(){
if($(this).text() == 'Book chapter'){
$(this).prop('selected', true).trigger('change');
}
});
}
var authors = msg['data']['author'];
authors = authors.split('and');
removeAuthorFields();
authors.forEach(function (author) {
author = author.trim();
addAuthorFields(_cnt_authors);
$('#auth' + _cnt_authors + 'affil').html(countries);
$('#auth' + _cnt_authors + 'citation').val(author);
author = author.split(' ');
$('#auth' + _cnt_authors + 'name1').val(author[0]);
if (author.length == 2) {
$('#auth' + _cnt_authors + 'lastname').val(author[1]);
}
else if (author.length == 3) {
$('#auth' + _cnt_authors + 'name2').val(author[1]);
$('#auth' + _cnt_authors + 'lastname').val(author[2]);
}
else if (author.length == 4) {
$('#auth' + _cnt_authors + 'name2').val(author[1]);
$('#auth' + _cnt_authors + 'lastname').val(author[2]);
$('#auth' + _cnt_authors + 'lastname2').val(author[3]);
}
_citation = ''
_citation = author.pop() + ', ';
for (pos = 0; pos<author.length; pos++) {
_citation += author[pos].charAt(0) +'. ';
}
$('#auth' + _cnt_authors + 'citation').val(_citation.trim());
_cnt_authors++;
});
$('#data').show();
}
else {
console.log(msg);
}
}
})
.fail (function() {
console.log('No response received from API!');
});
}
$(document).ready(function () {
$.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('');
// if everything is OK
if (msg['status'] == "200") {
msg['data'].forEach(function (item) {
$('#pubType').html( $('#pubType').html() + '<option value="' + item['id'] + '">' + item['name'] + '</option>');
});
fetchLanguages();
fetchCountries();
getTopicData();
}
else {
console.log(msg);
}
}
})
.fail (function() {
console.log('No response received from API!');
});
$('#language').change(function () {
if ($('#language').val() == '-1') {
$('#lang_add').show();
}
else {
$('#lang_add').hide();
}
});
$('#submit').click(function () {
myData = JSON.stringify($('#insert').serializeArray());
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'do_insert',
content: myData
}
})
.done (function (msg) {
if (msg == '') {
console.log('No response received from API!');
}
else if (msg['status'] == '406') {
alert ('Unfortunaly, your record cannod be added. Reason: ' + msg['data']);
}
else if (msg['status'] == '200') {
alert ('Thank you, your bibliographic entry has been accepted into the review process.');
window.location.replace('/');
}
else {
console.log(msg);
}
})
.fail (function() {
alert ('Unknown error has occured');
});
})
});
function fetchCountries () {
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'list_countries'
}
})
.done (function (msg) {
if (msg == '') {
console.log('No response received from API!');
}
else {
// if everything is OK
if (msg['status'] == "200") {
msg['data'].forEach(function (item) {
countries += '<option value="' + item['id'] + '">' + item['name'] + '</option>';
});
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);
$('#cnt_ess_round').html('');
// if everything is OK
if (msg['status'] == "200") {
msg['data'].forEach(function (item) {
$('#cnt_ess_round').html( $('#cnt_ess_round').html() +
'<input type="checkbox" name="round" value="' + item['id'] + '" id="_ess_round_' + item['id'] +'"><label for="_ess_round_' + item['id'] + '">' + item['name'] + '</label><br>');
});
console.log(msg);
toLoad++;
getItemsData();
}
else {
console.log(msg);
}
}
})
.fail (function() {
console.log('No response received from API!');
});
}
function fetchLanguages () {
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'list_languages'
}
})
.done (function (msg) {
if (msg == '') {
console.log('No response received from API!');
}
else {
// if everything is OK
if (msg['status'] == "200") {
msg['data'].forEach(function (item) {
languages += '<option value="' + item['id'] + '" ' + ((item['id'] == '2') ? 'selected="selected"' : '') + '>' + item['name'] + '</option>';
});
$('#language').html('<option value="-1">Add a new language</option>' + languages);
}
else {
console.log('Napaka: ' + msg);
}
}
})
.fail (function() {
console.log('No response received from API!');
});
}
function removeAuthorFields() {
$('.author_field').remove();
}
function addAuthorFields (offset) {
$('#cnt_addauth').before ('<div class="author_field" id="auth' + offset + '"><div class="browseFields left nomargin">'
+ '<div class="line"><label>Author ' + offset + ' first name:</label>'
+ '<input type="text" id="auth' + offset + 'name1" name="auth' + offset + 'name1"></div>'
+ '</div>'
+ ' <div class="browseFields right nomargin">'
+ '<div class="line"><label>Auth. ' + offset + ' middle name:</label>'
+ '<input type="text" id="auth' + offset + 'name2" name="auth' + offset + 'name2"></div>'
+ '</div>'
+ '<div class="browseFields left nomargin">'
+ '<div class="line"><label>Auth. ' + offset + ' last name:</label>'
+ '<input type="text" id="auth' + offset + 'lastname" name="auth' + offset + 'lastname"></div>'
+ '</div>'
+ '<div class="browseFields right nomargin">'
+ '<div class="line"><label>Auth. ' + offset + ' last name 2:</label>'
+ '<input type="text" id="auth' + offset + 'lastname2" name="auth' + offset + 'lastname2"></div>'
+ '</div>'
+ '<div class="browseFields left">'
+ '<div class="line"><label>Auth. ' + offset + ' citation:</label>'
+ '<input type="text" id="auth' + offset + 'citation" name="auth' + offset + 'citation"></div>'
+ '</div>'
+ '<div class="browseFields right">'
+ '<div class="line"><label>Auth. ' + offset + ' affil.:</label>'
+ '<select id="auth' + offset + 'affil" name="auth' + offset + 'affil"><option>Please wait...</option></select></div>'
+ '</div></div>');
}
function addJournalFields() {
$('#cntyear').after ('<div class="browseFields left nomargin">'
+ '<div class="line"><label>Journal name:</label>'
+ '<input type="text" id="journalName" name="journalName"></div>'
+ '</div>'
+ ' <div class="browseFields right nomargin">'
+ '<div class="line"><label>Publisher:</label>'
+ '<input type="text" id="publisher" name="publisher"></div>'
+ '</div>'
+ '<div class="browseFields left nomargin">'
+ '<div class="line"><label>Volume:</label>'
+ '<input type="text" id="volume" name="volume"></div>'
+ '</div>'
+ ' <div class="browseFields right nomargin">'
+ '<div class="line"><label>Issue:</label>'
+ '<input type="text" id="issue" name="issue"></div>'
+ '</div>'
+ '<div class="browseFields left nomargin">'
+ '<div class="line"><label>From page:</label>'
+ '<input type="text" id="fromPage" name="fromPage"></div>'
+ '</div>'
+ ' <div class="browseFields right nomargin">'
+ '<div class="line"><label>To page:</label>'
+ '<input type="text" id="toPage" name="toPage"></div>'
+ '</div>');
}
</script>