Skip to content
375 changes: 15 additions & 360 deletions citesphere/src/main/webapp/WEB-INF/views/auth/authorities/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,368 +2,23 @@

<head>
<script th:src="@{/resources/paginator/jquery.twbsPagination.min.js}"></script>
<script th:src="@{/resources/authorities/authority-search.js}"></script>
<script th:inline="javascript">
$(function() {

$("#uriLoadingSpinnerAuthor").hide();
$("#uriLoadingFailureAuthor").hide();
$("#uriLoadingFoundAuthor").hide();
$("#searchAuthorSpinner").hide();
$("#tr-uriAuthor").hide();
$("#tr-importerId").hide();
$("#tr-importerName").hide();
$("#importerId").hide();
$("#importerName").hide();

$("#firstNameAuthor").keyup(function(e) {
allowAuthoritySearch("Author");
});

$("#lastNameAuthor").keyup(function(e) {
allowAuthoritySearch("Author");
});

$("#addAuthorModalCancel").click(function() {
$("#authorModal").modal('hide');
resetPersonCreationModal("Author");
});

$("#clear").click(function() {
$("#tr-uriAuthor").hide();
$("#tr-importerId").hide();
$("#tr-importerName").hide();
});

$("#searchAuthor").click(function() {
$("#selectAuthorityModel").on('hidden.bs.modal', function(e) {
$('#selectAuthorityModel a:first').tab('show');
})
$("#searchAuthorSpinner").show();
$('#conceptpowerAuthority-pagination-top').twbsPagination('destroy');
$('#viafAuthority-pagination-top').twbsPagination('destroy');
$('#isisCBAuthority-pagination-top').twbsPagination('destroy');
getViafAuthorities('Author', 'Author', 0)
getConceptpowerAuthorities('Author', 'Author', 0)
getIsisCBAuthorities('Author', 'Author', 0)
$("#searchAuthorSpinner").hide();
});

$("#authorIconContainer").on('click', ".popover #authorCreateAuthority", function() {
name = $(this).closest("div").find(".name").text();
uri = $(this).closest("div").find(".uri").text();
importerId = $(this).closest("div").find(".importerId").text();
importerName = $(this).closes("div").find(".importerName").text();

showPerson(name, null, uri, importerId, importerName);
$("#authorCreateAuthority").hide();
$("#uriLoadingFoundAuthor").popover('hide');
$("#selectAuthorityModel").modal('hide');
$("#authorModal").modal('hide');
resetPersonCreationModal("Author");
});

var timer = null;
$("#uriAuthor").change(function() {
resetPersonAuthorityCreation("Author");
$("#uriLoadingSpinnerAuthor").show();
var uri = $("#uriAuthor").val();
clearTimeout(timer);
timer = setTimeout(function() {
getPersonAuthority(uri, "Author");
}, 1000);
});

$("#closeAuthoritySearchResult").click(function() {
$("#selectAuthorityModel").modal('hide');
$('#selectAuthorityModel a:first').tab('show');
});

});

function allowAuthoritySearch(element) {
if ($("#firstName" + element).val() == "" && $("#lastName" + element).val() == "") {
$("#search" + element).prop("disabled", true);
} else {
$("#search" + element).prop("disabled", false);
}
}

/* Function to populate name in modal fetched from uri */
function showPerson(name, description, uri, importerId, importerName) {
$("#name").val(name);

if (description != undefined && description != ' - ') {
$("#description").val(description);
}

if (uri != undefined && uri != '') {
$("#uri").val(uri);
$("#tr-uriAuthor").show();
}

if (importerId != undefined) {
$("#importerId").val(importerId);
}

if(importerName != undefined){
$("#importerName").val(importerName);
$("#importerName").show();
$("#tr-importerName").show();
}
}

