NIHVIVO-646 Filter existing authors out of autocomplete query results in add authors to publication form

This commit is contained in:
rjy7 2010-06-22 20:49:30 +00:00
parent 1b75f01825
commit bd39967cc9
3 changed files with 51 additions and 47 deletions

View file

@ -238,7 +238,7 @@ SPARQL queries for existing values. --%>
EditConfiguration.putConfigInSession(editConfig,session);
}
//editConfig.addValidator(new PublicationHasAuthorValidator());
editConfig.addValidator(new PublicationHasAuthorValidator());
Model model = (Model) application.getAttribute("jenaOntModel");
String objectUri = (String) request.getAttribute("objectUri");
@ -288,11 +288,14 @@ SPARQL queries for existing values. --%>
if ( author != null ) {
request.setAttribute("author", author);
%>
<%-- RY Should use author short view here instead? --%>
<c:url var="authorHref" value="/individual">
<c:param name="uri" value="${author.URI}"/>
</c:url>
<li><a href="${authorHref}" class="authorName">${author.name}</a><a href="" class="remove">Remove</a></li>
<li>
<span class="existingAuthorUri">${author.URI}</span>
<a href="${authorHref}" class="existingAuthor">${author.name}</a>
<a href="" class="remove">Remove</a>
</li>
<%
}
@ -340,28 +343,3 @@ SPARQL queries for existing values. --%>
<jsp:include page="${postForm}"/>
<%!
// We'll just rely on rdfs:label for now. In future, the label will be created by the app from
// last name, first name, and middle name fields, so we don't have to worry about inconsistent
// ordering.
/*
public String getAuthorName(Individual author) {
String name;
String lastName = author.getDataValue("http://xmlns.com/foaf/0.1/lastName");
String firstName = author.getDataValue("http://xmlns.com/foaf/0.1/firstName");
if (lastName != null && firstName != null) {
name = lastName + ", " + firstName;
String middleName = author.getDataValue("http://vivoweb.org/ontology/core#middleName");
if (middleName != null) {
name += " " + middleName;
}
}
else {
name = author.getName();
}
return name;
}
*/
%>

View file

@ -9,11 +9,16 @@
margin-bottom: .75em;
}
#authors a.authorName {
#authors a.existingAuthor {
display: inline-block;
width: 15em;
}
/* These are only here for JavaScript to pick up. Don't display!! */
#authors span.existingAuthorUri {
display: none;
}
/* Hide elements not used in non-JS version of form */
#showAddForm,
a.remove,

View file

@ -134,25 +134,38 @@ var addAuthorForm = {
var cache = {};
var url = $('#acUrl').val();
var existingAuthorUris = addAuthorForm.getExistingAuthorUris();
console.log(existingAuthorUris);
jQuery.each(existingAuthorUris, function(index, element) {
url += '&filter=' + element;
});
$('#lastName').autocomplete({
minLength: 2,
source: function(request, response) {
if (request.term in cache) {
response(cache[request.term]);
return;
}
$.ajax({
url: url,
dataType: 'json',
data: request,
success: function(data) {
cache[request.term] = data;
response(data);
}
});
},
source: url,
// RY For now, not using cache because there are complex interactions between filtering and caching.
// We want to filter out existingAuthors from autocomplete results, and this seems easiest to do
// server-side. But if an author gets removed, we need to put them back in the results. If results
// are cached, the cache needs to be cleared on a remove. Not sure if we have access to it there.
// Lots of complexity involved, so for now let's try without the cache.
// source: function(request, response) {
// if (request.term in cache) {
// //console.log("found term in cache");
// response(cache[request.term]);
// return;
// }
//
// $.ajax({
// url: url,
// dataType: 'json',
// data: request,
// success: function(data) {
// cache[request.term] = data;
// //console.log("not getting term from cache");
// response(data);
// }
//
// });
// },
select: function(event, ui) {
addAuthorForm.showSelectedAuthor(ui);
}
@ -160,6 +173,14 @@ var addAuthorForm = {
},
getExistingAuthorUris: function() {
var authorUris = $('span.existingAuthorUri');
return authorUris.map(function() {
return $(this).html();
});
},
prepareFieldValuesForSubmit: function() {
var firstName,
middleName,