function getConceptpowerAuthorities(modalType, personType, page) {
var firstName = $("#firstName" + personType).val();
var lastName = $("#lastName" + personType).val();
personType_lowerCase = personType.toLowerCase();
url = [[@{|/auth/authority/find/authorities/conceptpower|}]] + '?firstName=' + firstName + '&lastName=' + lastName + '&page=' + page;
$.ajax({
dataType: "json",
type: 'GET',
url: url,
async: false,
success: function(data) {
$("#conceptpowerAuthoritySearchResult").empty();
var content = '';
var importerId = 'authority.importer.conceptpower';
var importerName = /*[[${@environment.getProperty('_importer_name_authority.importer.conceptpower')}]]*/ '';
if (data['foundAuthorities'] != null && data['foundAuthorities'].length > 0) {
data['foundAuthorities'].forEach(function(elem) {
content += '<tr> <td class="name">' + elem['name'] + '</td> <td class="uri">' + elem['uri'] + '</td> <td class="description">';
if (elem['description'] == null) {
content += ' - </td>';
} else {
content += elem['description'] + '</td>';
}
content += '<td style="display: none;" class="importerName">' + importerName + '</td>';
content += '<td style="display: none;" class="importerId">' + importerId + '</td>';
content += '<td style="vertical-align: middle;"><span class="conceptpower-authority-entry btn btn-primary" title="Create new managed authority" style="padding: 5px;"><i class="icon-checkmark-alt" style="color: white;"></i></span></td></tr>';

});

$('#conceptpowerAuthority-pagination-top').twbsPagination({
totalPages: data['totalPages'],
startPage: data['currentPage'],
prev: "«",
next: "»",
visiblePages: 5,
initiateStartPageClick: false,
onPageClick: function(event, page) {
getConceptpowerAuthorities(modalType, personType, page)
}
});

}

$("#conceptpowerAuthoritySearchResult").append(content);
$(".conceptpower-authority-entry").click(function() {
name = $(this).closest("tr").find(".name").text();
uri = $(this).closest("tr").find(".uri").text();

description = $(this).closest("tr").find(".description").text();
importerId = $(this).closest("tr").find(".importerId").text();
importerName = $(this).closest("tr").find(".importerName").text()

showPerson(name, description, uri, importerId, importerName);
$("#selectAuthorityModel").modal('hide');
$("#authorModal").modal('hide');
resetPersonCreationModal("Author");
});
},
error: function(data) {
$('#conceptpowerAuthoritySearchResult').parents('table').hide()
$("#conceptpowerAuthoritiesError").show();
}

});
}

function getViafAuthorities(modalType, personType, page) {
var firstName = $("#firstName"+personType).val();
var lastName = $("#lastName"+personType).val();
personType_lowerCase = personType.toLowerCase();
url = [[@{|/auth/authority/find/authorities/viaf|}]] + '?firstName='+ firstName + '&lastName=' + lastName +'&page='+page;

$.ajax({
dataType: "json",
type: 'GET',
url: url ,
async: false,
success: function(data) {
$("#viafAuthoritySearchResult").empty();
var content = '';
var importerId = 'authority.importer.viaf';
var importerName = /*[[${@environment.getProperty('_importer_name_authority.importer.viaf')}]]*/ '';
if (data['foundAuthorities'] != null && data['foundAuthorities'].length > 0) {
data['foundAuthorities'].forEach(function(elem) {
content += '<tr> <td class="name">' + elem['name'] + '</td> <td class="uri">' + elem['uri'] + '</td> <td>';
if (elem['description'] == null) {
content += ' - </td>';
} else {
content += elem['description'] + '</td>';
}
content += '<td style="display: none;" class="importerName">' + importerName + '</td>';
content += '<td style="display: none;" class="importerId">' + importerId + '</td>';
content += '<td style="vertical-align: middle;"><span class="viaf-authority-entry btn btn-primary" title="Create new managed authority" style="padding: 5px;"><i class="icon-checkmark-alt" style="color: white;"></i></span></td></tr>';

});

$('#viafAuthority-pagination-top').twbsPagination({
totalPages: data['totalPages'],
startPage: data['currentPage'],
prev: "«",
next: "»",
visiblePages: 5,
initiateStartPageClick: false,
onPageClick: function(event, page) {
getViafAuthorities(modalType, personType, page-1)
}
});

}

$("#viafAuthoritySearchResult").append(content);
$(".viaf-authority-entry").click(function() {
name = $(this).closest("tr").find(".name").text();
uri = $(this).closest("tr").find(".uri").text();

description = $(this).closest("tr").find(".description").text();
importerId = $(this).closest("tr").find(".importerId").text();
importerName = $(this).closest("tr").find(".importerName").text();

showPerson(name, description, uri, importerId, importerName);
$("#selectAuthorityModel").modal('hide');
$("#authorModal").modal('hide');
resetPersonCreationModal("Author");
});

},
error: function(data) {
$('#viafAuthoritySearchResult').parents('table').hide()
$("#viafAuthoritiesError").show();
}

});
}

function getIsisCBAuthorities(modalType, personType, page) {
var firstName = $("#firstName" + personType).val();
var lastName = $("#lastName" + personType).val();
personType_lowerCase = personType.toLowerCase();
var limit = 20;
url = [[@{|/auth/authority/find/authorities/isiscb|}]] + '?firstName=' + firstName + '&lastName=' + lastName + '&page=' +page;
$.ajax({
dataType: "json",
type: 'GET',
url: url,
async: false,
success: function(data) {
$("#isisCBAuthoritySearchResult").empty();
var content = '';

if (data['foundAuthorities'] != null && data['foundAuthorities'].length > 0) {
data['foundAuthorities'].forEach(function(elem) {
content += '<tr> <td class="name">' + elem['name'] + '</td> <td class="uri">' + elem['uri'] + '</td> <td class="description">';
if (elem['description'] == null) {
content += ' - </td>';
} else {
content += elem['description'] + '</td>';
}
content += '<td style="vertical-align: middle;"><span class="isisCB-authority-entry btn btn-primary" title="Create new managed authority" style="padding: 5px;"><i class="icon-checkmark-alt" style="color: white;"></i></span></td></tr>';

});

$('#isisCBAuthority-pagination-top').twbsPagination({
totalPages: data['totalPages'],
startPage: data['currentPage'],
prev: "«",
next: "»",
visiblePages: 5,
initiateStartPageClick: false,
onPageClick: function(event, page) {
getIsisCBAuthorities(modalType, personType, page-1)
}
});

}

$("#isisCBAuthoritySearchResult").append(content) ;
$(".isisCB-authority-entry").click(function() {
name = $(this).closest("tr").find(".name").text();
uri = $(this).closest("tr").find(".uri").text();

description = $(this).closest("tr").find(".description").text();

showPerson(name, description, uri, undefined);
$("#selectAuthorityModel").modal('hide');
$("#authorModal").modal('hide');
resetPersonCreationModal("Author");
});
},
error: function(data) {
$('#isisCBAuthoritySearchResult').parents('table').hide()
$("#isisCBAuthoritiesError").show();
}

});
}

function resetPersonCreationModal(modalType) {
var modalNameLCase = modalType.toLowerCase();
$("#firstName" + modalType).val("");
$("#lastName" + modalType).val("");
$("#id" + modalType).attr("data-" + modalType + "-id", "");
$("#uri" + modalType).val("");
resetPersonAuthorityCreation(modalType);
}

function resetPersonAuthorityCreation(personType) {
$("#uriLoadingFound" + personType).hide();
$("#uriLoadingFailure" + personType).hide();
$("#uriLoadingSpinner" + personType).hide();
$("#uriLoadingFound" + personType).popover('hide');
$("#uriLoadingFailure" + personType).popover('hide');
}

function getPersonAuthority(uri, personType) {

personType_lowerCase = personType.toLowerCase();
$.get([[@{/auth/authority/get?uri=}]] + uri, function(data) {
$("#uriLoadingFound" + personType).attr("data-authority-uri", data['uri']);
var content = "Authority <b>" + uri + "</b>";
if (data['userAuthorityEntries'] != null && data['userAuthorityEntries'].length > 0) {
content += "<br><br>This authority entry has already been imported by you:";
content += '<ul class="foundAuthorities">';
data['userAuthorityEntries'].forEach(function(elem) {
content += '<li>' + elem['name'];
content += '</li>';
});
content += "</ul>";
} else if (data['importedAuthority'] != null) {
content += "<br><br>Following authority can be imported:<br>" + data['importedAuthority']['name'] +
'<button id="' + personType_lowerCase + 'CreateAuthority" type="submit" class="btn btn-link pull-right"><b>Import this authority</b><div style="display: none;">'
+'<p class="name">'+ data['importedAuthority']['name'] + '</p><p class="uri">'+ data['importedAuthority']['uri'] + '</p><p class="importerId">';
if (data['importedAuthority']['importerId'] != null) {
content += data['importedAuthority']['importerId'];
}
content += '</p></div></button>';
} else {
content += "<br><br>No authorities found for the given URI<br>";
}

$("#uriLoadingFound" + personType).attr("data-content", content);
$("#uriLoadingFound" + personType).attr("data-authority-uri", uri);
$("#uriLoadingFound" + personType).show();
$("#uriLoadingFound" + personType).popover('show');
})
.fail(function() {
$("#uriLoadingFailure" + personType).show();
})
.always(function() {
$("#uriLoadingSpinner" + personType).hide();
// Configure authority search endpoints and importer names from Thymeleaf
CitesphereAuthority.Config.setEndpoint('conceptpower', /*[[@{/auth/authority/find/authorities/conceptpower}]]*/ '');
CitesphereAuthority.Config.setEndpoint('viaf', /*[[@{/auth/authority/find/authorities/viaf}]]*/ '');
CitesphereAuthority.Config.setEndpoint('isiscb', /*[[@{/auth/authority/find/authorities/isiscb}]]*/ '');
CitesphereAuthority.Config.setEndpoint('getAuthority', /*[[@{/auth/authority/get}]]*/ '');
CitesphereAuthority.Config.setImporterName('conceptpower', /*[[${@environment.getProperty('_importer_name_authority.importer.conceptpower')}]]*/ '');
CitesphereAuthority.Config.setImporterName('viaf', /*[[${@environment.getProperty('_importer_name_authority.importer.viaf')}]]*/ '');

$(function() {
// Initialize the CreateHandler
var createHandler = new CitesphereAuthority.CreateHandler({
sources: ['conceptpower', 'viaf', 'isiscb']
});

}
createHandler.init();
});
</script>
</head>

Expand Down
Loading